/[RomCheater]/trunk/RomCheater/Docking/FloatingMemorySearcher.cs
ViewVC logotype

Annotation of /trunk/RomCheater/Docking/FloatingMemorySearcher.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 547 - (hide annotations) (download)
Wed Jun 5 23:19:19 2013 UTC (7 years, 4 months ago) by william
File size: 176515 byte(s)

1 william 414 #region Logging Defines
2     // include this any class or method that required logging, and comment-out what is not needed
3 william 415
4 william 414 #region Enabled logging levels
5     #define LOGGING_ENABLE_INFO
6     #define LOGGING_ENABLE_WARN
7     #define LOGGING_ENABLE_DEBUG
8     #define LOGGING_ENABLE_VERBOSEDEBUG
9     #define LOGGING_ENABLE_ERROR
10     #define LOGGING_ENABLE_VERBOSEERROR
11     #define LOGGING_ENABLE_PROFILER
12     #endregion
13     #endregion
14     //#define USE_AUTOMATIC_MEMORY_SEARCH_RANGE // when defined will automatically choose the best starting address and size for memory search otherwise it will use the constants defined in MemorySizeConstants
15 william 289 #if !USE_AUTOMATIC_MEMORY_SEARCH_RANGE
16 william 287 #define FORCE_USE_OF_MEMORYSIZECONSTANTS // when defined wil force the use of the constants defined in MemorySizeConstants for memory search range
17 william 289 #endif
18 william 452 #define DONOT_HAVE_RANGED_SEARCH_SUPPORT // when defined, indicates that ranged searches have not been implemented
19 william 280 #define INCREASE_NUMBER_OF_RESULTS_BEFORE_DISPLAY // when defined will set MIN RESULTS to 0x2701 otherwise 0x03e8
20     //#define DO_NOT_SUSPEND_RESUME_THREAD_ON_FREEZE // when defined will not freeze/resume thread on freeze
21 william 229 using System;
22 william 227 using System.Collections.Generic;
23     using System.ComponentModel;
24     using System.Data;
25     using System.Drawing;
26     using System.Linq;
27     using System.Text;
28     using System.Windows.Forms;
29     using WeifenLuo.WinFormsUI.Docking;
30     using RomCheater.PluginFramework.Interfaces;
31     using System.Diagnostics;
32 william 229 using RomCheater.Docking.MemorySearch;
33     using libWin32.Win32.Threading;
34 william 230 using System.Threading;
35     using RomCheater.Logging;
36     using System.IO;
37 william 242 using Sojaner.MemoryScanner.MemoryProviers;
38 william 275 using RomCheater.PluginFramework.Events;
39 william 287 using System.Reflection;
40 william 292 using Sojaner.MemoryScanner;
41 william 399 using System.Collections;
42 william 401 using RomCheater.Serialization;
43 william 511 using RomCheater.Core;
44 william 227
45     namespace RomCheater.Docking
46     {
47 william 228 public partial class FloatingMemorySearcher : DockContent,
48 william 243 IAcceptsPlugin<IConfigPlugin>,
49 william 477 IAcceptsProcess<Process>,
50 william 243 IAcceptsProcessAndConfig,
51 william 275 ISearchInProgress,
52 william 287 IAcceptsBrowseMemoryRegion,
53     IAcceptsMemoryRange
54 william 227 {
55 william 280 #if INCREASE_NUMBER_OF_RESULTS_BEFORE_DISPLAY
56     const int MIN_NUMBER_OF_RESULTS_BEFORE_DISPLAY = 0x2701; // 10,000 results
57     #else
58     const int MIN_NUMBER_OF_RESULTS_BEFORE_DISPLAY = 0x03e8; // 1,000 results
59     #endif
60    
61 william 546 const uint MEM_1MB = 0x00100000;
62    
63 william 452 const bool USE_OLD_SEARCH_RESULTS_COMPRATOR_CODE = false;
64 william 457 const bool USE_NONRANGE_SEARCH_RESULT_READER = false;
65 william 229 private bool DefaultUnsignedState = true; // set unsigned to true
66 william 477 public FloatingMemorySearcher() { InitializeComponent(); this.AcceptedPlugin = null; OnBrowseMemoryRegion = null; this.AcceptedProcess = null; SearchInProgess = false; Reload(); }
67 william 227 public FloatingMemorySearcher(IConfigPlugin config) : this() { this.AcceptedPlugin = config; }
68 william 477 public FloatingMemorySearcher(IConfigPlugin config, Process process) : this() { this.AcceptedPlugin = config; this.AcceptedProcess = process; }
69 william 227
70 william 462 //new Action<int, string>(UpdateProgress) to use this as a delegate
71 william 511
72     private void thread_UpdateProgress(object o)
73 william 461 {
74 william 511 IProgressMessage pm = (o as IProgressMessage);
75     if (pm == null) { return; }
76     resultsprogress.Value = pm.Progress;
77 william 517 resultsprogress.Message = pm.Message;
78 william 534 //Application.DoEvents();
79 william 461 }
80    
81 william 532 private bool ShouldCancelAnySearchOperation() { return SearchWorkerThread.CancellationPending; }
82    
83 william 511 private void UpdateProgress(int progress, string message)
84 william 532 {
85 william 511 // detach the progress update from execution within the current thread (so it does not block a cpu-intensive or long running sequence)
86     Thread t = new Thread(new ParameterizedThreadStart(thread_UpdateProgress));
87 william 517 t.SetApartmentState(ApartmentState.STA);
88 william 511 t.Start(new ProgressMessage(progress, message));
89 william 517 //resultsprogress.Value = progress;
90     //resultsprogress.Message = message;
91 william 511 }
92    
93 william 237 #region IAcceptsProcess<Process> Members
94 william 477 private Process _AcceptedProcess;
95     public Process AcceptedProcess { get { return _AcceptedProcess; } set { _AcceptedProcess = value; UpdateAcceptedProcess(value); } }
96 william 227 #endregion
97     #region IAcceptsPlugin<IConfigPlugin> Members
98 william 243 private IConfigPlugin _AcceptedPlugin;
99 william 305 public IConfigPlugin AcceptedPlugin { get { return _AcceptedPlugin; } set { _AcceptedPlugin = value; UpdateAcceptedPlugin(value); } }
100 william 227 #endregion
101 william 275 #region IAcceptsBrowseMemoryRegion members
102 william 287 public event BaseEventHandler<BrowseMemoryRegionEvent> OnBrowseMemoryRegion;
103 william 275 #endregion
104    
105 william 305 private void UpdateAcceptedPlugin(IConfigPlugin config)
106 william 243 {
107     this.lstResults.AcceptedPlugin = config;
108     this.lstPatchList.AcceptedPlugin = config;
109 william 389 if (config != null)
110     {
111     MemoryRangeStart = AcceptedPlugin.MemoryRangeStart;
112     MemoryRangeSize = AcceptedPlugin.MemoryRangeStart + AcceptedPlugin.MemoryRangeSize;
113     }
114 william 305 }
115 william 477 private void UpdateAcceptedProcess(Process process)
116     {
117     this.lstResults.AcceptedProcess = process;
118     this.lstPatchList.AcceptedProcess = process;
119 william 287 #if USE_AUTOMATIC_MEMORY_SEARCH_RANGE && FORCE_USE_OF_MEMORYSIZECONSTANTS
120     logger.Warn.WriteLine("FloatingMemorySearcher.UpdateAcceptedProcessAndConfig(IConfigPlugin config, Process process):");
121     logger.Warn.WriteLine("Both USE_AUTOMATIC_MEMORY_SEARCH_RANGE and FORCE_USE_OF_MEMORYSIZECONSTANTS are defined");
122     logger.Warn.WriteLine("FORCE_USE_OF_MEMORYSIZECONSTANTS will take precedence and will ignore the values supplied in the memeory search range");
123 william 289 #endif
124     #if FORCE_USE_OF_MEMORYSIZECONSTANTS
125     // force use of MemorySizeConstants
126 william 349 txtMemoryRangeStart.Value = MemorySizeConstants.MinimumSearchAddress;
127 william 401 txtMemoryRangeSize.Value = MemorySizeConstants.MinimumSearchAddress + MemorySizeConstants.MaximumSearchSize;
128 william 287 #endif
129     #if USE_AUTOMATIC_MEMORY_SEARCH_RANGE && !FORCE_USE_OF_MEMORYSIZECONSTANTS
130 william 318 ////// code to automatically choose the best starting memory address and size
131     //if (process != null)
132     //{
133     // string filename = process.MainModule.FileName;
134     // //string filename = @"c:\Windows\notepad.exe";
135     // PEReader peReader = new PEReader(filename);
136     //}
137     //else
138     //{
139 william 389 //txtMemoryRangeStart.Value = MemorySizeConstants.MinimumSearchAddress;
140     //txtMemoryRangeSize.Value = MemorySizeConstants.MinimumSearchAddress + MemorySizeConstants.MaximumSearchSize;
141 william 318 //}
142 william 389 if (AcceptedPlugin != null)
143     {
144     MemoryRangeStart = AcceptedPlugin.MemoryRangeStart;
145     MemoryRangeSize = AcceptedPlugin.MemoryRangeStart + AcceptedPlugin.MemoryRangeSize;
146     }
147    
148 william 287 #endif
149    
150 william 243 }
151 william 228 #region ISearchInProgress members
152 william 399 private bool _SearchInProgess;
153     public bool SearchInProgess
154     {
155     get { return _SearchInProgess; }
156     private set
157     {
158     _SearchInProgess = value;
159     if (this.AcceptedPlugin != null)
160     this.AcceptedPlugin.SetMemorySearchReference(this);
161     }
162     }
163 william 444 private Guid _SearchGuid;
164     public Guid SearchGuid
165     {
166     get { return _SearchGuid; }
167     private set { _SearchGuid = value; }
168     }
169 william 228 #endregion
170 william 229
171 william 287 #region IAcceptsMemoryRange
172     #if !FORCE_USE_OF_MEMORYSIZECONSTANTS
173 william 389 private uint _MemoryRangeStart;
174 william 287 private uint _MemoryRangeSize;
175     #endif
176 william 378 public uint MemoryRangeStart
177 william 287 {
178     get
179     {
180     #if FORCE_USE_OF_MEMORYSIZECONSTANTS
181 william 349 return MemorySizeConstants.MinimumSearchAddress;
182 william 287 #else
183     return _MemoryRangeStart;
184     #endif
185     }
186     set
187     {
188     #if !FORCE_USE_OF_MEMORYSIZECONSTANTS
189     _MemoryRangeStart = value;
190 william 389 txtMemoryRangeStart.Value = value;
191 william 287 #endif
192     }
193     }
194     public uint MemoryRangeSize
195     {
196     get
197     {
198     #if FORCE_USE_OF_MEMORYSIZECONSTANTS
199 william 401 return MemorySizeConstants.MinimumSearchAddress + MemorySizeConstants.MaximumSearchSize;
200 william 287 #else
201     return _MemoryRangeSize;
202     #endif
203     }
204     set
205     {
206     #if !FORCE_USE_OF_MEMORYSIZECONSTANTS
207     _MemoryRangeSize = value;
208 william 389 txtMemoryRangeSize.Value = value;
209 william 287 #endif
210     }
211     }
212     #endregion
213 william 229
214     public void Reload()
215     {
216     chkUnsigned.Checked = DefaultUnsignedState;
217     radio_8bits.Checked = true;
218     radiocompare_equal.Checked = true;
219     radio_oldvalue.Checked = true;
220 william 230 chkRefreshResults.Checked = true;
221 william 229 }
222 william 230 public enum eListViewResults
223     {
224     SEARCH_RESULTS_LIST = 0x3000,
225     PATCH_RESULTS_LIST = 0x3001,
226     UKNOWN_RESULTS_LIST = 0x3001
227     }
228 william 280 bool IsFirstSearch = true;
229 william 277 SearchType SearchArgs;
230 william 272 static int col_Found_Address = 1;
231     static int col_Found_Value = 2;
232 william 419 //static int col_Found_Frozen = 3; /* unused */
233 william 272 static int col_Added_Address = 1;
234     static int col_Added_Value = 2;
235 william 419 //static int col_Added_Frozen = 3; /* unused */
236 william 230 List<ListViewItem> ResultItems = new List<ListViewItem>();
237     List<ListViewItem> AddedItems = new List<ListViewItem>();
238     private bool _PatchedValue_NeedsUpdate;
239     bool PatchedValue_NeedsUpdate
240     {
241     get { if (_PatchedValue_NeedsUpdate) this.ThawResultsUpdate(); return _PatchedValue_NeedsUpdate; }
242     set { _PatchedValue_NeedsUpdate = value; if (value) this.ThawResultsUpdate(); }
243     }
244     private delegate ListViewItem ThreadSafe_GetResultItem(int index, int lv_type);
245     private ListViewItem GetResultItem(int index, int lv_type)
246     {
247     try
248     {
249     AddressValuePairList lv = null;
250     switch (lv_type)
251     {
252     case (int)eListViewResults.SEARCH_RESULTS_LIST: lv = lstResults; break;
253     case (int)eListViewResults.PATCH_RESULTS_LIST: lv = lstPatchList; break;
254     default: throw new IndexOutOfRangeException("Detected: " + Enum.GetName(typeof(eListViewResults), eListViewResults.UKNOWN_RESULTS_LIST) + " with value: " + lv_type.ToString("x4"));
255     }
256     ListViewItem item = new ListViewItem();
257     item = (ListViewItem)lv.Items[index].Clone();
258     return item;
259     }
260     catch (Exception)
261     {
262     return null;
263     }
264     }
265 william 229 private void radiocompare_equal_CheckedChanged(object sender, EventArgs e)
266     {
267     //if (!radiocompare_between.Checked && !radiocompare_notbetween.Checked)
268     //{
269     if (radio_oldvalue.Checked)
270     {
271     txtStartAddr.ReadOnly = true;
272     txtEndAddr.ReadOnly = true;
273     }
274     if (radio_specificvalue.Checked)
275     {
276     txtStartAddr.ReadOnly = false;
277     txtEndAddr.ReadOnly = true;
278     }
279     //}
280     }
281    
282     private void radiocompare_between_CheckedChanged(object sender, EventArgs e)
283     {
284     if (!radiocompare_equal.Checked &&
285     !radiocompare_greaterthan.Checked &&
286     !radiocompare_greaterthan.Checked &&
287     !radiocompare_lessthan.Checked &&
288     !radiocompare_greaterthan_orequal.Checked &&
289     !radiocompare_lessthan_orequal.Checked &&
290     !radiocompare_notequal.Checked)
291     if (radiocompare_between.Checked)
292     {
293     txtStartAddr.ReadOnly = false;
294     txtEndAddr.ReadOnly = false;
295     return;
296     }
297     if (!radiocompare_between.Checked && !radiocompare_notbetween.Checked)
298     {
299     if (radio_oldvalue.Checked)
300     {
301     txtStartAddr.ReadOnly = true;
302     txtEndAddr.ReadOnly = true;
303     }
304     if (radio_specificvalue.Checked)
305     {
306     txtStartAddr.ReadOnly = false;
307     txtEndAddr.ReadOnly = true;
308     }
309     }
310     }
311    
312     private void radiocompare_notbetween_CheckedChanged(object sender, EventArgs e)
313     {
314     if (!radiocompare_equal.Checked &&
315     !radiocompare_greaterthan.Checked &&
316     !radiocompare_greaterthan.Checked &&
317     !radiocompare_lessthan.Checked &&
318     !radiocompare_greaterthan_orequal.Checked &&
319     !radiocompare_lessthan_orequal.Checked &&
320     !radiocompare_notequal.Checked)
321     if (radiocompare_notbetween.Checked)
322     {
323     txtStartAddr.ReadOnly = false;
324     txtEndAddr.ReadOnly = false;
325     return;
326     }
327     if (!radiocompare_between.Checked && !radiocompare_notbetween.Checked)
328     {
329     if (radio_oldvalue.Checked)
330     {
331     txtStartAddr.ReadOnly = true;
332     txtEndAddr.ReadOnly = true;
333     }
334     if (radio_specificvalue.Checked)
335     {
336     txtStartAddr.ReadOnly = false;
337     txtEndAddr.ReadOnly = true;
338     }
339     }
340     }
341    
342     private void radio_8bits_CheckedChanged(object sender, EventArgs e)
343     {
344     if (chkUnsigned.Checked)
345     {
346     txtStartAddr.CreateTypeSize<byte>();
347     txtEndAddr.CreateTypeSize<byte>();
348     }
349     else
350     {
351     txtStartAddr.CreateTypeSize<sbyte>();
352     txtEndAddr.CreateTypeSize<sbyte>();
353     }
354     }
355    
356     private void radio_16bits_CheckedChanged(object sender, EventArgs e)
357     {
358     if (chkUnsigned.Checked)
359     {
360     txtStartAddr.CreateTypeSize<ushort>();
361     txtEndAddr.CreateTypeSize<ushort>();
362     }
363     else
364     {
365     txtStartAddr.CreateTypeSize<short>();
366     txtEndAddr.CreateTypeSize<short>();
367     }
368     }
369    
370     private void radio_32bits_CheckedChanged(object sender, EventArgs e)
371     {
372    
373     if (chkUnsigned.Checked)
374     {
375     txtStartAddr.CreateTypeSize<uint>();
376     txtEndAddr.CreateTypeSize<uint>();
377     }
378     else
379     {
380     txtStartAddr.CreateTypeSize<int>();
381     txtEndAddr.CreateTypeSize<int>();
382     }
383     }
384    
385     private void radio_64bits_CheckedChanged(object sender, EventArgs e)
386     {
387    
388     if (chkUnsigned.Checked)
389     {
390     txtStartAddr.CreateTypeSize<ulong>();
391     txtEndAddr.CreateTypeSize<ulong>();
392     }
393     else
394     {
395     txtStartAddr.CreateTypeSize<long>();
396     txtEndAddr.CreateTypeSize<long>();
397     }
398     }
399    
400     private void radio_oldvalue_CheckedChanged(object sender, EventArgs e)
401     {
402     if (!radiocompare_between.Checked && !radiocompare_notbetween.Checked)
403     {
404     txtStartAddr.ReadOnly = true;
405     txtEndAddr.ReadOnly = true;
406     }
407     }
408    
409     private void radio_specificvalue_CheckedChanged(object sender, EventArgs e)
410     {
411     if (!radiocompare_between.Checked && !radiocompare_notbetween.Checked)
412     {
413     txtStartAddr.ReadOnly = false;
414     txtEndAddr.ReadOnly = true;
415     }
416     }
417    
418     private void chkRefreshResults_CheckedChanged(object sender, EventArgs e)
419     {
420     if (chkRefreshResults.Checked)
421     {
422     timer_update_results.Enabled = true;
423     }
424     else
425     {
426     timer_update_results.Enabled = false;
427     ResultsUpdateWorkerThread.CancelAsync();
428     }
429     }
430    
431     private void timer_update_results_Tick(object sender, EventArgs e)
432     {
433     if (chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy)
434     {
435     ResultsUpdateWorkerThread.RunWorkerAsync();
436     }
437     }
438 william 230 private bool ShouldUpdateResults()
439     {
440 william 477 if (this.AcceptedProcess == null) return false;
441 william 230 if (SearchWorkerThread.IsBusy) return false;
442     //if (JokerSearchWorker.IsBusy) return false;
443     if (this.IsResultsUpdateFrozen) return false;
444     if (mnuAddedResults.Visible) return false;
445     if (mnuResults.Visible) return false;
446 william 477 if (Process.GetProcessById(this.AcceptedProcess.Id) == null) return false;
447 william 230 if (lstResults.Items.Count > 0) return true;
448     if (lstPatchList.Items.Count > 0) return true;
449     return false;
450     }
451 william 229 private void ResultsUpdateWorkerThread_DoWork(object sender, DoWorkEventArgs e)
452     {
453 william 230 Thread.Sleep(250); // keep thread from blocking
454     if (!this.ShouldUpdateResults()) return;
455     ////if (SearchArgs == null) return;
456     ////if (this.IsResultsUpdateFrozen) return;
457     ////// put thread to sleep for 500ms
458     ////System.Threading.Thread.Sleep(500);
459     //PCSX2MemoryProvider provider = new PCSX2MemoryProvider(this.SearchPCSX2ProcessPID, resultslog);
460     //byte[] buffered_mem = provider.GetMemory();
461     //MemoryStream ms = new MemoryStream(buffered_mem);
462     //BinaryReader r_ms = new BinaryReader(ms);
463 william 229
464 william 230 #region Update Results List
465     ResultItems = new List<ListViewItem>();
466     //r_ms.BaseStream.Seek(0, SeekOrigin.Begin);
467     for (int i = 0; i < lstResults.Items.Count; i++)
468     {
469     if (this.lstResults.InvokeRequired)
470     {
471     ThreadSafe_GetResultItem _get_item = new ThreadSafe_GetResultItem(GetResultItem);
472     object item = this.lstResults.Invoke(_get_item, new object[] { i, (int)eListViewResults.SEARCH_RESULTS_LIST });
473     if (item != null)
474     ResultItems.Add((ListViewItem)item);
475     }
476     else
477     {
478     ResultItems.Add(lstResults.Items[i]);
479     }
480    
481     }
482     for (int i = 0; i < ResultItems.Count; i++)
483     {
484     if (ResultsUpdateWorkerThread.CancellationPending == true)
485     {
486     e.Cancel = true;
487     return;
488     }
489 william 249 int Address = 0;
490 william 230 ResultDataType _result = (ResultDataType)ResultItems[i].Tag;
491    
492 william 249 Address = Convert.ToInt32(ResultItems[i].SubItems[col_Found_Address].Text, 16);
493 william 242 //r_ms.BaseStream.Seek(Address, SeekOrigin.Begin);
494 william 398 using (GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
495 william 230 {
496 william 398 provider.OpenProvider();
497     int bytesReadSize;
498     byte[] data;
499     uint bytesToRead = 0;
500     switch (_result.ValueType)
501     {
502     case SearchDataTypes._8bits:
503     bytesToRead = 1;
504     break;
505     case SearchDataTypes._16bits:
506     bytesToRead = 2;
507     break;
508     case SearchDataTypes._32bits:
509     bytesToRead = 4;
510     break;
511     case SearchDataTypes._64bits:
512     bytesToRead = 8;
513     break;
514     }
515     provider.ReadProcessMemory(Address, bytesToRead, out bytesReadSize, out data);
516     using (MemoryStream ms = new MemoryStream(data))
517     {
518     using (BinaryReader r_ms = new BinaryReader(ms))
519     {
520     switch (_result.ValueType)
521     {
522     case SearchDataTypes._8bits:
523     if (_result.IsUnsigned) { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x2}", r_ms.ReadByte()); }
524     else { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x2}", r_ms.ReadSByte()); }
525     break;
526     case SearchDataTypes._16bits:
527     if (_result.IsUnsigned) { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x4}", r_ms.ReadUInt16()); }
528     else { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x4}", r_ms.ReadInt16()); }
529     break;
530     case SearchDataTypes._32bits:
531     if (_result.IsUnsigned) { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x8}", r_ms.ReadUInt32()); }
532     else { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x8}", r_ms.ReadInt32()); }
533     break;
534     case SearchDataTypes._64bits:
535     if (_result.IsUnsigned) { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x16}", r_ms.ReadUInt64()); }
536     else { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x16}", r_ms.ReadInt64()); }
537     break;
538     }
539     r_ms.Close();
540     }
541     }
542 william 424 provider.CloseProvider();
543 william 230 }
544 william 398 //Application.DoEvents();
545 william 230 }
546     #endregion
547    
548     #region Update Added Results List
549     AddedItems = new List<ListViewItem>();
550     //r_ms.BaseStream.Seek(0, SeekOrigin.Begin);
551     for (int i = 0; i < lstPatchList.Items.Count; i++)
552     {
553     if (this.lstResults.InvokeRequired)
554     {
555     ThreadSafe_GetResultItem _get_item = new ThreadSafe_GetResultItem(GetResultItem);
556     object item = this.lstResults.Invoke(_get_item, new object[] { i, (int)eListViewResults.PATCH_RESULTS_LIST });
557     if (item != null)
558     AddedItems.Add((ListViewItem)item);
559     }
560     else
561     {
562     AddedItems.Add(lstPatchList.Items[i]);
563     }
564    
565     }
566     for (int i = 0; i < AddedItems.Count; i++)
567     {
568     if (ResultsUpdateWorkerThread.CancellationPending == true)
569     {
570     e.Cancel = true;
571     return;
572     }
573 william 249 int Address = 0;
574 william 230 ResultDataType _result = (ResultDataType)AddedItems[i].Tag;
575 william 249 Address = Convert.ToInt32(AddedItems[i].SubItems[col_Added_Address].Text, 16);
576 william 398 using (GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
577 william 230 {
578 william 398 provider.OpenProvider();
579     int bytesReadSize;
580     byte[] data;
581     uint bytesToRead = 0;
582     switch (_result.ValueType)
583     {
584     case SearchDataTypes._8bits:
585     bytesToRead = 1;
586     break;
587     case SearchDataTypes._16bits:
588     bytesToRead = 2;
589     break;
590     case SearchDataTypes._32bits:
591     bytesToRead = 4;
592     break;
593     case SearchDataTypes._64bits:
594     bytesToRead = 8;
595     break;
596     }
597     provider.ReadProcessMemory(Address, bytesToRead, out bytesReadSize, out data);
598 william 424 provider.CloseProvider();
599 william 398 using (MemoryStream ms = new MemoryStream(data))
600     {
601     using (BinaryReader r_ms = new BinaryReader(ms))
602     {
603     switch (_result.ValueType)
604     {
605     case SearchDataTypes._8bits:
606     if (_result.IsUnsigned) { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x2}", r_ms.ReadByte()); }
607     else { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x2}", r_ms.ReadSByte()); }
608     break;
609     case SearchDataTypes._16bits:
610     if (_result.IsUnsigned) { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x4}", r_ms.ReadUInt16()); }
611     else { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x4}", r_ms.ReadInt16()); }
612     break;
613     case SearchDataTypes._32bits:
614     if (_result.IsUnsigned) { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x8}", r_ms.ReadUInt32()); }
615     else { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x8}", r_ms.ReadInt32()); }
616     break;
617     case SearchDataTypes._64bits:
618     if (_result.IsUnsigned) { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x16}", r_ms.ReadUInt64()); }
619     else { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x16}", r_ms.ReadInt64()); }
620     break;
621     }
622     r_ms.Close();
623     }
624     }
625 william 230 }
626 william 398 //Application.DoEvents();
627 william 230 }
628     #endregion
629    
630    
631 william 229 }
632    
633     private void ResultsUpdateWorkerThread_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
634     {
635 william 230 try
636     {
637     //if ((lstResults.SelectedItems.Count > 0) && !PatchedValue_NeedsUpdate ) return;
638     //if ((lstPatchList.SelectedItems.Count > 0) && !PatchedValue_NeedsUpdate) return;
639     if (!this.ShouldUpdateResults()) return;
640     if (ResultItems.Count > 0)
641     {
642     //lstResults.Items.Clear();
643     //lstResults.Items.AddRange(ResultItems.ToArray());
644 william 229
645 william 230 for (int i = 0; i < ResultItems.Count; i++)
646     {
647     lstResults.Items[i].SubItems[new AVPColumnText(AVPColumnType.VALUE).ColumnIndex].Text =
648     ResultItems[i].SubItems[new AVPColumnText(AVPColumnType.VALUE).ColumnIndex].Text;
649     }
650    
651     }
652     if (AddedItems.Count > 0)
653     {
654     //lstPatchList.Items.Clear();
655     //lstPatchList.Items.AddRange(AddedItems.ToArray());
656    
657     for (int i = 0; i < AddedItems.Count; i++)
658     {
659     lstPatchList.Items[i].SubItems[new AVPColumnText(AVPColumnType.VALUE).ColumnIndex].Text =
660     AddedItems[i].SubItems[new AVPColumnText(AVPColumnType.VALUE).ColumnIndex].Text;
661     }
662    
663     }
664     PatchedValue_NeedsUpdate = false;
665     }
666     catch { }
667 william 229 }
668    
669     private void btnImportFile_Click(object sender, EventArgs e)
670     {
671     this.FreezeResultsUpdate();
672     if (!lstPatchList.ImportFromFile())
673     {
674     MessageBox.Show("Failed to Import Patch List from File.", "Import Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
675     this.ThawResultsUpdate();
676     return;
677     }
678     else
679     {
680     MessageBox.Show("Succesfully Imported Patch List from File.", "Import Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
681     this.ThawResultsUpdate();
682     return;
683     }
684     }
685     bool g_isFrozen = false;
686     private bool IsResultsUpdateFrozen
687     {
688     get { return g_isFrozen; }
689     set { g_isFrozen = value; }
690     }
691     private void ThawResultsUpdate()
692     {
693     this.IsResultsUpdateFrozen = false;
694 william 477 if (this.AcceptedProcess != null)
695 william 229 {
696     #if !DO_NOT_SUSPEND_RESUME_THREAD_ON_FREEZE
697 william 477 ThreadControl.ResumeProcess(this.AcceptedProcess.Id);
698 william 229 #endif
699     }
700     }
701    
702     private void FreezeResultsUpdate()
703     {
704     this.IsResultsUpdateFrozen = true;
705 william 285 //this.IsResultsUpdateFrozen = false;
706 william 477 if (this.AcceptedProcess != null)
707 william 229 {
708     #if !DO_NOT_SUSPEND_RESUME_THREAD_ON_FREEZE
709 william 477 ThreadControl.SuspendProcess(this.AcceptedProcess.Id);
710 william 229 #endif
711     }
712     }
713    
714     private void btnExportFile_Click(object sender, EventArgs e)
715     {
716     this.FreezeResultsUpdate();
717     if (!lstPatchList.ExportToFile())
718     {
719     MessageBox.Show("Failed to Export Patch List to File.", "Export Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
720     this.ThawResultsUpdate();
721     return;
722     }
723     else
724     {
725     MessageBox.Show("Succesfully Exported Patch List to File.", "Export Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
726     this.ThawResultsUpdate();
727     return;
728     }
729     }
730    
731     private void btnImportClipboard_Click(object sender, EventArgs e)
732     {
733     this.FreezeResultsUpdate();
734     if (!lstPatchList.ImportFromClipboard())
735     {
736     MessageBox.Show("Failed to Import Patch List from Clipboard.", "Import Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
737     this.ThawResultsUpdate();
738     return;
739     }
740     else
741     {
742     MessageBox.Show("Succesfully Import Patch List from Clipboard.", "Import Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
743     this.ThawResultsUpdate();
744     }
745     }
746    
747     private void btnExportClipboard_Click(object sender, EventArgs e)
748     {
749     this.FreezeResultsUpdate();
750     if (!lstPatchList.ExportToClipboard())
751     {
752     MessageBox.Show("Failed to Export Patch List to Clipboard.", "Export Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
753     this.ThawResultsUpdate();
754     return;
755     }
756     else
757     {
758     MessageBox.Show("Succesfully Exported Patch List to Clipboard.", "Export Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
759     this.ThawResultsUpdate();
760     return;
761     }
762     }
763    
764     private void btnAddPatchAddress_Click(object sender, EventArgs e)
765     {
766 william 245 PatchAdder adder = new PatchAdder((IAcceptsProcessAndConfig)this);
767 william 229 adder.ShowDialog();
768     if (adder.WasAPatchAdded) AddToPatchList(adder.AddedPatchValue);
769     }
770    
771     private void btnAddAddressRange_Click(object sender, EventArgs e)
772     {
773 william 245 PatchRangeAdder adder = new PatchRangeAdder((IAcceptsProcessAndConfig)this);
774 william 229 adder.ShowDialog();
775     if (adder.WasAPatchAdded) AddToPatchList(adder.AddedPatchValue);
776     }
777     private void AddToPatchList(List<ResultDataType> item) { foreach (ResultDataType data in item) { AddToPatchList(data); } }
778     private void AddToPatchList(ResultDataType item)
779     {
780     ResultItem item2 = null;
781     switch (item.ValueType)
782     {
783     case SearchDataTypes._8bits:
784     if (item.IsUnsigned) { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToByte(item.Value)); }
785     else { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToSByte(item.Value)); }
786     break;
787     case SearchDataTypes._16bits:
788     if (item.IsUnsigned) { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToUInt16(item.Value)); }
789     else { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToInt16(item.Value)); }
790     break;
791     case SearchDataTypes._32bits:
792     if (item.IsUnsigned) { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToUInt32(item.Value)); }
793     else { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToInt32(item.Value)); }
794     break;
795     case SearchDataTypes._64bits:
796     if (item.IsUnsigned) { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToUInt64(item.Value)); }
797     else { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToInt64(item.Value)); }
798     break;
799     }
800     this.AddToPatchList(item2);
801     }
802     private void AddToPatchList(ListViewItem item)
803     {
804     try
805     {
806     ResultDataType _result = (ResultDataType)item.Tag;
807     this.AddToPatchList(_result);
808     }
809     catch (InvalidCastException ex)
810     {
811     // unable to cast
812     MessageBox.Show(ex.Message, "Invalid Cast Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
813     }
814     catch (Exception ex)
815     {
816     // other exception
817     MessageBox.Show(ex.Message, "Unhandled Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
818     }
819     }
820     private void AddToPatchList(ResultItem item)
821     {
822     if (!lstPatchList.Items.Contains(item)) lstPatchList.Items.Add(item);
823     }
824     private void AddToPatchList(string address, SearchDataTypes bitsize, bool IsUnsigned)
825     {
826 william 245 ResultItemState state = new ResultItemState(address, bitsize, IsUnsigned, (IAcceptsProcessAndConfig)this);
827 william 229 ResultItem item = new ResultItem(state.Address, state.Value, state.Frozen, state.ValueType, state.IsUnsigned);
828     this.AddToPatchList(item);
829     }
830 william 230
831     private void mnuItemAddToPatchList_Click(object sender, EventArgs e)
832     {
833     if (!(lstResults.SelectedItems.Count > 0)) return;
834     //if (SearchArgs == null) return;
835    
836     try
837     {
838     for (int i = 0; i < lstResults.SelectedIndices.Count; i++)
839     {
840     //ResultDataType result = (ResultDataType)lstResults.Items[selected_index].Tag;
841     ListViewItem item = lstResults.Items[lstResults.SelectedIndices[i]];
842     this.AddToPatchList(item);
843     }
844     }
845     catch (Exception ex)
846     {
847     logger.Error.WriteLine(ex.ToString());
848     }
849     }
850    
851     private void mnuItemRemoveResult_Click(object sender, EventArgs e)
852     {
853     if (!(lstPatchList.SelectedItems.Count > 0)) return;
854     //if (SearchArgs == null) return;
855     try
856     {
857     this.FreezeResultsUpdate();
858     for (int i = 0; i < lstPatchList.SelectedIndices.Count; i++)
859     {
860     //lstPatchList.ThawItem(lstPatchList.SelectedIndices[i]);
861     lstPatchList.Items[lstPatchList.SelectedIndices[i]].Remove();
862     }
863     this.ThawResultsUpdate();
864     }
865     catch (Exception ex)
866     {
867     Debug.WriteLine(ex.ToString());
868     }
869     }
870     private void PatchRange(bool SingleEntry)
871     {
872     //if (SearchArgs == null) return;
873     #region Patch Selected Address
874     // stop ResultsUpdate Thread
875     ResultsUpdateWorkerThread.CancelAsync();
876    
877     List<ResultDataType> patch_list = new List<ResultDataType>();
878     List<int> SelectedIndexes = new List<int>();
879    
880     if (SingleEntry)
881     {
882     SelectedIndexes.Add(lstPatchList.SelectedIndices[0]);
883     }
884     else
885     {
886     foreach (int index in lstPatchList.SelectedIndices)
887     {
888     SelectedIndexes.Add(index);
889     }
890     }
891     //PCSX2MemoryProvider provider = new PCSX2MemoryProvider(this.SearchPCSX2ProcessPID, resultslog);
892     foreach (int index in SelectedIndexes)
893     {
894     if (SingleEntry)
895     {
896     SearchPatcher patcher = null;
897     uint Address = 0;
898     ListViewItem item = lstPatchList.Items[index];
899     ResultDataType _result = (ResultDataType)item.Tag;
900     Address = Convert.ToUInt32(item.SubItems[col_Found_Address].Text, 16);
901     switch (_result.ValueType)
902     {
903     case SearchDataTypes._8bits:
904     if (_result.IsUnsigned)
905     {
906     byte value = Convert.ToByte(item.SubItems[col_Found_Value].Text, 16);
907 william 243 patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
908 william 230 timer_update_results.Enabled = false;
909     patcher.ShowDialog();
910     timer_update_results.Enabled = true;
911     PatchedValue_NeedsUpdate = true;
912     if (!chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy)
913     ResultsUpdateWorkerThread.RunWorkerAsync();
914     }
915     else
916     {
917     sbyte value = Convert.ToSByte(item.SubItems[col_Found_Value].Text, 16);
918 william 243 patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
919 william 230 timer_update_results.Enabled = false;
920     patcher.ShowDialog();
921     timer_update_results.Enabled = true;
922     PatchedValue_NeedsUpdate = true;
923     if (!chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy)
924     ResultsUpdateWorkerThread.RunWorkerAsync();
925     }
926     break;
927     case SearchDataTypes._16bits:
928     if (_result.IsUnsigned)
929     {
930     ushort value = Convert.ToUInt16(item.SubItems[col_Found_Value].Text, 16);
931 william 243 patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
932 william 230 timer_update_results.Enabled = false;
933     patcher.ShowDialog();
934     timer_update_results.Enabled = true;
935     PatchedValue_NeedsUpdate = true;
936     if (!chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy)
937     ResultsUpdateWorkerThread.RunWorkerAsync();
938     }
939     else
940     {
941     short value = Convert.ToInt16(item.SubItems[col_Found_Value].Text, 16);
942 william 243 patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
943 william 230 timer_update_results.Enabled = false;
944     patcher.ShowDialog();
945     timer_update_results.Enabled = true;
946     PatchedValue_NeedsUpdate = true;
947     if (!chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy)
948     ResultsUpdateWorkerThread.RunWorkerAsync();
949     }
950     break;
951     case SearchDataTypes._32bits:
952     if (_result.IsUnsigned)
953     {
954     uint value = Convert.ToUInt32(item.SubItems[col_Found_Value].Text, 16);
955 william 243 patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
956 william 230 timer_update_results.Enabled = false;
957     patcher.ShowDialog();
958     timer_update_results.Enabled = true;
959     PatchedValue_NeedsUpdate = true;
960     if (!chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy)
961     ResultsUpdateWorkerThread.RunWorkerAsync();
962     }
963     else
964     {
965     int value = Convert.ToInt32(item.SubItems[col_Found_Value].Text, 16);
966 william 243 patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
967 william 230 timer_update_results.Enabled = false;
968     patcher.ShowDialog();
969     timer_update_results.Enabled = true;
970     PatchedValue_NeedsUpdate = true;
971     if (!chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy)
972     ResultsUpdateWorkerThread.RunWorkerAsync();
973     }
974     break;
975     case SearchDataTypes._64bits:
976     if (_result.IsUnsigned)
977     {
978     ulong value = Convert.ToUInt32(item.SubItems[col_Found_Value].Text, 16);
979 william 243 patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
980 william 230 timer_update_results.Enabled = false;
981     patcher.ShowDialog();
982     timer_update_results.Enabled = true;
983     PatchedValue_NeedsUpdate = true;
984     if (!chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy)
985     ResultsUpdateWorkerThread.RunWorkerAsync();
986     }
987     else
988     {
989     long value = Convert.ToInt32(item.SubItems[col_Found_Value].Text, 16);
990 william 243 patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
991 william 230 timer_update_results.Enabled = false;
992     patcher.ShowDialog();
993     timer_update_results.Enabled = true;
994     PatchedValue_NeedsUpdate = true;
995     if (!chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy)
996     ResultsUpdateWorkerThread.RunWorkerAsync();
997     }
998     break;
999     }
1000     }
1001     else
1002     {
1003    
1004     ListViewItem item = lstPatchList.Items[index];
1005     ResultDataType _result = (ResultDataType)item.Tag;
1006     patch_list.Add(_result);
1007     }
1008     }
1009    
1010     if (patch_list.Count > 0)
1011     {
1012 william 243 SearchRangePatcher rangePatcher = new SearchRangePatcher((IAcceptsProcessAndConfig)this, patch_list);
1013 william 230 rangePatcher.ShowDialog();
1014     }
1015    
1016     #endregion
1017     }
1018     private void mnuItemPatchSelectedEntry_Click(object sender, EventArgs e)
1019     {
1020     if (!(lstPatchList.SelectedItems.Count == 1)) return;
1021     PatchRange(true);
1022     }
1023    
1024     private void mnuItemPatchSelectedRange_Click(object sender, EventArgs e)
1025     {
1026     if (!(lstPatchList.SelectedItems.Count >= 1)) return;
1027     PatchRange(false);
1028     }
1029    
1030     private void mnuItemFreezeSelectedPatches_Click(object sender, EventArgs e)
1031     {
1032     if (!(lstPatchList.SelectedItems.Count > 0)) return;
1033     //if (SearchArgs == null) return;
1034     try
1035     {
1036 william 477 lstPatchList.ProcessID = this.AcceptedProcess.Id;
1037 william 230 this.FreezeResultsUpdate();
1038     for (int i = 0; i < lstPatchList.SelectedIndices.Count; i++)
1039     {
1040     lstPatchList.FreezeItem(lstPatchList.SelectedIndices[i]);
1041     }
1042     // force thaw and update
1043     this.ThawResultsUpdate();
1044     this.Update();
1045     }
1046     catch (Exception ex)
1047     {
1048     Debug.WriteLine(ex.ToString());
1049     }
1050     }
1051    
1052     private void mnuItemThawSelectedPatches_Click(object sender, EventArgs e)
1053     {
1054     if (!(lstPatchList.SelectedItems.Count > 0)) return;
1055     //if (SearchArgs == null) return;
1056     try
1057     {
1058 william 477 lstPatchList.ProcessID = this.AcceptedProcess.Id;
1059 william 230 this.FreezeResultsUpdate();
1060     for (int i = 0; i < lstPatchList.SelectedIndices.Count; i++)
1061     {
1062     lstPatchList.ThawItem(lstPatchList.SelectedIndices[i]);
1063     }
1064     // force thaw and update
1065     this.ThawResultsUpdate();
1066     this.Update();
1067     }
1068     catch (Exception ex)
1069     {
1070     Debug.WriteLine(ex.ToString());
1071     }
1072     }
1073 william 540
1074 william 230 private void SearchWorkerThread_DoWork(object sender, DoWorkEventArgs e)
1075     {
1076 william 410 try
1077 william 483 {
1078 william 410 Stopwatch st = new Stopwatch();
1079     st.Start();
1080 william 392
1081 william 410 Stopwatch st_first_search = new Stopwatch();
1082     Stopwatch st_nonrange_search = new Stopwatch();
1083     Stopwatch st_ranged_search = new Stopwatch();
1084 william 392
1085 william 410 e.Result = st;
1086     //List<ResultType<object>> tmp_Results = new List<ResultType<object>>();
1087 william 476 List<ResultType<ulong>> second_tmp_Results = new List<ResultType<ulong>>();
1088 william 410 //const int ElementsBeforeDisplay = 100;
1089     SearchArgs.LogSearchOptions();
1090     uint STEP_SIZE = (uint)SearchArgs.DataType / 8;
1091 william 399
1092 william 410 bool unsigned = SearchArgs.IsUnsignedDataType;
1093     SearchDataTypes sdt = SearchArgs.DataType;
1094     //byte[] buffered_mem = new byte[(MemoryRangeSize - MemoryRangeStart)]; // throws OutOfMemoryException if size is over 2G
1095     logger.Debug.WriteLine(string.Format("Buffered Memory Size -> 0x{0:x8}", MemoryRangeSize - MemoryRangeStart));
1096 william 517 UpdateProgress(0, string.Format("Search is Warming Up...Please Wait..."));
1097     //new Action<int, string>(UpdateProgress).Invoke(0, string.Format("Search is Warming Up...Please Wait..."));
1098 william 410 Stopwatch provider_st = new Stopwatch();
1099     provider_st.Start();
1100     using (GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1101     {
1102 william 483
1103 william 459 if (SearchArgs.IsFirstSearch)
1104     {
1105 william 460 provider.OpenProvider();
1106     int count = (int)((MemoryRangeSize - MemoryRangeStart) / STEP_SIZE);
1107 william 526 SearchResultWriter writer = new SearchResultWriter((int)(count), SearchGuid);
1108 william 525 int Last_Whole_Percent_Done = 0;
1109 william 547 uint size = 0;
1110     const uint MB_SIZE = 16; /* MEM_1MB * MB_SIZE = MB_SIZE in megabytes */
1111     switch (sdt)
1112     {
1113     case SearchDataTypes._8bits: size = STEP_SIZE * MEM_1MB * (MB_SIZE / BitTools.SizeOf<uint>(sdt)); break;
1114     case SearchDataTypes._16bits: size = STEP_SIZE * MEM_1MB * (MB_SIZE / BitTools.SizeOf<uint>(sdt)); break;
1115     case SearchDataTypes._32bits: size = STEP_SIZE * MEM_1MB * (MB_SIZE / BitTools.SizeOf<uint>(sdt)); break;
1116     case SearchDataTypes._64bits: size = STEP_SIZE * MEM_1MB * (MB_SIZE / BitTools.SizeOf<uint>(sdt)); break;
1117     }
1118     //uint size = STEP_SIZE * 4096;
1119 william 521 for (uint i = MemoryRangeStart; i < MemoryRangeSize; i+=size)
1120     {
1121    
1122     int bytesRead=0;
1123     byte[] data = new byte[size];
1124     provider.ReadProcessMemoryAtOnce(i, size, out bytesRead, out data);
1125     string message = string.Format(" -> Reading Address: 0x{0:x8}", (i + MemoryRangeStart));
1126     double double_percent_done = 100.0 * (double)((double)i / (double)MemoryRangeSize);
1127 william 525 int int_percent_done = (int)double_percent_done;
1128 william 547 if ( (int_percent_done != Last_Whole_Percent_Done))// && (i % 10000) == 0)
1129 william 521 {
1130     UpdateProgress((int)double_percent_done, message);
1131 william 525 Last_Whole_Percent_Done = int_percent_done;
1132 william 521 }
1133    
1134 william 526 uint address_index = i;
1135 william 521 #region comparison and serialization
1136     switch (sdt)
1137     {
1138     case SearchDataTypes._8bits:
1139     if (unsigned)
1140     {
1141     #region 8bits - unsigned
1142 william 534 var t_data = data;
1143 william 521 foreach (var Value in t_data)
1144     {
1145     if (SearchWorkerThread.CancellationPending) { break; }
1146 william 526 using (_8bit_unsigned_comparer_ comparer = new _8bit_unsigned_comparer_(SearchArgs, address_index))
1147 william 521 {
1148     byte value = 0;
1149     if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1150     {
1151     using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1152     {
1153     try
1154     {
1155     gmp.OpenProvider();
1156 william 526 gmp.ReadMemory(address_index, out value);
1157 william 521 gmp.CloseProvider();
1158     }
1159     catch (Exception ex)
1160     {
1161     logger.VerboseError.WriteLine(ex.ToString());
1162     }
1163     }
1164     comparer.Value = value;
1165     }
1166     else
1167     {
1168     value = Convert.ToByte(SearchArgs.CompareStartValue);
1169     comparer.Value = value;
1170     }
1171     if (comparer.Compare(Convert.ToByte(Value), value))
1172     {
1173     writer.WriteResult<byte>(comparer.Address, comparer.Value);
1174     }
1175     }
1176 william 526 address_index += STEP_SIZE;
1177 william 521 }
1178     #endregion
1179     }
1180     else
1181     {
1182     #region 8bits - signed
1183 william 534 var t_data = data;
1184 william 521 foreach (var Value in t_data)
1185     {
1186     if (SearchWorkerThread.CancellationPending) { break; }
1187 william 526 using (_8bit_signed_comparer_ comparer = new _8bit_signed_comparer_(SearchArgs, address_index))
1188 william 521 {
1189     sbyte value = 0;
1190     if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1191     {
1192     using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1193     {
1194     try
1195     {
1196     gmp.OpenProvider();
1197 william 526 gmp.ReadMemory(address_index, out value);
1198 william 521 gmp.CloseProvider();
1199     }
1200     catch (Exception ex)
1201     {
1202     logger.VerboseError.WriteLine(ex.ToString());
1203     }
1204     }
1205     comparer.Value = value;
1206     }
1207     else
1208     {
1209     value = Convert.ToSByte(SearchArgs.CompareStartValue);
1210     comparer.Value = value;
1211     }
1212     if (comparer.Compare(Convert.ToSByte(Value), value))
1213     {
1214     writer.WriteResult<sbyte>(comparer.Address, comparer.Value);
1215     }
1216     }
1217 william 526 address_index += STEP_SIZE;
1218 william 521 }
1219     #endregion
1220     } break;
1221     case SearchDataTypes._16bits:
1222     if (unsigned)
1223     {
1224     #region 16bits - unsigned
1225 william 532 var t_data = BitTools.ConvertByteArray<ushort>(data, new Func<bool>(ShouldCancelAnySearchOperation));
1226 william 521 foreach (var Value in t_data)
1227     {
1228     if (SearchWorkerThread.CancellationPending) { break; }
1229 william 526 using (_16bit_unsigned_comparer_ comparer = new _16bit_unsigned_comparer_(SearchArgs, address_index))
1230 william 521 {
1231     ushort value = 0;
1232     if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1233     {
1234     using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1235     {
1236     try
1237     {
1238     gmp.OpenProvider();
1239 william 526 gmp.ReadMemory(address_index, out value);
1240 william 521 gmp.CloseProvider();
1241     }
1242     catch (Exception ex)
1243     {
1244     logger.VerboseError.WriteLine(ex.ToString());
1245     }
1246     }
1247     comparer.Value = value;
1248     }
1249     else
1250     {
1251     value = Convert.ToUInt16(SearchArgs.CompareStartValue);
1252     comparer.Value = value;
1253     }
1254     if (comparer.Compare(Convert.ToUInt16(Value), value))
1255     {
1256     writer.WriteResult<ushort>(comparer.Address, comparer.Value);
1257     }
1258     }
1259 william 526 address_index += STEP_SIZE;
1260 william 521 }
1261     #endregion
1262     }
1263     else
1264     {
1265     #region 16bits - signed
1266 william 532 var t_data = BitTools.ConvertByteArray<short>(data, new Func<bool>(ShouldCancelAnySearchOperation));
1267 william 521 foreach (var Value in t_data)
1268     {
1269     if (SearchWorkerThread.CancellationPending) { break; }
1270 william 526 using (_16bit_signed_comparer_ comparer = new _16bit_signed_comparer_(SearchArgs, address_index))
1271 william 521 {
1272     short value = 0;
1273     if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1274     {
1275     using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1276     {
1277     try
1278     {
1279     gmp.OpenProvider();
1280 william 526 gmp.ReadMemory(address_index, out value);
1281 william 521 gmp.CloseProvider();
1282     }
1283     catch (Exception ex)
1284     {
1285     logger.VerboseError.WriteLine(ex.ToString());
1286     }
1287     }
1288     comparer.Value = value;
1289     }
1290     else
1291     {
1292     value = Convert.ToInt16(SearchArgs.CompareStartValue);
1293     comparer.Value = value;
1294     }
1295     if (comparer.Compare(Convert.ToSByte(Value), value))
1296     {
1297     writer.WriteResult<short>(comparer.Address, comparer.Value);
1298     }
1299     }
1300 william 526 address_index += STEP_SIZE;
1301 william 521 }
1302     #endregion
1303     } break;
1304     case SearchDataTypes._32bits:
1305     if (unsigned)
1306     {
1307     #region 32bits - unsigned
1308 william 532 var t_data = BitTools.ConvertByteArray<uint>(data, new Func<bool>(ShouldCancelAnySearchOperation));
1309 william 521 foreach (var Value in t_data)
1310     {
1311     if (SearchWorkerThread.CancellationPending) { break; }
1312 william 526 using (_32bit_unsigned_comparer_ comparer = new _32bit_unsigned_comparer_(SearchArgs, address_index))
1313 william 521 {
1314     uint value = 0;
1315     if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1316     {
1317     using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1318     {
1319     try
1320     {
1321     gmp.OpenProvider();
1322 william 526 gmp.ReadMemory(address_index, out value);
1323 william 521 gmp.CloseProvider();
1324     }
1325     catch (Exception ex)
1326     {
1327     logger.VerboseError.WriteLine(ex.ToString());
1328     }
1329     }
1330     comparer.Value = value;
1331     }
1332     else
1333     {
1334     value = Convert.ToUInt32(SearchArgs.CompareStartValue);
1335     comparer.Value = value;
1336     }
1337     if (comparer.Compare(Convert.ToUInt32(Value), value))
1338     {
1339     writer.WriteResult<uint>(comparer.Address, comparer.Value);
1340     }
1341     }
1342 william 526 address_index += STEP_SIZE;
1343 william 521 }
1344     #endregion
1345     }
1346     else
1347     {
1348     #region 32bits - signed
1349 william 532 var t_data = BitTools.ConvertByteArray<int>(data, new Func<bool>(ShouldCancelAnySearchOperation));
1350 william 521 foreach (var Value in t_data)
1351     {
1352     if (SearchWorkerThread.CancellationPending) { break; }
1353 william 526 using (_32bit_signed_comparer_ comparer = new _32bit_signed_comparer_(SearchArgs, address_index))
1354 william 521 {
1355     int value = 0;
1356     if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1357     {
1358     using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1359     {
1360     try
1361     {
1362     gmp.OpenProvider();
1363 william 526 gmp.ReadMemory(address_index, out value);
1364 william 521 gmp.CloseProvider();
1365     }
1366     catch (Exception ex)
1367     {
1368     logger.VerboseError.WriteLine(ex.ToString());
1369     }
1370     }
1371     comparer.Value = value;
1372     }
1373     else
1374     {
1375     value = Convert.ToInt32(SearchArgs.CompareStartValue);
1376     comparer.Value = value;
1377     }
1378     if (comparer.Compare(Convert.ToInt32(Value), value))
1379     {
1380     writer.WriteResult<int>(comparer.Address, comparer.Value);
1381     }
1382     }
1383 william 526 address_index += STEP_SIZE;
1384 william 521 }
1385     #endregion
1386     } break;
1387     case SearchDataTypes._64bits:
1388     if (unsigned)
1389     {
1390     #region 64bits - unsigned
1391 william 532 var t_data = BitTools.ConvertByteArray<ulong>(data, new Func<bool>(ShouldCancelAnySearchOperation));
1392 william 521 foreach (var Value in t_data)
1393     {
1394     if (SearchWorkerThread.CancellationPending) { break; }
1395 william 526 using (_64bit_unsigned_comparer_ comparer = new _64bit_unsigned_comparer_(SearchArgs, address_index))
1396 william 521 {
1397     ulong value = 0;
1398     if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1399     {
1400     using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1401     {
1402     try
1403     {
1404     gmp.OpenProvider();
1405 william 526 gmp.ReadMemory(address_index, out value);
1406 william 521 gmp.CloseProvider();
1407     }
1408     catch (Exception ex)
1409     {
1410     logger.VerboseError.WriteLine(ex.ToString());
1411     }
1412     }
1413     comparer.Value = value;
1414     }
1415     else
1416     {
1417     value = Convert.ToUInt64(SearchArgs.CompareStartValue);
1418     comparer.Value = value;
1419     }
1420     if (comparer.Compare(Convert.ToUInt64(Value), value))
1421     {
1422     writer.WriteResult<ulong>(comparer.Address, comparer.Value);
1423     }
1424     }
1425 william 526 address_index += STEP_SIZE;
1426 william 521 }
1427     #endregion
1428     }
1429     else
1430     {
1431     #region 64bits - signed
1432 william 532 var t_data = BitTools.ConvertByteArray<long>(data, new Func<bool>(ShouldCancelAnySearchOperation));
1433 william 521 foreach (var Value in t_data)
1434     {
1435     if (SearchWorkerThread.CancellationPending) { break; }
1436 william 526 using (_64bit_signed_comparer_ comparer = new _64bit_signed_comparer_(SearchArgs, address_index))
1437 william 521 {
1438     long value = 0;
1439     if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1440     {
1441     using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1442     {
1443     try
1444     {
1445     gmp.OpenProvider();
1446 william 526 gmp.ReadMemory(address_index, out value);
1447 william 521 gmp.CloseProvider();
1448     }
1449     catch (Exception ex)
1450     {
1451     logger.VerboseError.WriteLine(ex.ToString());
1452     }
1453     }
1454     comparer.Value = value;
1455     }
1456     else
1457     {
1458     value = Convert.ToInt64(SearchArgs.CompareStartValue);
1459     comparer.Value = value;
1460     }
1461     if (comparer.Compare(Convert.ToInt64(Value), value))
1462     {
1463     writer.WriteResult<long>(comparer.Address, comparer.Value);
1464     }
1465     }
1466 william 526 address_index += STEP_SIZE;
1467 william 521 }
1468     #endregion
1469     } break;
1470 william 526
1471 william 521 }
1472     #endregion
1473    
1474     if (SearchWorkerThread.CancellationPending)
1475     {
1476     provider_st.Stop();
1477     st.Stop();
1478     writer.CancelRequest();
1479     writer.Dispose();
1480     writer = null;
1481     e.Result = true;
1482     provider.CloseProvider();
1483     return;
1484     }
1485     }
1486    
1487 william 460 if (SearchWorkerThread.CancellationPending)
1488     {
1489     provider_st.Stop();
1490     st.Stop();
1491     writer.CancelRequest();
1492     writer.Dispose();
1493     writer = null;
1494     e.Result = true;
1495     provider.CloseProvider();
1496     return;
1497     }
1498     writer.Dispose();
1499     writer = null;
1500     provider.CloseProvider();
1501 william 459 }
1502     else
1503     {
1504 william 527 Guid new_SearchGuid = SearchGuid;
1505 william 545 //int Last_Whole_Percent_Done = 0;
1506 william 526 // need to get the address list
1507 william 540 using (SearchResultReader reader = new SearchResultReader(SearchGuid, true)) // delete the file on dispose
1508 william 526 {
1509 william 527 new_SearchGuid = GuidTools.IncrementGuid(SearchGuid);
1510     using (SearchResultWriter writer = new SearchResultWriter(0, new_SearchGuid))
1511     {
1512 william 542 //int index = 0;
1513    
1514 william 545 provider.OpenProvider();
1515     //int count = (int)((MemoryRangeSize - MemoryRangeStart) / STEP_SIZE);
1516     //SearchResultWriter writer = new SearchResultWriter((int)(count), SearchGuid);
1517     int Last_Whole_Percent_Done = 0;
1518 william 546 uint size = 0;
1519     const uint MB_SIZE = 16; /* MEM_1MB * MB_SIZE = MB_SIZE in megabytes */
1520     switch (sdt)
1521     {
1522     case SearchDataTypes._8bits: size = STEP_SIZE * MEM_1MB * (MB_SIZE / BitTools.SizeOf<uint>(sdt)); break;
1523     case SearchDataTypes._16bits: size = STEP_SIZE * MEM_1MB * (MB_SIZE / BitTools.SizeOf<uint>(sdt)); break;
1524     case SearchDataTypes._32bits: size = STEP_SIZE * MEM_1MB * (MB_SIZE / BitTools.SizeOf<uint>(sdt)); break;
1525     case SearchDataTypes._64bits: size = STEP_SIZE * MEM_1MB * (MB_SIZE / BitTools.SizeOf<uint>(sdt)); break;
1526     }
1527     //size = STEP_SIZE * 4096;
1528 william 545 for (uint i = MemoryRangeStart; i < MemoryRangeSize; i += size)
1529 william 527 {
1530 william 545
1531     int bytesRead = 0;
1532     byte[] data = new byte[size];
1533     provider.ReadProcessMemoryAtOnce(i, size, out bytesRead, out data);
1534     string message = string.Format(" -> Reading Address: 0x{0:x8}", (i + MemoryRangeStart));
1535     double double_percent_done = 100.0 * (double)((double)i / (double)MemoryRangeSize);
1536     int int_percent_done = (int)double_percent_done;
1537 william 547 if ((int_percent_done != Last_Whole_Percent_Done))// && (i % 10000) == 0)
1538 william 532 {
1539 william 545 UpdateProgress((int)double_percent_done, message);
1540     Last_Whole_Percent_Done = int_percent_done;
1541 william 532 }
1542 william 545
1543     uint address_index = i;
1544     #region comparison and serialization
1545     switch (sdt)
1546 william 534 {
1547 william 545 case SearchDataTypes._8bits:
1548     if (unsigned)
1549     {
1550     #region 8bits - unsigned
1551     var t_data = data;
1552     foreach (var Value in t_data)
1553     {
1554     if (SearchWorkerThread.CancellationPending) { break; }
1555     using (_8bit_unsigned_comparer_ comparer = new _8bit_unsigned_comparer_(SearchArgs, address_index))
1556     {
1557     byte value = 0;
1558     if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1559     {
1560     using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1561     {
1562     try
1563     {
1564     gmp.OpenProvider();
1565     gmp.ReadMemory(address_index, out value);
1566     gmp.CloseProvider();
1567     }
1568     catch (Exception ex)
1569     {
1570     logger.VerboseError.WriteLine(ex.ToString());
1571     }
1572     }
1573     comparer.Value = value;
1574     }
1575     else
1576     {
1577     value = Convert.ToByte(SearchArgs.CompareStartValue);
1578     comparer.Value = value;
1579     }
1580     if (comparer.Compare(Convert.ToByte(Value), value))
1581     {
1582 william 546 if (reader.ContainsAddress(comparer.Address, SearchArgs.IsUnsignedDataType, SearchArgs.DataType, new Action<int, string>(UpdateProgress), new Func<bool>(ShouldCancelAnySearchOperation)))
1583 william 545 {
1584     writer.WriteResult<byte>(comparer.Address, comparer.Value);
1585     }
1586     }
1587     }
1588     address_index += STEP_SIZE;
1589     }
1590     #endregion
1591     }
1592     else
1593     {
1594     #region 8bits - signed
1595     var t_data = data;
1596     foreach (var Value in t_data)
1597     {
1598     if (SearchWorkerThread.CancellationPending) { break; }
1599     using (_8bit_signed_comparer_ comparer = new _8bit_signed_comparer_(SearchArgs, address_index))
1600     {
1601     sbyte value = 0;
1602     if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1603     {
1604     using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1605     {
1606     try
1607     {
1608     gmp.OpenProvider();
1609     gmp.ReadMemory(address_index, out value);
1610     gmp.CloseProvider();
1611     }
1612     catch (Exception ex)
1613     {
1614     logger.VerboseError.WriteLine(ex.ToString());
1615     }
1616     }
1617     comparer.Value = value;
1618     }
1619     else
1620     {
1621     value = Convert.ToSByte(SearchArgs.CompareStartValue);
1622     comparer.Value = value;
1623     }
1624     if (comparer.Compare(Convert.ToSByte(Value), value))
1625     {
1626 william 546 if (reader.ContainsAddress(comparer.Address, SearchArgs.IsUnsignedDataType, SearchArgs.DataType, new Action<int, string>(UpdateProgress), new Func<bool>(ShouldCancelAnySearchOperation)))
1627 william 545 {
1628     writer.WriteResult<sbyte>(comparer.Address, comparer.Value);
1629     }
1630     }
1631     }
1632     address_index += STEP_SIZE;
1633     }
1634     #endregion
1635     } break;
1636     case SearchDataTypes._16bits:
1637     if (unsigned)
1638     {
1639     #region 16bits - unsigned
1640     var t_data = BitTools.ConvertByteArray<ushort>(data, new Func<bool>(ShouldCancelAnySearchOperation));
1641     foreach (var Value in t_data)
1642     {
1643     if (SearchWorkerThread.CancellationPending) { break; }
1644     using (_16bit_unsigned_comparer_ comparer = new _16bit_unsigned_comparer_(SearchArgs, address_index))
1645     {
1646     ushort value = 0;
1647     if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1648     {
1649     using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1650     {
1651     try
1652     {
1653     gmp.OpenProvider();
1654     gmp.ReadMemory(address_index, out value);
1655     gmp.CloseProvider();
1656     }
1657     catch (Exception ex)
1658     {
1659     logger.VerboseError.WriteLine(ex.ToString());
1660     }
1661     }
1662     comparer.Value = value;
1663     }
1664     else
1665     {
1666     value = Convert.ToUInt16(SearchArgs.CompareStartValue);
1667     comparer.Value = value;
1668     }
1669     if (comparer.Compare(Convert.ToUInt16(Value), value))
1670     {
1671 william 546 if (reader.ContainsAddress(comparer.Address, SearchArgs.IsUnsignedDataType, SearchArgs.DataType, new Action<int, string>(UpdateProgress), new Func<bool>(ShouldCancelAnySearchOperation)))
1672 william 545 {
1673     writer.WriteResult<ushort>(comparer.Address, comparer.Value);
1674     }
1675     }
1676     }
1677     address_index += STEP_SIZE;
1678     }
1679     #endregion
1680     }
1681     else
1682     {
1683     #region 16bits - signed
1684     var t_data = BitTools.ConvertByteArray<short>(data, new Func<bool>(ShouldCancelAnySearchOperation));
1685     foreach (var Value in t_data)
1686     {
1687     if (SearchWorkerThread.CancellationPending) { break; }
1688     using (_16bit_signed_comparer_ comparer = new _16bit_signed_comparer_(SearchArgs, address_index))
1689     {
1690     short value = 0;
1691     if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1692     {
1693     using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1694     {
1695     try
1696     {
1697     gmp.OpenProvider();
1698     gmp.ReadMemory(address_index, out value);
1699     gmp.CloseProvider();
1700     }
1701     catch (Exception ex)
1702     {
1703     logger.VerboseError.WriteLine(ex.ToString());
1704     }
1705     }
1706     comparer.Value = value;
1707     }
1708     else
1709     {
1710     value = Convert.ToInt16(SearchArgs.CompareStartValue);
1711     comparer.Value = value;
1712     }
1713     if (comparer.Compare(Convert.ToSByte(Value), value))
1714     {
1715 william 546 if (reader.ContainsAddress(comparer.Address, SearchArgs.IsUnsignedDataType, SearchArgs.DataType, new Action<int, string>(UpdateProgress), new Func<bool>(ShouldCancelAnySearchOperation)))
1716 william 545 {
1717     writer.WriteResult<short>(comparer.Address, comparer.Value);
1718     }
1719     }
1720     }
1721     address_index += STEP_SIZE;
1722     }
1723     #endregion
1724     } break;
1725     case SearchDataTypes._32bits:
1726     if (unsigned)
1727     {
1728     #region 32bits - unsigned
1729     var t_data = BitTools.ConvertByteArray<uint>(data, new Func<bool>(ShouldCancelAnySearchOperation));
1730     foreach (var Value in t_data)
1731     {
1732     if (SearchWorkerThread.CancellationPending) { break; }
1733     using (_32bit_unsigned_comparer_ comparer = new _32bit_unsigned_comparer_(SearchArgs, address_index))
1734     {
1735     uint value = 0;
1736     if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1737     {
1738     using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1739     {
1740     try
1741     {
1742     gmp.OpenProvider();
1743     gmp.ReadMemory(address_index, out value);
1744     gmp.CloseProvider();
1745     }
1746     catch (Exception ex)
1747     {
1748     logger.VerboseError.WriteLine(ex.ToString());
1749     }
1750     }
1751     comparer.Value = value;
1752     }
1753     else
1754     {
1755     value = Convert.ToUInt32(SearchArgs.CompareStartValue);
1756     comparer.Value = value;
1757     }
1758     if (comparer.Compare(Convert.ToUInt32(Value), value))
1759     {
1760 william 546 if (reader.ContainsAddress(comparer.Address, SearchArgs.IsUnsignedDataType, SearchArgs.DataType, new Action<int, string>(UpdateProgress), new Func<bool>(ShouldCancelAnySearchOperation)))
1761 william 545 {
1762     writer.WriteResult<uint>(comparer.Address, comparer.Value);
1763     }
1764     }
1765     }
1766     address_index += STEP_SIZE;
1767     }
1768     #endregion
1769     }
1770     else
1771     {
1772     #region 32bits - signed
1773     var t_data = BitTools.ConvertByteArray<int>(data, new Func<bool>(ShouldCancelAnySearchOperation));
1774     foreach (var Value in t_data)
1775     {
1776     if (SearchWorkerThread.CancellationPending) { break; }
1777     using (_32bit_signed_comparer_ comparer = new _32bit_signed_comparer_(SearchArgs, address_index))
1778     {
1779     int value = 0;
1780     if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1781     {
1782     using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1783     {
1784     try
1785     {
1786     gmp.OpenProvider();
1787     gmp.ReadMemory(address_index, out value);
1788     gmp.CloseProvider();
1789     }
1790     catch (Exception ex)
1791     {
1792     logger.VerboseError.WriteLine(ex.ToString());
1793     }
1794     }
1795     comparer.Value = value;
1796     }
1797     else
1798     {
1799     value = Convert.ToInt32(SearchArgs.CompareStartValue);
1800     comparer.Value = value;
1801     }
1802     if (comparer.Compare(Convert.ToInt32(Value), value))
1803     {
1804 william 546 if (reader.ContainsAddress(comparer.Address, SearchArgs.IsUnsignedDataType, SearchArgs.DataType, new Action<int, string>(UpdateProgress), new Func<bool>(ShouldCancelAnySearchOperation)))
1805 william 545 {
1806     writer.WriteResult<int>(comparer.Address, comparer.Value);
1807     }
1808     }
1809     }
1810     address_index += STEP_SIZE;
1811     }
1812     #endregion
1813     } break;
1814     case SearchDataTypes._64bits:
1815     if (unsigned)
1816     {
1817     #region 64bits - unsigned
1818     var t_data = BitTools.ConvertByteArray<ulong>(data, new Func<bool>(ShouldCancelAnySearchOperation));
1819     foreach (var Value in t_data)
1820     {
1821     if (SearchWorkerThread.CancellationPending) { break; }
1822     using (_64bit_unsigned_comparer_ comparer = new _64bit_unsigned_comparer_(SearchArgs, address_index))
1823     {
1824     ulong value = 0;
1825     if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1826     {
1827     using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1828     {
1829     try
1830     {
1831     gmp.OpenProvider();
1832     gmp.ReadMemory(address_index, out value);
1833     gmp.CloseProvider();
1834     }
1835     catch (Exception ex)
1836     {
1837     logger.VerboseError.WriteLine(ex.ToString());
1838     }
1839     }
1840     comparer.Value = value;
1841     }
1842     else
1843     {
1844     value = Convert.ToUInt64(SearchArgs.CompareStartValue);
1845     comparer.Value = value;
1846     }
1847     if (comparer.Compare(Convert.ToUInt64(Value), value))
1848     {
1849 william 546 if (reader.ContainsAddress(comparer.Address, SearchArgs.IsUnsignedDataType, SearchArgs.DataType, new Action<int, string>(UpdateProgress), new Func<bool>(ShouldCancelAnySearchOperation)))
1850 william 545 {
1851     writer.WriteResult<ulong>(comparer.Address, comparer.Value);
1852     }
1853     }
1854     }
1855     address_index += STEP_SIZE;
1856     }
1857     #endregion
1858     }
1859     else
1860     {
1861     #region 64bits - signed
1862     var t_data = BitTools.ConvertByteArray<long>(data, new Func<bool>(ShouldCancelAnySearchOperation));
1863     foreach (var Value in t_data)
1864     {
1865     if (SearchWorkerThread.CancellationPending) { break; }
1866     using (_64bit_signed_comparer_ comparer = new _64bit_signed_comparer_(SearchArgs, address_index))
1867     {
1868     long value = 0;
1869     if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1870     {
1871     using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1872     {
1873     try
1874     {
1875     gmp.OpenProvider();
1876     gmp.ReadMemory(address_index, out value);
1877     gmp.CloseProvider();
1878     }
1879     catch (Exception ex)
1880     {
1881     logger.VerboseError.WriteLine(ex.ToString());
1882     }
1883     }
1884     comparer.Value = value;
1885     }
1886     else
1887     {
1888     value = Convert.ToInt64(SearchArgs.CompareStartValue);
1889     comparer.Value = value;
1890     }
1891     if (comparer.Compare(Convert.ToInt64(Value), value))
1892     {
1893 william 546 if (reader.ContainsAddress(comparer.Address, SearchArgs.IsUnsignedDataType, SearchArgs.DataType, new Action<int, string>(UpdateProgress), new Func<bool>(ShouldCancelAnySearchOperation)))
1894 william 545 {
1895     writer.WriteResult<long>(comparer.Address, comparer.Value);
1896     }
1897     }
1898     }
1899     address_index += STEP_SIZE;
1900     }
1901     #endregion
1902     } break;
1903 william 530
1904 william 544 }
1905 william 545 #endregion
1906 william 544
1907     if (SearchWorkerThread.CancellationPending)
1908     {
1909     provider_st.Stop();
1910     st.Stop();
1911     writer.CancelRequest();
1912     writer.Dispose();
1913     e.Result = true;
1914 william 545 provider.CloseProvider();
1915     return;
1916 william 544 }
1917 william 460 }
1918 william 545 #region old-code2
1919     //const int ChunkCount = 0x100;
1920     //for (int ResultIndex = 0; ResultIndex < reader.ResultCount; ResultIndex += ChunkCount)
1921     //{
1922     // StructResultType<ulong>[] ChunkResults = new StructResultType<ulong>[ChunkCount];
1923     // for (int ChunkIndex = 0; ChunkIndex < ChunkCount; ChunkIndex++)
1924     // {
1925     // int ResultChunkIndex = (ResultIndex + ChunkIndex);
1926     // StructResultType<ulong> result = StructResultType<ulong>.Empty;
1927     // reader.GetResultAtIndex(ResultChunkIndex, SearchArgs.IsUnsignedDataType, SearchArgs.DataType, new Action<int, string>(UpdateProgress), out result, new Func<bool>(ShouldCancelAnySearchOperation));
1928     // ChunkResults[ChunkIndex] = result;
1929     // if (SearchWorkerThread.CancellationPending)
1930     // {
1931     // provider_st.Stop();
1932     // st.Stop();
1933     // writer.CancelRequest();
1934     // writer.Dispose();
1935     // e.Result = true;
1936     // break;
1937     // }
1938     // }
1939     // // Get update value(s) for each chunk result
1940     // ISerializedResult sr = (reader as ISerializedResult);
1941     // if(sr == null)
1942     // {
1943     // throw new ArgumentNullException("sr",string.Format("Unable to cast: '{0}' to '{1}'", reader.GetType().Name,typeof(ISerializedResult).Name));
1944     // }
1945     // Stopwatch st_memory_results_updater = new Stopwatch();
1946     // st_memory_results_updater.Start();
1947     // sr.UpdateResultValuesFromMemory(ref ChunkResults, SearchArgs.IsUnsignedDataType, SearchArgs.DataType, new Action<int, string>(UpdateProgress), new Func<bool>(ShouldCancelAnySearchOperation), (IAcceptsProcessAndConfig)this);
1948     // if (SearchWorkerThread.CancellationPending) // catch a cancelled operation from UpdateResultValuesFromMemory
1949     // {
1950     // provider_st.Stop();
1951     // st.Stop();
1952     // writer.CancelRequest();
1953     // writer.Dispose();
1954     // e.Result = true;
1955     // break;
1956     // }
1957     // st_memory_results_updater.Stop();
1958     // logger.Profiler.WriteLine("sr.UpdateResultValuesFromMemory [ResultIndex=0x{0} ChunkCount=0x{1}] took a total of {2} seconds to complete", ResultIndex.ToString("X"), ChunkCount.ToString("X"), st_memory_results_updater.Elapsed.TotalSeconds.ToString());
1959     // // ChunkResults should have had thier values updated from memory
1960     // string message = string.Format(" -> Updateing Values [ResultIndex=0x{0} of Total=0x{1}]", ResultIndex.ToString("X"), reader.ResultCount.ToString("X"));
1961     // double double_percent_done = 100.0 * (double)((double)ResultIndex / (double)reader.ResultCount);
1962     // int int_percent_done = (int)double_percent_done;
1963     // //if ((int_percent_done != Last_Whole_Percent_Done) && (index % 1000) == 0)
1964     // //{
1965     // // UpdateProgress((int)double_percent_done, message);
1966     // // Last_Whole_Percent_Done = int_percent_done;
1967     // //}
1968     // if (((double)ResultIndex % ((double)reader.ResultCount) * 0.25) == 0)
1969     // //if ((ResultIndex % 10000) == 0)
1970     // {
1971     // UpdateProgress((int)double_percent_done, message);
1972     // Last_Whole_Percent_Done = int_percent_done;
1973     // }
1974     // if (SearchWorkerThread.CancellationPending)
1975     // {
1976     // provider_st.Stop();
1977     // st.Stop();
1978     // writer.CancelRequest();
1979     // writer.Dispose();
1980     // e.Result = true;
1981     // break;
1982     // }
1983     //}
1984     #endregion
1985 william 496
1986 william 545 #region old-code1
1987 william 542 //foreach (var k in reader.GetResults(SearchArgs.IsUnsignedDataType, SearchArgs.DataType, new Action<int, string>(UpdateProgress), new Func<bool>(ShouldCancelAnySearchOperation)))
1988     //{
1989     // if (SearchWorkerThread.CancellationPending)
1990     // {
1991     // provider_st.Stop();
1992     // st.Stop();
1993     // writer.CancelRequest();
1994     // writer.Dispose();
1995     // e.Result = true;
1996     // return;
1997     // }
1998     // //int Last_Whole_Percent_Done = 0;
1999     // provider.OpenProvider();
2000     // int bytesRead = 0;
2001     // byte[] data = new byte[STEP_SIZE];
2002     // provider.ReadProcessMemory(k.Address, STEP_SIZE, out bytesRead, out data);
2003     // provider.CloseProvider();
2004     // if (SearchWorkerThread.CancellationPending)
2005     // {
2006     // provider_st.Stop();
2007     // st.Stop();
2008     // writer.CancelRequest();
2009     // writer.Dispose();
2010     // e.Result = true;
2011     // return;
2012     // }
2013     // uint address_index = k.Address;
2014     // string message = string.Format(" -> Reading Address 0x{0:x8} from index 0x{1}", k.Address, index.ToString("X"));
2015     // double double_percent_done = 100.0 * (double)((double)index / (double)reader.ResultCount);
2016     // int int_percent_done = (int)double_percent_done;
2017     // //if ((int_percent_done != Last_Whole_Percent_Done) && (index % 1000) == 0)
2018     // //{
2019     // // UpdateProgress((int)double_percent_done, message);
2020     // // Last_Whole_Percent_Done = int_percent_done;
2021     // //}
2022     // if ((index % 10000) == 0)
2023     // {
2024     // UpdateProgress((int)double_percent_done, message);
2025     // //Last_Whole_Percent_Done = int_percent_done;
2026     // }
2027     // #region comparison and serialization
2028     // switch (sdt)
2029     // {
2030     // case SearchDataTypes._8bits:
2031     // if (unsigned)
2032     // {
2033     // #region 8bits - unsigned
2034     // var t_data = data;
2035     // foreach (var Value in t_data)
2036     // {
2037     // if (SearchWorkerThread.CancellationPending) { break; }
2038     // using (_8bit_unsigned_comparer_ comparer = new _8bit_unsigned_comparer_(SearchArgs, address_index))
2039     // {
2040     // byte value = 0;
2041     // if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2042     // {
2043     // using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2044     // {
2045     // try
2046     // {
2047     // gmp.OpenProvider();
2048     // gmp.ReadMemory(address_index, out value);
2049     // gmp.CloseProvider();
2050     // }
2051     // catch (Exception ex)
2052     // {
2053     // logger.VerboseError.WriteLine(ex.ToString());
2054     // }
2055     // }
2056     // comparer.Value = value;
2057     // }
2058     // else
2059     // {
2060     // value = Convert.ToByte(SearchArgs.CompareStartValue);
2061     // comparer.Value = value;
2062     // }
2063     // if (comparer.Compare(Convert.ToByte(Value), value))
2064     // {
2065     // writer.WriteResult<byte>(comparer.Address, comparer.Value);
2066     // }
2067     // }
2068     // address_index += STEP_SIZE;
2069     // }
2070     // #endregion
2071     // }
2072     // else
2073     // {
2074     // #region 8bits - signed
2075     // var t_data = data;
2076     // foreach (var Value in t_data)
2077     // {
2078     // if (SearchWorkerThread.CancellationPending) { break; }
2079     // using (_8bit_signed_comparer_ comparer = new _8bit_signed_comparer_(SearchArgs, address_index))
2080     // {
2081     // sbyte value = 0;
2082     // if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2083     // {
2084     // using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2085     // {
2086     // try
2087     // {
2088     // gmp.OpenProvider();
2089     // gmp.ReadMemory(address_index, out value);
2090     // gmp.CloseProvider();
2091     // }
2092     // catch (Exception ex)
2093     // {
2094     // logger.VerboseError.WriteLine(ex.ToString());
2095     // }
2096     // }
2097     // comparer.Value = value;
2098     // }
2099     // else
2100     // {
2101     // value = Convert.ToSByte(SearchArgs.CompareStartValue);
2102     // comparer.Value = value;
2103     // }
2104     // if (comparer.Compare(Convert.ToSByte(Value), value))
2105     // {
2106     // writer.WriteResult<sbyte>(comparer.Address, comparer.Value);
2107     // }
2108     // }
2109     // address_index += STEP_SIZE;
2110     // }
2111     // #endregion
2112     // } break;
2113     // case SearchDataTypes._16bits:
2114     // if (unsigned)
2115     // {
2116     // #region 16bits - unsigned
2117     // var t_data = BitTools.ConvertByteArray<ushort>(data, new Func<bool>(ShouldCancelAnySearchOperation));
2118     // foreach (var Value in t_data)
2119     // {
2120     // if (SearchWorkerThread.CancellationPending) { break; }
2121     // using (_16bit_unsigned_comparer_ comparer = new _16bit_unsigned_comparer_(SearchArgs, address_index))
2122     // {
2123     // ushort value = 0;
2124     // if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2125     // {
2126     // using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2127     // {
2128     // try
2129     // {
2130     // gmp.OpenProvider();
2131     // gmp.ReadMemory(address_index, out value);
2132     // gmp.CloseProvider();
2133     // }
2134     // catch (Exception ex)
2135     // {
2136     // logger.VerboseError.WriteLine(ex.ToString());
2137     // }
2138     // }
2139     // comparer.Value = value;
2140     // }
2141     // else
2142     // {
2143     // value = Convert.ToUInt16(SearchArgs.CompareStartValue);
2144     // comparer.Value = value;
2145     // }
2146     // if (comparer.Compare(Convert.ToUInt16(Value), value))
2147     // {
2148     // writer.WriteResult<ushort>(comparer.Address, comparer.Value);
2149     // }
2150     // }
2151     // address_index += STEP_SIZE;
2152     // }
2153     // #endregion
2154     // }
2155     // else
2156     // {
2157     // #region 16bits - signed
2158     // var t_data = BitTools.ConvertByteArray<short>(data, new Func<bool>(ShouldCancelAnySearchOperation));
2159     // foreach (var Value in t_data)
2160     // {
2161     // if (SearchWorkerThread.CancellationPending) { break; }
2162     // using (_16bit_signed_comparer_ comparer = new _16bit_signed_comparer_(SearchArgs, address_index))
2163     // {
2164     // short value = 0;
2165     // if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2166     // {
2167     // using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2168     // {
2169     // try
2170     // {
2171     // gmp.OpenProvider();
2172     // gmp.ReadMemory(address_index, out value);
2173     // gmp.CloseProvider();
2174     // }
2175     // catch (Exception ex)
2176     // {
2177     // logger.VerboseError.WriteLine(ex.ToString());
2178     // }
2179     // }
2180     // comparer.Value = value;
2181     // }
2182     // else
2183     // {
2184     // value = Convert.ToInt16(SearchArgs.CompareStartValue);
2185     // comparer.Value = value;
2186     // }
2187     // if (comparer.Compare(Convert.ToSByte(Value), value))
2188     // {
2189     // writer.WriteResult<short>(comparer.Address, comparer.Value);
2190     // }
2191     // }
2192     // address_index += STEP_SIZE;
2193     // }
2194     // #endregion
2195     // } break;
2196     // case SearchDataTypes._32bits:
2197     // if (unsigned)
2198     // {
2199     // #region 32bits - unsigned
2200     // var t_data = BitTools.ConvertByteArray<uint>(data, new Func<bool>(ShouldCancelAnySearchOperation));
2201     // foreach (var Value in t_data)
2202     // {
2203     // if (SearchWorkerThread.CancellationPending) { break; }
2204     // using (_32bit_unsigned_comparer_ comparer = new _32bit_unsigned_comparer_(SearchArgs, address_index))
2205     // {
2206     // uint value = 0;
2207     // if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2208     // {
2209     // using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2210     // {
2211     // try
2212     // {
2213     // gmp.OpenProvider();
2214     // gmp.ReadMemory(address_index, out value);
2215     // gmp.CloseProvider();
2216     // }
2217     // catch (Exception ex)
2218     // {
2219     // logger.VerboseError.WriteLine(ex.ToString());
2220     // }
2221     // }
2222     // comparer.Value = value;
2223     // }
2224     // else
2225     // {
2226     // value = Convert.ToUInt32(SearchArgs.CompareStartValue);
2227     // comparer.Value = value;
2228     // }
2229     // if (comparer.Compare(Convert.ToUInt32(Value), value))
2230     // {
2231     // writer.WriteResult<uint>(comparer.Address, comparer.Value);
2232     // }
2233     // }
2234     // address_index += STEP_SIZE;
2235     // }
2236     // #endregion
2237     // }
2238     // else
2239     // {
2240     // #region 32bits - signed
2241     // var t_data = BitTools.ConvertByteArray<int>(data, new Func<bool>(ShouldCancelAnySearchOperation));
2242     // foreach (var Value in t_data)
2243     // {
2244     // if (SearchWorkerThread.CancellationPending) { break; }
2245     // using (_32bit_signed_comparer_ comparer = new _32bit_signed_comparer_(SearchArgs, address_index))
2246     // {
2247     // int value = 0;
2248     // if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2249     // {
2250     // using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2251     // {
2252     // try
2253     // {
2254     // gmp.OpenProvider();
2255     // gmp.ReadMemory(address_index, out value);
2256     // gmp.CloseProvider();
2257     // }
2258     // catch (Exception ex)
2259     // {
2260     // logger.VerboseError.WriteLine(ex.ToString());
2261     // }
2262     // }
2263     // comparer.Value = value;
2264     // }
2265     // else
2266     // {
2267     // value = Convert.ToInt32(SearchArgs.CompareStartValue);
2268     // comparer.Value = value;
2269     // }
2270     // if (comparer.Compare(Convert.ToInt32(Value), value))
2271     // {
2272     // writer.WriteResult<int>(comparer.Address, comparer.Value);
2273     // }
2274     // }
2275     // address_index += STEP_SIZE;
2276     // }
2277     // #endregion
2278     // } break;
2279     // case SearchDataTypes._64bits:
2280     // if (unsigned)
2281     // {
2282     // #region 64bits - unsigned
2283     // var t_data = BitTools.ConvertByteArray<ulong>(data, new Func<bool>(ShouldCancelAnySearchOperation));
2284     // foreach (var Value in t_data)
2285     // {
2286     // if (SearchWorkerThread.CancellationPending) { break; }
2287     // using (_64bit_unsigned_comparer_ comparer = new _64bit_unsigned_comparer_(SearchArgs, address_index))
2288     // {
2289     // ulong value = 0;
2290     // if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2291     // {
2292     // using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2293     // {
2294     // try
2295     // {
2296     // gmp.OpenProvider();
2297     // gmp.ReadMemory(address_index, out value);
2298     // gmp.CloseProvider();
2299     // }
2300     // catch (Exception ex)
2301     // {
2302     // logger.VerboseError.WriteLine(ex.ToString());
2303     // }
2304     // }
2305     // comparer.Value = value;
2306     // }
2307     // else
2308     // {
2309     // value = Convert.ToUInt64(SearchArgs.CompareStartValue);
2310     // comparer.Value = value;
2311     // }
2312     // if (comparer.Compare(Convert.ToUInt64(Value), value))
2313     // {
2314     // writer.WriteResult<ulong>(comparer.Address, comparer.Value);
2315     // }
2316     // }
2317     // address_index += STEP_SIZE;
2318     // }
2319     // #endregion
2320     // }
2321     // else
2322     // {
2323     // #region 64bits - signed
2324     // var t_data = BitTools.ConvertByteArray<long>(data, new Func<bool>(ShouldCancelAnySearchOperation));
2325     // foreach (var Value in t_data)
2326     // {
2327     // if (SearchWorkerThread.CancellationPending) { break; }
2328     // using (_64bit_signed_comparer_ comparer = new _64bit_signed_comparer_(SearchArgs, address_index))
2329     // {
2330     // long value = 0;
2331     // if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2332     // {
2333     // using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2334     // {
2335     // try
2336     // {
2337     // gmp.OpenProvider();
2338     // gmp.ReadMemory(address_index, out value);
2339     // gmp.CloseProvider();
2340     // }
2341     // catch (Exception ex)
2342     // {
2343     // logger.VerboseError.WriteLine(ex.ToString());
2344     // }
2345     // }
2346     // comparer.Value = value;
2347     // }
2348     // else
2349     // {
2350     // value = Convert.ToInt64(SearchArgs.CompareStartValue);
2351     // comparer.Value = value;
2352     // }
2353     // if (comparer.Compare(Convert.ToInt64(Value), value))
2354     // {
2355     // writer.WriteResult<long>(comparer.Address, comparer.Value);
2356     // }
2357     // }
2358     // address_index += STEP_SIZE;
2359     // }
2360     // #endregion
2361     // } break;
2362     // }
2363     // #endregion
2364     // index++;
2365     //}
2366     #endregion
2367 william 496
2368 william 545 #region reference-code (can be deleted - later)
2369 william 527 //ISerializedResult sr = (reader as ISerializedResult);
2370     //if (sr == null)
2371     //{
2372     // throw new ArgumentNullException("sr", string.Format("Unable to cast: '{0}' to '{1}'", reader.GetType().Name, typeof(ISerializedResult).Name));
2373