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

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

Parent Directory Parent Directory | Revision Log Revision Log


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