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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 892 - (show annotations) (download)
Wed Sep 17 05:56:41 2014 UTC (6 years, 10 months ago) by william
File size: 172901 byte(s)
+ alot of dang work to force an icon to be shown on the docked panels
  ** when it was as simple as setting: DockPanel.ShowDocumentIcon to true

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

  ViewVC Help
Powered by ViewVC 1.1.22