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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 533 - (show annotations) (download)
Wed Jun 5 09:09:08 2013 UTC (7 years, 4 months ago) by william
File size: 229597 byte(s)

1 #region Logging Defines
2 // include this any class or method that required logging, and comment-out what is not needed
3
4 #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 #if !USE_AUTOMATIC_MEMORY_SEARCH_RANGE
16 #define FORCE_USE_OF_MEMORYSIZECONSTANTS // when defined wil force the use of the constants defined in MemorySizeConstants for memory search range
17 #endif
18 #define DONOT_HAVE_RANGED_SEARCH_SUPPORT // when defined, indicates that ranged searches have not been implemented
19 #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 using System;
22 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 using RomCheater.Docking.MemorySearch;
33 using libWin32.Win32.Threading;
34 using System.Threading;
35 using RomCheater.Logging;
36 using System.IO;
37 using Sojaner.MemoryScanner.MemoryProviers;
38 using RomCheater.PluginFramework.Events;
39 using System.Reflection;
40 using Sojaner.MemoryScanner;
41 using System.Collections;
42 using RomCheater.Serialization;
43 using RomCheater.Core;
44
45 namespace RomCheater.Docking
46 {
47 public partial class FloatingMemorySearcher : DockContent,
48 IAcceptsPlugin<IConfigPlugin>,
49 IAcceptsProcess<Process>,
50 IAcceptsProcessAndConfig,
51 ISearchInProgress,
52 IAcceptsBrowseMemoryRegion,
53 IAcceptsMemoryRange
54 {
55 #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 const bool USE_OLD_SEARCH_RESULTS_COMPRATOR_CODE = false;
62 const bool USE_NONRANGE_SEARCH_RESULT_READER = false;
63 private bool DefaultUnsignedState = true; // set unsigned to true
64 public FloatingMemorySearcher() { InitializeComponent(); this.AcceptedPlugin = null; OnBrowseMemoryRegion = null; this.AcceptedProcess = null; SearchInProgess = false; Reload(); }
65 public FloatingMemorySearcher(IConfigPlugin config) : this() { this.AcceptedPlugin = config; }
66 public FloatingMemorySearcher(IConfigPlugin config, Process process) : this() { this.AcceptedPlugin = config; this.AcceptedProcess = process; }
67
68 //new Action<int, string>(UpdateProgress) to use this as a delegate
69
70 private void thread_UpdateProgress(object o)
71 {
72 IProgressMessage pm = (o as IProgressMessage);
73 if (pm == null) { return; }
74 resultsprogress.Value = pm.Progress;
75 resultsprogress.Message = pm.Message;
76 }
77
78 private bool ShouldCancelAnySearchOperation() { return SearchWorkerThread.CancellationPending; }
79
80 private void UpdateProgress(int progress, string message)
81 {
82 // 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 t.SetApartmentState(ApartmentState.STA);
85 t.Start(new ProgressMessage(progress, message));
86 //resultsprogress.Value = progress;
87 //resultsprogress.Message = message;
88 }
89
90 #region IAcceptsProcess<Process> Members
91 private Process _AcceptedProcess;
92 public Process AcceptedProcess { get { return _AcceptedProcess; } set { _AcceptedProcess = value; UpdateAcceptedProcess(value); } }
93 #endregion
94 #region IAcceptsPlugin<IConfigPlugin> Members
95 private IConfigPlugin _AcceptedPlugin;
96 public IConfigPlugin AcceptedPlugin { get { return _AcceptedPlugin; } set { _AcceptedPlugin = value; UpdateAcceptedPlugin(value); } }
97 #endregion
98 #region IAcceptsBrowseMemoryRegion members
99 public event BaseEventHandler<BrowseMemoryRegionEvent> OnBrowseMemoryRegion;
100 #endregion
101
102 private void UpdateAcceptedPlugin(IConfigPlugin config)
103 {
104 this.lstResults.AcceptedPlugin = config;
105 this.lstPatchList.AcceptedPlugin = config;
106 if (config != null)
107 {
108 MemoryRangeStart = AcceptedPlugin.MemoryRangeStart;
109 MemoryRangeSize = AcceptedPlugin.MemoryRangeStart + AcceptedPlugin.MemoryRangeSize;
110 }
111 }
112 private void UpdateAcceptedProcess(Process process)
113 {
114 this.lstResults.AcceptedProcess = process;
115 this.lstPatchList.AcceptedProcess = process;
116 #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 #endif
121 #if FORCE_USE_OF_MEMORYSIZECONSTANTS
122 // force use of MemorySizeConstants
123 txtMemoryRangeStart.Value = MemorySizeConstants.MinimumSearchAddress;
124 txtMemoryRangeSize.Value = MemorySizeConstants.MinimumSearchAddress + MemorySizeConstants.MaximumSearchSize;
125 #endif
126 #if USE_AUTOMATIC_MEMORY_SEARCH_RANGE && !FORCE_USE_OF_MEMORYSIZECONSTANTS
127 ////// 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 //txtMemoryRangeStart.Value = MemorySizeConstants.MinimumSearchAddress;
137 //txtMemoryRangeSize.Value = MemorySizeConstants.MinimumSearchAddress + MemorySizeConstants.MaximumSearchSize;
138 //}
139 if (AcceptedPlugin != null)
140 {
141 MemoryRangeStart = AcceptedPlugin.MemoryRangeStart;
142 MemoryRangeSize = AcceptedPlugin.MemoryRangeStart + AcceptedPlugin.MemoryRangeSize;
143 }
144
145 #endif
146
147 }
148 #region ISearchInProgress members
149 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 private Guid _SearchGuid;
161 public Guid SearchGuid
162 {
163 get { return _SearchGuid; }
164 private set { _SearchGuid = value; }
165 }
166 #endregion
167
168 #region IAcceptsMemoryRange
169 #if !FORCE_USE_OF_MEMORYSIZECONSTANTS
170 private uint _MemoryRangeStart;
171 private uint _MemoryRangeSize;
172 #endif
173 public uint MemoryRangeStart
174 {
175 get
176 {
177 #if FORCE_USE_OF_MEMORYSIZECONSTANTS
178 return MemorySizeConstants.MinimumSearchAddress;
179 #else
180 return _MemoryRangeStart;
181 #endif
182 }
183 set
184 {
185 #if !FORCE_USE_OF_MEMORYSIZECONSTANTS
186 _MemoryRangeStart = value;
187 txtMemoryRangeStart.Value = value;
188 #endif
189 }
190 }
191 public uint MemoryRangeSize
192 {
193 get
194 {
195 #if FORCE_USE_OF_MEMORYSIZECONSTANTS
196 return MemorySizeConstants.MinimumSearchAddress + MemorySizeConstants.MaximumSearchSize;
197 #else
198 return _MemoryRangeSize;
199 #endif
200 }
201 set
202 {
203 #if !FORCE_USE_OF_MEMORYSIZECONSTANTS
204 _MemoryRangeSize = value;
205 txtMemoryRangeSize.Value = value;
206 #endif
207 }
208 }
209 #endregion
210
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 chkRefreshResults.Checked = true;
218 }
219 public enum eListViewResults
220 {
221 SEARCH_RESULTS_LIST = 0x3000,
222 PATCH_RESULTS_LIST = 0x3001,
223 UKNOWN_RESULTS_LIST = 0x3001
224 }
225 bool IsFirstSearch = true;
226 SearchType SearchArgs;
227 static int col_Found_Address = 1;
228 static int col_Found_Value = 2;
229 //static int col_Found_Frozen = 3; /* unused */
230 static int col_Added_Address = 1;
231 static int col_Added_Value = 2;
232 //static int col_Added_Frozen = 3; /* unused */
233 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 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 private bool ShouldUpdateResults()
436 {
437 if (this.AcceptedProcess == null) return false;
438 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 if (Process.GetProcessById(this.AcceptedProcess.Id) == null) return false;
444 if (lstResults.Items.Count > 0) return true;
445 if (lstPatchList.Items.Count > 0) return true;
446 return false;
447 }
448 private void ResultsUpdateWorkerThread_DoWork(object sender, DoWorkEventArgs e)
449 {
450 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
461 #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 int Address = 0;
487 ResultDataType _result = (ResultDataType)ResultItems[i].Tag;
488
489 Address = Convert.ToInt32(ResultItems[i].SubItems[col_Found_Address].Text, 16);
490 //r_ms.BaseStream.Seek(Address, SeekOrigin.Begin);
491 using (GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
492 {
493 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 provider.CloseProvider();
540 }
541 //Application.DoEvents();
542 }
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 int Address = 0;
571 ResultDataType _result = (ResultDataType)AddedItems[i].Tag;
572 Address = Convert.ToInt32(AddedItems[i].SubItems[col_Added_Address].Text, 16);
573 using (GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
574 {
575 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 provider.CloseProvider();
596 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 }
623 //Application.DoEvents();
624 }
625 #endregion
626
627
628 }
629
630 private void ResultsUpdateWorkerThread_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
631 {
632 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
642 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 }
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 if (this.AcceptedProcess != null)
692 {
693 #if !DO_NOT_SUSPEND_RESUME_THREAD_ON_FREEZE
694 ThreadControl.ResumeProcess(this.AcceptedProcess.Id);
695 #endif
696 }
697 }
698
699 private void FreezeResultsUpdate()
700 {
701 this.IsResultsUpdateFrozen = true;
702 //this.IsResultsUpdateFrozen = false;
703 if (this.AcceptedProcess != null)
704 {
705 #if !DO_NOT_SUSPEND_RESUME_THREAD_ON_FREEZE
706 ThreadControl.SuspendProcess(this.AcceptedProcess.Id);
707 #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 PatchAdder adder = new PatchAdder((IAcceptsProcessAndConfig)this);
764 adder.ShowDialog();
765 if (adder.WasAPatchAdded) AddToPatchList(adder.AddedPatchValue);
766 }
767
768 private void btnAddAddressRange_Click(object sender, EventArgs e)
769 {
770 PatchRangeAdder adder = new PatchRangeAdder((IAcceptsProcessAndConfig)this);
771 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 ResultItemState state = new ResultItemState(address, bitsize, IsUnsigned, (IAcceptsProcessAndConfig)this);
824 ResultItem item = new ResultItem(state.Address, state.Value, state.Frozen, state.ValueType, state.IsUnsigned);
825 this.AddToPatchList(item);
826 }
827
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 patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
905 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 patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
916 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 patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
929 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 patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
940 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 patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
953 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 patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
964 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 patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
977 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 patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
988 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 SearchRangePatcher rangePatcher = new SearchRangePatcher((IAcceptsProcessAndConfig)this, patch_list);
1010 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 lstPatchList.ProcessID = this.AcceptedProcess.Id;
1034 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 lstPatchList.ProcessID = this.AcceptedProcess.Id;
1056 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
1071 #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 #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
1464 // 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
1774 private void SearchWorkerThread_DoWork(object sender, DoWorkEventArgs e)
1775 {
1776 try
1777 {
1778 Stopwatch st = new Stopwatch();
1779 st.Start();
1780
1781 Stopwatch st_first_search = new Stopwatch();
1782 Stopwatch st_nonrange_search = new Stopwatch();
1783 Stopwatch st_ranged_search = new Stopwatch();
1784
1785 e.Result = st;
1786 //List<ResultType<object>> tmp_Results = new List<ResultType<object>>();
1787 List<ResultType<ulong>> second_tmp_Results = new List<ResultType<ulong>>();
1788 //const int ElementsBeforeDisplay = 100;
1789 SearchArgs.LogSearchOptions();
1790 uint STEP_SIZE = (uint)SearchArgs.DataType / 8;
1791
1792 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 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 Stopwatch provider_st = new Stopwatch();
1799 provider_st.Start();
1800 using (GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1801 {
1802
1803 if (SearchArgs.IsFirstSearch)
1804 {
1805 provider.OpenProvider();
1806 int count = (int)((MemoryRangeSize - MemoryRangeStart) / STEP_SIZE);
1807 SearchResultWriter writer = new SearchResultWriter((int)(count), SearchGuid);
1808 int Last_Whole_Percent_Done = 0;
1809 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 int int_percent_done = (int)double_percent_done;
1819 if ( (int_percent_done != Last_Whole_Percent_Done) && (i % 10000) == 0)
1820 {
1821 UpdateProgress((int)double_percent_done, message);
1822 Last_Whole_Percent_Done = int_percent_done;
1823 }
1824
1825 uint address_index = i;
1826 #region comparison and serialization
1827 switch (sdt)
1828 {
1829 case SearchDataTypes._8bits:
1830 if (unsigned)
1831 {
1832 #region 8bits - unsigned
1833 var t_data = BitTools.ConvertByteArray<byte>(data, new Func<bool>(ShouldCancelAnySearchOperation));
1834 foreach (var Value in t_data)
1835 {
1836 if (SearchWorkerThread.CancellationPending) { break; }
1837 using (_8bit_unsigned_comparer_ comparer = new _8bit_unsigned_comparer_(SearchArgs, address_index))
1838 {
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 gmp.ReadMemory(address_index, out value);
1848 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 address_index += STEP_SIZE;
1868 }
1869 #endregion
1870 }
1871 else
1872 {
1873 #region 8bits - signed
1874 var t_data = BitTools.ConvertByteArray<sbyte>(data, new Func<bool>(ShouldCancelAnySearchOperation));
1875 foreach (var Value in t_data)
1876 {
1877 if (SearchWorkerThread.CancellationPending) { break; }
1878 using (_8bit_signed_comparer_ comparer = new _8bit_signed_comparer_(SearchArgs, address_index))
1879 {
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 gmp.ReadMemory(address_index, out value);
1889 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 address_index += STEP_SIZE;
1909 }
1910 #endregion
1911 } break;
1912 case SearchDataTypes._16bits:
1913 if (unsigned)
1914 {
1915 #region 16bits - unsigned
1916 var t_data = BitTools.ConvertByteArray<ushort>(data, new Func<bool>(ShouldCancelAnySearchOperation));
1917 foreach (var Value in t_data)
1918 {
1919 if (SearchWorkerThread.CancellationPending) { break; }
1920 using (_16bit_unsigned_comparer_ comparer = new _16bit_unsigned_comparer_(SearchArgs, address_index))
1921 {
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 gmp.ReadMemory(address_index, out value);
1931 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 address_index += STEP_SIZE;
1951 }
1952 #endregion
1953 }
1954 else
1955 {
1956 #region 16bits - signed
1957 var t_data = BitTools.ConvertByteArray<short>(data, new Func<bool>(ShouldCancelAnySearchOperation));
1958 foreach (var Value in t_data)
1959 {
1960 if (SearchWorkerThread.CancellationPending) { break; }
1961 using (_16bit_signed_comparer_ comparer = new _16bit_signed_comparer_(SearchArgs, address_index))
1962 {
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 gmp.ReadMemory(address_index, out value);
1972 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 address_index += STEP_SIZE;
1992 }
1993 #endregion
1994 } break;
1995 case SearchDataTypes._32bits:
1996 if (unsigned)
1997 {
1998 #region 32bits - unsigned
1999 var t_data = BitTools.ConvertByteArray<uint>(data, new Func<bool>(ShouldCancelAnySearchOperation));
2000 foreach (var Value in t_data)
2001 {
2002 if (SearchWorkerThread.CancellationPending) { break; }
2003 using (_32bit_unsigned_comparer_ comparer = new _32bit_unsigned_comparer_(SearchArgs, address_index))
2004 {
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 gmp.ReadMemory(address_index, out value);
2014 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 address_index += STEP_SIZE;
2034 }
2035 #endregion
2036 }
2037 else
2038 {
2039 #region 32bits - signed
2040 var t_data = BitTools.ConvertByteArray<int>(data, new Func<bool>(ShouldCancelAnySearchOperation));
2041 foreach (var Value in t_data)
2042 {
2043 if (SearchWorkerThread.CancellationPending) { break; }
2044 using (_32bit_signed_comparer_ comparer = new _32bit_signed_comparer_(SearchArgs, address_index))
2045 {
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 gmp.ReadMemory(address_index, out value);
2055 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 address_index += STEP_SIZE;
2075 }
2076 #endregion
2077 } break;
2078 case SearchDataTypes._64bits:
2079 if (unsigned)
2080 {
2081 #region 64bits - unsigned
2082 var t_data = BitTools.ConvertByteArray<ulong>(data, new Func<bool>(ShouldCancelAnySearchOperation));
2083 foreach (var Value in t_data)
2084 {
2085 if (SearchWorkerThread.CancellationPending) { break; }
2086 using (_64bit_unsigned_comparer_ comparer = new _64bit_unsigned_comparer_(SearchArgs, address_index))
2087 {
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 gmp.ReadMemory(address_index, out value);
2097 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 address_index += STEP_SIZE;
2117 }
2118 #endregion
2119 }
2120 else
2121 {
2122 #region 64bits - signed
2123 var t_data = BitTools.ConvertByteArray<long>(data, new Func<bool>(ShouldCancelAnySearchOperation));
2124 foreach (var Value in t_data)
2125 {
2126 if (SearchWorkerThread.CancellationPending) { break; }
2127 using (_64bit_signed_comparer_ comparer = new _64bit_signed_comparer_(SearchArgs, address_index))
2128 {
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 gmp.ReadMemory(address_index, out value);
2138 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 address_index += STEP_SIZE;
2158 }
2159 #endregion
2160 } break;
2161
2162 }
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 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 }
2194 else
2195 {
2196 Guid new_SearchGuid = SearchGuid;
2197 // 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
2216 //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 #endregion
2273
2274 new_SearchGuid = GuidTools.IncrementGuid(SearchGuid);
2275 using (SearchResultWriter writer = new SearchResultWriter(0, new_SearchGuid))
2276 {
2277 int index = 0;
2278 foreach (var k in reader.GetResults(SearchArgs.IsUnsignedDataType, SearchArgs.DataType, new Action<int, string>(UpdateProgress), new Func<bool>(ShouldCancelAnySearchOperation)))
2279 {
2280 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 int Last_Whole_Percent_Done = 0;
2290 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
2296 uint address_index = k.Address;
2297
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 if ((int_percent_done != Last_Whole_Percent_Done) && (index % 1000000) == 0)
2302 {
2303 UpdateProgress((int)double_percent_done, message);
2304 Last_Whole_Percent_Done = int_percent_done;
2305 }
2306
2307 #region comparison and serialization
2308 switch (sdt)
2309 {
2310 case SearchDataTypes._8bits:
2311 if (unsigned)
2312 {
2313 #region 8bits - unsigned
2314 var t_data = BitTools.ConvertByteArray<byte>(data, new Func<bool>(ShouldCancelAnySearchOperation));
2315 foreach (var Value in t_data)
2316 {
2317 if (SearchWorkerThread.CancellationPending) { break; }
2318 using (_8bit_unsigned_comparer_ comparer = new _8bit_unsigned_comparer_(SearchArgs, address_index))
2319 {
2320 byte value = 0;
2321 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2322 {
2323 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2324 {
2325 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 }
2336 comparer.Value = value;
2337 }
2338 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 }
2348 address_index += STEP_SIZE;
2349 }
2350 #endregion
2351 }
2352 else
2353 {
2354 #region 8bits - signed
2355 var t_data = BitTools.ConvertByteArray<sbyte>(data, new Func<bool>(ShouldCancelAnySearchOperation));
2356 foreach (var Value in t_data)
2357 {
2358 if (SearchWorkerThread.CancellationPending) { break; }
2359 using (_8bit_signed_comparer_ comparer = new _8bit_signed_comparer_(SearchArgs, address_index))
2360 {
2361 sbyte value = 0;
2362 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2363 {
2364 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2365 {
2366 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 }
2377 comparer.Value = value;
2378 }
2379 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 }
2389 address_index += STEP_SIZE;
2390 }
2391 #endregion
2392 } break;
2393 case SearchDataTypes._16bits:
2394 if (unsigned)
2395 {
2396 #region 16bits - unsigned
2397 var t_data = BitTools.ConvertByteArray<ushort>(data, new Func<bool>(ShouldCancelAnySearchOperation));
2398 foreach (var Value in t_data)
2399 {
2400 if (SearchWorkerThread.CancellationPending) { break; }
2401 using (_16bit_unsigned_comparer_ comparer = new _16bit_unsigned_comparer_(SearchArgs, address_index))
2402 {
2403 ushort value = 0;
2404 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2405 {
2406 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2407 {
2408 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 }
2419 comparer.Value = value;
2420 }
2421 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 }
2431 address_index += STEP_SIZE;
2432 }
2433 #endregion
2434 }
2435 else
2436 {
2437 #region 16bits - signed
2438 var t_data = BitTools.ConvertByteArray<short>(data, new Func<bool>(ShouldCancelAnySearchOperation));
2439 foreach (var Value in t_data)
2440 {
2441 if (SearchWorkerThread.CancellationPending) { break; }
2442 using (_16bit_signed_comparer_ comparer = new _16bit_signed_comparer_(SearchArgs, address_index))
2443 {
2444 short value = 0;
2445 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2446 {
2447 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2448 {
2449 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 }
2460 comparer.Value = value;
2461 }
2462 else
2463 {
2464 value = Convert.ToInt16(SearchArgs.CompareStartValue);
2465 comparer.Value = value;
2466 }
2467 if (comparer.Compare(Convert.ToSByte(Value), value))
2468 {
2469 writer.WriteResult<short>(comparer.Address, comparer.Value);
2470 }
2471 }
2472 address_index += STEP_SIZE;
2473 }
2474 #endregion
2475 } break;
2476 case SearchDataTypes._32bits:
2477 if (unsigned)
2478 {
2479 #region 32bits - unsigned
2480 var t_data = BitTools.ConvertByteArray<uint>(data, new Func<bool>(ShouldCancelAnySearchOperation));
2481 foreach (var Value in t_data)
2482 {
2483 if (SearchWorkerThread.CancellationPending) { break; }
2484 using (_32bit_unsigned_comparer_ comparer = new _32bit_unsigned_comparer_(SearchArgs, address_index))
2485 {
2486 uint value = 0;
2487 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2488 {
2489 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2490 {
2491 try
2492 {
2493 gmp.OpenProvider();
2494 gmp.ReadMemory(address_index, out value);
2495 gmp.CloseProvider();
2496 }
2497 catch (Exception ex)
2498 {
2499 logger.VerboseError.WriteLine(ex.ToString());
2500 }
2501 }
2502 comparer.Value = value;
2503 }
2504 else
2505 {
2506 value = Convert.ToUInt32(SearchArgs.CompareStartValue);
2507 comparer.Value = value;
2508 }
2509 if (comparer.Compare(Convert.ToUInt32(Value), value))
2510 {
2511 writer.WriteResult<uint>(comparer.Address, comparer.Value);
2512 }
2513 }
2514 address_index += STEP_SIZE;
2515 }
2516 #endregion
2517 }
2518 else
2519 {
2520 #region 32bits - signed
2521 var t_data = BitTools.ConvertByteArray<int>(data, new Func<bool>(ShouldCancelAnySearchOperation));
2522 foreach (var Value in t_data)
2523 {
2524 if (SearchWorkerThread.CancellationPending) { break; }
2525 using (_32bit_signed_comparer_ comparer = new _32bit_signed_comparer_(SearchArgs, address_index))
2526 {
2527 int value = 0;
2528 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2529 {
2530 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2531 {
2532 try
2533 {
2534 gmp.OpenProvider();
2535 gmp.ReadMemory(address_index, out value);
2536 gmp.CloseProvider();
2537 }
2538 catch (Exception ex)
2539 {
2540 logger.VerboseError.WriteLine(ex.ToString());
2541 }
2542 }
2543 comparer.Value = value;
2544 }
2545 else
2546 {
2547 value = Convert.ToInt32(SearchArgs.CompareStartValue);
2548 comparer.Value = value;
2549 }
2550 if (comparer.Compare(Convert.ToInt32(Value), value))
2551 {
2552 writer.WriteResult<int>(comparer.Address, comparer.Value);
2553 }
2554 }
2555 address_index += STEP_SIZE;
2556 }
2557 #endregion
2558 } break;
2559 case SearchDataTypes._64bits:
2560 if (unsigned)
2561 {
2562 #region 64bits - unsigned
2563 var t_data = BitTools.ConvertByteArray<ulong>(data, new Func<bool>(ShouldCancelAnySearchOperation));
2564 foreach (var Value in t_data)
2565 {
2566 if (SearchWorkerThread.CancellationPending) { break; }
2567 using (_64bit_unsigned_comparer_ comparer = new _64bit_unsigned_comparer_(SearchArgs, address_index))
2568 {
2569 ulong value = 0;
2570 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2571 {
2572 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2573 {
2574 try
2575 {
2576 gmp.OpenProvider();
2577 gmp.ReadMemory(address_index, out value);
2578 gmp.CloseProvider();
2579 }
2580 catch (Exception ex)
2581 {
2582 logger.VerboseError.WriteLine(ex.ToString());
2583 }
2584 }
2585 comparer.Value = value;
2586 }
2587 else
2588 {
2589 value = Convert.ToUInt64(SearchArgs.CompareStartValue);
2590 comparer.Value = value;
2591 }
2592 if (comparer.Compare(Convert.ToUInt64(Value), value))
2593 {
2594 writer.WriteResult<ulong>(comparer.Address, comparer.Value);
2595 }
2596 }
2597 address_index += STEP_SIZE;
2598 }
2599 #endregion
2600 }
2601 else
2602 {
2603 #region 64bits - signed
2604 var t_data = BitTools.ConvertByteArray<long>(data, new Func<bool>(ShouldCancelAnySearchOperation));
2605 foreach (var Value in t_data)
2606 {
2607 if (SearchWorkerThread.CancellationPending) { break; }
2608 using (_64bit_signed_comparer_ comparer = new _64bit_signed_comparer_(SearchArgs, address_index))
2609 {
2610 long value = 0;
2611 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2612 {
2613 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2614 {
2615 try
2616 {
2617 gmp.OpenProvider();
2618 gmp.ReadMemory(address_index, out value);
2619 gmp.CloseProvider();
2620 }
2621 catch (Exception ex)
2622 {
2623 logger.VerboseError.WriteLine(ex.ToString());
2624 }
2625 }
2626 comparer.Value = value;
2627 }
2628 else
2629 {
2630 value = Convert.ToInt64(SearchArgs.CompareStartValue);
2631 comparer.Value = value;
2632 }
2633 if (comparer.Compare(Convert.ToInt64(Value), value))
2634 {
2635 writer.WriteResult<long>(comparer.Address, comparer.Value);
2636 }
2637 }
2638 address_index += STEP_SIZE;
2639 }
2640 #endregion
2641 } break;
2642
2643 }
2644 #endregion
2645
2646 index++;
2647 }
2648
2649
2650 //ISerializedResult sr = (reader as ISerializedResult);
2651 //if (sr == null)
2652 //{
2653 // throw new ArgumentNullException("sr", string.Format("Unable to cast: '{0}' to '{1}'", reader.GetType().Name, typeof(ISerializedResult).Name));
2654 //}
2655 //int sr_index = 0;
2656 //try
2657 //{
2658 // if (sr.ContainsAddress(obre_CurrentIndex, obre_unsigned, obre_sdt, new Action<int, string>(this.UpdateProgress), out sr_index))
2659 // {
2660 // StructResultType<ulong> result = StructResultType<ulong>.Empty;
2661 // sr.GetResultAtIndex(sr_index, obre_unsigned, obre_sdt, new Action<int, string>(this.UpdateProgress), out result);
2662 // if (Debugger.IsAttached)
2663 // {
2664 // Debugger.Break();
2665 // }
2666 // }
2667 //}
2668
2669 }
2670
2671 }
2672 SearchGuid = new_SearchGuid; // update with out new guid
2673 }
2674 }
2675 provider_st.Stop();
2676 logger.Profiler.WriteLine("It took a total of {0} seconds for the memory provider to complete it's operation(s).", provider_st.Elapsed.TotalSeconds);
2677 //if (buffered_mem.Length == 0) { logger.Warn.WriteLine("Buffered Memory is Zero Length."); return; }
2678 //int Last_Whole_Percent_Done = 0;
2679
2680
2681 #region Subsequent Searches
2682 //r_ms.BaseStream.Seek(0, SeekOrigin.Begin);
2683
2684
2685 // hack to help with OutOfMemory Exceptions (OldValue and Equal compare will always add all found search results)
2686 bool NeedToCompare = true;
2687 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue &&
2688 SearchArgs.CompareType == SearchCompareTypes.Equal &&
2689 SearchArgs.IsFirstSearch)
2690 {
2691 NeedToCompare = false;
2692 //second_tmp_Results = null; // Free Memory
2693 }
2694
2695 if (NeedToCompare)
2696 {
2697 if (SearchArgs.CompareType != SearchCompareTypes.Between && SearchArgs.CompareType != SearchCompareTypes.NotBetween)
2698 {
2699 #region Non-Range Searches
2700 if (USE_NONRANGE_SEARCH_RESULT_READER)
2701 {
2702 st_nonrange_search.Start();
2703 //second_tmp_Results = new List<ResultType<object>>(SearchArgs.Results.Count * 1024);
2704 ////second_tmp_Results.c
2705 try
2706 {
2707 using (SearchResultReader reader = new SearchResultReader(SearchGuid))
2708 {
2709 try
2710 {
2711
2712 #region new comparator-support
2713 //second_tmp_Results = new List<StructResultType<object>>(reader.GetResults(SearchArgs.IsUnsignedDataType, SearchArgs.DataType, new Action<int, string>(UpdateProgress)));
2714 #endregion
2715
2716 #region USE_OLD_SEARCH_RESULTS_COMPRATOR_CODE
2717 if (USE_OLD_SEARCH_RESULTS_COMPRATOR_CODE)
2718 {
2719 for (int i = 0; i < reader.ResultCount; i += 1)
2720 {
2721 object result_value = 0;
2722 uint address = 0;
2723 #region switch (SearchArgs.DataType)
2724 switch (SearchArgs.DataType)
2725 {
2726 case SearchDataTypes._8bits: if (unsigned)
2727 {
2728 using (ResultType<byte> result = reader.GetNextResult<byte>())
2729 {
2730 address = result.Address;
2731 result_value = result.Value;
2732 }
2733 }
2734 else
2735 {
2736 using (ResultType<sbyte> result = reader.GetNextResult<sbyte>())
2737 {
2738 address = result.Address;
2739 result_value = result.Value;
2740 }
2741 } break;
2742 case SearchDataTypes._16bits: if (unsigned)
2743 {
2744 using (ResultType<ushort> result = reader.GetNextResult<ushort>())
2745 {
2746 address = result.Address;
2747 result_value = result.Value;
2748 }
2749 }
2750 else
2751 {
2752 using (ResultType<short> result = reader.GetNextResult<short>())
2753 {
2754 address = result.Address;
2755 result_value = result.Value;
2756 }
2757 } break;
2758 case SearchDataTypes._32bits: if (unsigned)
2759 {
2760 using (ResultType<uint> result = reader.GetNextResult<uint>())
2761 {
2762 address = result.Address;
2763 result_value = result.Value;
2764 }
2765 }
2766 else
2767 {
2768 using (ResultType<int> result = reader.GetNextResult<int>())
2769 {
2770 address = result.Address;
2771 result_value = result.Value;
2772 }
2773 } break;
2774 case SearchDataTypes._64bits: if (unsigned)
2775 {
2776 using (ResultType<ulong> result = reader.GetNextResult<ulong>())
2777 {
2778 address = result.Address;
2779 result_value = result.Value;
2780 }
2781 }
2782 else
2783 {
2784 using (ResultType<long> result = reader.GetNextResult<long>())
2785 {
2786 address = result.Address;
2787 result_value = result.Value;
2788 }
2789 } break;
2790 }
2791 #endregion
2792 if (MemoryRangeStart > 0 && !SearchArgs.IsFirstSearch) { address = address - MemoryRangeStart; }
2793 try
2794 {
2795 //r_ms.BaseStream.Seek(address, SeekOrigin.Begin);
2796 }
2797 catch (Exception)
2798 {
2799 throw;
2800 }
2801 switch (SearchArgs.DataType)
2802 {
2803 #region Comparer Support
2804 #region case SearchDataTypes._8bits:
2805 case SearchDataTypes._8bits:
2806 if (SearchArgs.IsUnsignedDataType)
2807 {
2808 byte lookup_value = 0;
2809 //using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this)) { gmp.OpenProvider(); gmp.ReadMemory(address, out lookup_value); gmp.CloseProvider(); }
2810 lookup_value = Convert.ToByte(result_value);
2811 using (_8bit_unsigned_comparer_ comparer = new _8bit_unsigned_comparer_(SearchArgs, address))
2812 {
2813 byte value = 0;
2814 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2815 {
2816 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2817 {
2818 try
2819 {
2820 gmp.OpenProvider();
2821 gmp.ReadMemory(address, out value);
2822 gmp.CloseProvider();
2823 }
2824 catch (Exception ex)
2825 {
2826 logger.VerboseError.WriteLine(ex.ToString());
2827 }
2828 }
2829 comparer.Value = value;
2830 }
2831 else
2832 {
2833 value = Convert.ToByte(SearchArgs.CompareStartValue);
2834 comparer.Value = value;
2835 }
2836 if (comparer.Compare(lookup_value, value))
2837 {
2838 second_tmp_Results.Add(new ResultType<ulong>(comparer.Address, comparer.Value));
2839 }
2840 }
2841 }
2842 else
2843 {
2844 sbyte lookup_value = 0;
2845 //using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this)) { gmp.OpenProvider(); gmp.ReadMemory(address, out lookup_value); gmp.CloseProvider(); }
2846 lookup_value = Convert.ToSByte(result_value);
2847 using (_8bit_signed_comparer_ comparer = new _8bit_signed_comparer_(SearchArgs, address))
2848 {
2849 sbyte value = 0;
2850 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2851 {
2852 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2853 {
2854 try
2855 {
2856 gmp.OpenProvider();
2857 gmp.ReadMemory(address, out value);
2858 gmp.CloseProvider();
2859 }
2860 catch (Exception ex)
2861 {
2862 logger.VerboseError.WriteLine(ex.ToString());
2863 }
2864 }
2865 comparer.Value = value;
2866 }
2867 else
2868 {
2869 value = Convert.ToSByte(SearchArgs.CompareStartValue);
2870 }
2871 if (comparer.Compare(lookup_value, value))
2872 {
2873 second_tmp_Results.Add(new ResultType<ulong>(comparer.Address, (ulong)comparer.Value));
2874 }
2875 }
2876 }
2877 break;
2878 #endregion
2879 #region case SearchDataTypes._16bits:
2880 case SearchDataTypes._16bits:
2881 if (SearchArgs.IsUnsignedDataType)
2882 {
2883 ushort lookup_value = 0;
2884 //using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this)) { gmp.OpenProvider(); gmp.ReadMemory(address, out lookup_value); gmp.CloseProvider(); }
2885 lookup_value = Convert.ToUInt16(result_value);
2886 using (_16bit_unsigned_comparer_ comparer = new _16bit_unsigned_comparer_(SearchArgs, address))
2887 {
2888 ushort value = 0;
2889 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2890 {
2891 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2892 {
2893 try
2894 {
2895 gmp.OpenProvider();
2896 gmp.ReadMemory(address, out value);
2897 gmp.CloseProvider();
2898 }
2899 catch (Exception ex)
2900 {
2901 logger.VerboseError.WriteLine(ex.ToString());
2902 }
2903 }
2904 comparer.Value = value;
2905 }
2906 else
2907 {
2908 value = Convert.ToUInt16(SearchArgs.CompareStartValue);
2909 comparer.Value = value;
2910 }
2911 if (comparer.Compare(lookup_value, value))
2912 {
2913 second_tmp_Results.Add(new ResultType<ulong>(comparer.Address, comparer.Value));
2914 }
2915 }
2916 }
2917 else
2918 {
2919 short lookup_value = 0;
2920 //using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this)) { gmp.OpenProvider(); gmp.ReadMemory(address, out lookup_value); gmp.CloseProvider(); }
2921 lookup_value = Convert.ToInt16(result_value);
2922 using (_16bit_signed_comparer_ comparer = new _16bit_signed_comparer_(SearchArgs, address))
2923 {
2924 short value = 0;
2925 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2926 {
2927 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2928 {
2929 try
2930 {
2931 gmp.OpenProvider();
2932 gmp.ReadMemory(address, out value);
2933 gmp.CloseProvider();
2934 }
2935 catch (Exception ex)
2936 {
2937 logger.VerboseError.WriteLine(ex.ToString());
2938 }
2939 }
2940 comparer.Value = value;
2941 }
2942 else
2943 {
2944 value = Convert.ToInt16(SearchArgs.CompareStartValue);
2945 }
2946 if (comparer.Compare(lookup_value, value))
2947 {
2948 second_tmp_Results.Add(new ResultType<ulong>(comparer.Address, (ulong)comparer.Value));
2949 }
2950 }
2951 }
2952 break;
2953 #endregion
2954 #region case SearchDataTypes._32bits:
2955 case SearchDataTypes._32bits:
2956 if (SearchArgs.IsUnsignedDataType)
2957 {
2958 uint lookup_value = 0;
2959 //using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this)) { gmp.OpenProvider(); gmp.ReadMemory(address, out lookup_value); gmp.CloseProvider(); }
2960 lookup_value = Convert.ToUInt32(result_value);
2961 using (_32bit_unsigned_comparer_ comparer = new _32bit_unsigned_comparer_(SearchArgs, address))
2962 {
2963 uint value = 0;
2964 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2965 {
2966 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2967 {
2968 try
2969 {
2970 gmp.OpenProvider();
2971 gmp.ReadMemory(address, out value);
2972 gmp.CloseProvider();
2973 }
2974 catch (Exception ex)
2975 {
2976 logger.VerboseError.WriteLine(ex.ToString());
2977 }
2978 }
2979 comparer.Value = value;
2980 }
2981 else
2982 {
2983 value = Convert.ToUInt32(SearchArgs.CompareStartValue);
2984 comparer.Value = value;
2985 }
2986 if (comparer.Compare(lookup_value, value))
2987 {
2988 second_tmp_Results.Add(new ResultType<ulong>(comparer.Address, comparer.Value));
2989 }
2990 }
2991 }
2992 else
2993 {
2994 int lookup_value = 0;
2995 //using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this)) { gmp.OpenProvider(); gmp.ReadMemory(address, out lookup_value); gmp.CloseProvider(); }
2996 lookup_value = Convert.ToInt32(result_value);
2997 using (_32bit_signed_comparer_ comparer = new _32bit_signed_comparer_(SearchArgs, address))
2998 {
2999 int value = 0;
3000 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
3001 {
3002 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
3003 {
3004 try
3005 {
3006 gmp.OpenProvider();
3007 gmp.ReadMemory(address, out value);
3008 gmp.CloseProvider();
3009 }
3010 catch (Exception ex)
3011 {
3012 logger.VerboseError.WriteLine(ex.ToString());
3013 }
3014 }
3015 comparer.Value = value;
3016 }
3017 else
3018 {
3019 value = Convert.ToInt32(SearchArgs.CompareStartValue);
3020 }
3021 if (comparer.Compare(lookup_value, value))
3022 {
3023 second_tmp_Results.Add(new ResultType<ulong>(comparer.Address, (ulong)comparer.Value));
3024 }
3025 }
3026 }
3027 break;
3028 #endregion
3029 #region case SearchDataTypes._64bits:
3030 case SearchDataTypes._64bits:
3031 if (SearchArgs.IsUnsignedDataType)
3032 {
3033 ulong lookup_value = 0;
3034 //using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this)) { gmp.OpenProvider(); gmp.ReadMemory(address, out lookup_value); gmp.CloseProvider(); }
3035 lookup_value = Convert.ToUInt64(result_value);
3036 using (_64bit_unsigned_comparer_ comparer = new _64bit_unsigned_comparer_(SearchArgs, address))
3037 {
3038 ulong value = 0;
3039 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
3040 {
3041 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
3042 {
3043 try
3044 {
3045 gmp.OpenProvider();
3046 gmp.ReadMemory(address, out value);
3047 gmp.CloseProvider();
3048 }
3049 catch (Exception ex)
3050 {
3051 logger.VerboseError.WriteLine(ex.ToString());
3052 }
3053 }
3054 comparer.Value = value;
3055 }
3056 else
3057 {
3058 value = Convert.ToUInt64(SearchArgs.CompareStartValue);
3059 comparer.Value = value;
3060 }
3061 if (comparer.Compare(lookup_value, value))
3062 {
3063 second_tmp_Results.Add(new ResultType<ulong>(comparer.Address, comparer.Value));
3064 }
3065 }
3066 }
3067 else
3068 {
3069 long lookup_value = 0;
3070 //using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this)) { gmp.OpenProvider(); gmp.ReadMemory(address, out lookup_value); gmp.CloseProvider(); }
3071 lookup_value = Convert.ToInt64(result_value);
3072 using (_64bit_signed_comparer_ comparer = new _64bit_signed_comparer_(SearchArgs, address))
3073 {
3074 long value = 0;
3075 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
3076 {
3077 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
3078 {
3079 try
3080 {
3081 gmp.OpenProvider();
3082 gmp.ReadMemory(address, out value);
3083 gmp.CloseProvider();
3084 }
3085 catch (Exception ex)
3086 {
3087 logger.VerboseError.WriteLine(ex.ToString());
3088 }
3089 }
3090 comparer.Value = value;
3091 }
3092 else
3093 {
3094 value = Convert.ToInt64(SearchArgs.CompareStartValue);
3095 }
3096 if (comparer.Compare(lookup_value, value))
3097 {
3098 second_tmp_Results.Add(new ResultType<ulong>(comparer.Address, (ulong)comparer.Value));
3099 }
3100 }
3101 }
3102 break;
3103 #endregion
3104 #endregion
3105 }
3106 double double_percent_done = 100.0 * (double)((double)i / (double)reader.ResultCount);
3107 int int_percent_done = (int)double_percent_done;
3108 //if (int_percent_done != Last_Whole_Percent_Done && i % 100000 == 0)
3109 //{
3110 if (int_percent_done <= 100)
3111 {
3112 //Last_Whole_Percent_Done = int_percent_done;
3113 UpdateProgress(int_percent_done, string.Format(" -> Reading Address: 0x{0:x8}", i + MemoryRangeStart));
3114 //new Action<int, string>(UpdateProgress).Invoke(int_percent_done, string.Format(" -> Reading Address: 0x{0:x8}", i + MemoryRangeStart));
3115 }
3116 //}
3117 //this.Refresh();
3118 }
3119 }
3120 #endregion
3121 }
3122 catch (Exception ex)
3123 {
3124 throw ex;
3125 }
3126 }
3127 }
3128 catch (Exception ex)
3129 {
3130 throw ex;
3131 }
3132 st_nonrange_search.Stop();
3133 logger.Profiler.WriteLine("Non-Ranged search took a total of {0} seconds to complete.", st_nonrange_search.Elapsed.TotalSeconds);
3134 //Last_Whole_Percent_Done = 0;
3135 }
3136 #endregion
3137 }
3138 #region Ranged Searches
3139 #if !DONOT_HAVE_RANGED_SEARCH_SUPPORT
3140 if (SearchArgs.CompareType == SearchCompareTypes.Between || SearchArgs.CompareType == SearchCompareTypes.NotBetween)
3141 {
3142 st_ranged_search.Start();
3143 object start, end;
3144
3145 start = SearchArgs.CompareStartValue;
3146 end = SearchArgs.CompareEndValue;
3147 using (SearchResultReader reader = new SearchResultReader(SearchGuid))
3148 {
3149 for (int i = 0; i < reader.ResultCount; i += 1)
3150 {
3151 uint address = 0;
3152 #region switch (SearchArgs.DataType)
3153 switch (SearchArgs.DataType)
3154 {
3155 case SearchDataTypes._8bits: if (unsigned) { using (ResultType<byte> result = reader.GetNextResult<byte>()) { address = result.Address; } }
3156 else { using (ResultType<sbyte> result = reader.GetNextResult<sbyte>()) { address = result.Address; } } break;
3157 case SearchDataTypes._16bits: if (unsigned) { using (ResultType<ushort> result = reader.GetNextResult<ushort>()) { address = result.Address; } }
3158 else { using (ResultType<short> result = reader.GetNextResult<short>()) { address = result.Address; } } break;
3159 case SearchDataTypes._32bits: if (unsigned) { using (ResultType<uint> result = reader.GetNextResult<uint>()) { address = result.Address; } }
3160 else { using (ResultType<int> result = reader.GetNextResult<int>()) { address = result.Address; } } break;
3161 case SearchDataTypes._64bits: if (unsigned) { using (ResultType<ulong> result = reader.GetNextResult<ulong>()) { address = result.Address; } }
3162 else { using (ResultType<long> result = reader.GetNextResult<long>()) { address = result.Address; } } break;
3163 }
3164 #endregion
3165
3166 if (MemoryRangeStart > 0 && !SearchArgs.IsFirstSearch) { address = address - MemoryRangeStart; }
3167 //r_ms.BaseStream.Seek(address, SeekOrigin.Begin);
3168 if (SearchArgs.CompareType == SearchCompareTypes.Between)
3169 {
3170 using (InRangeComparer comparer = new InRangeComparer(address, 0))
3171 {
3172 if (comparer.Compare(start, end, SearchArgs.DataType, SearchArgs.IsUnsignedDataType, (IAcceptsProcessAndConfig)this))
3173 {
3174 using (ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value))
3175 {
3176 second_tmp_Results.Add(_tmp_result);
3177 }
3178 }
3179 }
3180 }
3181 else if (SearchArgs.CompareType == SearchCompareTypes.NotBetween)
3182 {
3183 using (NotInRangeComparer comparer = new NotInRangeComparer(address, 0))
3184 {
3185 if (comparer.Compare(start, end, SearchArgs.DataType, SearchArgs.IsUnsignedDataType, (IAcceptsProcessAndConfig)this))
3186 {
3187 using (ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value))
3188 {
3189 second_tmp_Results.Add(_tmp_result);
3190 }
3191 }
3192 }
3193 }
3194 else
3195 {
3196 throw new InvalidOperationException("Encounted unkown range search type: " <