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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 522 - (show annotations) (download)
Wed Jun 5 07:14:15 2013 UTC (7 years, 4 months ago) by william
File size: 205098 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 private void search_provider_OnBytesRead(OnBytesReadEventArgs e)
1425 {
1426 if (SearchWorkerThread.CancellationPending) { e.Canceled = true; return; }
1427 SearchDataTypes sdt = SearchArgs.DataType;
1428 bool unsigned = SearchArgs.IsUnsignedDataType;
1429 int Last_Whole_Percent_Done = 0;
1430 uint CurrentIndex = e.CurrentIndex;
1431 if (e.UserState != null)
1432 {
1433 SearchResultWriter writer = (e.UserState as SearchResultWriter);
1434 if (writer == null)
1435 throw new InvalidOperationException("writer cannot be null");
1436
1437
1438 using (MemoryStream ms = new MemoryStream(e.Data))
1439 {
1440 using (BinaryReader br = new BinaryReader(ms))
1441 {
1442 while (br.BaseStream.Position < br.BaseStream.Length)
1443 {
1444 try
1445 {
1446 //if (e.ReportProgress)
1447 //{
1448 // double double_percent_done = 100.0 * (double)((double)CurrentIndex / (double)e.TotalCount);
1449 // int int_percent_done = (int)double_percent_done;
1450 // int align_base = 100;
1451 // int align_power = 1;
1452 // int align = align_base * align_power;
1453 // if (int_percent_done != Last_Whole_Percent_Done && (CurrentIndex % align) == 0)
1454 // {
1455 // string message = string.Format(" -> Reading Address: 0x{0:x8}", (CurrentIndex + MemoryRangeStart));
1456 // UpdateProgress((int)double_percent_done, message);
1457 // //new Action<int, string>(UpdateProgress).Invoke(int_percent_done, message);
1458 // Last_Whole_Percent_Done = int_percent_done;
1459 // if (SearchWorkerThread.CancellationPending) { e.Canceled = true; return; }
1460 // }
1461 //}
1462
1463 switch (sdt)
1464 {
1465 case SearchDataTypes._8bits:
1466 if (unsigned)
1467 {
1468 #region 8bits - unsigned
1469 var Value = br.ReadByte();
1470 using (_8bit_unsigned_comparer_ comparer = new _8bit_unsigned_comparer_(SearchArgs, CurrentIndex))
1471 {
1472 byte value = 0;
1473 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1474 {
1475 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1476 {
1477 try
1478 {
1479 gmp.OpenProvider();
1480 gmp.ReadMemory(CurrentIndex, out value);
1481 gmp.CloseProvider();
1482 }
1483 catch (Exception ex)
1484 {
1485 logger.VerboseError.WriteLine(ex.ToString());
1486 }
1487 }
1488 comparer.Value = value;
1489 }
1490 else
1491 {
1492 value = Convert.ToByte(SearchArgs.CompareStartValue);
1493 comparer.Value = value;
1494 }
1495 if (comparer.Compare(Convert.ToByte(Value), value))
1496 {
1497 writer.WriteResult<byte>(comparer.Address, comparer.Value);
1498 }
1499 }
1500 #endregion
1501 }
1502 else
1503 {
1504 #region 8bits - signed
1505 var Value = br.ReadSByte();
1506 using (_8bit_signed_comparer_ comparer = new _8bit_signed_comparer_(SearchArgs, CurrentIndex))
1507 {
1508 sbyte value = 0;
1509 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1510 {
1511 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1512 {
1513 try
1514 {
1515 gmp.OpenProvider();
1516 gmp.ReadMemory(CurrentIndex, out value);
1517 gmp.CloseProvider();
1518 }
1519 catch (Exception ex)
1520 {
1521 logger.VerboseError.WriteLine(ex.ToString());
1522 }
1523 }
1524 comparer.Value = value;
1525 }
1526 else
1527 {
1528 value = Convert.ToSByte(SearchArgs.CompareStartValue);
1529 comparer.Value = value;
1530 }
1531 if (comparer.Compare(Convert.ToSByte(Value), value))
1532 {
1533 writer.WriteResult<sbyte>(comparer.Address, comparer.Value);
1534 }
1535 }
1536 #endregion
1537 } break;
1538 case SearchDataTypes._16bits:
1539 if (unsigned)
1540 {
1541 #region 16bits - unsigned
1542 var Value = br.ReadUInt16();
1543 using (_16bit_unsigned_comparer_ comparer = new _16bit_unsigned_comparer_(SearchArgs, CurrentIndex))
1544 {
1545 ushort value = 0;
1546 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1547 {
1548 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1549 {
1550 try
1551 {
1552 gmp.OpenProvider();
1553 gmp.ReadMemory(CurrentIndex, out value);
1554 gmp.CloseProvider();
1555 }
1556 catch (Exception ex)
1557 {
1558 logger.VerboseError.WriteLine(ex.ToString());
1559 }
1560 }
1561 comparer.Value = value;
1562 }
1563 else
1564 {
1565 value = Convert.ToUInt16(SearchArgs.CompareStartValue);
1566 comparer.Value = value;
1567 }
1568 if (comparer.Compare(Convert.ToUInt16(Value), value))
1569 {
1570 writer.WriteResult<ushort>(comparer.Address, comparer.Value);
1571 }
1572 }
1573 #endregion
1574 }
1575 else
1576 {
1577 #region 16bits - signed
1578 var Value = br.ReadInt16();
1579 using (_16bit_signed_comparer_ comparer = new _16bit_signed_comparer_(SearchArgs, CurrentIndex))
1580 {
1581 short value = 0;
1582 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1583 {
1584 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1585 {
1586 try
1587 {
1588 gmp.OpenProvider();
1589 gmp.ReadMemory(CurrentIndex, out value);
1590 gmp.CloseProvider();
1591 }
1592 catch (Exception ex)
1593 {
1594 logger.VerboseError.WriteLine(ex.ToString());
1595 }
1596 }
1597 comparer.Value = value;
1598 }
1599 else
1600 {
1601 value = Convert.ToInt16(SearchArgs.CompareStartValue);
1602 comparer.Value = value;
1603 }
1604 if (comparer.Compare(Convert.ToSByte(Value), value))
1605 {
1606 writer.WriteResult<short>(comparer.Address, comparer.Value);
1607 }
1608 }
1609 #endregion
1610 } break;
1611 case SearchDataTypes._32bits:
1612 if (unsigned)
1613 {
1614 #region 32bits - unsigned
1615 var Value = br.ReadUInt32();
1616 using (_32bit_unsigned_comparer_ comparer = new _32bit_unsigned_comparer_(SearchArgs, CurrentIndex))
1617 {
1618 uint value = 0;
1619 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1620 {
1621 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1622 {
1623 try
1624 {
1625 gmp.OpenProvider();
1626 gmp.ReadMemory(CurrentIndex, out value);
1627 gmp.CloseProvider();
1628 }
1629 catch (Exception ex)
1630 {
1631 logger.VerboseError.WriteLine(ex.ToString());
1632 }
1633 }
1634 comparer.Value = value;
1635 }
1636 else
1637 {
1638 value = Convert.ToUInt32(SearchArgs.CompareStartValue);
1639 comparer.Value = value;
1640 }
1641 if (comparer.Compare(Convert.ToUInt32(Value), value))
1642 {
1643 writer.WriteResult<uint>(comparer.Address, comparer.Value);
1644 }
1645 }
1646 #endregion
1647 }
1648 else
1649 {
1650 #region 32bits - signed
1651 var Value = br.ReadInt32();
1652 using (_32bit_signed_comparer_ comparer = new _32bit_signed_comparer_(SearchArgs, CurrentIndex))
1653 {
1654 int value = 0;
1655 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1656 {
1657 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1658 {
1659 try
1660 {
1661 gmp.OpenProvider();
1662 gmp.ReadMemory(CurrentIndex, out value);
1663 gmp.CloseProvider();
1664 }
1665 catch (Exception ex)
1666 {
1667 logger.VerboseError.WriteLine(ex.ToString());
1668 }
1669 }
1670 comparer.Value = value;
1671 }
1672 else
1673 {
1674 value = Convert.ToInt32(SearchArgs.CompareStartValue);
1675 comparer.Value = value;
1676 }
1677 if (comparer.Compare(Convert.ToInt32(Value), value))
1678 {
1679 writer.WriteResult<int>(comparer.Address, comparer.Value);
1680 }
1681 }
1682 #endregion
1683 } break;
1684 case SearchDataTypes._64bits:
1685 if (unsigned)
1686 {
1687 #region 64bits - unsigned
1688 var Value = br.ReadUInt64();
1689 using (_64bit_unsigned_comparer_ comparer = new _64bit_unsigned_comparer_(SearchArgs, CurrentIndex))
1690 {
1691 ulong value = 0;
1692 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1693 {
1694 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1695 {
1696 try
1697 {
1698 gmp.OpenProvider();
1699 gmp.ReadMemory(CurrentIndex, out value);
1700 gmp.CloseProvider();
1701 }
1702 catch (Exception ex)
1703 {
1704 logger.VerboseError.WriteLine(ex.ToString());
1705 }
1706 }
1707 comparer.Value = value;
1708 }
1709 else
1710 {
1711 value = Convert.ToUInt64(SearchArgs.CompareStartValue);
1712 comparer.Value = value;
1713 }
1714 if (comparer.Compare(Convert.ToUInt64(Value), value))
1715 {
1716 writer.WriteResult<ulong>(comparer.Address, comparer.Value);
1717 }
1718 }
1719 #endregion
1720 }
1721 else
1722 {
1723 #region 64bits - signed
1724 var Value = br.ReadInt64();
1725 using (_64bit_signed_comparer_ comparer = new _64bit_signed_comparer_(SearchArgs, CurrentIndex))
1726 {
1727 long value = 0;
1728 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1729 {
1730 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1731 {
1732 try
1733 {
1734 gmp.OpenProvider();
1735 gmp.ReadMemory(CurrentIndex, out value);
1736 gmp.CloseProvider();
1737 }
1738 catch (Exception ex)
1739 {
1740 logger.VerboseError.WriteLine(ex.ToString());
1741 }
1742 }
1743 comparer.Value = value;
1744 }
1745 else
1746 {
1747 value = Convert.ToInt64(SearchArgs.CompareStartValue);
1748 comparer.Value = value;
1749 }
1750 if (comparer.Compare(Convert.ToInt64(Value), value))
1751 {
1752 writer.WriteResult<long>(comparer.Address, comparer.Value);
1753 }
1754 }
1755 #endregion
1756 } break;
1757 }
1758 if (SearchWorkerThread.CancellationPending) { e.Canceled = true; return; }
1759 }
1760 catch (EndOfStreamException) { }
1761
1762 uint size = 0;
1763 BitTools.SizeOf(sdt, out size);
1764 CurrentIndex += size;
1765 }
1766 }
1767 }
1768 }
1769 if (SearchWorkerThread.CancellationPending) { e.Canceled = true; return; }
1770 }
1771 private void SearchWorkerThread_DoWork(object sender, DoWorkEventArgs e)
1772 {
1773 try
1774 {
1775 Stopwatch st = new Stopwatch();
1776 st.Start();
1777
1778 Stopwatch st_first_search = new Stopwatch();
1779 Stopwatch st_nonrange_search = new Stopwatch();
1780 Stopwatch st_ranged_search = new Stopwatch();
1781
1782 e.Result = st;
1783 //List<ResultType<object>> tmp_Results = new List<ResultType<object>>();
1784 List<ResultType<ulong>> second_tmp_Results = new List<ResultType<ulong>>();
1785 //const int ElementsBeforeDisplay = 100;
1786 SearchArgs.LogSearchOptions();
1787 uint STEP_SIZE = (uint)SearchArgs.DataType / 8;
1788
1789 bool unsigned = SearchArgs.IsUnsignedDataType;
1790 SearchDataTypes sdt = SearchArgs.DataType;
1791 //byte[] buffered_mem = new byte[(MemoryRangeSize - MemoryRangeStart)]; // throws OutOfMemoryException if size is over 2G
1792 logger.Debug.WriteLine(string.Format("Buffered Memory Size -> 0x{0:x8}", MemoryRangeSize - MemoryRangeStart));
1793 UpdateProgress(0, string.Format("Search is Warming Up...Please Wait..."));
1794 //new Action<int, string>(UpdateProgress).Invoke(0, string.Format("Search is Warming Up...Please Wait..."));
1795 Stopwatch provider_st = new Stopwatch();
1796 provider_st.Start();
1797 using (GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1798 {
1799
1800 if (SearchArgs.IsFirstSearch)
1801 {
1802 provider.OpenProvider();
1803 int count = (int)((MemoryRangeSize - MemoryRangeStart) / STEP_SIZE);
1804 SearchResultWriter writer = new SearchResultWriter((int)(count), SearchGuid);
1805 //provider.OnBytesRead += new BaseEventHandler<OnBytesReadEventArgs>(search_provider_OnBytesRead);
1806 //provider.ReadProcessMemoryAtOnce(MemoryRangeStart, (MemoryRangeSize - MemoryRangeStart), writer);
1807
1808
1809 Stopwatch st_profiler = new Stopwatch();
1810 st_profiler.Start();
1811 //int Last_Whole_Percent_Done = 0;
1812 uint size = STEP_SIZE * 4096;
1813 for (uint i = MemoryRangeStart; i < MemoryRangeSize; i+=size)
1814 {
1815
1816 int bytesRead=0;
1817 byte[] data = new byte[size];
1818 //provider.ReadProcessMemory(i, size, out bytesRead, out data);
1819
1820 provider.ReadProcessMemoryAtOnce(i, size, out bytesRead, out data);
1821
1822 //OnBytesReadEventArgs t_args = new OnBytesReadEventArgs(this, writer, data, i, MemoryRangeSize, true);
1823 //search_provider_OnBytesRead(t_args);
1824 //t_args = null;
1825
1826 string message = string.Format(" -> Reading Address: 0x{0:x8}", (i + MemoryRangeStart));
1827 double double_percent_done = 100.0 * (double)((double)i / (double)MemoryRangeSize);
1828 //int int_percent_done = (int)double_percent_done;
1829 if ((i % 10000) == 0)
1830 {
1831 UpdateProgress((int)double_percent_done, message);
1832 logger.Profiler.WriteLine("Memory Search Operation Profiler: search operation has taken {0} seconds", st_profiler.Elapsed.TotalSeconds.ToString());
1833 //Last_Whole_Percent_Done = int_percent_done;
1834 }
1835
1836
1837 #region comparison and serialization
1838 switch (sdt)
1839 {
1840 case SearchDataTypes._8bits:
1841 if (unsigned)
1842 {
1843 #region 8bits - unsigned
1844 var t_data = BitTools.ConvertByteArray<byte>(data);
1845 foreach (var Value in t_data)
1846 {
1847 if (SearchWorkerThread.CancellationPending) { break; }
1848 using (_8bit_unsigned_comparer_ comparer = new _8bit_unsigned_comparer_(SearchArgs, i))
1849 {
1850 byte value = 0;
1851 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1852 {
1853 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1854 {
1855 try
1856 {
1857 gmp.OpenProvider();
1858 gmp.ReadMemory(i, out value);
1859 gmp.CloseProvider();
1860 }
1861 catch (Exception ex)
1862 {
1863 logger.VerboseError.WriteLine(ex.ToString());
1864 }
1865 }
1866 comparer.Value = value;
1867 }
1868 else
1869 {
1870 value = Convert.ToByte(SearchArgs.CompareStartValue);
1871 comparer.Value = value;
1872 }
1873 if (comparer.Compare(Convert.ToByte(Value), value))
1874 {
1875 writer.WriteResult<byte>(comparer.Address, comparer.Value);
1876 }
1877 }
1878 }
1879 #endregion
1880 }
1881 else
1882 {
1883 #region 8bits - signed
1884 var t_data = BitTools.ConvertByteArray<sbyte>(data);
1885 foreach (var Value in t_data)
1886 {
1887 if (SearchWorkerThread.CancellationPending) { break; }
1888 using (_8bit_signed_comparer_ comparer = new _8bit_signed_comparer_(SearchArgs, i))
1889 {
1890 sbyte value = 0;
1891 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1892 {
1893 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1894 {
1895 try
1896 {
1897 gmp.OpenProvider();
1898 gmp.ReadMemory(i, out value);
1899 gmp.CloseProvider();
1900 }
1901 catch (Exception ex)
1902 {
1903 logger.VerboseError.WriteLine(ex.ToString());
1904 }
1905 }
1906 comparer.Value = value;
1907 }
1908 else
1909 {
1910 value = Convert.ToSByte(SearchArgs.CompareStartValue);
1911 comparer.Value = value;
1912 }
1913 if (comparer.Compare(Convert.ToSByte(Value), value))
1914 {
1915 writer.WriteResult<sbyte>(comparer.Address, comparer.Value);
1916 }
1917 }
1918 }
1919 #endregion
1920 } break;
1921 case SearchDataTypes._16bits:
1922 if (unsigned)
1923 {
1924 #region 16bits - unsigned
1925 var t_data = BitTools.ConvertByteArray<ushort>(data);
1926 foreach (var Value in t_data)
1927 {
1928 if (SearchWorkerThread.CancellationPending) { break; }
1929 using (_16bit_unsigned_comparer_ comparer = new _16bit_unsigned_comparer_(SearchArgs, i))
1930 {
1931 ushort value = 0;
1932 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1933 {
1934 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1935 {
1936 try
1937 {
1938 gmp.OpenProvider();
1939 gmp.ReadMemory(i, out value);
1940 gmp.CloseProvider();
1941 }
1942 catch (Exception ex)
1943 {
1944 logger.VerboseError.WriteLine(ex.ToString());
1945 }
1946 }
1947 comparer.Value = value;
1948 }
1949 else
1950 {
1951 value = Convert.ToUInt16(SearchArgs.CompareStartValue);
1952 comparer.Value = value;
1953 }
1954 if (comparer.Compare(Convert.ToUInt16(Value), value))
1955 {
1956 writer.WriteResult<ushort>(comparer.Address, comparer.Value);
1957 }
1958 }
1959 }
1960 #endregion
1961 }
1962 else
1963 {
1964 #region 16bits - signed
1965 var t_data = BitTools.ConvertByteArray<short>(data);
1966 foreach (var Value in t_data)
1967 {
1968 if (SearchWorkerThread.CancellationPending) { break; }
1969 using (_16bit_signed_comparer_ comparer = new _16bit_signed_comparer_(SearchArgs, i))
1970 {
1971 short value = 0;
1972 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1973 {
1974 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1975 {
1976 try
1977 {
1978 gmp.OpenProvider();
1979 gmp.ReadMemory(i, out value);
1980 gmp.CloseProvider();
1981 }
1982 catch (Exception ex)
1983 {
1984 logger.VerboseError.WriteLine(ex.ToString());
1985 }
1986 }
1987 comparer.Value = value;
1988 }
1989 else
1990 {
1991 value = Convert.ToInt16(SearchArgs.CompareStartValue);
1992 comparer.Value = value;
1993 }
1994 if (comparer.Compare(Convert.ToSByte(Value), value))
1995 {
1996 writer.WriteResult<short>(comparer.Address, comparer.Value);
1997 }
1998 }
1999 }
2000 #endregion
2001 } break;
2002 case SearchDataTypes._32bits:
2003 if (unsigned)
2004 {
2005 #region 32bits - unsigned
2006 var t_data = BitTools.ConvertByteArray<uint>(data);
2007 foreach (var Value in t_data)
2008 {
2009 if (SearchWorkerThread.CancellationPending) { break; }
2010 using (_32bit_unsigned_comparer_ comparer = new _32bit_unsigned_comparer_(SearchArgs, i))
2011 {
2012 uint value = 0;
2013 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2014 {
2015 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2016 {
2017 try
2018 {
2019 gmp.OpenProvider();
2020 gmp.ReadMemory(i, out value);
2021 gmp.CloseProvider();
2022 }
2023 catch (Exception ex)
2024 {
2025 logger.VerboseError.WriteLine(ex.ToString());
2026 }
2027 }
2028 comparer.Value = value;
2029 }
2030 else
2031 {
2032 value = Convert.ToUInt32(SearchArgs.CompareStartValue);
2033 comparer.Value = value;
2034 }
2035 if (comparer.Compare(Convert.ToUInt32(Value), value))
2036 {
2037 writer.WriteResult<uint>(comparer.Address, comparer.Value);
2038 }
2039 }
2040 }
2041 #endregion
2042 }
2043 else
2044 {
2045 #region 32bits - signed
2046 var t_data = BitTools.ConvertByteArray<int>(data);
2047 foreach (var Value in t_data)
2048 {
2049 if (SearchWorkerThread.CancellationPending) { break; }
2050 using (_32bit_signed_comparer_ comparer = new _32bit_signed_comparer_(SearchArgs, i))
2051 {
2052 int value = 0;
2053 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2054 {
2055 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2056 {
2057 try
2058 {
2059 gmp.OpenProvider();
2060 gmp.ReadMemory(i, out value);
2061 gmp.CloseProvider();
2062 }
2063 catch (Exception ex)
2064 {
2065 logger.VerboseError.WriteLine(ex.ToString());
2066 }
2067 }
2068 comparer.Value = value;
2069 }
2070 else
2071 {
2072 value = Convert.ToInt32(SearchArgs.CompareStartValue);
2073 comparer.Value = value;
2074 }
2075 if (comparer.Compare(Convert.ToInt32(Value), value))
2076 {
2077 writer.WriteResult<int>(comparer.Address, comparer.Value);
2078 }
2079 }
2080 }
2081 #endregion
2082 } break;
2083 case SearchDataTypes._64bits:
2084 if (unsigned)
2085 {
2086 #region 64bits - unsigned
2087 var t_data = BitTools.ConvertByteArray<ulong>(data);
2088 foreach (var Value in t_data)
2089 {
2090 if (SearchWorkerThread.CancellationPending) { break; }
2091 using (_64bit_unsigned_comparer_ comparer = new _64bit_unsigned_comparer_(SearchArgs, i))
2092 {
2093 ulong value = 0;
2094 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2095 {
2096 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2097 {
2098 try
2099 {
2100 gmp.OpenProvider();
2101 gmp.ReadMemory(i, out value);
2102 gmp.CloseProvider();
2103 }
2104 catch (Exception ex)
2105 {
2106 logger.VerboseError.WriteLine(ex.ToString());
2107 }
2108 }
2109 comparer.Value = value;
2110 }
2111 else
2112 {
2113 value = Convert.ToUInt64(SearchArgs.CompareStartValue);
2114 comparer.Value = value;
2115 }
2116 if (comparer.Compare(Convert.ToUInt64(Value), value))
2117 {
2118 writer.WriteResult<ulong>(comparer.Address, comparer.Value);
2119 }
2120 }
2121 }
2122 #endregion
2123 }
2124 else
2125 {
2126 #region 64bits - signed
2127 var t_data = BitTools.ConvertByteArray<long>(data);
2128 foreach (var Value in t_data)
2129 {
2130 if (SearchWorkerThread.CancellationPending) { break; }
2131 using (_64bit_signed_comparer_ comparer = new _64bit_signed_comparer_(SearchArgs, i))
2132 {
2133 long value = 0;
2134 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2135 {
2136 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2137 {
2138 try
2139 {
2140 gmp.OpenProvider();
2141 gmp.ReadMemory(i, out value);
2142 gmp.CloseProvider();
2143 }
2144 catch (Exception ex)
2145 {
2146 logger.VerboseError.WriteLine(ex.ToString());
2147 }
2148 }
2149 comparer.Value = value;
2150 }
2151 else
2152 {
2153 value = Convert.ToInt64(SearchArgs.CompareStartValue);
2154 comparer.Value = value;
2155 }
2156 if (comparer.Compare(Convert.ToInt64(Value), value))
2157 {
2158 writer.WriteResult<long>(comparer.Address, comparer.Value);
2159 }
2160 }
2161 }
2162 #endregion
2163 } break;
2164 }
2165
2166 //using (MemoryStream ms = new MemoryStream(data))
2167 //{
2168 // using (BinaryReader br = new BinaryReader(ms))
2169 // {
2170 // while (br.BaseStream.Position < br.BaseStream.Length)
2171 // {
2172 // if (SearchWorkerThread.CancellationPending)
2173 // {
2174 // break;
2175 // }
2176 // }
2177 // }
2178 //}
2179 #endregion
2180
2181
2182 if (SearchWorkerThread.CancellationPending)
2183 {
2184 st_profiler.Stop();
2185 provider_st.Stop();
2186 st.Stop();
2187 writer.CancelRequest();
2188 writer.Dispose();
2189 writer = null;
2190 e.Result = true;
2191 provider.CloseProvider();
2192 logger.Profiler.WriteLine("Memory Search Operation Profiler: search operation took {0} seconds", st_profiler.Elapsed.TotalSeconds.ToString());
2193 return;
2194 }
2195 }
2196
2197 st_profiler.Stop();
2198
2199 logger.Profiler.WriteLine("Memory Search Operation Profiler: search operation took {0} seconds", st_profiler.Elapsed.TotalSeconds.ToString());
2200
2201 if (SearchWorkerThread.CancellationPending)
2202 {
2203 provider_st.Stop();
2204 st.Stop();
2205 writer.CancelRequest();
2206 writer.Dispose();
2207 writer = null;
2208 e.Result = true;
2209 provider.CloseProvider();
2210 return;
2211 }
2212 writer.Dispose();
2213 writer = null;
2214 provider.CloseProvider();
2215 }
2216 else
2217 {
2218
2219 #region action_onbytesread :: custom in-line delegate for processing read bytes
2220 // custom in-line delegate for processing read bytes
2221 Action<OnBytesReadEventArgs> action_onbytesread = delegate(OnBytesReadEventArgs obre)
2222 {
2223 SearchDataTypes obre_sdt = SearchArgs.DataType;
2224 bool obre_unsigned = SearchArgs.IsUnsignedDataType;
2225 uint obre_CurrentIndex = obre.CurrentIndex; // this should represent the address
2226 SearchResultReader reader = null;
2227 if (obre.UserState != null)
2228 {
2229 reader = (obre.UserState as SearchResultReader);
2230 if (reader == null)
2231 throw new InvalidOperationException("writer cannot be null");
2232 }
2233 else
2234 {
2235 throw new ArgumentNullException("UserState", "UserState cannot be null, it must be an instance of a SearchResultReader");
2236 }
2237 using (MemoryStream ms = new MemoryStream(obre.Data))
2238 {
2239 using (BinaryReader br = new BinaryReader(ms))
2240 {
2241 while (br.BaseStream.Position < br.BaseStream.Length)
2242 {
2243 ISerializedResult sr = (reader as ISerializedResult);
2244 if (sr == null)
2245 {
2246 throw new ArgumentNullException("sr", string.Format("Unable to cast: '{0}' to '{1}'", reader.GetType().Name, typeof(ISerializedResult).Name));
2247 }
2248 int sr_index = 0;
2249 try
2250 {
2251 if (sr.ContainsAddress(obre_CurrentIndex, obre_unsigned, obre_sdt, new Action<int, string>(this.UpdateProgress), out sr_index))
2252 {
2253 StructResultType<ulong> result = StructResultType<ulong>.Empty;
2254 sr.GetResultAtIndex(sr_index, obre_unsigned, obre_sdt, new Action<int, string>(this.UpdateProgress), out result);
2255 if (Debugger.IsAttached)
2256 {
2257 Debugger.Break();
2258 }
2259
2260 }
2261 }
2262 catch (Exception ex)
2263 {
2264 throw ex;
2265 }
2266 switch (obre_sdt)
2267 {
2268 case SearchDataTypes._8bits:
2269 if (obre_unsigned)
2270 {
2271 #region 8bit - unsigned
2272 var new_value = br.ReadByte(); // this should contain the updated value from memory
2273 using (_8bit_unsigned_comparer_ comparer = new _8bit_unsigned_comparer_(SearchArgs, obre_CurrentIndex))
2274 {
2275 byte value = 0; // this is the vaule we want to compare against
2276 value = Convert.ToByte(SearchArgs.CompareStartValue);
2277 comparer.Value = value;
2278 if (comparer.Compare(new_value, value))
2279 {
2280 //writer.WriteResult<byte>(comparer.Address, comparer.Value);
2281 }
2282 }
2283 #endregion
2284 }
2285 else
2286 {
2287 }
2288 break;
2289 case SearchDataTypes._16bits:
2290 if (obre_unsigned)
2291 {
2292 }
2293 else
2294 {
2295 }
2296 break;
2297 case SearchDataTypes._32bits:
2298 if (obre_unsigned)
2299 {
2300 }
2301 else
2302 {
2303 }
2304 break;
2305 case SearchDataTypes._64bits:
2306 if (obre_unsigned)
2307 {
2308 }
2309 else
2310 {
2311 }
2312 break;
2313 }
2314 uint size = 0;
2315 BitTools.SizeOf(obre_sdt, out size);
2316 obre_CurrentIndex += size;
2317 }
2318 }
2319 }
2320 };
2321 #endregion
2322 // need to get the address list
2323 using (SearchResultReader reader = new SearchResultReader(SearchGuid, false)) // delete the file on dispose
2324 {
2325
2326
2327 provider.OpenProvider();
2328 //int count = (int)((MemoryRangeSize - MemoryRangeStart) / STEP_SIZE);
2329 //SearchResultWriter writer = new SearchResultWriter((int)(count), SearchGuid);
2330 provider.OnBytesRead += new BaseEventHandler<OnBytesReadEventArgs>(action_onbytesread);
2331 provider.ReadProcessMemoryAtOnce(MemoryRangeStart, (MemoryRangeSize - MemoryRangeStart), reader);
2332 if (SearchWorkerThread.CancellationPending)
2333 {
2334 provider_st.Stop();
2335 st.Stop();
2336 e.Result = true;
2337 provider.CloseProvider();
2338 return;
2339 }
2340 provider.CloseProvider();
2341
2342 //byte[] guid = SearchGuid.ToByteArray();
2343 //guid[guid.Length - 1]++; // increment the search guid by 1
2344 //Guid new_SearchGuid = new Guid(guid);
2345 ////const int item_count = 0x100;
2346 //using (SearchResultWriter writer = new SearchResultWriter((int)(reader.ResultCount), new_SearchGuid))
2347 //{
2348 // var items = reader.GetSearchAddressValueMatches((IAcceptsProcessAndConfig)this, SearchArgs, new Action<int, string>(UpdateProgress));
2349 // reader.Dispose(); // delete the result file, if allowed
2350 // foreach (var item in items)
2351 // {
2352 // switch (SearchArgs.DataType)
2353 // {
2354 // case SearchDataTypes._8bits:
2355 // if (SearchArgs.IsUnsignedDataType)
2356 // {
2357 // writer.WriteResult<byte>(item.Address, Convert.ToByte(item.Value));
2358 // }
2359 // else
2360 // {
2361 // writer.WriteResult<sbyte>(item.Address, Convert.ToSByte(item.Value));
2362 // }
2363 // break;
2364 // case SearchDataTypes._16bits:
2365 // if (SearchArgs.IsUnsignedDataType)
2366 // {
2367 // writer.WriteResult<ushort>(item.Address, Convert.ToUInt16(item.Value));
2368 // }
2369 // else
2370 // {
2371 // writer.WriteResult<short>(item.Address, Convert.ToInt16(item.Value));
2372 // }
2373 // break;
2374 // case SearchDataTypes._32bits:
2375 // if (SearchArgs.IsUnsignedDataType)
2376 // {
2377 // writer.WriteResult<uint>(item.Address, Convert.ToUInt32(item.Value));
2378 // }
2379 // else
2380 // {
2381 // writer.WriteResult<int>(item.Address, Convert.ToInt32(item.Value));
2382 // }
2383 // break;
2384 // case SearchDataTypes._64bits:
2385 // if (SearchArgs.IsUnsignedDataType)
2386 // {
2387 // writer.WriteResult<ulong>(item.Address, Convert.ToUInt64(item.Value));
2388 // }
2389 // else
2390 // {
2391 // writer.WriteResult<long>(item.Address, Convert.ToInt64(item.Value));
2392 // }
2393 // break;
2394 // }
2395 // }
2396 //}
2397 //SearchGuid = new_SearchGuid;
2398 }
2399 }
2400 }
2401 provider_st.Stop();
2402 logger.Profiler.WriteLine("It took a total of {0} seconds for the memory provider to complete it's operation(s).", provider_st.Elapsed.TotalSeconds);
2403 //if (buffered_mem.Length == 0) { logger.Warn.WriteLine("Buffered Memory is Zero Length."); return; }
2404 //int Last_Whole_Percent_Done = 0;
2405
2406
2407 #region Subsequent Searches
2408 //r_ms.BaseStream.Seek(0, SeekOrigin.Begin);
2409
2410
2411 // hack to help with OutOfMemory Exceptions (OldValue and Equal compare will always add all found search results)
2412 bool NeedToCompare = true;
2413 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue &&
2414 SearchArgs.CompareType == SearchCompareTypes.Equal &&
2415 SearchArgs.IsFirstSearch)
2416 {
2417 NeedToCompare = false;
2418 //second_tmp_Results = null; // Free Memory
2419 }
2420
2421 if (NeedToCompare)
2422 {
2423 if (SearchArgs.CompareType != SearchCompareTypes.Between && SearchArgs.CompareType != SearchCompareTypes.NotBetween)
2424 {
2425 #region Non-Range Searches
2426 if (USE_NONRANGE_SEARCH_RESULT_READER)
2427 {
2428 st_nonrange_search.Start();
2429 //second_tmp_Results = new List<ResultType<object>>(SearchArgs.Results.Count * 1024);
2430 ////second_tmp_Results.c
2431 try
2432 {
2433 using (SearchResultReader reader = new SearchResultReader(SearchGuid))
2434 {
2435 try
2436 {
2437
2438 #region new comparator-support
2439 //second_tmp_Results = new List<StructResultType<object>>(reader.GetResults(SearchArgs.IsUnsignedDataType, SearchArgs.DataType, new Action<int, string>(UpdateProgress)));
2440 #endregion
2441
2442 #region USE_OLD_SEARCH_RESULTS_COMPRATOR_CODE
2443 if (USE_OLD_SEARCH_RESULTS_COMPRATOR_CODE)
2444 {
2445 for (int i = 0; i < reader.ResultCount; i += 1)
2446 {
2447 object result_value = 0;
2448 uint address = 0;
2449 #region switch (SearchArgs.DataType)
2450 switch (SearchArgs.DataType)
2451 {
2452 case SearchDataTypes._8bits: if (unsigned)
2453 {
2454 using (ResultType<byte> result = reader.GetNextResult<byte>())
2455 {
2456 address = result.Address;
2457 result_value = result.Value;
2458 }
2459 }
2460 else
2461 {
2462 using (ResultType<sbyte> result = reader.GetNextResult<sbyte>())
2463 {
2464 address = result.Address;
2465 result_value = result.Value;
2466 }
2467 } break;
2468 case SearchDataTypes._16bits: if (unsigned)
2469 {
2470 using (ResultType<ushort> result = reader.GetNextResult<ushort>())
2471 {
2472 address = result.Address;
2473 result_value = result.Value;
2474 }
2475 }
2476 else
2477 {
2478 using (ResultType<short> result = reader.GetNextResult<short>())
2479 {
2480 address = result.Address;
2481 result_value = result.Value;
2482 }
2483 } break;
2484 case SearchDataTypes._32bits: if (unsigned)
2485 {
2486 using (ResultType<uint> result = reader.GetNextResult<uint>())
2487 {
2488 address = result.Address;
2489 result_value = result.Value;
2490 }
2491 }
2492 else
2493 {
2494 using (ResultType<int> result = reader.GetNextResult<int>())
2495 {
2496 address = result.Address;
2497 result_value = result.Value;
2498 }
2499 } break;
2500 case SearchDataTypes._64bits: if (unsigned)
2501 {
2502 using (ResultType<ulong> result = reader.GetNextResult<ulong>())
2503 {
2504 address = result.Address;
2505 result_value = result.Value;
2506 }
2507 }
2508 else
2509 {
2510 using (ResultType<long> result = reader.GetNextResult<long>())
2511 {
2512 address = result.Address;
2513 result_value = result.Value;
2514 }
2515 } break;
2516 }
2517 #endregion
2518 if (MemoryRangeStart > 0 && !SearchArgs.IsFirstSearch) { address = address - MemoryRangeStart; }
2519 try
2520 {
2521 //r_ms.BaseStream.Seek(address, SeekOrigin.Begin);
2522 }
2523 catch (Exception)
2524 {
2525 throw;
2526 }
2527 switch (SearchArgs.DataType)
2528 {
2529 #region Comparer Support
2530 #region case SearchDataTypes._8bits:
2531 case SearchDataTypes._8bits:
2532 if (SearchArgs.IsUnsignedDataType)
2533 {
2534 byte lookup_value = 0;
2535 //using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this)) { gmp.OpenProvider(); gmp.ReadMemory(address, out lookup_value); gmp.CloseProvider(); }
2536 lookup_value = Convert.ToByte(result_value);
2537 using (_8bit_unsigned_comparer_ comparer = new _8bit_unsigned_comparer_(SearchArgs, address))
2538 {
2539 byte value = 0;
2540 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2541 {
2542 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2543 {
2544 try
2545 {
2546 gmp.OpenProvider();
2547 gmp.ReadMemory(address, out value);
2548 gmp.CloseProvider();
2549 }
2550 catch (Exception ex)
2551 {
2552 logger.VerboseError.WriteLine(ex.ToString());
2553 }
2554 }
2555 comparer.Value = value;
2556 }
2557 else
2558 {
2559 value = Convert.ToByte(SearchArgs.CompareStartValue);
2560 comparer.Value = value;
2561 }
2562 if (comparer.Compare(lookup_value, value))
2563 {
2564 second_tmp_Results.Add(new ResultType<ulong>(comparer.Address, comparer.Value));
2565 }
2566 }
2567 }
2568 else
2569 {
2570 sbyte lookup_value = 0;
2571 //using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this)) { gmp.OpenProvider(); gmp.ReadMemory(address, out lookup_value); gmp.CloseProvider(); }
2572 lookup_value = Convert.ToSByte(result_value);
2573 using (_8bit_signed_comparer_ comparer = new _8bit_signed_comparer_(SearchArgs, address))
2574 {
2575 sbyte value = 0;
2576 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2577 {
2578 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2579 {
2580 try
2581 {
2582 gmp.OpenProvider();
2583 gmp.ReadMemory(address, out value);
2584 gmp.CloseProvider();
2585 }
2586 catch (Exception ex)
2587 {
2588 logger.VerboseError.WriteLine(ex.ToString());
2589 }
2590 }
2591 comparer.Value = value;
2592 }
2593 else
2594 {
2595 value = Convert.ToSByte(SearchArgs.CompareStartValue);
2596 }
2597 if (comparer.Compare(lookup_value, value))
2598 {
2599 second_tmp_Results.Add(new ResultType<ulong>(comparer.Address, (ulong)comparer.Value));
2600 }
2601 }
2602 }
2603 break;
2604 #endregion
2605 #region case SearchDataTypes._16bits:
2606 case SearchDataTypes._16bits:
2607 if (SearchArgs.IsUnsignedDataType)
2608 {
2609 ushort lookup_value = 0;
2610 //using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this)) { gmp.OpenProvider(); gmp.ReadMemory(address, out lookup_value); gmp.CloseProvider(); }
2611 lookup_value = Convert.ToUInt16(result_value);
2612 using (_16bit_unsigned_comparer_ comparer = new _16bit_unsigned_comparer_(SearchArgs, address))
2613 {
2614 ushort value = 0;
2615 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2616 {
2617 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2618 {
2619 try
2620 {
2621 gmp.OpenProvider();
2622 gmp.ReadMemory(address, out value);
2623 gmp.CloseProvider();
2624 }
2625 catch (Exception ex)
2626 {
2627 logger.VerboseError.WriteLine(ex.ToString());
2628 }
2629 }
2630 comparer.Value = value;
2631 }
2632 else
2633 {
2634 value = Convert.ToUInt16(SearchArgs.CompareStartValue);
2635 comparer.Value = value;
2636 }
2637 if (comparer.Compare(lookup_value, value))
2638 {
2639 second_tmp_Results.Add(new ResultType<ulong>(comparer.Address, comparer.Value));
2640 }
2641 }
2642 }
2643 else
2644 {
2645 short lookup_value = 0;
2646 //using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this)) { gmp.OpenProvider(); gmp.ReadMemory(address, out lookup_value); gmp.CloseProvider(); }
2647 lookup_value = Convert.ToInt16(result_value);
2648 using (_16bit_signed_comparer_ comparer = new _16bit_signed_comparer_(SearchArgs, address))
2649 {
2650 short value = 0;
2651 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2652 {
2653 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2654 {
2655 try
2656 {
2657 gmp.OpenProvider();
2658 gmp.ReadMemory(address, out value);
2659 gmp.CloseProvider();
2660 }
2661 catch (Exception ex)
2662 {
2663 logger.VerboseError.WriteLine(ex.ToString());
2664 }
2665 }
2666 comparer.Value = value;
2667 }
2668 else
2669 {
2670 value = Convert.ToInt16(SearchArgs.CompareStartValue);
2671 }
2672 if (comparer.Compare(lookup_value, value))
2673 {
2674 second_tmp_Results.Add(new ResultType<ulong>(comparer.Address, (ulong)comparer.Value));
2675 }
2676 }
2677 }
2678 break;
2679 #endregion
2680 #region case SearchDataTypes._32bits:
2681 case SearchDataTypes._32bits:
2682 if (SearchArgs.IsUnsignedDataType)
2683 {
2684 uint lookup_value = 0;
2685 //using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this)) { gmp.OpenProvider(); gmp.ReadMemory(address, out lookup_value); gmp.CloseProvider(); }
2686 lookup_value = Convert.ToUInt32(result_value);
2687 using (_32bit_unsigned_comparer_ comparer = new _32bit_unsigned_comparer_(SearchArgs, address))
2688 {
2689 uint value = 0;
2690 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2691 {
2692 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2693 {
2694 try
2695 {
2696 gmp.OpenProvider();
2697 gmp.ReadMemory(address, out value);
2698 gmp.CloseProvider();
2699 }
2700 catch (Exception ex)
2701 {
2702 logger.VerboseError.WriteLine(ex.ToString());
2703 }
2704 }
2705 comparer.Value = value;
2706 }
2707 else
2708 {
2709 value = Convert.ToUInt32(SearchArgs.CompareStartValue);
2710 comparer.Value = value;
2711 }
2712 if (comparer.Compare(lookup_value, value))
2713 {
2714 second_tmp_Results.Add(new ResultType<ulong>(comparer.Address, comparer.Value));
2715 }
2716 }
2717 }
2718 else
2719 {
2720 int lookup_value = 0;
2721 //using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this)) { gmp.OpenProvider(); gmp.ReadMemory(address, out lookup_value); gmp.CloseProvider(); }
2722 lookup_value = Convert.ToInt32(result_value);
2723 using (_32bit_signed_comparer_ comparer = new _32bit_signed_comparer_(SearchArgs, address))
2724 {
2725 int value = 0;
2726 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2727 {
2728 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2729 {
2730 try
2731 {
2732 gmp.OpenProvider();
2733 gmp.ReadMemory(address, out value);
2734 gmp.CloseProvider();
2735 }
2736 catch (Exception ex)
2737 {
2738 logger.VerboseError.WriteLine(ex.ToString());
2739 }
2740 }
2741 comparer.Value = value;
2742 }
2743 else
2744 {
2745 value = Convert.ToInt32(SearchArgs.CompareStartValue);
2746 }
2747 if (comparer.Compare(lookup_value, value))
2748 {
2749 second_tmp_Results.Add(new ResultType<ulong>(comparer.Address, (ulong)comparer.Value));
2750 }
2751 }
2752 }
2753 break;
2754 #endregion
2755 #region case SearchDataTypes._64bits:
2756 case SearchDataTypes._64bits:
2757 if (SearchArgs.IsUnsignedDataType)
2758 {
2759 ulong lookup_value = 0;
2760 //using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this)) { gmp.OpenProvider(); gmp.ReadMemory(address, out lookup_value); gmp.CloseProvider(); }
2761 lookup_value = Convert.ToUInt64(result_value);
2762 using (_64bit_unsigned_comparer_ comparer = new _64bit_unsigned_comparer_(SearchArgs, address))
2763 {
2764 ulong value = 0;
2765 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2766 {
2767 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2768 {
2769 try
2770 {
2771 gmp.OpenProvider();
2772 gmp.ReadMemory(address, out value);
2773 gmp.CloseProvider();
2774 }
2775 catch (Exception ex)
2776 {
2777 logger.VerboseError.WriteLine(ex.ToString());
2778 }
2779 }
2780 comparer.Value = value;
2781 }
2782 else
2783 {
2784 value = Convert.ToUInt64(SearchArgs.CompareStartValue);
2785 comparer.Value = value;
2786 }
2787 if (comparer.Compare(lookup_value, value))
2788 {
2789 second_tmp_Results.Add(new ResultType<ulong>(comparer.Address, comparer.Value));
2790 }
2791 }
2792 }
2793 else
2794 {
2795 long lookup_value = 0;
2796 //using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this)) { gmp.OpenProvider(); gmp.ReadMemory(address, out lookup_value); gmp.CloseProvider(); }
2797 lookup_value = Convert.ToInt64(result_value);
2798 using (_64bit_signed_comparer_ comparer = new _64bit_signed_comparer_(SearchArgs, address))
2799 {
2800 long value = 0;
2801 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
2802 {
2803 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
2804 {
2805 try
2806 {
2807 gmp.OpenProvider();
2808 gmp.ReadMemory(address, out value);
2809 gmp.CloseProvider();
2810 }
2811 catch (Exception ex)
2812 {
2813 logger.VerboseError.WriteLine(ex.ToString());
2814 }
2815 }
2816 comparer.Value = value;
2817 }
2818 else
2819 {
2820 value = Convert.ToInt64(SearchArgs.CompareStartValue);
2821 }
2822 if (comparer.Compare(lookup_value, value))
2823 {
2824 second_tmp_Results.Add(new ResultType<ulong>(comparer.Address, (ulong)comparer.Value));
2825 }
2826 }
2827 }
2828 break;
2829 #endregion
2830 #endregion
2831 }
2832 double double_percent_done = 100.0 * (double)((double)i / (double)reader.ResultCount);
2833 int int_percent_done = (int)double_percent_done;
2834 //if (int_percent_done != Last_Whole_Percent_Done && i % 100000 == 0)
2835 //{
2836 if (int_percent_done <= 100)
2837 {
2838 //Last_Whole_Percent_Done = int_percent_done;
2839 UpdateProgress(int_percent_done, string.Format(" -> Reading Address: 0x{0:x8}", i + MemoryRangeStart));
2840 //new Action<int, string>(UpdateProgress).Invoke(int_percent_done, string.Format(" -> Reading Address: 0x{0:x8}", i + MemoryRangeStart));
2841 }
2842 //}
2843 //this.Refresh();
2844 }
2845 }
2846 #endregion
2847 }
2848 catch (Exception ex)
2849 {
2850 throw ex;
2851 }
2852 }
2853 }
2854 catch (Exception ex)
2855 {
2856 throw ex;
2857 }
2858 st_nonrange_search.Stop();
2859 logger.Profiler.WriteLine("Non-Ranged search took a total of {0} seconds to complete.", st_nonrange_search.Elapsed.TotalSeconds);
2860 //Last_Whole_Percent_Done = 0;
2861 }
2862 #endregion
2863 }
2864 #region Ranged Searches
2865 #if !DONOT_HAVE_RANGED_SEARCH_SUPPORT
2866 if (SearchArgs.CompareType == SearchCompareTypes.Between || SearchArgs.CompareType == SearchCompareTypes.NotBetween)
2867 {
2868 st_ranged_search.Start();
2869 object start, end;
2870
2871 start = SearchArgs.CompareStartValue;
2872 end = SearchArgs.CompareEndValue;
2873 using (SearchResultReader reader = new SearchResultReader(SearchGuid))
2874 {
2875 for (int i = 0; i < reader.ResultCount; i += 1)
2876 {
2877 uint address = 0;
2878 #region switch (SearchArgs.DataType)
2879 switch (SearchArgs.DataType)
2880 {
2881 case SearchDataTypes._8bits: if (unsigned) { using (ResultType<byte> result = reader.GetNextResult<byte>()) { address = result.Address; } }
2882 else { using (ResultType<sbyte> result = reader.GetNextResult<sbyte>()) { address = result.Address; } } break;
2883 case SearchDataTypes._16bits: if (unsigned) { using (ResultType<ushort> result = reader.GetNextResult<ushort>()) { address = result.Address; } }
2884 else { using (ResultType<short> result = reader.GetNextResult<short>()) { address = result.Address; } } break;
2885 case SearchDataTypes._32bits: if (unsigned) { using (ResultType<uint> result = reader.GetNextResult<uint>()) { address = result.Address; } }
2886 else { using (ResultType<int> result = reader.GetNextResult<int>()) { address = result.Address; } } break;
2887 case SearchDataTypes._64bits: if (unsigned) { using (ResultType<ulong> result = reader.GetNextResult<ulong>()) { address = result.Address; } }
2888 else { using (ResultType<long> result = reader.GetNextResult<long>()) { address = result.Address; } } break;
2889 }
2890 #endregion
2891
2892 if (MemoryRangeStart > 0 && !SearchArgs.IsFirstSearch) { address = address - MemoryRangeStart; }
2893 //r_ms.BaseStream.Seek(address, SeekOrigin.Begin);
2894 if (SearchArgs.CompareType == SearchCompareTypes.Between)
2895 {
2896 using (InRangeComparer comparer = new InRangeComparer(address, 0))
2897 {
2898 if (comparer.Compare(start, end, SearchArgs.DataType, SearchArgs.IsUnsignedDataType, (IAcceptsProcessAndConfig)this))
2899 {
2900 using (ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value))
2901 {
2902 second_tmp_Results.Add(_tmp_result);
2903 }
2904 }
2905 }
2906 }
2907 else if (SearchArgs.CompareType == SearchCompareTypes.NotBetween)
2908 {
2909 using (NotInRangeComparer comparer = new NotInRangeComparer(address, 0))
2910 {
2911 if (comparer.Compare(start, end, SearchArgs.DataType, SearchArgs.IsUnsignedDataType, (IAcceptsProcessAndConfig)this))
2912 {
2913 using (ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value))
2914 {
2915 second_tmp_Results.Add(_tmp_result);
2916 }
2917 }
2918 }
2919 }
2920 else
2921 {
2922 throw new InvalidOperationException("Encounted unkown range search type: " + SearchArgs.CompareType);
2923 }
2924 double double_percent_done = 100.0 * (double)((double)i / (double)reader.ResultCount);
2925 int int_percent_done = (int)double_percent_done;
2926 if (int_percent_done != Last_Whole_Percent_Done)
2927 {
2928 if (int_percent_done <= 100)
2929 {
2930 resultsprogress.Value = int_percent_done;
2931 resultsprogress.Message = string.Format(" -> Reading Address: 0x{0:x8}", i + MemoryRangeStart);
2932 Last_Whole_Percent_Done = int_percent_done;
2933 }
2934 }
2935 }
2936 }
2937 st_ranged_search.Stop();
2938 logger.Profiler.WriteLine("Ranged search took a total of {0} seconds to complete.", st_ranged_search.Elapsed.TotalSeconds);
2939 }
2940 #endif
2941 #endregion
2942
2943 }
2944 #endregion
2945 //// leave SearchArgs.Results alone, if false
2946 //if (NeedToCompare)
2947 //{
2948 // // fix addresses when memory start is not zero
2949 // 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; } }
2950 // using (SearchResultWriter writer = new SearchResultWriter(second_tmp_Results.Count, SearchGuid))
2951 // {
2952 // for (int i = 0; i < second_tmp_Results.Count; i++)
2953 // {
2954 // switch (sdt)
2955 // {
2956 // case SearchDataTypes._8bits:
2957 // if (unsigned) { writer.WriteResult<Byte>(second_tmp_Results[i].Address, Convert.ToByte(second_tmp_Results[i].Value)); }
2958 // else { writer.WriteResult<SByte>(second_tmp_Results[i].Address, Convert.ToSByte(second_tmp_Results[i].Value)); } break;
2959 // case SearchDataTypes._16bits:
2960 // if (unsigned) { writer.WriteResult<UInt16>(second_tmp_Results[i].Address, Convert.ToUInt16(second_tmp_Results[i].Value)); }
2961 // else { writer.WriteResult<Int16>(second_tmp_Results[i].Address, Convert.ToInt16(second_tmp_Results[i].Value)); } break;
2962 // case SearchDataTypes._32bits:
2963 // if (unsigned) { writer.WriteResult<UInt32>(second_tmp_Results[i].Address, Convert.ToUInt32(second_tmp_Results[i].Value)); }
2964 // else { writer.WriteResult<Int32>(second_tmp_Results[i].Address, Convert.ToInt32(second_tmp_Results[i].Value)); } break;
2965 // case SearchDataTypes._64bits:
2966 // if (unsigned) { writer.WriteResult<UInt64>(second_tmp_Results[i].Address, Convert.ToUInt64(second_tmp_Results[i].Value)); }
2967 // else { writer.WriteResult<Int64>(second_tmp_Results[i].Address, Convert.ToInt64(second_tmp_Results[i].Value)); } break;
2968 // }
2969 // }
2970 // }
2971 // second_tmp_Results = null; // free memory
2972 //}
2973 }
2974 catch (OutOfMemoryException ex)
2975 {
2976 e.Result = true;
2977 logger.Error.WriteLine("Encounted {0} for search: {0}", ex.GetType().Name, SearchGuid.ToString());
2978 logger.VerboseError.WriteLine(ex.ToString());
2979 MessageBox.Show(string.Format("Encounted {0} for search: {0} ... Please try again.", ex.GetType().Name, SearchGuid.ToString()), string.Format("{0} was thrown", ex.GetType().Name), MessageBoxButtons.OK, MessageBoxIcon.Error);
2980 return;
2981 }
2982 catch (Exception ex)
2983 {
2984 throw ex;
2985 }
2986 }
2987
2988
2989
2990 private void SearchWorkerThread_ProgressChanged(object sender, ProgressChangedEventArgs e)
2991 {
2992 //if (SearchArgs.ProgressLogger != null)
2993 //{
2994 // resultsprogress.Value = e.ProgressPercentage;
2995 // //Application.DoEvents();
2996 //}
2997 }
2998
2999 private void SearchWorkerThread_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
3000 {
3001 try { if ((bool)e.Result) { logger.Warn.WriteLine("Search operation was cancelled.");
3002 //new Action<int, string>(UpdateProgress).Invoke(0, string.Empty);
3003 UpdateProgress(0, string.Empty);
3004 return; }
3005 }
3006 catch (InvalidCastException) { }
3007 try
3008 {
3009 Stopwatch st = (Stopwatch)e.Result;
3010 st.Stop();
3011 logger.Profiler.WriteLine("Search took {0} seconds, overall, to complete.", st.Elapsed.TotalSeconds);
3012 }
3013 catch (InvalidCastException) { }
3014 catch (Exception ex) { throw ex; }
3015
3016 UpdateProgress(100, String.Empty);
3017 //new Action<int, string>(UpdateProgress).Invoke(100, string.Empty);
3018 bool unsigned = SearchArgs.IsUnsignedDataType;
3019 using (SearchResultReader reader = new SearchResultReader(SearchGuid))
3020 {
3021 logger.Info.WriteLine(string.Format("Found 0x{0:x8} results", reader.ResultCount));
3022
3023 if (reader.ResultCount <= MIN_NUMBER_OF_RESULTS_BEFORE_DISPLAY)
3024 {
3025 lstResults.Items.Clear();
3026 //List<ResultItem> items = new List<ResultItem>();
3027 //for (int i = 0; i < reader.ResultCount; i++)
3028 //{
3029 // ResultItem item = new ResultItem(0, false);
3030 // //item.Text = string.Format("0x{0:x8}", SearchArgs.Results[i].Address);
3031 // //item.SubItems.Add(string.Format("0x{0:x8}", SearchArgs.Results[i].Address));
3032 // switch (SearchArgs.DataType)
3033 // {
3034 // case SearchDataTypes._8bits:
3035 // if (SearchArgs.IsUnsignedDataType) { ResultType<byte> result = new ResultType<byte>(); item = new ResultItem(result.Address, false, result.Value); }
3036 // else { ResultType<sbyte> result = reader.GetNextResult<sbyte>(); item = new ResultItem(result.Address, false, result.Value); }
3037 // break;
3038 // case SearchDataTypes._16bits:
3039 // if (SearchArgs.IsUnsignedDataType) { ResultType<ushort> result = reader.GetNextResult<ushort>(); item = new ResultItem(result.Address, false, result.Value); }
3040 // else { ResultType<short> result = reader.GetNextResult<short>(); item = new ResultItem(result.Address, false, result.Value); }
3041 // break;
3042 // case SearchDataTypes._32bits:
3043 // if (SearchArgs.IsUnsignedDataType) { ResultType<uint> result = reader.GetNextResult<uint>(); item = new ResultItem(result.Address, false, result.Value); }
3044 // else { ResultType<int> result = reader.GetNextResult<int>(); item = new ResultItem(result.Address, false, result.Value); }
3045 // break;
3046 // case SearchDataTypes._64bits:
3047 // if (SearchArgs.IsUnsignedDataType) { ResultType<ulong> result = reader.GetNextResult<ulong>(); item = new ResultItem(result.Address, false, result.Value); }
3048 // else { ResultType<long> result = reader.GetNextResult<long>(); item = new ResultItem(result.Address, false, result.Value); }
3049 // break;
3050 // }
3051 // if (!items.Contains(item))
3052 // items.Add(item);
3053 //}
3054 //lstResults.Items.AddRange(reader.GetResultItems(SearchArgs.IsUnsignedDataType, SearchArgs.DataType, new Action<int, string>(UpdateProgress)));
3055 }
3056 }
3057
3058 this.DoSearchDoneSpecific();
3059 //System.Threading.Thread.Sleep(100);
3060 //if (_SEARCH_MODE != SearchMode.SEARCH_MODE_NORMAL_WITH_JOKER)
3061 this.ThawResultsUpdate();
3062 Application.DoEvents();
3063 }
3064 private void DoSearchDoneSpecific()
3065 {
3066 SearchWorkerThread.CancelAsync();
3067 if (lstResults.Items.Count > 0) { timer_update_results.Enabled = true; }
3068 else { timer_update_results.Enabled = false; }
3069
3070 search_progress_updater.Enabled = false;
3071
3072 btnCancel.Enabled = false;
3073 btnReset.Enabled = true;
3074 btnSearch.Enabled = true;
3075 grpCompareType.Enabled = true;
3076 grpCompareValue.Enabled = true;
3077 UpdateProgress(0, string.Empty);
3078 //new Action<int, string>(UpdateProgress).Invoke(0, string.Empty);
3079 grpDataType.Enabled = false;
3080 // resume process on reset, incase it was suspended
3081 ThreadControl.ResumeProcess(this.AcceptedProcess.Id);
3082 //Application.DoEvents();
3083 this.Refresh();
3084 }
3085
3086 private void DoCancelSpecific()
3087 {
3088 this.DoSearchDoneSpecific();
3089 }
3090 private void DoResetSpecific()
3091 {
3092 this.DoCancelSpecific();
3093 IsFirstSearch = true;
3094 grpDataType.Enabled = true;
3095 btnReset.Enabled = false;
3096
3097 // delete any temporary search result files
3098 SearchResultWriter.CleanupTemporarySearchResultFiles();
3099
3100 }
3101 private void search_progress_updater_Tick(object sender, EventArgs e)
3102 {
3103 if ((this.AcceptedProcess ==null) || Process.GetProcessById(this.AcceptedProcess.Id) == null)
3104 {
3105 SearchWorkerThread.CancelAsync();
3106 //JokerSearchWorker.CancelAsync();
3107 ResultsUpdateWorkerThread.CancelAsync();
3108 }
3109 }
3110
3111 #region Search Button
3112 private void btnSearch_Click(object sender, EventArgs e)
3113 {
3114 if (this.SearchGuid == Guid.Empty)
3115 this.SearchGuid = Guid.NewGuid();
3116 chkMemoryRangeExpertMode.Enabled = false;
3117 this.SearchInProgess = true;
3118 btnCancel.Enabled = true;
3119 btnReset.Enabled = false; // disable during search
3120 btnSearch.Enabled = false;
3121 this.FreezeResultsUpdate();
3122 this.handle_btnSearch_Click();
3123 }
3124 private void handle_btnSearch_Click()
3125 {
3126 //this.FreezeResultsUpdate();
3127 lstResults.Items.Clear();
3128
3129 if (lstResults.Items.Count > 0) { timer_update_results.Enabled = true; }
3130 else { timer_update_results.Enabled = false; }
3131 UpdateProgress(0, string.Empty);
3132 //new Action<int, string>(UpdateProgress).Invoke(0, string.Empty);
3133 bool _is_unsigned = chkUnsigned.Checked;
3134 SearchType search_type = new SearchType();
3135 SearchDataTypes _data_type = new SearchDataTypes();
3136 SearchCompareTypes _compare_type = new SearchCompareTypes();
3137 CompareValueTypes _compare_value_type = new CompareValueTypes();
3138 object start_value = 0;
3139 object end_value = 0;
3140 // get datatype
3141 if (radio_8bits.Checked) { _data_type = SearchDataTypes._8bits; }
3142 else if (radio_16bits.Checked) { _data_type = SearchDataTypes._16bits; }
3143 else if (radio_32bits.Checked) { _data_type = SearchDataTypes._32bits; }
3144 else if (radio_64bits.Checked) { _data_type = SearchDataTypes._64bits; }
3145 else { logger.Error.WriteLine("Could not determine search data type bit size. (was not 8/16/32/or 64bits)");