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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 814 - (hide annotations) (download)
Tue Apr 15 15:58:50 2014 UTC (7 years ago) by william
File size: 161065 byte(s)

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