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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 527 - (show annotations) (download)
Wed Jun 5 08:09:59 2013 UTC (7 years, 4 months ago) by william
File size: 227265 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 void UpdateProgress(int progress, string message)
79 {
80 // detach the progress update from execution within the current thread (so it does not block a cpu-intensive or long running sequence)
81 Thread t = new Thread(new ParameterizedThreadStart(thread_UpdateProgress));
82 t.SetApartmentState(ApartmentState.STA);
83 t.Start(new ProgressMessage(progress, message));
84 //resultsprogress.Value = progress;
85 //resultsprogress.Message = message;
86 }
87
88 #region IAcceptsProcess<Process> Members
89 private Process _AcceptedProcess;
90 public Process AcceptedProcess { get { return _AcceptedProcess; } set { _AcceptedProcess = value; UpdateAcceptedProcess(value); } }
91 #endregion
92 #region IAcceptsPlugin<IConfigPlugin> Members
93 private IConfigPlugin _AcceptedPlugin;
94 public IConfigPlugin AcceptedPlugin { get { return _AcceptedPlugin; } set { _AcceptedPlugin = value; UpdateAcceptedPlugin(value); } }
95 #endregion
96 #region IAcceptsBrowseMemoryRegion members
97 public event BaseEventHandler<BrowseMemoryRegionEvent> OnBrowseMemoryRegion;
98 #endregion
99
100 private void UpdateAcceptedPlugin(IConfigPlugin config)
101 {
102 this.lstResults.AcceptedPlugin = config;
103 this.lstPatchList.AcceptedPlugin = config;
104 if (config != null)
105 {
106 MemoryRangeStart = AcceptedPlugin.MemoryRangeStart;
107 MemoryRangeSize = AcceptedPlugin.MemoryRangeStart + AcceptedPlugin.MemoryRangeSize;
108 }
109 }
110 private void UpdateAcceptedProcess(Process process)
111 {
112 this.lstResults.AcceptedProcess = process;
113 this.lstPatchList.AcceptedProcess = process;
114 #if USE_AUTOMATIC_MEMORY_SEARCH_RANGE && FORCE_USE_OF_MEMORYSIZECONSTANTS
115 logger.Warn.WriteLine("FloatingMemorySearcher.UpdateAcceptedProcessAndConfig(IConfigPlugin config, Process process):");
116 logger.Warn.WriteLine("Both USE_AUTOMATIC_MEMORY_SEARCH_RANGE and FORCE_USE_OF_MEMORYSIZECONSTANTS are defined");
117 logger.Warn.WriteLine("FORCE_USE_OF_MEMORYSIZECONSTANTS will take precedence and will ignore the values supplied in the memeory search range");
118 #endif
119 #if FORCE_USE_OF_MEMORYSIZECONSTANTS
120 // force use of MemorySizeConstants
121 txtMemoryRangeStart.Value = MemorySizeConstants.MinimumSearchAddress;
122 txtMemoryRangeSize.Value = MemorySizeConstants.MinimumSearchAddress + MemorySizeConstants.MaximumSearchSize;
123 #endif
124 #if USE_AUTOMATIC_MEMORY_SEARCH_RANGE && !FORCE_USE_OF_MEMORYSIZECONSTANTS
125 ////// code to automatically choose the best starting memory address and size
126 //if (process != null)
127 //{
128 // string filename = process.MainModule.FileName;
129 // //string filename = @"c:\Windows\notepad.exe";
130 // PEReader peReader = new PEReader(filename);
131 //}
132 //else
133 //{
134 //txtMemoryRangeStart.Value = MemorySizeConstants.MinimumSearchAddress;
135 //txtMemoryRangeSize.Value = MemorySizeConstants.MinimumSearchAddress + MemorySizeConstants.MaximumSearchSize;
136 //}
137 if (AcceptedPlugin != null)
138 {
139 MemoryRangeStart = AcceptedPlugin.MemoryRangeStart;
140 MemoryRangeSize = AcceptedPlugin.MemoryRangeStart + AcceptedPlugin.MemoryRangeSize;
141 }
142
143 #endif
144
145 }
146 #region ISearchInProgress members
147 private bool _SearchInProgess;
148 public bool SearchInProgess
149 {
150 get { return _SearchInProgess; }
151 private set
152 {
153 _SearchInProgess = value;
154 if (this.AcceptedPlugin != null)
155 this.AcceptedPlugin.SetMemorySearchReference(this);
156 }
157 }
158 private Guid _SearchGuid;
159 public Guid SearchGuid
160 {
161 get { return _SearchGuid; }
162 private set { _SearchGuid = value; }
163 }
164 #endregion
165
166 #region IAcceptsMemoryRange
167 #if !FORCE_USE_OF_MEMORYSIZECONSTANTS
168 private uint _MemoryRangeStart;
169 private uint _MemoryRangeSize;
170 #endif
171 public uint MemoryRangeStart
172 {
173 get
174 {
175 #if FORCE_USE_OF_MEMORYSIZECONSTANTS
176 return MemorySizeConstants.MinimumSearchAddress;
177 #else
178 return _MemoryRangeStart;
179 #endif
180 }
181 set
182 {
183 #if !FORCE_USE_OF_MEMORYSIZECONSTANTS
184 _MemoryRangeStart = value;
185 txtMemoryRangeStart.Value = value;
186 #endif
187 }
188 }
189 public uint MemoryRangeSize
190 {
191 get
192 {
193 #if FORCE_USE_OF_MEMORYSIZECONSTANTS
194 return MemorySizeConstants.MinimumSearchAddress + MemorySizeConstants.MaximumSearchSize;
195 #else
196 return _MemoryRangeSize;
197 #endif
198 }
199 set
200 {
201 #if !FORCE_USE_OF_MEMORYSIZECONSTANTS
202 _MemoryRangeSize = value;
203 txtMemoryRangeSize.Value = value;
204 #endif
205 }
206 }
207 #endregion
208
209 public void Reload()
210 {
211 chkUnsigned.Checked = DefaultUnsignedState;
212 radio_8bits.Checked = true;
213 radiocompare_equal.Checked = true;
214 radio_oldvalue.Checked = true;
215 chkRefreshResults.Checked = true;
216 }
217 public enum eListViewResults
218 {
219 SEARCH_RESULTS_LIST = 0x3000,
220 PATCH_RESULTS_LIST = 0x3001,
221 UKNOWN_RESULTS_LIST = 0x3001
222 }
223 bool IsFirstSearch = true;
224 SearchType SearchArgs;
225 static int col_Found_Address = 1;
226 static int col_Found_Value = 2;
227 //static int col_Found_Frozen = 3; /* unused */
228 static int col_Added_Address = 1;
229 static int col_Added_Value = 2;
230 //static int col_Added_Frozen = 3; /* unused */
231 List<ListViewItem> ResultItems = new List<ListViewItem>();
232 List<ListViewItem> AddedItems = new List<ListViewItem>();
233 private bool _PatchedValue_NeedsUpdate;
234 bool PatchedValue_NeedsUpdate
235 {
236 get { if (_PatchedValue_NeedsUpdate) this.ThawResultsUpdate(); return _PatchedValue_NeedsUpdate; }
237 set { _PatchedValue_NeedsUpdate = value; if (value) this.ThawResultsUpdate(); }
238 }
239 private delegate ListViewItem ThreadSafe_GetResultItem(int index, int lv_type);
240 private ListViewItem GetResultItem(int index, int lv_type)
241 {
242 try
243 {
244 AddressValuePairList lv = null;
245 switch (lv_type)
246 {
247 case (int)eListViewResults.SEARCH_RESULTS_LIST: lv = lstResults; break;
248 case (int)eListViewResults.PATCH_RESULTS_LIST: lv = lstPatchList; break;
249 default: throw new IndexOutOfRangeException("Detected: " + Enum.GetName(typeof(eListViewResults), eListViewResults.UKNOWN_RESULTS_LIST) + " with value: " + lv_type.ToString("x4"));
250 }
251 ListViewItem item = new ListViewItem();
252 item = (ListViewItem)lv.Items[index].Clone();
253 return item;
254 }
255 catch (Exception)
256 {
257 return null;
258 }
259 }
260 private void radiocompare_equal_CheckedChanged(object sender, EventArgs e)
261 {
262 //if (!radiocompare_between.Checked && !radiocompare_notbetween.Checked)
263 //{
264 if (radio_oldvalue.Checked)
265 {
266 txtStartAddr.ReadOnly = true;
267 txtEndAddr.ReadOnly = true;
268 }
269 if (radio_specificvalue.Checked)
270 {
271 txtStartAddr.ReadOnly = false;
272 txtEndAddr.ReadOnly = true;
273 }
274 //}
275 }
276
277 private void radiocompare_between_CheckedChanged(object sender, EventArgs e)
278 {
279 if (!radiocompare_equal.Checked &&
280 !radiocompare_greaterthan.Checked &&
281 !radiocompare_greaterthan.Checked &&
282 !radiocompare_lessthan.Checked &&
283 !radiocompare_greaterthan_orequal.Checked &&
284 !radiocompare_lessthan_orequal.Checked &&
285 !radiocompare_notequal.Checked)
286 if (radiocompare_between.Checked)
287 {
288 txtStartAddr.ReadOnly = false;
289 txtEndAddr.ReadOnly = false;
290 return;
291 }
292 if (!radiocompare_between.Checked && !radiocompare_notbetween.Checked)
293 {
294 if (radio_oldvalue.Checked)
295 {
296 txtStartAddr.ReadOnly = true;
297 txtEndAddr.ReadOnly = true;
298 }
299 if (radio_specificvalue.Checked)
300 {
301 txtStartAddr.ReadOnly = false;
302 txtEndAddr.ReadOnly = true;
303 }
304 }
305 }
306
307 private void radiocompare_notbetween_CheckedChanged(object sender, EventArgs e)
308 {
309 if (!radiocompare_equal.Checked &&
310 !radiocompare_greaterthan.Checked &&
311 !radiocompare_greaterthan.Checked &&
312 !radiocompare_lessthan.Checked &&
313 !radiocompare_greaterthan_orequal.Checked &&
314 !radiocompare_lessthan_orequal.Checked &&
315 !radiocompare_notequal.Checked)
316 if (radiocompare_notbetween.Checked)
317 {
318 txtStartAddr.ReadOnly = false;
319 txtEndAddr.ReadOnly = false;
320 return;
321 }
322 if (!radiocompare_between.Checked && !radiocompare_notbetween.Checked)
323 {
324 if (radio_oldvalue.Checked)
325 {
326 txtStartAddr.ReadOnly = true;
327 txtEndAddr.ReadOnly = true;
328 }
329 if (radio_specificvalue.Checked)
330 {
331 txtStartAddr.ReadOnly = false;
332 txtEndAddr.ReadOnly = true;
333 }
334 }
335 }
336
337 private void radio_8bits_CheckedChanged(object sender, EventArgs e)
338 {
339 if (chkUnsigned.Checked)
340 {
341 txtStartAddr.CreateTypeSize<byte>();
342 txtEndAddr.CreateTypeSize<byte>();
343 }
344 else
345 {
346 txtStartAddr.CreateTypeSize<sbyte>();
347 txtEndAddr.CreateTypeSize<sbyte>();
348 }
349 }
350
351 private void radio_16bits_CheckedChanged(object sender, EventArgs e)
352 {
353 if (chkUnsigned.Checked)
354 {
355 txtStartAddr.CreateTypeSize<ushort>();
356 txtEndAddr.CreateTypeSize<ushort>();
357 }
358 else
359 {
360 txtStartAddr.CreateTypeSize<short>();
361 txtEndAddr.CreateTypeSize<short>();
362 }
363 }
364
365 private void radio_32bits_CheckedChanged(object sender, EventArgs e)
366 {
367
368 if (chkUnsigned.Checked)
369 {
370 txtStartAddr.CreateTypeSize<uint>();
371 txtEndAddr.CreateTypeSize<uint>();
372 }
373 else
374 {
375 txtStartAddr.CreateTypeSize<int>();
376 txtEndAddr.CreateTypeSize<int>();
377 }
378 }
379
380 private void radio_64bits_CheckedChanged(object sender, EventArgs e)
381 {
382
383 if (chkUnsigned.Checked)
384 {
385 txtStartAddr.CreateTypeSize<ulong>();
386 txtEndAddr.CreateTypeSize<ulong>();
387 }
388 else
389 {
390 txtStartAddr.CreateTypeSize<long>();
391 txtEndAddr.CreateTypeSize<long>();
392 }
393 }
394
395 private void radio_oldvalue_CheckedChanged(object sender, EventArgs e)
396 {
397 if (!radiocompare_between.Checked && !radiocompare_notbetween.Checked)
398 {
399 txtStartAddr.ReadOnly = true;
400 txtEndAddr.ReadOnly = true;
401 }
402 }
403
404 private void radio_specificvalue_CheckedChanged(object sender, EventArgs e)
405 {
406 if (!radiocompare_between.Checked && !radiocompare_notbetween.Checked)
407 {
408 txtStartAddr.ReadOnly = false;
409 txtEndAddr.ReadOnly = true;
410 }
411 }
412
413 private void chkRefreshResults_CheckedChanged(object sender, EventArgs e)
414 {
415 if (chkRefreshResults.Checked)
416 {
417 timer_update_results.Enabled = true;
418 }
419 else
420 {
421 timer_update_results.Enabled = false;
422 ResultsUpdateWorkerThread.CancelAsync();
423 }
424 }
425
426 private void timer_update_results_Tick(object sender, EventArgs e)
427 {
428 if (chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy)
429 {
430 ResultsUpdateWorkerThread.RunWorkerAsync();
431 }
432 }
433 private bool ShouldUpdateResults()
434 {
435 if (this.AcceptedProcess == null) return false;
436 if (SearchWorkerThread.IsBusy) return false;
437 //if (JokerSearchWorker.IsBusy) return false;
438 if (this.IsResultsUpdateFrozen) return false;
439 if (mnuAddedResults.Visible) return false;
440 if (mnuResults.Visible) return false;
441 if (Process.GetProcessById(this.AcceptedProcess.Id) == null) return false;
442 if (lstResults.Items.Count > 0) return true;
443 if (lstPatchList.Items.Count > 0) return true;
444 return false;
445 }
446 private void ResultsUpdateWorkerThread_DoWork(object sender, DoWorkEventArgs e)
447 {
448 Thread.Sleep(250); // keep thread from blocking
449 if (!this.ShouldUpdateResults()) return;
450 ////if (SearchArgs == null) return;
451 ////if (this.IsResultsUpdateFrozen) return;
452 ////// put thread to sleep for 500ms
453 ////System.Threading.Thread.Sleep(500);
454 //PCSX2MemoryProvider provider = new PCSX2MemoryProvider(this.SearchPCSX2ProcessPID, resultslog);
455 //byte[] buffered_mem = provider.GetMemory();
456 //MemoryStream ms = new MemoryStream(buffered_mem);
457 //BinaryReader r_ms = new BinaryReader(ms);
458
459 #region Update Results List
460 ResultItems = new List<ListViewItem>();
461 //r_ms.BaseStream.Seek(0, SeekOrigin.Begin);
462 for (int i = 0; i < lstResults.Items.Count; i++)
463 {
464 if (this.lstResults.InvokeRequired)
465 {
466 ThreadSafe_GetResultItem _get_item = new ThreadSafe_GetResultItem(GetResultItem);
467 object item = this.lstResults.Invoke(_get_item, new object[] { i, (int)eListViewResults.SEARCH_RESULTS_LIST });
468 if (item != null)
469 ResultItems.Add((ListViewItem)item);
470 }
471 else
472 {
473 ResultItems.Add(lstResults.Items[i]);
474 }
475
476 }
477 for (int i = 0; i < ResultItems.Count; i++)
478 {
479 if (ResultsUpdateWorkerThread.CancellationPending == true)
480 {
481 e.Cancel = true;
482 return;
483 }
484 int Address = 0;
485 ResultDataType _result = (ResultDataType)ResultItems[i].Tag;
486
487 Address = Convert.ToInt32(ResultItems[i].SubItems[col_Found_Address].Text, 16);
488 //r_ms.BaseStream.Seek(Address, SeekOrigin.Begin);
489 using (GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
490 {
491 provider.OpenProvider();
492 int bytesReadSize;
493 byte[] data;
494 uint bytesToRead = 0;
495 switch (_result.ValueType)
496 {
497 case SearchDataTypes._8bits:
498 bytesToRead = 1;
499 break;
500 case SearchDataTypes._16bits:
501 bytesToRead = 2;
502 break;
503 case SearchDataTypes._32bits:
504 bytesToRead = 4;
505 break;
506 case SearchDataTypes._64bits:
507 bytesToRead = 8;
508 break;
509 }
510 provider.ReadProcessMemory(Address, bytesToRead, out bytesReadSize, out data);
511 using (MemoryStream ms = new MemoryStream(data))
512 {
513 using (BinaryReader r_ms = new BinaryReader(ms))
514 {
515 switch (_result.ValueType)
516 {
517 case SearchDataTypes._8bits:
518 if (_result.IsUnsigned) { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x2}", r_ms.ReadByte()); }
519 else { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x2}", r_ms.ReadSByte()); }
520 break;
521 case SearchDataTypes._16bits:
522 if (_result.IsUnsigned) { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x4}", r_ms.ReadUInt16()); }
523 else { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x4}", r_ms.ReadInt16()); }
524 break;
525 case SearchDataTypes._32bits:
526 if (_result.IsUnsigned) { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x8}", r_ms.ReadUInt32()); }
527 else { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x8}", r_ms.ReadInt32()); }
528 break;
529 case SearchDataTypes._64bits:
530 if (_result.IsUnsigned) { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x16}", r_ms.ReadUInt64()); }
531 else { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x16}", r_ms.ReadInt64()); }
532 break;
533 }
534 r_ms.Close();
535 }
536 }
537 provider.CloseProvider();
538 }
539 //Application.DoEvents();
540 }
541 #endregion
542
543 #region Update Added Results List
544 AddedItems = new List<ListViewItem>();
545 //r_ms.BaseStream.Seek(0, SeekOrigin.Begin);
546 for (int i = 0; i < lstPatchList.Items.Count; i++)
547 {
548 if (this.lstResults.InvokeRequired)
549 {
550 ThreadSafe_GetResultItem _get_item = new ThreadSafe_GetResultItem(GetResultItem);
551 object item = this.lstResults.Invoke(_get_item, new object[] { i, (int)eListViewResults.PATCH_RESULTS_LIST });
552 if (item != null)
553 AddedItems.Add((ListViewItem)item);
554 }
555 else
556 {
557 AddedItems.Add(lstPatchList.Items[i]);
558 }
559
560 }
561 for (int i = 0; i < AddedItems.Count; i++)
562 {
563 if (ResultsUpdateWorkerThread.CancellationPending == true)
564 {
565 e.Cancel = true;
566 return;
567 }
568 int Address = 0;
569 ResultDataType _result = (ResultDataType)AddedItems[i].Tag;
570 Address = Convert.ToInt32(AddedItems[i].SubItems[col_Added_Address].Text, 16);
571 using (GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
572 {
573 provider.OpenProvider();
574 int bytesReadSize;
575 byte[] data;
576 uint bytesToRead = 0;
577 switch (_result.ValueType)
578 {
579 case SearchDataTypes._8bits:
580 bytesToRead = 1;
581 break;
582 case SearchDataTypes._16bits:
583 bytesToRead = 2;
584 break;
585 case SearchDataTypes._32bits:
586 bytesToRead = 4;
587 break;
588 case SearchDataTypes._64bits:
589 bytesToRead = 8;
590 break;
591 }
592 provider.ReadProcessMemory(Address, bytesToRead, out bytesReadSize, out data);
593 provider.CloseProvider();
594 using (MemoryStream ms = new MemoryStream(data))
595 {
596 using (BinaryReader r_ms = new BinaryReader(ms))
597 {
598 switch (_result.ValueType)
599 {
600 case SearchDataTypes._8bits:
601 if (_result.IsUnsigned) { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x2}", r_ms.ReadByte()); }
602 else { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x2}", r_ms.ReadSByte()); }
603 break;
604 case SearchDataTypes._16bits:
605 if (_result.IsUnsigned) { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x4}", r_ms.ReadUInt16()); }
606 else { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x4}", r_ms.ReadInt16()); }
607 break;
608 case SearchDataTypes._32bits:
609 if (_result.IsUnsigned) { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x8}", r_ms.ReadUInt32()); }
610 else { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x8}", r_ms.ReadInt32()); }
611 break;
612 case SearchDataTypes._64bits:
613 if (_result.IsUnsigned) { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x16}", r_ms.ReadUInt64()); }
614 else { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x16}", r_ms.ReadInt64()); }
615 break;
616 }
617 r_ms.Close();
618 }
619 }
620 }
621 //Application.DoEvents();
622 }
623 #endregion
624
625
626 }
627
628 private void ResultsUpdateWorkerThread_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
629 {
630 try
631 {
632 //if ((lstResults.SelectedItems.Count > 0) && !PatchedValue_NeedsUpdate ) return;
633 //if ((lstPatchList.SelectedItems.Count > 0) && !PatchedValue_NeedsUpdate) return;
634 if (!this.ShouldUpdateResults()) return;
635 if (ResultItems.Count > 0)
636 {
637 //lstResults.Items.Clear();
638 //lstResults.Items.AddRange(ResultItems.ToArray());
639
640 for (int i = 0; i < ResultItems.Count; i++)
641 {
642 lstResults.Items[i].SubItems[new AVPColumnText(AVPColumnType.VALUE).ColumnIndex].Text =
643 ResultItems[i].SubItems[new AVPColumnText(AVPColumnType.VALUE).ColumnIndex].Text;
644 }
645
646 }
647 if (AddedItems.Count > 0)
648 {
649 //lstPatchList.Items.Clear();
650 //lstPatchList.Items.AddRange(AddedItems.ToArray());
651
652 for (int i = 0; i < AddedItems.Count; i++)
653 {
654 lstPatchList.Items[i].SubItems[new AVPColumnText(AVPColumnType.VALUE).ColumnIndex].Text =
655 AddedItems[i].SubItems[new AVPColumnText(AVPColumnType.VALUE).ColumnIndex].Text;
656 }
657
658 }
659 PatchedValue_NeedsUpdate = false;
660 }
661 catch { }
662 }
663
664 private void btnImportFile_Click(object sender, EventArgs e)
665 {
666 this.FreezeResultsUpdate();
667 if (!lstPatchList.ImportFromFile())
668 {
669 MessageBox.Show("Failed to Import Patch List from File.", "Import Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
670 this.ThawResultsUpdate();
671 return;
672 }
673 else
674 {
675 MessageBox.Show("Succesfully Imported Patch List from File.", "Import Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
676 this.ThawResultsUpdate();
677 return;
678 }
679 }
680 bool g_isFrozen = false;
681 private bool IsResultsUpdateFrozen
682 {
683 get { return g_isFrozen; }
684 set { g_isFrozen = value; }
685 }
686 private void ThawResultsUpdate()
687 {
688 this.IsResultsUpdateFrozen = false;
689 if (this.AcceptedProcess != null)
690 {
691 #if !DO_NOT_SUSPEND_RESUME_THREAD_ON_FREEZE
692 ThreadControl.ResumeProcess(this.AcceptedProcess.Id);
693 #endif
694 }
695 }
696
697 private void FreezeResultsUpdate()
698 {
699 this.IsResultsUpdateFrozen = true;
700 //this.IsResultsUpdateFrozen = false;
701 if (this.AcceptedProcess != null)
702 {
703 #if !DO_NOT_SUSPEND_RESUME_THREAD_ON_FREEZE
704 ThreadControl.SuspendProcess(this.AcceptedProcess.Id);
705 #endif
706 }
707 }
708
709 private void btnExportFile_Click(object sender, EventArgs e)
710 {
711 this.FreezeResultsUpdate();
712 if (!lstPatchList.ExportToFile())
713 {
714 MessageBox.Show("Failed to Export Patch List to File.", "Export Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
715 this.ThawResultsUpdate();
716 return;
717 }
718 else
719 {
720 MessageBox.Show("Succesfully Exported Patch List to File.", "Export Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
721 this.ThawResultsUpdate();
722 return;
723 }
724 }
725
726 private void btnImportClipboard_Click(object sender, EventArgs e)
727 {
728 this.FreezeResultsUpdate();
729 if (!lstPatchList.ImportFromClipboard())
730 {
731 MessageBox.Show("Failed to Import Patch List from Clipboard.", "Import Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
732 this.ThawResultsUpdate();
733 return;
734 }
735 else
736 {
737 MessageBox.Show("Succesfully Import Patch List from Clipboard.", "Import Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
738 this.ThawResultsUpdate();
739 }
740 }
741
742 private void btnExportClipboard_Click(object sender, EventArgs e)
743 {
744 this.FreezeResultsUpdate();
745 if (!lstPatchList.ExportToClipboard())
746 {
747 MessageBox.Show("Failed to Export Patch List to Clipboard.", "Export Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
748 this.ThawResultsUpdate();
749 return;
750 }
751 else
752 {
753 MessageBox.Show("Succesfully Exported Patch List to Clipboard.", "Export Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
754 this.ThawResultsUpdate();
755 return;
756 }
757 }
758
759 private void btnAddPatchAddress_Click(object sender, EventArgs e)
760 {
761 PatchAdder adder = new PatchAdder((IAcceptsProcessAndConfig)this);
762 adder.ShowDialog();
763 if (adder.WasAPatchAdded) AddToPatchList(adder.AddedPatchValue);
764 }
765
766 private void btnAddAddressRange_Click(object sender, EventArgs e)
767 {
768 PatchRangeAdder adder = new PatchRangeAdder((IAcceptsProcessAndConfig)this);
769 adder.ShowDialog();
770 if (adder.WasAPatchAdded) AddToPatchList(adder.AddedPatchValue);
771 }
772 private void AddToPatchList(List<ResultDataType> item) { foreach (ResultDataType data in item) { AddToPatchList(data); } }
773 private void AddToPatchList(ResultDataType item)
774 {
775 ResultItem item2 = null;
776 switch (item.ValueType)
777 {
778 case SearchDataTypes._8bits:
779 if (item.IsUnsigned) { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToByte(item.Value)); }
780 else { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToSByte(item.Value)); }
781 break;
782 case SearchDataTypes._16bits:
783 if (item.IsUnsigned) { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToUInt16(item.Value)); }
784 else { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToInt16(item.Value)); }
785 break;
786 case SearchDataTypes._32bits:
787 if (item.IsUnsigned) { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToUInt32(item.Value)); }
788 else { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToInt32(item.Value)); }
789 break;
790 case SearchDataTypes._64bits:
791 if (item.IsUnsigned) { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToUInt64(item.Value)); }
792 else { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToInt64(item.Value)); }
793 break;
794 }
795 this.AddToPatchList(item2);
796 }
797 private void AddToPatchList(ListViewItem item)
798 {
799 try
800 {
801 ResultDataType _result = (ResultDataType)item.Tag;
802 this.AddToPatchList(_result);
803 }
804 catch (InvalidCastException ex)
805 {
806 // unable to cast
807 MessageBox.Show(ex.Message, "Invalid Cast Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
808 }
809 catch (Exception ex)
810 {
811 // other exception
812 MessageBox.Show(ex.Message, "Unhandled Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
813 }
814 }
815 private void AddToPatchList(ResultItem item)
816 {
817 if (!lstPatchList.Items.Contains(item)) lstPatchList.Items.Add(item);
818 }
819 private void AddToPatchList(string address, SearchDataTypes bitsize, bool IsUnsigned)
820 {
821 ResultItemState state = new ResultItemState(address, bitsize, IsUnsigned, (IAcceptsProcessAndConfig)this);
822 ResultItem item = new ResultItem(state.Address, state.Value, state.Frozen, state.ValueType, state.IsUnsigned);
823 this.AddToPatchList(item);
824 }
825
826 private void mnuItemAddToPatchList_Click(object sender, EventArgs e)
827 {
828 if (!(lstResults.SelectedItems.Count > 0)) return;
829 //if (SearchArgs == null) return;
830
831 try
832 {
833 for (int i = 0; i < lstResults.SelectedIndices.Count; i++)
834 {
835 //ResultDataType result = (ResultDataType)lstResults.Items[selected_index].Tag;
836 ListViewItem item = lstResults.Items[lstResults.SelectedIndices[i]];
837 this.AddToPatchList(item);
838 }
839 }
840 catch (Exception ex)
841 {
842 logger.Error.WriteLine(ex.ToString());
843 }
844 }
845
846 private void mnuItemRemoveResult_Click(object sender, EventArgs e)
847 {
848 if (!(lstPatchList.SelectedItems.Count > 0)) return;
849 //if (SearchArgs == null) return;
850 try
851 {
852 this.FreezeResultsUpdate();
853 for (int i = 0; i < lstPatchList.SelectedIndices.Count; i++)
854 {
855 //lstPatchList.ThawItem(lstPatchList.SelectedIndices[i]);
856 lstPatchList.Items[lstPatchList.SelectedIndices[i]].Remove();
857 }
858 this.ThawResultsUpdate();
859 }
860 catch (Exception ex)
861 {
862 Debug.WriteLine(ex.ToString());
863 }
864 }
865 private void PatchRange(bool SingleEntry)
866 {
867 //if (SearchArgs == null) return;
868 #region Patch Selected Address
869 // stop ResultsUpdate Thread
870 ResultsUpdateWorkerThread.CancelAsync();
871
872 List<ResultDataType> patch_list = new List<ResultDataType>();
873 List<int> SelectedIndexes = new List<int>();
874
875 if (SingleEntry)
876 {
877 SelectedIndexes.Add(lstPatchList.SelectedIndices[0]);
878 }
879 else
880 {
881 foreach (int index in lstPatchList.SelectedIndices)
882 {
883 SelectedIndexes.Add(index);
884 }
885 }
886 //PCSX2MemoryProvider provider = new PCSX2MemoryProvider(this.SearchPCSX2ProcessPID, resultslog);
887 foreach (int index in SelectedIndexes)
888 {
889 if (SingleEntry)
890 {
891 SearchPatcher patcher = null;
892 uint Address = 0;
893 ListViewItem item = lstPatchList.Items[index];
894 ResultDataType _result = (ResultDataType)item.Tag;
895 Address = Convert.ToUInt32(item.SubItems[col_Found_Address].Text, 16);
896 switch (_result.ValueType)
897 {
898 case SearchDataTypes._8bits:
899 if (_result.IsUnsigned)
900 {
901 byte value = Convert.ToByte(item.SubItems[col_Found_Value].Text, 16);
902 patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
903 timer_update_results.Enabled = false;
904 patcher.ShowDialog();
905 timer_update_results.Enabled = true;
906 PatchedValue_NeedsUpdate = true;
907 if (!chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy)
908 ResultsUpdateWorkerThread.RunWorkerAsync();
909 }
910 else
911 {
912 sbyte value = Convert.ToSByte(item.SubItems[col_Found_Value].Text, 16);
913 patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
914 timer_update_results.Enabled = false;
915 patcher.ShowDialog();
916 timer_update_results.Enabled = true;
917 PatchedValue_NeedsUpdate = true;
918 if (!chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy)
919 ResultsUpdateWorkerThread.RunWorkerAsync();
920 }
921 break;
922 case SearchDataTypes._16bits:
923 if (_result.IsUnsigned)
924 {
925 ushort value = Convert.ToUInt16(item.SubItems[col_Found_Value].Text, 16);
926 patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
927 timer_update_results.Enabled = false;
928 patcher.ShowDialog();
929 timer_update_results.Enabled = true;
930 PatchedValue_NeedsUpdate = true;
931 if (!chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy)
932 ResultsUpdateWorkerThread.RunWorkerAsync();
933 }
934 else
935 {
936 short value = Convert.ToInt16(item.SubItems[col_Found_Value].Text, 16);
937 patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
938 timer_update_results.Enabled = false;
939 patcher.ShowDialog();
940 timer_update_results.Enabled = true;
941 PatchedValue_NeedsUpdate = true;
942 if (!chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy)
943 ResultsUpdateWorkerThread.RunWorkerAsync();
944 }
945 break;
946 case SearchDataTypes._32bits:
947 if (_result.IsUnsigned)
948 {
949 uint value = Convert.ToUInt32(item.SubItems[col_Found_Value].Text, 16);
950 patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
951 timer_update_results.Enabled = false;
952 patcher.ShowDialog();
953 timer_update_results.Enabled = true;
954 PatchedValue_NeedsUpdate = true;
955 if (!chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy)
956 ResultsUpdateWorkerThread.RunWorkerAsync();
957 }
958 else
959 {
960 int value = Convert.ToInt32(item.SubItems[col_Found_Value].Text, 16);
961 patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
962 timer_update_results.Enabled = false;
963 patcher.ShowDialog();
964 timer_update_results.Enabled = true;
965 PatchedValue_NeedsUpdate = true;
966 if (!chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy)
967 ResultsUpdateWorkerThread.RunWorkerAsync();
968 }
969 break;
970 case SearchDataTypes._64bits:
971 if (_result.IsUnsigned)
972 {
973 ulong value = Convert.ToUInt32(item.SubItems[col_Found_Value].Text, 16);
974 patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
975 timer_update_results.Enabled = false;
976 patcher.ShowDialog();
977 timer_update_results.Enabled = true;
978 PatchedValue_NeedsUpdate = true;
979 if (!chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy)
980 ResultsUpdateWorkerThread.RunWorkerAsync();
981 }
982 else
983 {
984 long value = Convert.ToInt32(item.SubItems[col_Found_Value].Text, 16);
985 patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
986 timer_update_results.Enabled = false;
987 patcher.ShowDialog();
988 timer_update_results.Enabled = true;
989 PatchedValue_NeedsUpdate = true;
990 if (!chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy)
991 ResultsUpdateWorkerThread.RunWorkerAsync();
992 }
993 break;
994 }
995 }
996 else
997 {
998
999 ListViewItem item = lstPatchList.Items[index];
1000 ResultDataType _result = (ResultDataType)item.Tag;
1001 patch_list.Add(_result);
1002 }
1003 }
1004
1005 if (patch_list.Count > 0)
1006 {
1007 SearchRangePatcher rangePatcher = new SearchRangePatcher((IAcceptsProcessAndConfig)this, patch_list);
1008 rangePatcher.ShowDialog();
1009 }
1010
1011 #endregion
1012 }
1013 private void mnuItemPatchSelectedEntry_Click(object sender, EventArgs e)
1014 {
1015 if (!(lstPatchList.SelectedItems.Count == 1)) return;
1016 PatchRange(true);
1017 }
1018
1019 private void mnuItemPatchSelectedRange_Click(object sender, EventArgs e)
1020 {
1021 if (!(lstPatchList.SelectedItems.Count >= 1)) return;
1022 PatchRange(false);
1023 }
1024
1025 private void mnuItemFreezeSelectedPatches_Click(object sender, EventArgs e)
1026 {
1027 if (!(lstPatchList.SelectedItems.Count > 0)) return;
1028 //if (SearchArgs == null) return;
1029 try
1030 {
1031 lstPatchList.ProcessID = this.AcceptedProcess.Id;
1032 this.FreezeResultsUpdate();
1033 for (int i = 0; i < lstPatchList.SelectedIndices.Count; i++)
1034 {
1035 lstPatchList.FreezeItem(lstPatchList.SelectedIndices[i]);
1036 }
1037 // force thaw and update
1038 this.ThawResultsUpdate();
1039 this.Update();
1040 }
1041 catch (Exception ex)
1042 {
1043 Debug.WriteLine(ex.ToString());
1044 }
1045 }
1046
1047 private void mnuItemThawSelectedPatches_Click(object sender, EventArgs e)
1048 {
1049 if (!(lstPatchList.SelectedItems.Count > 0)) return;
1050 //if (SearchArgs == null) return;
1051 try
1052 {
1053 lstPatchList.ProcessID = this.AcceptedProcess.Id;
1054 this.FreezeResultsUpdate();
1055 for (int i = 0; i < lstPatchList.SelectedIndices.Count; i++)
1056 {
1057 lstPatchList.ThawItem(lstPatchList.SelectedIndices[i]);
1058 }
1059 // force thaw and update
1060 this.ThawResultsUpdate();
1061 this.Update();
1062 }
1063 catch (Exception ex)
1064 {
1065 Debug.WriteLine(ex.ToString());
1066 }
1067 }
1068
1069 #region old-code: private void search_provider_OnBytesRead_compare_only(OnBytesReadEventArgs e)
1070 //private void search_provider_OnBytesRead_compare_only(OnBytesReadEventArgs e)
1071 //{
1072 // if (SearchWorkerThread.CancellationPending) { e.Canceled = true; return; }
1073 // SearchDataTypes sdt = SearchArgs.DataType;
1074 // bool unsigned = SearchArgs.IsUnsignedDataType;
1075 // //int Last_Whole_Percent_Done = 0;
1076 // uint CurrentIndex = e.CurrentIndex;
1077 // if (e.UserState != null)
1078 // {
1079 // SearchResultWriter writer = (e.UserState as SearchResultWriter);
1080 // if (writer == null)
1081 // throw new InvalidOperationException("writer cannot be null");
1082 // using (MemoryStream ms = new MemoryStream(e.Data))
1083 // {
1084 // using (BinaryReader br = new BinaryReader(ms))
1085 // {
1086 // while (br.BaseStream.Position < br.BaseStream.Length)
1087 // {
1088 // try
1089 // {
1090 // switch (sdt)
1091 // {
1092 // case SearchDataTypes._8bits:
1093 // if (unsigned)
1094 // {
1095 // #region 8bits - unsigned
1096 // var Value = br.ReadByte();
1097 // using (_8bit_unsigned_comparer_ comparer = new _8bit_unsigned_comparer_(SearchArgs, CurrentIndex))
1098 // {
1099 // byte value = 0;
1100 // if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1101 // {
1102 // using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1103 // {
1104 // try
1105 // {
1106 // gmp.OpenProvider();
1107 // gmp.ReadMemory(CurrentIndex, out value);
1108 // gmp.CloseProvider();
1109 // }
1110 // catch (Exception ex)
1111 // {
1112 // logger.VerboseError.WriteLine(ex.ToString());
1113 // }
1114 // }
1115 // comparer.Value = value;
1116 // }
1117 // else
1118 // {
1119 // value = Convert.ToByte(SearchArgs.CompareStartValue);
1120 // comparer.Value = value;
1121 // }
1122 // if (comparer.Compare(Convert.ToByte(Value), value))
1123 // {
1124 // writer.WriteResult<byte>(comparer.Address, comparer.Value);
1125 // }
1126 // }
1127 // #endregion
1128 // }
1129 // else
1130 // {
1131 // #region 8bits - signed
1132 // var Value = br.ReadSByte();
1133 // using (_8bit_signed_comparer_ comparer = new _8bit_signed_comparer_(SearchArgs, CurrentIndex))
1134 // {
1135 // sbyte value = 0;
1136 // if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1137 // {
1138 // using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1139 // {
1140 // try
1141 // {
1142 // gmp.OpenProvider();
1143 // gmp.ReadMemory(CurrentIndex, out value);
1144 // gmp.CloseProvider();
1145 // }
1146 // catch (Exception ex)
1147 // {
1148 // logger.VerboseError.WriteLine(ex.ToString());
1149 // }
1150 // }
1151 // comparer.Value = value;
1152 // }
1153 // else
1154 // {
1155 // value = Convert.ToSByte(SearchArgs.CompareStartValue);
1156 // comparer.Value = value;
1157 // }
1158 // if (comparer.Compare(Convert.ToSByte(Value), value))
1159 // {
1160 // writer.WriteResult<sbyte>(comparer.Address, comparer.Value);
1161 // }
1162 // }
1163 // #endregion
1164 // } break;
1165 // case SearchDataTypes._16bits:
1166 // if (unsigned)
1167 // {
1168 // #region 16bits - unsigned
1169 // var Value = br.ReadUInt16();
1170 // using (_16bit_unsigned_comparer_ comparer = new _16bit_unsigned_comparer_(SearchArgs, CurrentIndex))
1171 // {
1172 // ushort value = 0;
1173 // if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1174 // {
1175 // using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1176 // {
1177 // try
1178 // {
1179 // gmp.OpenProvider();
1180 // gmp.ReadMemory(CurrentIndex, out value);
1181 // gmp.CloseProvider();
1182 // }
1183 // catch (Exception ex)
1184 // {
1185 // logger.VerboseError.WriteLine(ex.ToString());
1186 // }
1187 // }
1188 // comparer.Value = value;
1189 // }
1190 // else
1191 // {
1192 // value = Convert.ToUInt16(SearchArgs.CompareStartValue);
1193 // comparer.Value = value;
1194 // }
1195 // if (comparer.Compare(Convert.ToUInt16(Value), value))
1196 // {
1197 // writer.WriteResult<ushort>(comparer.Address, comparer.Value);
1198 // }
1199 // }
1200 // #endregion
1201 // }
1202 // else
1203 // {
1204 // #region 16bits - signed
1205 // var Value = br.ReadInt16();
1206 // using (_16bit_signed_comparer_ comparer = new _16bit_signed_comparer_(SearchArgs, CurrentIndex))
1207 // {
1208 // short value = 0;
1209 // if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1210 // {
1211 // using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1212 // {
1213 // try
1214 // {
1215 // gmp.OpenProvider();
1216 // gmp.ReadMemory(CurrentIndex, out value);
1217 // gmp.CloseProvider();
1218 // }
1219 // catch (Exception ex)
1220 // {
1221 // logger.VerboseError.WriteLine(ex.ToString());
1222 // }
1223 // }
1224 // comparer.Value = value;
1225 // }
1226 // else
1227 // {
1228 // value = Convert.ToInt16(SearchArgs.CompareStartValue);
1229 // comparer.Value = value;
1230 // }
1231 // if (comparer.Compare(Convert.ToSByte(Value), value))
1232 // {
1233 // writer.WriteResult<short>(comparer.Address, comparer.Value);
1234 // }
1235 // }
1236 // #endregion
1237 // } break;
1238 // case SearchDataTypes._32bits:
1239 // if (unsigned)
1240 // {
1241 // #region 32bits - unsigned
1242 // var Value = br.ReadUInt32();
1243 // using (_32bit_unsigned_comparer_ comparer = new _32bit_unsigned_comparer_(SearchArgs, CurrentIndex))
1244 // {
1245 // uint value = 0;
1246 // if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1247 // {
1248 // using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1249 // {
1250 // try
1251 // {
1252 // gmp.OpenProvider();
1253 // gmp.ReadMemory(CurrentIndex, out value);
1254 // gmp.CloseProvider();
1255 // }
1256 // catch (Exception ex)
1257 // {
1258 // logger.VerboseError.WriteLine(ex.ToString());
1259 // }
1260 // }
1261 // comparer.Value = value;
1262 // }
1263 // else
1264 // {
1265 // value = Convert.ToUInt32(SearchArgs.CompareStartValue);
1266 // comparer.Value = value;
1267 // }
1268 // if (comparer.Compare(Convert.ToUInt32(Value), value))
1269 // {
1270 // writer.WriteResult<uint>(comparer.Address, comparer.Value);
1271 // }
1272 // }
1273 // #endregion
1274 // }
1275 // else
1276 // {
1277 // #region 32bits - signed
1278 // var Value = br.ReadInt32();
1279 // using (_32bit_signed_comparer_ comparer = new _32bit_signed_comparer_(SearchArgs, CurrentIndex))
1280 // {
1281 // int value = 0;
1282 // if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1283 // {
1284 // using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1285 // {
1286 // try
1287 // {
1288 // gmp.OpenProvider();
1289 // gmp.ReadMemory(CurrentIndex, out value);
1290 // gmp.CloseProvider();
1291 // }
1292 // catch (Exception ex)
1293 // {
1294 // logger.VerboseError.WriteLine(ex.ToString());
1295 // }
1296 // }
1297 // comparer.Value = value;
1298 // }
1299 // else
1300 // {
1301 // value = Convert.ToInt32(SearchArgs.CompareStartValue);
1302 // comparer.Value = value;
1303 // }
1304 // if (comparer.Compare(Convert.ToInt32(Value), value))
1305 // {
1306 // writer.WriteResult<int>(comparer.Address, comparer.Value);
1307 // }
1308 // }
1309 // #endregion
1310 // } break;
1311 // case SearchDataTypes._64bits:
1312 // if (unsigned)
1313 // {
1314 // #region 64bits - unsigned
1315 // var Value = br.ReadUInt64();
1316 // using (_64bit_unsigned_comparer_ comparer = new _64bit_unsigned_comparer_(SearchArgs, CurrentIndex))
1317 // {
1318 // ulong value = 0;
1319 // if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1320 // {
1321 // using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1322 // {
1323 // try
1324 // {
1325 // gmp.OpenProvider();
1326 // gmp.ReadMemory(CurrentIndex, out value);
1327 // gmp.CloseProvider();
1328 // }
1329 // catch (Exception ex)
1330 // {
1331 // logger.VerboseError.WriteLine(ex.ToString());
1332 // }
1333 // }
1334 // comparer.Value = value;
1335 // }
1336 // else
1337 // {
1338 // value = Convert.ToUInt64(SearchArgs.CompareStartValue);
1339 // comparer.Value = value;
1340 // }
1341 // if (comparer.Compare(Convert.ToUInt64(Value), value))
1342 // {
1343 // writer.WriteResult<ulong>(comparer.Address, comparer.Value);
1344 // }
1345 // }
1346 // #endregion
1347 // }
1348 // else
1349 // {
1350 // #region 64bits - signed
1351 // var Value = br.ReadInt64();
1352 // using (_64bit_signed_comparer_ comparer = new _64bit_signed_comparer_(SearchArgs, CurrentIndex))
1353 // {
1354 // long value = 0;
1355 // if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1356 // {
1357 // using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1358 // {
1359 // try
1360 // {
1361 // gmp.OpenProvider();
1362 // gmp.ReadMemory(CurrentIndex, out value);
1363 // gmp.CloseProvider();
1364 // }
1365 // catch (Exception ex)
1366 // {
1367 // logger.VerboseError.WriteLine(ex.ToString());
1368 // }
1369 // }
1370 // comparer.Value = value;
1371 // }
1372 // else
1373 // {
1374 // value = Convert.ToInt64(SearchArgs.CompareStartValue);
1375 // comparer.Value = value;
1376 // }
1377 // if (comparer.Compare(Convert.ToInt64(Value), value))
1378 // {
1379 // writer.WriteResult<long>(comparer.Address, comparer.Value);
1380 // }
1381 // }
1382 // #endregion
1383 // } break;
1384 // }
1385 // if (SearchWorkerThread.CancellationPending) { e.Canceled = true; return; }
1386 // }
1387 // catch (EndOfStreamException) { }
1388 // if (e.ReportProgress)
1389 // {
1390 // double double_percent_done = 100.0 * (double)((double)CurrentIndex / (double)e.TotalCount);
1391 // int int_percent_done = (int)double_percent_done;
1392 // //if (CurrentIndex % 10 == 0)
1393 // //{
1394 // // if (int_percent_done <= 100)
1395 // // {
1396 // new Action<int, string>(UpdateProgress).Invoke(int_percent_done, string.Format(" -> Reading Index: 0x{0:x8} of 0x{1:x8}", CurrentIndex, e.TotalCount));
1397 // // }
1398 // // if (SearchWorkerThread.CancellationPending) { e.Canceled = true; return; }
1399 // //}
1400 // }
1401 // //switch (sdt)
1402 // //{
1403 // // case SearchDataTypes._8bits:
1404 // // CurrentIndex += sizeof(byte);
1405 // // break;
1406 // // case SearchDataTypes._16bits:
1407 // // CurrentIndex += sizeof(ushort);
1408 // // break;
1409 // // case SearchDataTypes._32bits:
1410 // // CurrentIndex += sizeof(uint);
1411 // // break;
1412 // // case SearchDataTypes._64bits:
1413 // // CurrentIndex += sizeof(ulong);
1414 // // break;
1415 // //}
1416 // }
1417 // }
1418 // }
1419 // }
1420 // if (SearchWorkerThread.CancellationPending) { e.Canceled = true; return; }
1421 //}
1422 #endregion
1423
1424 #region old-code: private void search_provider_OnBytesRead(OnBytesReadEventArgs e)
1425 //private void search_provider_OnBytesRead(OnBytesReadEventArgs e)
1426 //{
1427 // if (SearchWorkerThread.CancellationPending) { e.Canceled = true; return; }
1428 // SearchDataTypes sdt = SearchArgs.DataType;
1429 // bool unsigned = SearchArgs.IsUnsignedDataType;
1430 // int Last_Whole_Percent_Done = 0;
1431 // uint CurrentIndex = e.CurrentIndex;
1432 // if (e.UserState != null)
1433 // {
1434 // SearchResultWriter writer = (e.UserState as SearchResultWriter);
1435 // if (writer == null)
1436 // throw new InvalidOperationException("writer cannot be null");
1437 // using (MemoryStream ms = new MemoryStream(e.Data))
1438 // {
1439 // using (BinaryReader br = new BinaryReader(ms))
1440 // {
1441 // while (br.BaseStream.Position < br.BaseStream.Length)
1442 // {
1443 // try
1444 // {
1445 // //if (e.ReportProgress)
1446 // //{
1447 // // double double_percent_done = 100.0 * (double)((double)CurrentIndex / (double)e.TotalCount);
1448 // // int int_percent_done = (int)double_percent_done;
1449 // // int align_base = 100;
1450 // // int align_power = 1;
1451 // // int align = align_base * align_power;
1452 // // if (int_percent_done != Last_Whole_Percent_Done && (CurrentIndex % align) == 0)
1453 // // {
1454 // // string message = string.Format(" -> Reading Address: 0x{0:x8}", (CurrentIndex + MemoryRangeStart));
1455 // // UpdateProgress((int)double_percent_done, message);
1456 // // //new Action<int, string>(UpdateProgress).Invoke(int_percent_done, message);
1457 // // Last_Whole_Percent_Done = int_percent_done;
1458 // // if (SearchWorkerThread.CancellationPending) { e.Canceled = true; return; }
1459 // // }
1460 // //}
1461
1462 // switch (sdt)
1463 // {
1464 // case SearchDataTypes._8bits:
1465 // if (unsigned)
1466 // {
1467 // #region 8bits - unsigned
1468 // var Value = br.ReadByte();
1469 // using (_8bit_unsigned_comparer_ comparer = new _8bit_unsigned_comparer_(SearchArgs, CurrentIndex))
1470 // {
1471 // byte value = 0;
1472 // if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1473 // {
1474 // using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1475 // {
1476 // try
1477 // {
1478 // gmp.OpenProvider();
1479 // gmp.ReadMemory(CurrentIndex, out value);
1480 // gmp.CloseProvider();
1481 // }
1482 // catch (Exception ex)
1483 // {
1484 // logger.VerboseError.WriteLine(ex.ToString());
1485 // }
1486 // }
1487 // comparer.Value = value;
1488 // }
1489 // else
1490 // {
1491 // value = Convert.ToByte(SearchArgs.CompareStartValue);
1492 // comparer.Value = value;
1493 // }
1494 // if (comparer.Compare(Convert.ToByte(Value), value))
1495 // {
1496 // writer.WriteResult<byte>(comparer.Address, comparer.Value);
1497 // }
1498 // }
1499 // #endregion
1500 // }
1501 // else
1502 // {
1503 // #region 8bits - signed
1504 // var Value = br.ReadSByte();
1505 // using (_8bit_signed_comparer_ comparer = new _8bit_signed_comparer_(SearchArgs, CurrentIndex))
1506 // {
1507 // sbyte value = 0;
1508 // if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1509 // {
1510 // using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1511 // {
1512 // try
1513 // {
1514 // gmp.OpenProvider();
1515 // gmp.ReadMemory(CurrentIndex, out value);
1516 // gmp.CloseProvider();
1517 // }
1518 // catch (Exception ex)
1519 // {
1520 // logger.VerboseError.WriteLine(ex.ToString());
1521 // }
1522 // }
1523 // comparer.Value = value;
1524 // }
1525 // else
1526 // {
1527 // value = Convert.ToSByte(SearchArgs.CompareStartValue);
1528 // comparer.Value = value;
1529 // }
1530 // if (comparer.Compare(Convert.ToSByte(Value), value))
1531 // {
1532 // writer.WriteResult<sbyte>(comparer.Address, comparer.Value);
1533 // }
1534 // }
1535 // #endregion
1536 // } break;
1537 // case SearchDataTypes._16bits:
1538 // if (unsigned)
1539 // {
1540 // #region 16bits - unsigned
1541 // var Value = br.ReadUInt16();
1542 // using (_16bit_unsigned_comparer_ comparer = new _16bit_unsigned_comparer_(SearchArgs, CurrentIndex))
1543 // {
1544 // ushort value = 0;
1545 // if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1546 // {
1547 // using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1548 // {
1549 // try
1550 // {
1551 // gmp.OpenProvider();
1552 // gmp.ReadMemory(CurrentIndex, out value);
1553 // gmp.CloseProvider();
1554 // }
1555 // catch (Exception ex)
1556 // {
1557 // logger.VerboseError.WriteLine(ex.ToString());
1558 // }
1559 // }
1560 // comparer.Value = value;
1561 // }
1562 // else
1563 // {
1564 // value = Convert.ToUInt16(SearchArgs.CompareStartValue);
1565 // comparer.Value = value;
1566 // }
1567 // if (comparer.Compare(Convert.ToUInt16(Value), value))
1568 // {
1569 // writer.WriteResult<ushort>(comparer.Address, comparer.Value);
1570 // }
1571 // }
1572 // #endregion
1573 // }
1574 // else
1575 // {
1576 // #region 16bits - signed
1577 // var Value = br.ReadInt16();
1578 // using (_16bit_signed_comparer_ comparer = new _16bit_signed_comparer_(SearchArgs, CurrentIndex))
1579 // {
1580 // short value = 0;
1581 // if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1582 // {
1583 // using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1584 // {
1585 // try
1586 // {
1587 // gmp.OpenProvider();
1588 // gmp.ReadMemory(CurrentIndex, out value);
1589 // gmp.CloseProvider();
1590 // }
1591 // catch (Exception ex)
1592 // {
1593 // logger.VerboseError.WriteLine(ex.ToString());
1594 // }
1595 // }
1596 // comparer.Value = value;
1597 // }
1598 // else
1599 // {
1600 // value = Convert.ToInt16(SearchArgs.CompareStartValue);
1601 // comparer.Value = value;
1602 // }
1603 // if (comparer.Compare(Convert.ToSByte(Value), value))
1604 // {
1605 // writer.WriteResult<short>(comparer.Address, comparer.Value);
1606 // }
1607 // }
1608 // #endregion
1609 // } break;
1610 // case SearchDataTypes._32bits:
1611 // if (unsigned)
1612 // {
1613 // #region 32bits - unsigned
1614 // var Value = br.ReadUInt32();
1615 // using (_32bit_unsigned_comparer_ comparer = new _32bit_unsigned_comparer_(SearchArgs, CurrentIndex))
1616 // {
1617 // uint value = 0;
1618 // if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1619 // {
1620 // using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1621 // {
1622 // try
1623 // {
1624 // gmp.OpenProvider();
1625 // gmp.ReadMemory(CurrentIndex, out value);
1626 // gmp.CloseProvider();
1627 // }
1628 // catch (Exception ex)
1629 // {
1630 // logger.VerboseError.WriteLine(ex.ToString());
1631 // }
1632 // }
1633 // comparer.Value = value;
1634 // }
1635 // else
1636 // {
1637 // value = Convert.ToUInt32(SearchArgs.CompareStartValue);
1638 // comparer.Value = value;
1639 // }
1640 // if (comparer.Compare(Convert.ToUInt32(Value), value))
1641 // {
1642 // writer.WriteResult<uint>(comparer.Address, comparer.Value);
1643 // }
1644 // }
1645 // #endregion
1646 // }
1647 // else
1648 // {
1649 // #region 32bits - signed
1650 // var Value = br.ReadInt32();
1651 // using (_32bit_signed_comparer_ comparer = new _32bit_signed_comparer_(SearchArgs, CurrentIndex))
1652 // {
1653 // int value = 0;
1654 // if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1655 // {
1656 // using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1657 // {
1658 // try
1659 // {
1660 // gmp.OpenProvider();
1661 // gmp.ReadMemory(CurrentIndex, out value);
1662 // gmp.CloseProvider();
1663 // }
1664 // catch (Exception ex)
1665 // {
1666 // logger.VerboseError.WriteLine(ex.ToString());
1667 // }
1668 // }
1669 // comparer.Value = value;
1670 // }
1671 // else
1672 // {
1673 // value = Convert.ToInt32(SearchArgs.CompareStartValue);
1674 // comparer.Value = value;
1675 // }
1676 // if (comparer.Compare(Convert.ToInt32(Value), value))
1677 // {
1678 // writer.WriteResult<int>(comparer.Address, comparer.Value);
1679 // }
1680 // }
1681 // #endregion
1682 // } break;
1683 // case SearchDataTypes._64bits:
1684 // if (unsigned)
1685 // {
1686 // #region 64bits - unsigned
1687 // var Value = br.ReadUInt64();
1688 // using (_64bit_unsigned_comparer_ comparer = new _64bit_unsigned_comparer_(SearchArgs, CurrentIndex))
1689 // {
1690 // ulong value = 0;
1691 // if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1692 // {
1693 // using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1694 // {
1695 // try
1696 // {
1697 // gmp.OpenProvider();
1698 // gmp.ReadMemory(CurrentIndex, out value);
1699 // gmp.CloseProvider();
1700 // }
1701 // catch (Exception ex)
1702 // {
1703 // logger.VerboseError.WriteLine(ex.ToString());
1704 // }
1705 // }
1706 // comparer.Value = value;
1707 // }
1708 // else
1709 // {
1710 // value = Convert.ToUInt64(SearchArgs.CompareStartValue);
1711 // comparer.Value = value;
1712 // }
1713 // if (comparer.Compare(Convert.ToUInt64(Value), value))
1714 // {
1715 // writer.WriteResult<ulong>(comparer.Address, comparer.Value);
1716 // }
1717 // }
1718 // #endregion
1719 // }
1720 // else
1721 // {
1722 // #region 64bits - signed
1723 // var Value = br.ReadInt64();
1724 // using (_64bit_signed_comparer_ comparer = new _64bit_signed_comparer_(SearchArgs, CurrentIndex))
1725 // {
1726 // long value = 0;
1727 // if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1728 // {
1729 // using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1730 // {
1731 // try
1732 // {
1733 // gmp.OpenProvider();
1734 // gmp.ReadMemory(CurrentIndex, out value);
1735 // gmp.CloseProvider();
1736 // }
1737 // catch (Exception ex)
1738 // {
1739 // logger.VerboseError.WriteLine(ex.ToString());
1740 // }
1741 // }
1742 // comparer.Value = value;
1743 // }
1744 // else
1745 // {
1746 // value = Convert.ToInt64(SearchArgs.CompareStartValue);
1747 // comparer.Value = value;
1748 // }
1749 // if (comparer.Compare(Convert.ToInt64(Value), value))
1750 // {
1751 // writer.WriteResult<long>(comparer.Address, comparer.Value);
1752 // }
1753 // }
1754 // #endregion
1755 // } break;
1756 // }
1757 // if (SearchWorkerThread.CancellationPending) { e.Canceled = true; return; }
1758 // }
1759 // catch (EndOfStreamException) { }
1760
1761 // uint size = 0;
1762 // BitTools.SizeOf(sdt, out size);
1763 // CurrentIndex += size;
1764 // }
1765 // }
1766 // }
1767 // }
1768 // if (SearchWorkerThread.CancellationPending) { e.Canceled = true; return; }
1769 //}
1770 #endregion
1771
1772 private void SearchWorkerThread_DoWork(object sender, DoWorkEventArgs e)
1773 {
1774 try
1775 {
1776 Stopwatch st = new Stopwatch();
1777 st.Start();
1778
1779 Stopwatch st_first_search = new Stopwatch();
1780 Stopwatch st_nonrange_search = new Stopwatch();
1781 Stopwatch st_ranged_search = new Stopwatch();
1782
1783 e.Result = st;
1784 //List<ResultType<object>> tmp_Results = new List<ResultType<object>>();
1785 List<ResultType<ulong>> second_tmp_Results = new List<ResultType<ulong>>();
1786 //const int ElementsBeforeDisplay = 100;
1787 SearchArgs.LogSearchOptions();
1788 uint STEP_SIZE = (uint)SearchArgs.DataType / 8;
1789
1790 bool unsigned = SearchArgs.IsUnsignedDataType;
1791 SearchDataTypes sdt = SearchArgs.DataType;
1792 //byte[] buffered_mem = new byte[(MemoryRangeSize - MemoryRangeStart)]; // throws OutOfMemoryException if size is over 2G
1793 logger.Debug.WriteLine(string.Format("Buffered Memory Size -> 0x{0:x8}", MemoryRangeSize - MemoryRangeStart));
1794 UpdateProgress(0, string.Format("Search is Warming Up...Please Wait..."));
1795 //new Action<int, string>(UpdateProgress).Invoke(0, string.Format("Search is Warming Up...Please Wait..."));
1796 Stopwatch provider_st = new Stopwatch();
1797 provider_st.Start();
1798 using (GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1799 {
1800
1801 if (SearchArgs.IsFirstSearch)
1802 {
1803 provider.OpenProvider();
1804 int count = (int)((MemoryRangeSize - MemoryRangeStart) / STEP_SIZE);
1805 SearchResultWriter writer = new SearchResultWriter((int)(count), SearchGuid);
1806 int Last_Whole_Percent_Done = 0;
1807 uint size = STEP_SIZE * 4096;
1808 for (uint i = MemoryRangeStart; i < MemoryRangeSize; i+=size)
1809 {
1810
1811 int bytesRead=0;
1812 byte[] data = new byte[size];
1813 provider.ReadProcessMemoryAtOnce(i, size, out bytesRead, out data);
1814 string message = string.Format(" -> Reading Address: 0x{0:x8}", (i + MemoryRangeStart));
1815 double double_percent_done = 100.0 * (double)((double)i / (double)MemoryRangeSize);
1816 int int_percent_done = (int)double_percent_done;
1817 if ( (int_percent_done != Last_Whole_Percent_Done) && (i % 10000) == 0)
1818 {
1819 UpdateProgress((int)double_percent_done, message);
1820 Last_Whole_Percent_Done = int_percent_done;
1821 }
1822
1823 uint address_index = i;
1824 #region comparison and serialization
1825 switch (sdt)
1826 {
1827 case SearchDataTypes._8bits:
1828 if (unsigned)
1829 {
1830 #region 8bits - unsigned
1831 var t_data = BitTools.ConvertByteArray<byte>(data);
1832 foreach (var Value in t_data)
1833 {
1834 if (SearchWorkerThread.CancellationPending) { break; }
1835 using (_8bit_unsigned_comparer_ comparer = new _8bit_unsigned_comparer_(SearchArgs, address_index))
1836 {
1837 byte value = 0;
1838 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1839 {
1840 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1841 {
1842 try
1843 {
1844 gmp.OpenProvider();
1845 gmp.ReadMemory(address_index, out value);
1846 gmp.CloseProvider();
1847 }
1848 catch (Exception ex)
1849 {
1850 logger.VerboseError.WriteLine(ex.ToString());
1851 }
1852 }
1853 comparer.Value = value;
1854 }
1855 else
1856 {
1857 value = Convert.ToByte(SearchArgs.CompareStartValue);
1858 comparer.Value = value;
1859 }
1860 if (comparer.Compare(Convert.ToByte(Value), value))
1861 {
1862 writer.WriteResult<byte>(comparer.Address, comparer.Value);
1863 }
1864 }
1865 address_index += STEP_SIZE;
1866 }
1867 #endregion
1868 }
1869 else
1870 {
1871 #region 8bits - signed
1872 var t_data = BitTools.ConvertByteArray<sbyte>(data);
1873 foreach (var Value in t_data)
1874 {
1875 if (SearchWorkerThread.CancellationPending) { break; }
1876 using (_8bit_signed_comparer_ comparer = new _8bit_signed_comparer_(SearchArgs, address_index))
1877 {
1878 sbyte value = 0;
1879 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1880 {
1881 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1882 {
1883 try
1884 {
1885 gmp.OpenProvider();
1886 gmp.ReadMemory(address_index, out value);
1887 gmp.CloseProvider();
1888 }
1889 catch (Exception ex)
1890 {
1891 logger.VerboseError.WriteLine(ex.ToString());
1892 }
1893 }
1894 comparer.Value = value;
1895 }
1896 else
1897 {
1898 value = Convert.ToSByte(SearchArgs.CompareStartValue);
1899 comparer.Value = value;
1900 }
1901 if (comparer.Compare(Convert.ToSByte(Value), value))
1902 {
1903 writer.WriteResult<sbyte>(comparer.Address, comparer.Value);
1904 }
1905 }
1906 address_index += STEP_SIZE;
1907 }
1908 #endregion
1909 } break;
1910 case SearchDataTypes._16bits:
1911 if (unsigned)
1912 {
1913 #region 16bits - unsigned
1914 var t_data = BitTools.ConvertByteArray<ushort>(data);
1915 foreach (var Value in t_data)
1916 {
1917 if (SearchWorkerThread.CancellationPending) { break; }
1918 using (_16bit_unsigned_comparer_ comparer = new _16bit_unsigned_comparer_(SearchArgs, address_index))
1919 {
1920 ushort value = 0;
1921 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1922 {
1923 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1924 {
1925 try
1926 {
1927 gmp.OpenProvider();
1928 gmp.ReadMemory(address_index, out value);
1929 gmp.CloseProvider();
1930 }
1931 catch (Exception ex)
1932 {
1933 logger.VerboseError.WriteLine(ex.ToString());
1934 }
1935 }
1936 comparer.Value = value;
1937 }
1938 else
1939 {
1940 value = Convert.ToUInt16(SearchArgs.CompareStartValue);
1941 comparer.Value = value;
1942 }
1943 if (comparer.Compare(Convert.ToUInt16(Value), value))
1944 {
1945 writer.WriteResult<ushort>(comparer.Address, comparer.Value);
1946 }
1947 }
1948 address_index += STEP_SIZE;
1949 }
1950 #endregion
1951 }
1952 else
1953 {
1954 #region 16bits - signed
1955 var t_data = BitTools.ConvertByteArray<short>(data);
1956 foreach (var Value in t_data)
1957 {
1958 if (SearchWorkerThread.CancellationPending) { break; }
1959 using (_16bit_signed_comparer_ comparer = new _16bit_signed_comparer_(SearchArgs, address_index))
1960 {
1961 short value = 0;
1962 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1963 {
1964 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1965 {
1966 try
1967 {
1968 gmp.OpenProvider();
1969 gmp.ReadMemory(address_index, out value);
1970 gmp.CloseProvider();
1971 }
1972 catch (Exception ex)
1973 {
1974 logger.VerboseError.WriteLine(ex.ToString());
1975 }
1976 }
1977 comparer.Value = value;
1978 }
1979 else
1980 {
1981 value = Convert.ToInt16(SearchArgs.CompareStartValue);
1982 comparer.Value = value;
1983 }
1984 if (comparer.Compare(Convert.ToSByte(Value), value))
1985 {
1986 writer.WriteResult<short>(comparer.Address, comparer.Value);
1987 }
1988 }
1989 address_index += STEP_SIZE;
1990 }
1991 #endregion
1992 } break;
1993 case SearchDataTypes._32bits:
1994 if (unsigned)
1995 {
1996 #region 32bits - unsigned
1997 var t_data = BitTools.ConvertByteArray<uint>(data);
1998 foreach (var Value in t_data)
1999 {
2000 if (SearchWorkerThread.CancellationPending) { break; }
2001 using (_32bit_unsigned_comparer_ comparer = new _32bit_unsigned_comparer_(SearchArgs, address_index))
2002 {
2003 uint value = 0;
2004 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2005 {
2006 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2007 {
2008 try
2009 {
2010 gmp.OpenProvider();
2011 gmp.ReadMemory(address_index, out value);
2012 gmp.CloseProvider();
2013 }
2014 catch (Exception ex)
2015 {
2016 logger.VerboseError.WriteLine(ex.ToString());
2017 }
2018 }
2019 comparer.Value = value;
2020 }
2021 else
2022 {
2023 value = Convert.ToUInt32(SearchArgs.CompareStartValue);
2024 comparer.Value = value;
2025 }
2026 if (comparer.Compare(Convert.ToUInt32(Value), value))
2027 {
2028 writer.WriteResult<uint>(comparer.Address, comparer.Value);
2029 }
2030 }
2031 address_index += STEP_SIZE;
2032 }
2033 #endregion
2034 }
2035 else
2036 {
2037 #region 32bits - signed
2038 var t_data = BitTools.ConvertByteArray<int>(data);
2039 foreach (var Value in t_data)
2040 {
2041 if (SearchWorkerThread.CancellationPending) { break; }
2042 using (_32bit_signed_comparer_ comparer = new _32bit_signed_comparer_(SearchArgs, address_index))
2043 {
2044 int value = 0;
2045 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2046 {
2047 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2048 {
2049 try
2050 {
2051 gmp.OpenProvider();
2052 gmp.ReadMemory(address_index, out value);
2053 gmp.CloseProvider();
2054 }
2055 catch (Exception ex)
2056 {
2057 logger.VerboseError.WriteLine(ex.ToString());
2058 }
2059 }
2060 comparer.Value = value;
2061 }
2062 else
2063 {
2064 value = Convert.ToInt32(SearchArgs.CompareStartValue);
2065 comparer.Value = value;
2066 }
2067 if (comparer.Compare(Convert.ToInt32(Value), value))
2068 {
2069 writer.WriteResult<int>(comparer.Address, comparer.Value);
2070 }
2071 }
2072 address_index += STEP_SIZE;
2073 }
2074 #endregion
2075 } break;
2076 case SearchDataTypes._64bits:
2077 if (unsigned)
2078 {
2079 #region 64bits - unsigned
2080 var t_data = BitTools.ConvertByteArray<ulong>(data);
2081 foreach (var Value in t_data)
2082 {
2083 if (SearchWorkerThread.CancellationPending) { break; }
2084 using (_64bit_unsigned_comparer_ comparer = new _64bit_unsigned_comparer_(SearchArgs, address_index))
2085 {
2086 ulong value = 0;
2087 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2088 {
2089 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2090 {
2091 try
2092 {
2093 gmp.OpenProvider();
2094 gmp.ReadMemory(address_index, out value);
2095 gmp.CloseProvider();
2096 }
2097 catch (Exception ex)
2098 {
2099 logger.VerboseError.WriteLine(ex.ToString());
2100 }
2101 }
2102 comparer.Value = value;
2103 }
2104 else
2105 {
2106 value = Convert.ToUInt64(SearchArgs.CompareStartValue);
2107 comparer.Value = value;
2108 }
2109 if (comparer.Compare(Convert.ToUInt64(Value), value))
2110 {
2111 writer.WriteResult<ulong>(comparer.Address, comparer.Value);
2112 }
2113 }
2114 address_index += STEP_SIZE;
2115 }
2116 #endregion
2117 }
2118 else
2119 {
2120 #region 64bits - signed
2121 var t_data = BitTools.ConvertByteArray<long>(data);
2122 foreach (var Value in t_data)
2123 {
2124 if (SearchWorkerThread.CancellationPending) { break; }
2125 using (_64bit_signed_comparer_ comparer = new _64bit_signed_comparer_(SearchArgs, address_index))
2126 {
2127 long value = 0;
2128 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2129 {
2130 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2131 {
2132 try
2133 {
2134 gmp.OpenProvider();
2135 gmp.ReadMemory(address_index, out value);
2136 gmp.CloseProvider();
2137 }
2138 catch (Exception ex)
2139 {
2140 logger.VerboseError.WriteLine(ex.ToString());
2141 }
2142 }
2143 comparer.Value = value;
2144 }
2145 else
2146 {
2147 value = Convert.ToInt64(SearchArgs.CompareStartValue);
2148 comparer.Value = value;
2149 }
2150 if (comparer.Compare(Convert.ToInt64(Value), value))
2151 {
2152 writer.WriteResult<long>(comparer.Address, comparer.Value);
2153 }
2154 }
2155 address_index += STEP_SIZE;
2156 }
2157 #endregion
2158 } break;
2159
2160 }
2161 #endregion
2162
2163
2164 if (SearchWorkerThread.CancellationPending)
2165 {
2166 provider_st.Stop();
2167 st.Stop();
2168 writer.CancelRequest();
2169 writer.Dispose();
2170 writer = null;
2171 e.Result = true;
2172 provider.CloseProvider();
2173 return;
2174 }
2175 }
2176
2177 if (SearchWorkerThread.CancellationPending)
2178 {
2179 provider_st.Stop();
2180 st.Stop();
2181 writer.CancelRequest();
2182 writer.Dispose();
2183 writer = null;
2184 e.Result = true;
2185 provider.CloseProvider();
2186 return;
2187 }
2188 writer.Dispose();
2189 writer = null;
2190 provider.CloseProvider();
2191 }
2192 else
2193 {
2194 Guid new_SearchGuid = SearchGuid;
2195 // need to get the address list
2196 using (SearchResultReader reader = new SearchResultReader(SearchGuid, false)) // delete the file on dispose
2197 {
2198 #region old-code
2199 //provider.OpenProvider();
2200 ////int count = (int)((MemoryRangeSize - MemoryRangeStart) / STEP_SIZE);
2201 ////SearchResultWriter writer = new SearchResultWriter((int)(count), SearchGuid);
2202 //provider.OnBytesRead += new BaseEventHandler<OnBytesReadEventArgs>(action_onbytesread);
2203 //provider.ReadProcessMemoryAtOnce(MemoryRangeStart, (MemoryRangeSize - MemoryRangeStart), reader);
2204 //if (SearchWorkerThread.CancellationPending)
2205 //{
2206 // provider_st.Stop();
2207 // st.Stop();
2208 // e.Result = true;
2209 // provider.CloseProvider();
2210 // return;
2211 //}
2212 //provider.CloseProvider();
2213
2214 //byte[] guid = SearchGuid.ToByteArray();
2215 //guid[guid.Length - 1]++; // increment the search guid by 1
2216 //Guid new_SearchGuid = new Guid(guid);
2217 ////const int item_count = 0x100;
2218 //using (SearchResultWriter writer = new SearchResultWriter((int)(reader.ResultCount), new_SearchGuid))
2219 //{
2220 // var items = reader.GetSearchAddressValueMatches((IAcceptsProcessAndConfig)this, SearchArgs, new Action<int, string>(UpdateProgress));
2221 // reader.Dispose(); // delete the result file, if allowed
2222 // foreach (var item in items)
2223 // {
2224 // switch (SearchArgs.DataType)
2225 // {
2226 // case SearchDataTypes._8bits:
2227 // if (SearchArgs.IsUnsignedDataType)
2228 // {
2229 // writer.WriteResult<byte>(item.Address, Convert.ToByte(item.Value));
2230 // }
2231 // else
2232 // {
2233 // writer.WriteResult<sbyte>(item.Address, Convert.ToSByte(item.Value));
2234 // }
2235 // break;
2236 // case SearchDataTypes._16bits:
2237 // if (SearchArgs.IsUnsignedDataType)
2238 // {
2239 // writer.WriteResult<ushort>(item.Address, Convert.ToUInt16(item.Value));
2240 // }
2241 // else
2242 // {
2243 // writer.WriteResult<short>(item.Address, Convert.ToInt16(item.Value));
2244 // }
2245 // break;
2246 // case SearchDataTypes._32bits:
2247 // if (SearchArgs.IsUnsignedDataType)
2248 // {
2249 // writer.WriteResult<uint>(item.Address, Convert.ToUInt32(item.Value));
2250 // }
2251 // else
2252 // {
2253 // writer.WriteResult<int>(item.Address, Convert.ToInt32(item.Value));
2254 // }
2255 // break;
2256 // case SearchDataTypes._64bits:
2257 // if (SearchArgs.IsUnsignedDataType)
2258 // {
2259 // writer.WriteResult<ulong>(item.Address, Convert.ToUInt64(item.Value));
2260 // }
2261 // else
2262 // {
2263 // writer.WriteResult<long>(item.Address, Convert.ToInt64(item.Value));
2264 // }
2265 // break;
2266 // }
2267 // }
2268 //}
2269 //SearchGuid = new_SearchGuid;
2270 #endregion
2271
2272 new_SearchGuid = GuidTools.IncrementGuid(SearchGuid);
2273 using (SearchResultWriter writer = new SearchResultWriter(0, new_SearchGuid))
2274 {
2275 foreach (var k in reader.GetResults(SearchArgs.IsUnsignedDataType, SearchArgs.DataType, new Action<int, string>(UpdateProgress)))
2276 {
2277 provider.OpenProvider();
2278 int bytesRead = 0;
2279 byte[] data = new byte[STEP_SIZE];
2280 provider.ReadProcessMemory(k.Address, STEP_SIZE, out bytesRead, out data);
2281 provider.CloseProvider();
2282
2283 uint address_index = k.Address;
2284 #region comparison and serialization
2285 switch (sdt)
2286 {
2287 case SearchDataTypes._8bits:
2288 if (unsigned)
2289 {
2290 #region 8bits - unsigned
2291 var t_data = BitTools.ConvertByteArray<byte>(data);
2292 foreach (var Value in t_data)
2293 {
2294 if (SearchWorkerThread.CancellationPending) { break; }
2295 using (_8bit_unsigned_comparer_ comparer = new _8bit_unsigned_comparer_(SearchArgs, address_index))
2296 {
2297 byte value = 0;
2298 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2299 {
2300 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2301 {
2302 try
2303 {
2304 gmp.OpenProvider();
2305 gmp.ReadMemory(address_index, out value);
2306 gmp.CloseProvider();
2307 }
2308 catch (Exception ex)
2309 {
2310 logger.VerboseError.WriteLine(ex.ToString());
2311 }
2312 }
2313 comparer.Value = value;
2314 }
2315 else
2316 {
2317 value = Convert.ToByte(SearchArgs.CompareStartValue);
2318 comparer.Value = value;
2319 }
2320 if (comparer.Compare(Convert.ToByte(Value), value))
2321 {
2322 writer.WriteResult<byte>(comparer.Address, comparer.Value);
2323 }
2324 }
2325 address_index += STEP_SIZE;
2326 }
2327 #endregion
2328 }
2329 else
2330 {
2331 #region 8bits - signed
2332 var t_data = BitTools.ConvertByteArray<sbyte>(data);
2333 foreach (var Value in t_data)
2334 {
2335 if (SearchWorkerThread.CancellationPending) { break; }
2336 using (_8bit_signed_comparer_ comparer = new _8bit_signed_comparer_(SearchArgs, address_index))
2337 {
2338 sbyte value = 0;
2339 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2340 {
2341 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2342 {
2343 try
2344 {
2345 gmp.OpenProvider();
2346 gmp.ReadMemory(address_index, out value);
2347 gmp.CloseProvider();
2348 }
2349 catch (Exception ex)
2350 {
2351 logger.VerboseError.WriteLine(ex.ToString());
2352 }
2353 }
2354 comparer.Value = value;
2355 }
2356 else
2357 {
2358 value = Convert.ToSByte(SearchArgs.CompareStartValue);
2359 comparer.Value = value;
2360 }
2361 if (comparer.Compare(Convert.ToSByte(Value), value))
2362 {
2363 writer.WriteResult<sbyte>(comparer.Address, comparer.Value);
2364 }
2365 }
2366 address_index += STEP_SIZE;
2367 }
2368 #endregion
2369 } break;
2370 case SearchDataTypes._16bits:
2371 if (unsigned)
2372 {
2373 #region 16bits - unsigned
2374 var t_data = BitTools.ConvertByteArray<ushort>(data);
2375 foreach (var Value in t_data)
2376 {
2377 if (SearchWorkerThread.CancellationPending) { break; }
2378 using (_16bit_unsigned_comparer_ comparer = new _16bit_unsigned_comparer_(SearchArgs, address_index))
2379 {
2380 ushort value = 0;
2381 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2382 {
2383 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2384 {
2385 try
2386 {
2387 gmp.OpenProvider();
2388 gmp.ReadMemory(address_index, out value);
2389 gmp.CloseProvider();
2390 }
2391 catch (Exception ex)
2392 {
2393 logger.VerboseError.WriteLine(ex.ToString());
2394 }
2395 }
2396 comparer.Value = value;
2397 }
2398 else
2399 {
2400 value = Convert.ToUInt16(SearchArgs.CompareStartValue);
2401 comparer.Value = value;
2402 }
2403 if (comparer.Compare(Convert.ToUInt16(Value), value))
2404 {
2405 writer.WriteResult<ushort>(comparer.Address, comparer.Value);
2406 }
2407 }
2408 address_index += STEP_SIZE;
2409 }
2410 #endregion
2411 }
2412 else
2413 {
2414 #region 16bits - signed
2415 var t_data = BitTools.ConvertByteArray<short>(data);
2416 foreach (var Value in t_data)
2417 {
2418 if (SearchWorkerThread.CancellationPending) { break; }
2419 using (_16bit_signed_comparer_ comparer = new _16bit_signed_comparer_(SearchArgs, address_index))
2420 {
2421 short value = 0;
2422 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2423 {
2424 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2425 {
2426 try
2427 {
2428 gmp.OpenProvider();
2429 gmp.ReadMemory(address_index, out value);
2430 gmp.CloseProvider();
2431 }
2432 catch (Exception ex)
2433 {
2434 logger.VerboseError.WriteLine(ex.ToString());
2435 }
2436 }
2437 comparer.Value = value;
2438 }
2439 else
2440 {
2441 value = Convert.ToInt16(SearchArgs.CompareStartValue);
2442 comparer.Value = value;
2443 }
2444 if (comparer.Compare(Convert.ToSByte(Value), value))
2445 {
2446 writer.WriteResult<short>(comparer.Address, comparer.Value);
2447 }
2448 }
2449 address_index += STEP_SIZE;
2450 }
2451 #endregion
2452 } break;
2453 case SearchDataTypes._32bits:
2454 if (unsigned)
2455 {
2456 #region 32bits - unsigned
2457 var t_data = BitTools.ConvertByteArray<uint>(data);
2458 foreach (var Value in t_data)
2459 {
2460 if (SearchWorkerThread.CancellationPending) { break; }
2461 using (_32bit_unsigned_comparer_ comparer = new _32bit_unsigned_comparer_(SearchArgs, address_index))
2462 {
2463 uint value = 0;
2464 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2465 {
2466 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2467 {
2468 try
2469 {
2470 gmp.OpenProvider();
2471 gmp.ReadMemory(address_index, out value);
2472 gmp.CloseProvider();
2473 }
2474 catch (Exception ex)
2475 {
2476 logger.VerboseError.WriteLine(ex.ToString());
2477 }
2478 }
2479 comparer.Value = value;
2480 }
2481 else
2482 {
2483 value = Convert.ToUInt32(SearchArgs.CompareStartValue);
2484 comparer.Value = value;
2485 }
2486 if (comparer.Compare(Convert.ToUInt32(Value), value))
2487 {
2488 writer.WriteResult<uint>(comparer.Address, comparer.Value);
2489 }
2490 }
2491 address_index += STEP_SIZE;
2492 }
2493 #endregion
2494 }
2495 else
2496 {
2497 #region 32bits - signed
2498 var t_data = BitTools.ConvertByteArray<int>(data);
2499 foreach (var Value in t_data)
2500 {
2501 if (SearchWorkerThread.CancellationPending) { break; }
2502 using (_32bit_signed_comparer_ comparer = new _32bit_signed_comparer_(SearchArgs, address_index))
2503 {
2504 int value = 0;
2505 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2506 {
2507 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2508 {
2509 try
2510 {
2511 gmp.OpenProvider();
2512 gmp.ReadMemory(address_index, out value);
2513 gmp.CloseProvider();
2514 }
2515 catch (Exception ex)
2516 {
2517 logger.VerboseError.WriteLine(ex.ToString());
2518 }
2519 }
2520 comparer.Value = value;
2521 }
2522 else
2523 {
2524 value = Convert.ToInt32(SearchArgs.CompareStartValue);
2525 comparer.Value = value;
2526 }
2527 if (comparer.Compare(Convert.ToInt32(Value), value))
2528 {
2529 writer.WriteResult<int>(comparer.Address, comparer.Value);
2530 }
2531 }
2532 address_index += STEP_SIZE;
2533 }
2534 #endregion
2535 } break;
2536 case SearchDataTypes._64bits:
2537 if (unsigned)
2538 {
2539 #region 64bits - unsigned
2540 var t_data = BitTools.ConvertByteArray<ulong>(data);
2541 foreach (var Value in t_data)
2542 {
2543 if (SearchWorkerThread.CancellationPending) { break; }
2544 using (_64bit_unsigned_comparer_ comparer = new _64bit_unsigned_comparer_(SearchArgs, address_index))
2545 {
2546 ulong value = 0;
2547 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2548 {
2549 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2550 {
2551 try
2552 {
2553 gmp.OpenProvider();
2554 gmp.ReadMemory(address_index, out value);
2555 gmp.CloseProvider();
2556 }
2557 catch (Exception ex)
2558 {
2559 logger.VerboseError.WriteLine(ex.ToString());
2560 }
2561 }
2562 comparer.Value = value;
2563 }
2564 else
2565 {
2566 value = Convert.ToUInt64(SearchArgs.CompareStartValue);
2567 comparer.Value = value;
2568 }
2569 if (comparer.Compare(Convert.ToUInt64(Value), value))
2570 {
2571 writer.WriteResult<ulong>(comparer.Address, comparer.Value);
2572 }
2573 }
2574 address_index += STEP_SIZE;
2575 }
2576 #endregion
2577 }
2578 else
2579 {
2580 #region 64bits - signed
2581 var t_data = BitTools.ConvertByteArray<long>(data);
2582 foreach (var Value in t_data)
2583 {
2584 if (SearchWorkerThread.CancellationPending) { break; }
2585 using (_64bit_signed_comparer_ comparer = new _64bit_signed_comparer_(SearchArgs, address_index))
2586 {
2587 long value = 0;
2588 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2589 {
2590 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2591 {
2592 try
2593 {
2594 gmp.OpenProvider();
2595 gmp.ReadMemory(address_index, out value);
2596 gmp.CloseProvider();
2597 }
2598 catch (Exception ex)
2599 {
2600 logger.VerboseError.WriteLine(ex.ToString());
2601 }
2602 }
2603 comparer.Value = value;
2604 }
2605 else
2606 {
2607 value = Convert.ToInt64(SearchArgs.CompareStartValue);
2608 comparer.Value = value;
2609 }
2610 if (comparer.Compare(Convert.ToInt64(Value), value))
2611 {
2612 writer.WriteResult<long>(comparer.Address, comparer.Value);
2613 }
2614 }
2615 address_index += STEP_SIZE;
2616 }
2617 #endregion
2618 } break;
2619
2620 }
2621 #endregion
2622
2623 }
2624
2625
2626 //ISerializedResult sr = (reader as ISerializedResult);
2627 //if (sr == null)
2628 //{
2629 // throw new ArgumentNullException("sr", string.Format("Unable to cast: '{0}' to '{1}'", reader.GetType().Name, typeof(ISerializedResult).Name));
2630 //}
2631 //int sr_index = 0;
2632 //try
2633 //{
2634 // if (sr.ContainsAddress(obre_CurrentIndex, obre_unsigned, obre_sdt, new Action<int, string>(this.UpdateProgress), out sr_index))
2635 // {
2636 // StructResultType<ulong> result = StructResultType<ulong>.Empty;
2637 // sr.GetResultAtIndex(sr_index, obre_unsigned, obre_sdt, new Action<int, string>(this.UpdateProgress), out result);
2638 // if (Debugger.IsAttached)
2639 // {
2640 // Debugger.Break();
2641 // }
2642 // }
2643 //}
2644
2645 }
2646
2647 }
2648 SearchGuid = new_SearchGuid; // update with out new guid
2649 }
2650 }
2651 provider_st.Stop();
2652 logger.Profiler.WriteLine("It took a total of {0} seconds for the memory provider to complete it's operation(s).", provider_st.Elapsed.TotalSeconds);
2653 //if (buffered_mem.Length == 0) { logger.Warn.WriteLine("Buffered Memory is Zero Length."); return; }
2654 //int Last_Whole_Percent_Done = 0;
2655
2656
2657 #region Subsequent Searches
2658 //r_ms.BaseStream.Seek(0, SeekOrigin.Begin);
2659
2660
2661 // hack to help with OutOfMemory Exceptions (OldValue and Equal compare will always add all found search results)
2662 bool NeedToCompare = true;
2663 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue &&
2664 SearchArgs.CompareType == SearchCompareTypes.Equal &&
2665 SearchArgs.IsFirstSearch)
2666 {
2667 NeedToCompare = false;
2668 //second_tmp_Results = null; // Free Memory
2669 }
2670
2671 if (NeedToCompare)
2672 {
2673 if (SearchArgs.CompareType != SearchCompareTypes.Between && SearchArgs.CompareType != SearchCompareTypes.NotBetween)
2674 {
2675 #region Non-Range Searches
2676 if (USE_NONRANGE_SEARCH_RESULT_READER)
2677 {
2678 st_nonrange_search.Start();
2679 //second_tmp_Results = new List<ResultType<object>>(SearchArgs.Results.Count * 1024);
2680 ////second_tmp_Results.c
2681 try
2682 {
2683 using (SearchResultReader reader = new SearchResultReader(SearchGuid))
2684 {
2685 try
2686 {
2687
2688 #region new comparator-support
2689 //second_tmp_Results = new List<StructResultType<object>>(reader.GetResults(SearchArgs.IsUnsignedDataType, SearchArgs.DataType, new Action<int, string>(UpdateProgress)));
2690 #endregion
2691
2692 #region USE_OLD_SEARCH_RESULTS_COMPRATOR_CODE
2693 if (USE_OLD_SEARCH_RESULTS_COMPRATOR_CODE)
2694 {
2695 for (int i = 0; i < reader.ResultCount; i += 1)
2696 {
2697 object result_value = 0;
2698 uint address = 0;
2699 #region switch (SearchArgs.DataType)
2700 switch (SearchArgs.DataType)
2701 {
2702 case SearchDataTypes._8bits: if (unsigned)
2703 {
2704 using (ResultType<byte> result = reader.GetNextResult<byte>())
2705 {
2706 address = result.Address;
2707 result_value = result.Value;
2708 }
2709 }
2710 else
2711 {
2712 using (ResultType<sbyte> result = reader.GetNextResult<sbyte>())
2713 {
2714 address = result.Address;
2715 result_value = result.Value;
2716 }
2717 } break;
2718 case SearchDataTypes._16bits: if (unsigned)
2719 {
2720 using (ResultType<ushort> result = reader.GetNextResult<ushort>())
2721 {
2722 address = result.Address;
2723 result_value = result.Value;
2724 }
2725 }
2726 else
2727 {
2728 using (ResultType<short> result = reader.GetNextResult<short>())
2729 {
2730 address = result.Address;
2731 result_value = result.Value;
2732 }
2733 } break;
2734 case SearchDataTypes._32bits: if (unsigned)
2735 {
2736 using (ResultType<uint> result = reader.GetNextResult<uint>())
2737 {
2738 address = result.Address;
2739 result_value = result.Value;
2740 }
2741 }
2742 else
2743 {
2744 using (ResultType<int> result = reader.GetNextResult<int>())
2745 {
2746 address = result.Address;
2747 result_value = result.Value;
2748 }
2749 } break;
2750 case SearchDataTypes._64bits: if (unsigned)
2751 {
2752 using (ResultType<ulong> result = reader.GetNextResult<ulong>())
2753 {
2754 address = result.Address;
2755 result_value = result.Value;
2756 }
2757 }
2758 else
2759 {
2760 using (ResultType<long> result = reader.GetNextResult<long>())
2761 {
2762 address = result.Address;
2763 result_value = result.Value;
2764 }
2765 } break;
2766 }
2767 #endregion
2768 if (MemoryRangeStart > 0 && !SearchArgs.IsFirstSearch) { address = address - MemoryRangeStart; }
2769 try
2770 {
2771 //r_ms.BaseStream.Seek(address, SeekOrigin.Begin);
2772 }
2773 catch (Exception)
2774 {
2775 throw;
2776 }
2777 switch (SearchArgs.DataType)
2778 {
2779 #region Comparer Support
2780 #region case SearchDataTypes._8bits:
2781 case SearchDataTypes._8bits:
2782 if (SearchArgs.IsUnsignedDataType)
2783 {
2784 byte lookup_value = 0;
2785 //using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this)) { gmp.OpenProvider(); gmp.ReadMemory(address, out lookup_value); gmp.CloseProvider(); }
2786 lookup_value = Convert.ToByte(result_value);
2787 using (_8bit_unsigned_comparer_ comparer = new _8bit_unsigned_comparer_(SearchArgs, address))
2788 {
2789 byte value = 0;
2790 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2791 {
2792 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2793 {
2794 try
2795 {
2796 gmp.OpenProvider();
2797 gmp.ReadMemory(address, out value);
2798 gmp.CloseProvider();
2799 }
2800 catch (Exception ex)
2801 {
2802 logger.VerboseError.WriteLine(ex.ToString());
2803 }
2804 }
2805 comparer.Value = value;
2806 }
2807 else
2808 {
2809 value = Convert.ToByte(SearchArgs.CompareStartValue);
2810 comparer.Value = value;
2811 }
2812 if (comparer.Compare(lookup_value, value))
2813 {
2814 second_tmp_Results.Add(new ResultType<ulong>(comparer.Address, comparer.Value));
2815 }
2816 }
2817 }
2818 else
2819 {
2820 sbyte lookup_value = 0;
2821 //using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this)) { gmp.OpenProvider(); gmp.ReadMemory(address, out lookup_value); gmp.CloseProvider(); }
2822 lookup_value = Convert.ToSByte(result_value);
2823 using (_8bit_signed_comparer_ comparer = new _8bit_signed_comparer_(SearchArgs, address))
2824 {
2825 sbyte value = 0;
2826 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2827 {
2828 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2829 {
2830 try
2831 {
2832 gmp.OpenProvider();
2833 gmp.ReadMemory(address, out value);
2834 gmp.CloseProvider();
2835 }
2836 catch (Exception ex)
2837 {
2838 logger.VerboseError.WriteLine(ex.ToString());
2839 }
2840 }
2841 comparer.Value = value;
2842 }
2843 else
2844 {
2845 value = Convert.ToSByte(SearchArgs.CompareStartValue);
2846 }
2847 if (comparer.Compare(lookup_value, value))
2848 {
2849 second_tmp_Results.Add(new ResultType<ulong>(comparer.Address, (ulong)comparer.Value));
2850 }
2851 }
2852 }
2853 break;
2854 #endregion
2855 #region case SearchDataTypes._16bits:
2856 case SearchDataTypes._16bits:
2857 if (SearchArgs.IsUnsignedDataType)
2858 {
2859 ushort lookup_value = 0;
2860 //using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this)) { gmp.OpenProvider(); gmp.ReadMemory(address, out lookup_value); gmp.CloseProvider(); }
2861 lookup_value = Convert.ToUInt16(result_value);
2862 using (_16bit_unsigned_comparer_ comparer = new _16bit_unsigned_comparer_(SearchArgs, address))
2863 {
2864 ushort value = 0;
2865 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2866 {
2867 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2868 {
2869 try
2870 {
2871 gmp.OpenProvider();
2872 gmp.ReadMemory(address, out value);
2873 gmp.CloseProvider();
2874 }
2875 catch (Exception ex)
2876 {
2877 logger.VerboseError.WriteLine(ex.ToString());
2878 }
2879 }
2880 comparer.Value = value;
2881 }
2882 else
2883 {
2884 value = Convert.ToUInt16(SearchArgs.CompareStartValue);
2885 comparer.Value = value;
2886 }
2887 if (comparer.Compare(lookup_value, value))
2888 {
2889 second_tmp_Results.Add(new ResultType<ulong>(comparer.Address, comparer.Value));
2890 }
2891 }
2892 }
2893 else
2894 {
2895 short lookup_value = 0;
2896 //using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this)) { gmp.OpenProvider(); gmp.ReadMemory(address, out lookup_value); gmp.CloseProvider(); }
2897 lookup_value = Convert.ToInt16(result_value);
2898 using (_16bit_signed_comparer_ comparer = new _16bit_signed_comparer_(SearchArgs, address))
2899 {
2900 short value = 0;
2901 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2902 {
2903 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2904 {
2905 try
2906 {
2907 gmp.OpenProvider();
2908 gmp.ReadMemory(address, out value);
2909 gmp.CloseProvider();
2910 }
2911 catch (Exception ex)
2912 {
2913 logger.VerboseError.WriteLine(ex.ToString());
2914 }
2915 }
2916 comparer.Value = value;
2917 }
2918 else
2919 {
2920 value = Convert.ToInt16(SearchArgs.CompareStartValue);
2921 }
2922 if (comparer.Compare(lookup_value, value))
2923 {
2924 second_tmp_Results.Add(new ResultType<ulong>(comparer.Address, (ulong)comparer.Value));
2925 }
2926 }
2927 }
2928 break;
2929 #endregion
2930 #region case SearchDataTypes._32bits:
2931 case SearchDataTypes._32bits:
2932 if (SearchArgs.IsUnsignedDataType)
2933 {
2934 uint lookup_value = 0;
2935 //using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this)) { gmp.OpenProvider(); gmp.ReadMemory(address, out lookup_value); gmp.CloseProvider(); }
2936 lookup_value = Convert.ToUInt32(result_value);
2937 using (_32bit_unsigned_comparer_ comparer = new _32bit_unsigned_comparer_(SearchArgs, address))
2938 {
2939 uint value = 0;
2940 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2941 {
2942 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2943 {
2944 try
2945 {
2946 gmp.OpenProvider();
2947 gmp.ReadMemory(address, out value);
2948 gmp.CloseProvider();
2949 }
2950 catch (Exception ex)
2951 {
2952 logger.VerboseError.WriteLine(ex.ToString());
2953 }
2954 }
2955 comparer.Value = value;
2956 }
2957 else
2958 {
2959 value = Convert.ToUInt32(SearchArgs.CompareStartValue);
2960 comparer.Value = value;
2961 }
2962 if (comparer.Compare(lookup_value, value))
2963 {
2964 second_tmp_Results.Add(new ResultType<ulong>(comparer.Address, comparer.Value));
2965 }
2966 }
2967 }
2968 else
2969 {
2970 int lookup_value = 0;
2971 //using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this)) { gmp.OpenProvider(); gmp.ReadMemory(address, out lookup_value); gmp.CloseProvider(); }
2972 lookup_value = Convert.ToInt32(result_value);
2973 using (_32bit_signed_comparer_ comparer = new _32bit_signed_comparer_(SearchArgs, address))
2974 {
2975 int value = 0;
2976 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2977 {
2978 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2979 {
2980 try
2981 {
2982 gmp.OpenProvider();
2983 gmp.ReadMemory(address, out value);
2984 gmp.CloseProvider();
2985 }
2986 catch (Exception ex)
2987 {
2988 logger.VerboseError.WriteLine(ex.ToString());
2989 }
2990 }
2991 comparer.Value = value;
2992 }
2993 else
2994 {
2995 value = Convert.ToInt32(SearchArgs.CompareStartValue);
2996 }
2997 if (comparer.Compare(lookup_value, value))
2998 {
2999 second_tmp_Results.Add(new ResultType<ulong>(comparer.Address, (ulong)comparer.Value));
3000 }
3001 }
3002 }
3003 break;
3004 #endregion
3005 #region case SearchDataTypes._64bits:
3006 case SearchDataTypes._64bits:
3007 if (SearchArgs.IsUnsignedDataType)
3008 {
3009 ulong lookup_value = 0;
3010 //using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this)) { gmp.OpenProvider(); gmp.ReadMemory(address, out lookup_value); gmp.CloseProvider(); }
3011 lookup_value = Convert.ToUInt64(result_value);
3012 using (_64bit_unsigned_comparer_ comparer = new _64bit_unsigned_comparer_(SearchArgs, address))
3013 {
3014 ulong value = 0;
3015 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
3016 {
3017 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
3018 {
3019 try
3020 {
3021 gmp.OpenProvider();
3022 gmp.ReadMemory(address, out value);
3023 gmp.CloseProvider();
3024 }
3025 catch (Exception ex)
3026 {
3027 logger.VerboseError.WriteLine(ex.ToString());
3028 }
3029 }
3030 comparer.Value = value;
3031 }
3032 else
3033 {
3034 value = Convert.ToUInt64(SearchArgs.CompareStartValue);
3035 comparer.Value = value;
3036 }
3037 if (comparer.Compare(lookup_value, value))
3038 {
3039 second_tmp_Results.Add(new ResultType<ulong>(comparer.Address, comparer.Value));
3040 }
3041 }
3042 }
3043 else
3044 {
3045 long lookup_value = 0;
3046 //using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this)) { gmp.OpenProvider(); gmp.ReadMemory(address, out lookup_value); gmp.CloseProvider(); }
3047 lookup_value = Convert.ToInt64(result_value);
3048 using (_64bit_signed_comparer_ comparer = new _64bit_signed_comparer_(SearchArgs, address))
3049 {
3050 long value = 0;
3051 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
3052 {
3053 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
3054 {
3055 try
3056 {
3057 gmp.OpenProvider();
3058 gmp.ReadMemory(address, out value);
3059 gmp.CloseProvider();
3060 }
3061 catch (Exception ex)
3062 {
3063 logger.VerboseError.WriteLine(ex.ToString());
3064 }
3065 }
3066 comparer.Value = value;
3067 }
3068 else
3069 {
3070 value = Convert.ToInt64(SearchArgs.CompareStartValue);
3071 }
3072 if (comparer.Compare(lookup_value, value))
3073 {
3074 second_tmp_Results.Add(new ResultType<ulong>(comparer.Address, (ulong)comparer.Value));
3075 }
3076 }
3077 }
3078 break;
3079 #endregion
3080 #endregion
3081 }
3082 double double_percent_done = 100.0 * (double)((double)i / (double)reader.ResultCount);
3083 int int_percent_done = (int)double_percent_done;
3084 //if (int_percent_done != Last_Whole_Percent_Done && i % 100000 == 0)
3085 //{
3086 if (int_percent_done <= 100)
3087 {
3088 //Last_Whole_Percent_Done = int_percent_done;
3089 UpdateProgress(int_percent_done, string.Format(" -> Reading Address: 0x{0:x8}", i + MemoryRangeStart));
3090 //new Action<int, string>(UpdateProgress).Invoke(int_percent_done, string.Format(" -> Reading Address: 0x{0:x8}", i + MemoryRangeStart));
3091 }
3092 //}
3093 //this.Refresh();
3094 }
3095 }
3096 #endregion
3097 }
3098 catch (Exception ex)
3099 {
3100 throw ex;
3101 }
3102 }
3103 }
3104 catch (Exception ex)
3105 {
3106 throw ex;
3107 }
3108 st_nonrange_search.Stop();
3109 logger.Profiler.WriteLine("Non-Ranged search took a total of {0} seconds to complete.", st_nonrange_search.Elapsed.TotalSeconds);
3110 //Last_Whole_Percent_Done = 0;
3111 }
3112 #endregion
3113 }
3114 #region Ranged Searches
3115 #if !DONOT_HAVE_RANGED_SEARCH_SUPPORT
3116 if (SearchArgs.CompareType == SearchCompareTypes.Between || SearchArgs.CompareType == SearchCompareTypes.NotBetween)
3117 {
3118 st_ranged_search.Start();
3119 object start, end;
3120
3121 start = SearchArgs.CompareStartValue;
3122 end = SearchArgs.CompareEndValue;
3123 using (SearchResultReader reader = new SearchResultReader(SearchGuid))
3124 {
3125 for (int i = 0; i < reader.ResultCount; i += 1)
3126 {
3127 uint address = 0;
3128 #region switch (SearchArgs.DataType)
3129 switch (SearchArgs.DataType)
3130 {
3131 case SearchDataTypes._8bits: if (unsigned) { using (ResultType<byte> result = reader.GetNextResult<byte>()) { address = result.Address; } }
3132 else { using (ResultType<sbyte> result = reader.GetNextResult<sbyte>()) { address = result.Address; } } break;
3133 case SearchDataTypes._16bits: if (unsigned) { using (ResultType<ushort> result = reader.GetNextResult<ushort>()) { address = result.Address; } }
3134 else { using (ResultType<short> result = reader.GetNextResult<short>()) { address = result.Address; } } break;
3135 case SearchDataTypes._32bits: if (unsigned) { using (ResultType<uint> result = reader.GetNextResult<uint>()) { address = result.Address; } }
3136 else { using (ResultType<int> result = reader.GetNextResult<int>()) { address = result.Address; } } break;
3137 case SearchDataTypes._64bits: if (unsigned) { using (ResultType<ulong> result = reader.GetNextResult<ulong>()) { address = result.Address; } }
3138 else { using (ResultType<long> result = reader.GetNextResult<long>()) { address = result.Address; } } break;
3139 }
3140 #endregion
3141
3142 if (MemoryRangeStart > 0 && !SearchArgs.IsFirstSearch) { address = address - MemoryRangeStart; }
3143 //r_ms.BaseStream.Seek(address, SeekOrigin.Begin);
3144 if (SearchArgs.CompareType == SearchCompareTypes.Between)
3145 {
3146 using (InRangeComparer comparer = new InRangeComparer(address, 0))
3147 {
3148 if (comparer.Compare(start, end, SearchArgs.DataType, SearchArgs.IsUnsignedDataType, (IAcceptsProcessAndConfig)this))
3149 {
3150 using (ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value))
3151 {
3152 second_tmp_Results.Add(_tmp_result);
3153 }
3154 }
3155 }
3156 }
3157 else if (SearchArgs.CompareType == SearchCompareTypes.NotBetween)
3158 {
3159 using (NotInRangeComparer comparer = new NotInRangeComparer(address, 0))
3160 {
3161 if (comparer.Compare(start, end, SearchArgs.DataType, SearchArgs.IsUnsignedDataType, (IAcceptsProcessAndConfig)this))
3162 {
3163 using (ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value))
3164 {
3165 second_tmp_Results.Add(_tmp_result);
3166 }
3167 }
3168 }
3169 }
3170 else
3171 {
3172 throw new InvalidOperationException("Encounted unkown range search type: " + SearchArgs.CompareType);
3173 }
3174 double double_percent_done = 100.0 * (double)((double)i / (double)reader.ResultCount);
3175 int int_percent_done = (int)double_percent_done;
3176 if (int_percent_done != Last_Whole_Percent_Done)
3177 {
3178 if (int_percent_done <= 100)
3179 {
3180 resultsprogress.Value = int_percent_done;
3181 resultsprogress.Message = string.Format(" -> Reading Address: 0x{0:x8}", i + MemoryRangeStart);
3182 Last_Whole_Percent_Done = int_percent_done;
3183 }
3184 }
3185 }
3186 }
3187 st_ranged_search.Stop();
3188 logger.Profiler.WriteLine("Ranged search took a total of {0} seconds to complete.", st_ranged_search.Elapsed.TotalSeconds);
3189 }
3190 #endif
3191 #endregion
3192
3193 }
3194 #endregion
3195 //// leave SearchArgs.Results alone, if false
3196 //if (NeedToCompare)
3197 //{
3198 // // fix addresses when memory start is not zero
3199 // if (MemoryRangeStart > 0 && SearchArgs.IsFirstSearch) { for (int i = 0; i < second_tmp_Results.Count; i++) { second_tmp_Results[i].Address = second_tmp_Results[i].Address + MemoryRangeStart; } }
3200 // using (SearchResultWriter writer = new SearchResultWriter(second_tmp_Results.Count, SearchGuid))
3201 // {
3202 // for (int i = 0; i < second_tmp_Results.Count; i++)
3203 // {
3204 // switch (sdt)
3205 // {
3206 // case SearchDataTypes._8bits:
3207 // if (unsigned) { writer.WriteResult<Byte>(second_tmp_Results[i].Address, Convert.ToByte(second_tmp_Results[i].Value)); }
3208 // else { writer.WriteResult<SByte>(second_tmp_Results[i].Address, Convert.ToSByte(second_tmp_Results[i].Value)); } break;
3209 // case SearchDataTypes._16bits:
3210 // if (unsigned) { writer.WriteResult<UInt16>(second_tmp_Results[i].Address, Convert.ToUInt16(second_tmp_Results[i].Value)); }
3211 // else { writer.WriteResult<Int16>(second_tmp_Results[i].Address, Convert.ToInt16(second_tmp_Results[i].Value)); } break;
3212 // case SearchDataTypes._32bits:
3213 // if (unsigned) { writer.WriteResult<UInt32>(second_tmp_Results[i].Address, Convert.ToUInt32(second_tmp_Results[i].Value)); }
3214 // else { writer.WriteResult<Int32>(second_tmp_Results[i].Address, Convert.ToInt32(second_tmp_Results[i].Value)); } break;
3215 // case SearchDataTypes._64bits:
3216 // if (unsigned) { writer.WriteResult<UInt64>(second_tmp_Results[i].Address, Convert.ToUInt64(second_tmp_Results[i].Value)); }
3217 // else { writer.WriteResult<Int64>(second_tmp_Results[i].Address, Convert.ToIn