ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/RomCheater/trunk/RomCheater/Docking/FloatingMemorySearcher.cs
Revision: 401
Committed: Thu Jun 21 05:14:38 2012 UTC (11 years, 5 months ago) by william
File size: 92974 byte(s)
Log Message:
+ add serialization writer

File Contents

# Content
1 //#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
2 #if !USE_AUTOMATIC_MEMORY_SEARCH_RANGE
3 #define FORCE_USE_OF_MEMORYSIZECONSTANTS // when defined wil force the use of the constants defined in MemorySizeConstants for memory search range
4 #endif
5 //#define DONOT_HAVE_RANGED_SEARCH_SUPPORT // when defined, indicates that ranged searches have not been implemented
6 #define INCREASE_NUMBER_OF_RESULTS_BEFORE_DISPLAY // when defined will set MIN RESULTS to 0x2701 otherwise 0x03e8
7 //#define DO_NOT_SUSPEND_RESUME_THREAD_ON_FREEZE // when defined will not freeze/resume thread on freeze
8 using System;
9 using System.Collections.Generic;
10 using System.ComponentModel;
11 using System.Data;
12 using System.Drawing;
13 using System.Linq;
14 using System.Text;
15 using System.Windows.Forms;
16 using WeifenLuo.WinFormsUI.Docking;
17 using RomCheater.PluginFramework.Interfaces;
18 using System.Diagnostics;
19 using RomCheater.Docking.MemorySearch;
20 using libWin32.Win32.Threading;
21 using System.Threading;
22 using RomCheater.Logging;
23 using System.IO;
24 using Sojaner.MemoryScanner.MemoryProviers;
25 using RomCheater.PluginFramework.Events;
26 using System.Reflection;
27 using Sojaner.MemoryScanner;
28 using System.Collections;
29 using RomCheater.Serialization;
30
31 namespace RomCheater.Docking
32 {
33 public partial class FloatingMemorySearcher : DockContent,
34 IAcceptsPlugin<IConfigPlugin>,
35 IAcceptsProcess<Process>,
36 IAcceptsProcessAndConfig,
37 ISearchInProgress,
38 IAcceptsBrowseMemoryRegion,
39 IAcceptsMemoryRange
40 {
41 #if INCREASE_NUMBER_OF_RESULTS_BEFORE_DISPLAY
42 const int MIN_NUMBER_OF_RESULTS_BEFORE_DISPLAY = 0x2701; // 10,000 results
43 #else
44 const int MIN_NUMBER_OF_RESULTS_BEFORE_DISPLAY = 0x03e8; // 1,000 results
45 #endif
46
47 private bool DefaultUnsignedState = true; // set unsigned to true
48 public FloatingMemorySearcher() { InitializeComponent(); this.AcceptedPlugin = null; OnBrowseMemoryRegion = null; this.AcceptedProcess = null; SearchInProgess = false; Reload(); }
49 public FloatingMemorySearcher(IConfigPlugin config) : this() { this.AcceptedPlugin = config; }
50 public FloatingMemorySearcher(IConfigPlugin config, Process process) : this() { this.AcceptedPlugin = config; this.AcceptedProcess = process; }
51
52 #region IAcceptsProcess<Process> Members
53 private Process _AcceptedProcess;
54 public Process AcceptedProcess { get { return _AcceptedProcess; } set { _AcceptedProcess = value; UpdateAcceptedProcess(value); } }
55 #endregion
56 #region IAcceptsPlugin<IConfigPlugin> Members
57 private IConfigPlugin _AcceptedPlugin;
58 public IConfigPlugin AcceptedPlugin { get { return _AcceptedPlugin; } set { _AcceptedPlugin = value; UpdateAcceptedPlugin(value); } }
59 #endregion
60 #region IAcceptsBrowseMemoryRegion members
61 public event BaseEventHandler<BrowseMemoryRegionEvent> OnBrowseMemoryRegion;
62 #endregion
63
64 private void UpdateAcceptedPlugin(IConfigPlugin config)
65 {
66 this.lstResults.AcceptedPlugin = config;
67 this.lstPatchList.AcceptedPlugin = config;
68 if (config != null)
69 {
70 MemoryRangeStart = AcceptedPlugin.MemoryRangeStart;
71 MemoryRangeSize = AcceptedPlugin.MemoryRangeStart + AcceptedPlugin.MemoryRangeSize;
72 }
73 }
74 private void UpdateAcceptedProcess(Process process)
75 {
76 this.lstResults.AcceptedProcess = process;
77 this.lstPatchList.AcceptedProcess = process;
78 #if USE_AUTOMATIC_MEMORY_SEARCH_RANGE && FORCE_USE_OF_MEMORYSIZECONSTANTS
79 logger.Warn.WriteLine("FloatingMemorySearcher.UpdateAcceptedProcessAndConfig(IConfigPlugin config, Process process):");
80 logger.Warn.WriteLine("Both USE_AUTOMATIC_MEMORY_SEARCH_RANGE and FORCE_USE_OF_MEMORYSIZECONSTANTS are defined");
81 logger.Warn.WriteLine("FORCE_USE_OF_MEMORYSIZECONSTANTS will take precedence and will ignore the values supplied in the memeory search range");
82 #endif
83 #if FORCE_USE_OF_MEMORYSIZECONSTANTS
84 // force use of MemorySizeConstants
85 txtMemoryRangeStart.Value = MemorySizeConstants.MinimumSearchAddress;
86 txtMemoryRangeSize.Value = MemorySizeConstants.MinimumSearchAddress + MemorySizeConstants.MaximumSearchSize;
87 #endif
88 #if USE_AUTOMATIC_MEMORY_SEARCH_RANGE && !FORCE_USE_OF_MEMORYSIZECONSTANTS
89 ////// code to automatically choose the best starting memory address and size
90 //if (process != null)
91 //{
92 // string filename = process.MainModule.FileName;
93 // //string filename = @"c:\Windows\notepad.exe";
94 // PEReader peReader = new PEReader(filename);
95 //}
96 //else
97 //{
98 //txtMemoryRangeStart.Value = MemorySizeConstants.MinimumSearchAddress;
99 //txtMemoryRangeSize.Value = MemorySizeConstants.MinimumSearchAddress + MemorySizeConstants.MaximumSearchSize;
100 //}
101 if (AcceptedPlugin != null)
102 {
103 MemoryRangeStart = AcceptedPlugin.MemoryRangeStart;
104 MemoryRangeSize = AcceptedPlugin.MemoryRangeStart + AcceptedPlugin.MemoryRangeSize;
105 }
106
107 #endif
108
109 }
110 #region ISearchInProgress members
111 private bool _SearchInProgess;
112 public bool SearchInProgess
113 {
114 get { return _SearchInProgess; }
115 private set
116 {
117 _SearchInProgess = value;
118 if (this.AcceptedPlugin != null)
119 this.AcceptedPlugin.SetMemorySearchReference(this);
120 }
121 }
122 #endregion
123
124 #region IAcceptsMemoryRange
125 #if !FORCE_USE_OF_MEMORYSIZECONSTANTS
126 private uint _MemoryRangeStart;
127 private uint _MemoryRangeSize;
128 #endif
129 public uint MemoryRangeStart
130 {
131 get
132 {
133 #if FORCE_USE_OF_MEMORYSIZECONSTANTS
134 return MemorySizeConstants.MinimumSearchAddress;
135 #else
136 return _MemoryRangeStart;
137 #endif
138 }
139 set
140 {
141 #if !FORCE_USE_OF_MEMORYSIZECONSTANTS
142 _MemoryRangeStart = value;
143 txtMemoryRangeStart.Value = value;
144 #endif
145 }
146 }
147 public uint MemoryRangeSize
148 {
149 get
150 {
151 #if FORCE_USE_OF_MEMORYSIZECONSTANTS
152 return MemorySizeConstants.MinimumSearchAddress + MemorySizeConstants.MaximumSearchSize;
153 #else
154 return _MemoryRangeSize;
155 #endif
156 }
157 set
158 {
159 #if !FORCE_USE_OF_MEMORYSIZECONSTANTS
160 _MemoryRangeSize = value;
161 txtMemoryRangeSize.Value = value;
162 #endif
163 }
164 }
165 #endregion
166
167 public void Reload()
168 {
169 chkUnsigned.Checked = DefaultUnsignedState;
170 radio_8bits.Checked = true;
171 radiocompare_equal.Checked = true;
172 radio_oldvalue.Checked = true;
173 chkRefreshResults.Checked = true;
174 }
175 public enum eListViewResults
176 {
177 SEARCH_RESULTS_LIST = 0x3000,
178 PATCH_RESULTS_LIST = 0x3001,
179 UKNOWN_RESULTS_LIST = 0x3001
180 }
181 bool IsFirstSearch = true;
182 SearchType SearchArgs;
183 static int col_Found_Address = 1;
184 static int col_Found_Value = 2;
185 static int col_Found_Frozen = 3;
186 static int col_Added_Address = 1;
187 static int col_Added_Value = 2;
188 static int col_Added_Frozen = 3;
189 List<ListViewItem> ResultItems = new List<ListViewItem>();
190 List<ListViewItem> AddedItems = new List<ListViewItem>();
191 private bool _PatchedValue_NeedsUpdate;
192 bool PatchedValue_NeedsUpdate
193 {
194 get { if (_PatchedValue_NeedsUpdate) this.ThawResultsUpdate(); return _PatchedValue_NeedsUpdate; }
195 set { _PatchedValue_NeedsUpdate = value; if (value) this.ThawResultsUpdate(); }
196 }
197 private delegate ListViewItem ThreadSafe_GetResultItem(int index, int lv_type);
198 private ListViewItem GetResultItem(int index, int lv_type)
199 {
200 try
201 {
202 AddressValuePairList lv = null;
203 switch (lv_type)
204 {
205 case (int)eListViewResults.SEARCH_RESULTS_LIST: lv = lstResults; break;
206 case (int)eListViewResults.PATCH_RESULTS_LIST: lv = lstPatchList; break;
207 default: throw new IndexOutOfRangeException("Detected: " + Enum.GetName(typeof(eListViewResults), eListViewResults.UKNOWN_RESULTS_LIST) + " with value: " + lv_type.ToString("x4"));
208 }
209 ListViewItem item = new ListViewItem();
210 item = (ListViewItem)lv.Items[index].Clone();
211 return item;
212 }
213 catch (Exception)
214 {
215 return null;
216 }
217 }
218 private void radiocompare_equal_CheckedChanged(object sender, EventArgs e)
219 {
220 //if (!radiocompare_between.Checked && !radiocompare_notbetween.Checked)
221 //{
222 if (radio_oldvalue.Checked)
223 {
224 txtStartAddr.ReadOnly = true;
225 txtEndAddr.ReadOnly = true;
226 }
227 if (radio_specificvalue.Checked)
228 {
229 txtStartAddr.ReadOnly = false;
230 txtEndAddr.ReadOnly = true;
231 }
232 //}
233 }
234
235 private void radiocompare_between_CheckedChanged(object sender, EventArgs e)
236 {
237 if (!radiocompare_equal.Checked &&
238 !radiocompare_greaterthan.Checked &&
239 !radiocompare_greaterthan.Checked &&
240 !radiocompare_lessthan.Checked &&
241 !radiocompare_greaterthan_orequal.Checked &&
242 !radiocompare_lessthan_orequal.Checked &&
243 !radiocompare_notequal.Checked)
244 if (radiocompare_between.Checked)
245 {
246 txtStartAddr.ReadOnly = false;
247 txtEndAddr.ReadOnly = false;
248 return;
249 }
250 if (!radiocompare_between.Checked && !radiocompare_notbetween.Checked)
251 {
252 if (radio_oldvalue.Checked)
253 {
254 txtStartAddr.ReadOnly = true;
255 txtEndAddr.ReadOnly = true;
256 }
257 if (radio_specificvalue.Checked)
258 {
259 txtStartAddr.ReadOnly = false;
260 txtEndAddr.ReadOnly = true;
261 }
262 }
263 }
264
265 private void radiocompare_notbetween_CheckedChanged(object sender, EventArgs e)
266 {
267 if (!radiocompare_equal.Checked &&
268 !radiocompare_greaterthan.Checked &&
269 !radiocompare_greaterthan.Checked &&
270 !radiocompare_lessthan.Checked &&
271 !radiocompare_greaterthan_orequal.Checked &&
272 !radiocompare_lessthan_orequal.Checked &&
273 !radiocompare_notequal.Checked)
274 if (radiocompare_notbetween.Checked)
275 {
276 txtStartAddr.ReadOnly = false;
277 txtEndAddr.ReadOnly = false;
278 return;
279 }
280 if (!radiocompare_between.Checked && !radiocompare_notbetween.Checked)
281 {
282 if (radio_oldvalue.Checked)
283 {
284 txtStartAddr.ReadOnly = true;
285 txtEndAddr.ReadOnly = true;
286 }
287 if (radio_specificvalue.Checked)
288 {
289 txtStartAddr.ReadOnly = false;
290 txtEndAddr.ReadOnly = true;
291 }
292 }
293 }
294
295 private void radio_8bits_CheckedChanged(object sender, EventArgs e)
296 {
297 if (chkUnsigned.Checked)
298 {
299 txtStartAddr.CreateTypeSize<byte>();
300 txtEndAddr.CreateTypeSize<byte>();
301 }
302 else
303 {
304 txtStartAddr.CreateTypeSize<sbyte>();
305 txtEndAddr.CreateTypeSize<sbyte>();
306 }
307 }
308
309 private void radio_16bits_CheckedChanged(object sender, EventArgs e)
310 {
311 if (chkUnsigned.Checked)
312 {
313 txtStartAddr.CreateTypeSize<ushort>();
314 txtEndAddr.CreateTypeSize<ushort>();
315 }
316 else
317 {
318 txtStartAddr.CreateTypeSize<short>();
319 txtEndAddr.CreateTypeSize<short>();
320 }
321 }
322
323 private void radio_32bits_CheckedChanged(object sender, EventArgs e)
324 {
325
326 if (chkUnsigned.Checked)
327 {
328 txtStartAddr.CreateTypeSize<uint>();
329 txtEndAddr.CreateTypeSize<uint>();
330 }
331 else
332 {
333 txtStartAddr.CreateTypeSize<int>();
334 txtEndAddr.CreateTypeSize<int>();
335 }
336 }
337
338 private void radio_64bits_CheckedChanged(object sender, EventArgs e)
339 {
340
341 if (chkUnsigned.Checked)
342 {
343 txtStartAddr.CreateTypeSize<ulong>();
344 txtEndAddr.CreateTypeSize<ulong>();
345 }
346 else
347 {
348 txtStartAddr.CreateTypeSize<long>();
349 txtEndAddr.CreateTypeSize<long>();
350 }
351 }
352
353 private void radio_oldvalue_CheckedChanged(object sender, EventArgs e)
354 {
355 if (!radiocompare_between.Checked && !radiocompare_notbetween.Checked)
356 {
357 txtStartAddr.ReadOnly = true;
358 txtEndAddr.ReadOnly = true;
359 }
360 }
361
362 private void radio_specificvalue_CheckedChanged(object sender, EventArgs e)
363 {
364 if (!radiocompare_between.Checked && !radiocompare_notbetween.Checked)
365 {
366 txtStartAddr.ReadOnly = false;
367 txtEndAddr.ReadOnly = true;
368 }
369 }
370
371 private void chkRefreshResults_CheckedChanged(object sender, EventArgs e)
372 {
373 if (chkRefreshResults.Checked)
374 {
375 timer_update_results.Enabled = true;
376 }
377 else
378 {
379 timer_update_results.Enabled = false;
380 ResultsUpdateWorkerThread.CancelAsync();
381 }
382 }
383
384 private void timer_update_results_Tick(object sender, EventArgs e)
385 {
386 if (chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy)
387 {
388 ResultsUpdateWorkerThread.RunWorkerAsync();
389 }
390 }
391 private bool ShouldUpdateResults()
392 {
393 if (this.AcceptedProcess == null) return false;
394 if (SearchWorkerThread.IsBusy) return false;
395 //if (JokerSearchWorker.IsBusy) return false;
396 if (this.IsResultsUpdateFrozen) return false;
397 if (mnuAddedResults.Visible) return false;
398 if (mnuResults.Visible) return false;
399 if (Process.GetProcessById(this.AcceptedProcess.Id) == null) return false;
400 if (lstResults.Items.Count > 0) return true;
401 if (lstPatchList.Items.Count > 0) return true;
402 return false;
403 }
404 private void ResultsUpdateWorkerThread_DoWork(object sender, DoWorkEventArgs e)
405 {
406 Thread.Sleep(250); // keep thread from blocking
407 if (!this.ShouldUpdateResults()) return;
408 ////if (SearchArgs == null) return;
409 ////if (this.IsResultsUpdateFrozen) return;
410 ////// put thread to sleep for 500ms
411 ////System.Threading.Thread.Sleep(500);
412 //PCSX2MemoryProvider provider = new PCSX2MemoryProvider(this.SearchPCSX2ProcessPID, resultslog);
413 //byte[] buffered_mem = provider.GetMemory();
414 //MemoryStream ms = new MemoryStream(buffered_mem);
415 //BinaryReader r_ms = new BinaryReader(ms);
416
417 #region Update Results List
418 ResultItems = new List<ListViewItem>();
419 //r_ms.BaseStream.Seek(0, SeekOrigin.Begin);
420 for (int i = 0; i < lstResults.Items.Count; i++)
421 {
422 if (this.lstResults.InvokeRequired)
423 {
424 ThreadSafe_GetResultItem _get_item = new ThreadSafe_GetResultItem(GetResultItem);
425 object item = this.lstResults.Invoke(_get_item, new object[] { i, (int)eListViewResults.SEARCH_RESULTS_LIST });
426 if (item != null)
427 ResultItems.Add((ListViewItem)item);
428 }
429 else
430 {
431 ResultItems.Add(lstResults.Items[i]);
432 }
433
434 }
435 for (int i = 0; i < ResultItems.Count; i++)
436 {
437 if (ResultsUpdateWorkerThread.CancellationPending == true)
438 {
439 e.Cancel = true;
440 return;
441 }
442 int Address = 0;
443 ResultDataType _result = (ResultDataType)ResultItems[i].Tag;
444
445 Address = Convert.ToInt32(ResultItems[i].SubItems[col_Found_Address].Text, 16);
446 //r_ms.BaseStream.Seek(Address, SeekOrigin.Begin);
447 using (GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
448 {
449 provider.OpenProvider();
450 int bytesReadSize;
451 byte[] data;
452 uint bytesToRead = 0;
453 switch (_result.ValueType)
454 {
455 case SearchDataTypes._8bits:
456 bytesToRead = 1;
457 break;
458 case SearchDataTypes._16bits:
459 bytesToRead = 2;
460 break;
461 case SearchDataTypes._32bits:
462 bytesToRead = 4;
463 break;
464 case SearchDataTypes._64bits:
465 bytesToRead = 8;
466 break;
467 }
468 provider.ReadProcessMemory(Address, bytesToRead, out bytesReadSize, out data);
469 using (MemoryStream ms = new MemoryStream(data))
470 {
471 using (BinaryReader r_ms = new BinaryReader(ms))
472 {
473 switch (_result.ValueType)
474 {
475 case SearchDataTypes._8bits:
476 if (_result.IsUnsigned) { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x2}", r_ms.ReadByte()); }
477 else { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x2}", r_ms.ReadSByte()); }
478 break;
479 case SearchDataTypes._16bits:
480 if (_result.IsUnsigned) { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x4}", r_ms.ReadUInt16()); }
481 else { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x4}", r_ms.ReadInt16()); }
482 break;
483 case SearchDataTypes._32bits:
484 if (_result.IsUnsigned) { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x8}", r_ms.ReadUInt32()); }
485 else { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x8}", r_ms.ReadInt32()); }
486 break;
487 case SearchDataTypes._64bits:
488 if (_result.IsUnsigned) { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x16}", r_ms.ReadUInt64()); }
489 else { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x16}", r_ms.ReadInt64()); }
490 break;
491 }
492 r_ms.Close();
493 }
494 }
495 provider.CloseProvider();
496 }
497 //Application.DoEvents();
498 }
499 #endregion
500
501 #region Update Added Results List
502 AddedItems = new List<ListViewItem>();
503 //r_ms.BaseStream.Seek(0, SeekOrigin.Begin);
504 for (int i = 0; i < lstPatchList.Items.Count; i++)
505 {
506 if (this.lstResults.InvokeRequired)
507 {
508 ThreadSafe_GetResultItem _get_item = new ThreadSafe_GetResultItem(GetResultItem);
509 object item = this.lstResults.Invoke(_get_item, new object[] { i, (int)eListViewResults.PATCH_RESULTS_LIST });
510 if (item != null)
511 AddedItems.Add((ListViewItem)item);
512 }
513 else
514 {
515 AddedItems.Add(lstPatchList.Items[i]);
516 }
517
518 }
519 for (int i = 0; i < AddedItems.Count; i++)
520 {
521 if (ResultsUpdateWorkerThread.CancellationPending == true)
522 {
523 e.Cancel = true;
524 return;
525 }
526 int Address = 0;
527 ResultDataType _result = (ResultDataType)AddedItems[i].Tag;
528 Address = Convert.ToInt32(AddedItems[i].SubItems[col_Added_Address].Text, 16);
529 using (GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
530 {
531 provider.OpenProvider();
532 int bytesReadSize;
533 byte[] data;
534 uint bytesToRead = 0;
535 switch (_result.ValueType)
536 {
537 case SearchDataTypes._8bits:
538 bytesToRead = 1;
539 break;
540 case SearchDataTypes._16bits:
541 bytesToRead = 2;
542 break;
543 case SearchDataTypes._32bits:
544 bytesToRead = 4;
545 break;
546 case SearchDataTypes._64bits:
547 bytesToRead = 8;
548 break;
549 }
550 provider.ReadProcessMemory(Address, bytesToRead, out bytesReadSize, out data);
551 provider.CloseProvider();
552 using (MemoryStream ms = new MemoryStream(data))
553 {
554 using (BinaryReader r_ms = new BinaryReader(ms))
555 {
556 switch (_result.ValueType)
557 {
558 case SearchDataTypes._8bits:
559 if (_result.IsUnsigned) { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x2}", r_ms.ReadByte()); }
560 else { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x2}", r_ms.ReadSByte()); }
561 break;
562 case SearchDataTypes._16bits:
563 if (_result.IsUnsigned) { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x4}", r_ms.ReadUInt16()); }
564 else { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x4}", r_ms.ReadInt16()); }
565 break;
566 case SearchDataTypes._32bits:
567 if (_result.IsUnsigned) { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x8}", r_ms.ReadUInt32()); }
568 else { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x8}", r_ms.ReadInt32()); }
569 break;
570 case SearchDataTypes._64bits:
571 if (_result.IsUnsigned) { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x16}", r_ms.ReadUInt64()); }
572 else { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x16}", r_ms.ReadInt64()); }
573 break;
574 }
575 r_ms.Close();
576 }
577 }
578 }
579 //Application.DoEvents();
580 }
581 #endregion
582
583
584 }
585
586 private void ResultsUpdateWorkerThread_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
587 {
588 try
589 {
590 //if ((lstResults.SelectedItems.Count > 0) && !PatchedValue_NeedsUpdate ) return;
591 //if ((lstPatchList.SelectedItems.Count > 0) && !PatchedValue_NeedsUpdate) return;
592 if (!this.ShouldUpdateResults()) return;
593 if (ResultItems.Count > 0)
594 {
595 //lstResults.Items.Clear();
596 //lstResults.Items.AddRange(ResultItems.ToArray());
597
598 for (int i = 0; i < ResultItems.Count; i++)
599 {
600 lstResults.Items[i].SubItems[new AVPColumnText(AVPColumnType.VALUE).ColumnIndex].Text =
601 ResultItems[i].SubItems[new AVPColumnText(AVPColumnType.VALUE).ColumnIndex].Text;
602 }
603
604 }
605 if (AddedItems.Count > 0)
606 {
607 //lstPatchList.Items.Clear();
608 //lstPatchList.Items.AddRange(AddedItems.ToArray());
609
610 for (int i = 0; i < AddedItems.Count; i++)
611 {
612 lstPatchList.Items[i].SubItems[new AVPColumnText(AVPColumnType.VALUE).ColumnIndex].Text =
613 AddedItems[i].SubItems[new AVPColumnText(AVPColumnType.VALUE).ColumnIndex].Text;
614 }
615
616 }
617 PatchedValue_NeedsUpdate = false;
618 }
619 catch { }
620 }
621
622 private void btnImportFile_Click(object sender, EventArgs e)
623 {
624 this.FreezeResultsUpdate();
625 if (!lstPatchList.ImportFromFile())
626 {
627 MessageBox.Show("Failed to Import Patch List from File.", "Import Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
628 this.ThawResultsUpdate();
629 return;
630 }
631 else
632 {
633 MessageBox.Show("Succesfully Imported Patch List from File.", "Import Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
634 this.ThawResultsUpdate();
635 return;
636 }
637 }
638 bool g_isFrozen = false;
639 private bool IsResultsUpdateFrozen
640 {
641 get { return g_isFrozen; }
642 set { g_isFrozen = value; }
643 }
644 private void ThawResultsUpdate()
645 {
646 this.IsResultsUpdateFrozen = false;
647 if (this.AcceptedProcess != null)
648 {
649 #if !DO_NOT_SUSPEND_RESUME_THREAD_ON_FREEZE
650 ThreadControl.ResumeProcess(this.AcceptedProcess.Id);
651 #endif
652 }
653 }
654
655 private void FreezeResultsUpdate()
656 {
657 this.IsResultsUpdateFrozen = true;
658 //this.IsResultsUpdateFrozen = false;
659 if (this.AcceptedProcess != null)
660 {
661 #if !DO_NOT_SUSPEND_RESUME_THREAD_ON_FREEZE
662 ThreadControl.SuspendProcess(this.AcceptedProcess.Id);
663 #endif
664 }
665 }
666
667 private void btnExportFile_Click(object sender, EventArgs e)
668 {
669 this.FreezeResultsUpdate();
670 if (!lstPatchList.ExportToFile())
671 {
672 MessageBox.Show("Failed to Export Patch List to File.", "Export Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
673 this.ThawResultsUpdate();
674 return;
675 }
676 else
677 {
678 MessageBox.Show("Succesfully Exported Patch List to File.", "Export Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
679 this.ThawResultsUpdate();
680 return;
681 }
682 }
683
684 private void btnImportClipboard_Click(object sender, EventArgs e)
685 {
686 this.FreezeResultsUpdate();
687 if (!lstPatchList.ImportFromClipboard())
688 {
689 MessageBox.Show("Failed to Import Patch List from Clipboard.", "Import Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
690 this.ThawResultsUpdate();
691 return;
692 }
693 else
694 {
695 MessageBox.Show("Succesfully Import Patch List from Clipboard.", "Import Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
696 this.ThawResultsUpdate();
697 }
698 }
699
700 private void btnExportClipboard_Click(object sender, EventArgs e)
701 {
702 this.FreezeResultsUpdate();
703 if (!lstPatchList.ExportToClipboard())
704 {
705 MessageBox.Show("Failed to Export Patch List to Clipboard.", "Export Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
706 this.ThawResultsUpdate();
707 return;
708 }
709 else
710 {
711 MessageBox.Show("Succesfully Exported Patch List to Clipboard.", "Export Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
712 this.ThawResultsUpdate();
713 return;
714 }
715 }
716
717 private void btnAddPatchAddress_Click(object sender, EventArgs e)
718 {
719 PatchAdder adder = new PatchAdder((IAcceptsProcessAndConfig)this);
720 adder.ShowDialog();
721 if (adder.WasAPatchAdded) AddToPatchList(adder.AddedPatchValue);
722 }
723
724 private void btnAddAddressRange_Click(object sender, EventArgs e)
725 {
726 PatchRangeAdder adder = new PatchRangeAdder((IAcceptsProcessAndConfig)this);
727 adder.ShowDialog();
728 if (adder.WasAPatchAdded) AddToPatchList(adder.AddedPatchValue);
729 }
730 private void AddToPatchList(List<ResultDataType> item) { foreach (ResultDataType data in item) { AddToPatchList(data); } }
731 private void AddToPatchList(ResultDataType item)
732 {
733 ResultItem item2 = null;
734 switch (item.ValueType)
735 {
736 case SearchDataTypes._8bits:
737 if (item.IsUnsigned) { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToByte(item.Value)); }
738 else { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToSByte(item.Value)); }
739 break;
740 case SearchDataTypes._16bits:
741 if (item.IsUnsigned) { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToUInt16(item.Value)); }
742 else { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToInt16(item.Value)); }
743 break;
744 case SearchDataTypes._32bits:
745 if (item.IsUnsigned) { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToUInt32(item.Value)); }
746 else { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToInt32(item.Value)); }
747 break;
748 case SearchDataTypes._64bits:
749 if (item.IsUnsigned) { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToUInt64(item.Value)); }
750 else { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToInt64(item.Value)); }
751 break;
752 }
753 this.AddToPatchList(item2);
754 }
755 private void AddToPatchList(ListViewItem item)
756 {
757 try
758 {
759 ResultDataType _result = (ResultDataType)item.Tag;
760 this.AddToPatchList(_result);
761 }
762 catch (InvalidCastException ex)
763 {
764 // unable to cast
765 MessageBox.Show(ex.Message, "Invalid Cast Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
766 }
767 catch (Exception ex)
768 {
769 // other exception
770 MessageBox.Show(ex.Message, "Unhandled Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
771 }
772 }
773 private void AddToPatchList(ResultItem item)
774 {
775 if (!lstPatchList.Items.Contains(item)) lstPatchList.Items.Add(item);
776 }
777 private void AddToPatchList(string address, SearchDataTypes bitsize, bool IsUnsigned)
778 {
779 ResultItemState state = new ResultItemState(address, bitsize, IsUnsigned, (IAcceptsProcessAndConfig)this);
780 ResultItem item = new ResultItem(state.Address, state.Value, state.Frozen, state.ValueType, state.IsUnsigned);
781 this.AddToPatchList(item);
782 }
783
784 private void mnuItemAddToPatchList_Click(object sender, EventArgs e)
785 {
786 if (!(lstResults.SelectedItems.Count > 0)) return;
787 //if (SearchArgs == null) return;
788
789 try
790 {
791 for (int i = 0; i < lstResults.SelectedIndices.Count; i++)
792 {
793 //ResultDataType result = (ResultDataType)lstResults.Items[selected_index].Tag;
794 ListViewItem item = lstResults.Items[lstResults.SelectedIndices[i]];
795 this.AddToPatchList(item);
796 }
797 }
798 catch (Exception ex)
799 {
800 logger.Error.WriteLine(ex.ToString());
801 }
802 }
803
804 private void mnuItemRemoveResult_Click(object sender, EventArgs e)
805 {
806 if (!(lstPatchList.SelectedItems.Count > 0)) return;
807 //if (SearchArgs == null) return;
808 try
809 {
810 this.FreezeResultsUpdate();
811 for (int i = 0; i < lstPatchList.SelectedIndices.Count; i++)
812 {
813 //lstPatchList.ThawItem(lstPatchList.SelectedIndices[i]);
814 lstPatchList.Items[lstPatchList.SelectedIndices[i]].Remove();
815 }
816 this.ThawResultsUpdate();
817 }
818 catch (Exception ex)
819 {
820 Debug.WriteLine(ex.ToString());
821 }
822 }
823 private void PatchRange(bool SingleEntry)
824 {
825 //if (SearchArgs == null) return;
826 #region Patch Selected Address
827 // stop ResultsUpdate Thread
828 ResultsUpdateWorkerThread.CancelAsync();
829
830 List<ResultDataType> patch_list = new List<ResultDataType>();
831 List<int> SelectedIndexes = new List<int>();
832
833 if (SingleEntry)
834 {
835 SelectedIndexes.Add(lstPatchList.SelectedIndices[0]);
836 }
837 else
838 {
839 foreach (int index in lstPatchList.SelectedIndices)
840 {
841 SelectedIndexes.Add(index);
842 }
843 }
844 //PCSX2MemoryProvider provider = new PCSX2MemoryProvider(this.SearchPCSX2ProcessPID, resultslog);
845 foreach (int index in SelectedIndexes)
846 {
847 if (SingleEntry)
848 {
849 SearchPatcher patcher = null;
850 uint Address = 0;
851 ListViewItem item = lstPatchList.Items[index];
852 ResultDataType _result = (ResultDataType)item.Tag;
853 Address = Convert.ToUInt32(item.SubItems[col_Found_Address].Text, 16);
854 switch (_result.ValueType)
855 {
856 case SearchDataTypes._8bits:
857 if (_result.IsUnsigned)
858 {
859 byte value = Convert.ToByte(item.SubItems[col_Found_Value].Text, 16);
860 patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
861 timer_update_results.Enabled = false;
862 patcher.ShowDialog();
863 timer_update_results.Enabled = true;
864 PatchedValue_NeedsUpdate = true;
865 if (!chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy)
866 ResultsUpdateWorkerThread.RunWorkerAsync();
867 }
868 else
869 {
870 sbyte value = Convert.ToSByte(item.SubItems[col_Found_Value].Text, 16);
871 patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
872 timer_update_results.Enabled = false;
873 patcher.ShowDialog();
874 timer_update_results.Enabled = true;
875 PatchedValue_NeedsUpdate = true;
876 if (!chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy)
877 ResultsUpdateWorkerThread.RunWorkerAsync();
878 }
879 break;
880 case SearchDataTypes._16bits:
881 if (_result.IsUnsigned)
882 {
883 ushort value = Convert.ToUInt16(item.SubItems[col_Found_Value].Text, 16);
884 patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
885 timer_update_results.Enabled = false;
886 patcher.ShowDialog();
887 timer_update_results.Enabled = true;
888 PatchedValue_NeedsUpdate = true;
889 if (!chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy)
890 ResultsUpdateWorkerThread.RunWorkerAsync();
891 }
892 else
893 {
894 short value = Convert.ToInt16(item.SubItems[col_Found_Value].Text, 16);
895 patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
896 timer_update_results.Enabled = false;
897 patcher.ShowDialog();
898 timer_update_results.Enabled = true;
899 PatchedValue_NeedsUpdate = true;
900 if (!chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy)
901 ResultsUpdateWorkerThread.RunWorkerAsync();
902 }
903 break;
904 case SearchDataTypes._32bits:
905 if (_result.IsUnsigned)
906 {
907 uint value = Convert.ToUInt32(item.SubItems[col_Found_Value].Text, 16);
908 patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
909 timer_update_results.Enabled = false;
910 patcher.ShowDialog();
911 timer_update_results.Enabled = true;
912 PatchedValue_NeedsUpdate = true;
913 if (!chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy)
914 ResultsUpdateWorkerThread.RunWorkerAsync();
915 }
916 else
917 {
918 int value = Convert.ToInt32(item.SubItems[col_Found_Value].Text, 16);
919 patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
920 timer_update_results.Enabled = false;
921 patcher.ShowDialog();
922 timer_update_results.Enabled = true;
923 PatchedValue_NeedsUpdate = true;
924 if (!chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy)
925 ResultsUpdateWorkerThread.RunWorkerAsync();
926 }
927 break;
928 case SearchDataTypes._64bits:
929 if (_result.IsUnsigned)
930 {
931 ulong value = Convert.ToUInt32(item.SubItems[col_Found_Value].Text, 16);
932 patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
933 timer_update_results.Enabled = false;
934 patcher.ShowDialog();
935 timer_update_results.Enabled = true;
936 PatchedValue_NeedsUpdate = true;
937 if (!chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy)
938 ResultsUpdateWorkerThread.RunWorkerAsync();
939 }
940 else
941 {
942 long value = Convert.ToInt32(item.SubItems[col_Found_Value].Text, 16);
943 patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
944 timer_update_results.Enabled = false;
945 patcher.ShowDialog();
946 timer_update_results.Enabled = true;
947 PatchedValue_NeedsUpdate = true;
948 if (!chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy)
949 ResultsUpdateWorkerThread.RunWorkerAsync();
950 }
951 break;
952 }
953 }
954 else
955 {
956
957 ListViewItem item = lstPatchList.Items[index];
958 ResultDataType _result = (ResultDataType)item.Tag;
959 patch_list.Add(_result);
960 }
961 }
962
963 if (patch_list.Count > 0)
964 {
965 SearchRangePatcher rangePatcher = new SearchRangePatcher((IAcceptsProcessAndConfig)this, patch_list);
966 rangePatcher.ShowDialog();
967 }
968
969 #endregion
970 }
971 private void mnuItemPatchSelectedEntry_Click(object sender, EventArgs e)
972 {
973 if (!(lstPatchList.SelectedItems.Count == 1)) return;
974 PatchRange(true);
975 }
976
977 private void mnuItemPatchSelectedRange_Click(object sender, EventArgs e)
978 {
979 if (!(lstPatchList.SelectedItems.Count >= 1)) return;
980 PatchRange(false);
981 }
982
983 private void mnuItemFreezeSelectedPatches_Click(object sender, EventArgs e)
984 {
985 if (!(lstPatchList.SelectedItems.Count > 0)) return;
986 //if (SearchArgs == null) return;
987 try
988 {
989 lstPatchList.ProcessID = this.AcceptedProcess.Id;
990 this.FreezeResultsUpdate();
991 for (int i = 0; i < lstPatchList.SelectedIndices.Count; i++)
992 {
993 lstPatchList.FreezeItem(lstPatchList.SelectedIndices[i]);
994 }
995 // force thaw and update
996 this.ThawResultsUpdate();
997 this.Update();
998 }
999 catch (Exception ex)
1000 {
1001 Debug.WriteLine(ex.ToString());
1002 }
1003 }
1004
1005 private void mnuItemThawSelectedPatches_Click(object sender, EventArgs e)
1006 {
1007 if (!(lstPatchList.SelectedItems.Count > 0)) return;
1008 //if (SearchArgs == null) return;
1009 try
1010 {
1011 lstPatchList.ProcessID = this.AcceptedProcess.Id;
1012 this.FreezeResultsUpdate();
1013 for (int i = 0; i < lstPatchList.SelectedIndices.Count; i++)
1014 {
1015 lstPatchList.ThawItem(lstPatchList.SelectedIndices[i]);
1016 }
1017 // force thaw and update
1018 this.ThawResultsUpdate();
1019 this.Update();
1020 }
1021 catch (Exception ex)
1022 {
1023 Debug.WriteLine(ex.ToString());
1024 }
1025 }
1026
1027 private void SearchWorkerThread_DoWork(object sender, DoWorkEventArgs e)
1028 {
1029 Stopwatch st = new Stopwatch();
1030 st.Start();
1031
1032 Stopwatch st_first_search = new Stopwatch();
1033 Stopwatch st_nonrange_search = new Stopwatch();
1034 Stopwatch st_ranged_search = new Stopwatch();
1035
1036 e.Result = st;
1037 //List<ResultType<object>> tmp_Results = new List<ResultType<object>>();
1038 List<ResultType<object>> second_tmp_Results = new List<ResultType<object>>();
1039 const int ElementsBeforeDisplay = 100;
1040 SearchArgs.LogSearchOptions();
1041 uint STEP_SIZE = (uint)SearchArgs.DataType / 8;
1042
1043 bool unsigned = SearchArgs.IsUnsignedDataType;
1044 SearchDataTypes sdt = SearchArgs.DataType;
1045 byte[] buffered_mem = new byte[(MemoryRangeSize - MemoryRangeStart)]; // throws OutOfMemoryException if size is over 2G
1046 using (GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1047 {
1048 provider.OpenProvider();
1049 int bytes_read = 0;
1050 provider.ReadProcessMemoryAtOnce(MemoryRangeStart, (MemoryRangeSize - MemoryRangeStart), out bytes_read, out buffered_mem);
1051 provider.CloseProvider();
1052 }
1053 if (buffered_mem.Length == 0) { logger.Warn.WriteLine("Buffered Memory is Zero Length."); return; }
1054 using (MemoryStream ms = new MemoryStream(buffered_mem))
1055 {
1056 using (BinaryReader r_ms = new BinaryReader(ms))
1057 {
1058 logger.Debug.WriteLine(string.Format("Buffered Memory Size -> 0x{0:x8}", buffered_mem.Length));
1059 int Last_Whole_Percent_Done = 0;
1060
1061 #region First Search
1062 if (SearchArgs.IsFirstSearch)
1063 {
1064 st_first_search.Start();
1065 //SearchArgs.Results.Clear();
1066 r_ms.BaseStream.Seek(0, SeekOrigin.Begin);
1067 using (SearchResultWriter writer = new SearchResultWriter((int)buffered_mem.Length / (int)STEP_SIZE))
1068 {
1069 //List<ResultType<object>> results_list = new List<ResultType<object>>();
1070 //for (uint i = 0; i < buffered_mem.Length; i += STEP_SIZE)
1071 //{
1072 #region while (r_ms.BaseStream.Position < r_ms.BaseStream.Length)
1073 while (r_ms.BaseStream.Position < r_ms.BaseStream.Length)
1074 {
1075 //using (ResultType<object> _tmp_result = new ResultType<object>())
1076 //{
1077 switch (sdt)
1078 {
1079 case SearchDataTypes._8bits:
1080 if (unsigned) { writer.WriteResult<Byte>((uint)r_ms.BaseStream.Position, r_ms.ReadByte()); }
1081 else { writer.WriteResult<SByte>((uint)r_ms.BaseStream.Position, r_ms.ReadSByte()); } break;
1082 case SearchDataTypes._16bits:
1083 if (unsigned) { writer.WriteResult<UInt16>((uint)r_ms.BaseStream.Position, r_ms.ReadUInt16()); }
1084 else { writer.WriteResult<Int16>((uint)r_ms.BaseStream.Position, r_ms.ReadInt16()); } break;
1085 case SearchDataTypes._32bits:
1086 if (unsigned) { writer.WriteResult<UInt32>((uint)r_ms.BaseStream.Position, r_ms.ReadUInt32()); }
1087 else { writer.WriteResult<Int32>((uint)r_ms.BaseStream.Position, r_ms.ReadInt32()); } break;
1088 case SearchDataTypes._64bits:
1089 if (unsigned) { writer.WriteResult<UInt64>((uint)r_ms.BaseStream.Position, r_ms.ReadUInt64()); }
1090 else { writer.WriteResult<Int64>((uint)r_ms.BaseStream.Position, r_ms.ReadInt64()); } break;
1091 }
1092 //results_list.Add(_tmp_result);
1093 //SearchArgs.Results.Add(_tmp_result);
1094 double double_percent_done = 100.0 * (double)((double)r_ms.BaseStream.Position / (double)r_ms.BaseStream.Length);
1095 int int_percent_done = (int)double_percent_done;
1096 if (int_percent_done != Last_Whole_Percent_Done)
1097 {
1098 resultsprogress.Value = int_percent_done;
1099 resultsprogress.Message = string.Format(" -> Reading Address: 0x{0:x8}", (r_ms.BaseStream.Position + MemoryRangeStart));
1100 Last_Whole_Percent_Done = int_percent_done;
1101 //Application.DoEvents();
1102 }
1103 }
1104 if (SearchWorkerThread.CancellationPending == true)
1105 {
1106 e.Cancel = true;
1107 return;
1108 }
1109 #endregion
1110 }
1111 //}
1112 //SearchArgs.Results.AddRange(results_list);
1113 //results_list = null;
1114 resultsprogress.Value = 100;
1115 resultsprogress.Message = "";
1116 //Application.DoEvents();
1117 st_first_search.Stop();
1118 logger.Profiler.WriteLine("First search took a total of {0} seconds to complete.", st_first_search.Elapsed.TotalSeconds);
1119 }
1120 #endregion
1121
1122 #region Subsequent Searches
1123 r_ms.BaseStream.Seek(0, SeekOrigin.Begin);
1124
1125
1126 // hack to help with OutOfMemory Exceptions (OldValue and Equal compare will always add all found search results)
1127 bool NeedToCompare = true;
1128 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue &&
1129 SearchArgs.CompareType == SearchCompareTypes.Equal &&
1130 SearchArgs.IsFirstSearch)
1131 {
1132 NeedToCompare = false;
1133 second_tmp_Results = null; // Free Memory
1134 }
1135
1136 if (NeedToCompare)
1137 {
1138 if (SearchArgs.CompareType != SearchCompareTypes.Between && SearchArgs.CompareType != SearchCompareTypes.NotBetween)
1139 {
1140 #region Non-Range Searches
1141 st_nonrange_search.Start();
1142 //second_tmp_Results = new List<ResultType<object>>(SearchArgs.Results.Count * 1024);
1143 ////second_tmp_Results.c
1144 for (int i = 0; i < SearchArgs.Results.Count; i += 1)
1145 {
1146 uint address = SearchArgs.Results[i].Address;
1147 if (MemoryRangeStart > 0 && !SearchArgs.IsFirstSearch) { address = address - MemoryRangeStart; }
1148 r_ms.BaseStream.Seek(address, SeekOrigin.Begin);
1149 switch (SearchArgs.DataType)
1150 {
1151 #region Comparer Support
1152 #region case SearchDataTypes._8bits:
1153 case SearchDataTypes._8bits:
1154 if (SearchArgs.IsUnsignedDataType)
1155 {
1156 byte lookup_value = r_ms.ReadByte();
1157 _8bit_unsigned_comparer_ comparer = new _8bit_unsigned_comparer_(SearchArgs, address);
1158 byte value = 0;
1159 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1160 {
1161 value = Convert.ToByte(SearchArgs.Results[i].Value);
1162 comparer.Value = value;
1163 }
1164 else
1165 {
1166 value = Convert.ToByte(SearchArgs.CompareStartValue);
1167 comparer.Value = value;
1168 }
1169 if (comparer.Compare(lookup_value, value))
1170 {
1171 //ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
1172 //second_tmp_Results.Add(_tmp_result);
1173 //_tmp_result = null; // free memory
1174 //SearchArgs.Results.RemoveAt(i);
1175 SearchArgs.Results[i].Value = comparer.Value;
1176 second_tmp_Results.Add(SearchArgs.Results[i]);
1177 }
1178 comparer = null; // free memory
1179 }
1180 else
1181 {
1182 sbyte lookup_value = r_ms.ReadSByte();
1183 _8bit_signed_comparer_ comparer = new _8bit_signed_comparer_(SearchArgs, address);
1184 sbyte value = 0;
1185 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1186 {
1187 value = Convert.ToSByte(SearchArgs.Results[i].Value);
1188 }
1189 else
1190 {
1191 value = Convert.ToSByte(SearchArgs.CompareStartValue);
1192 }
1193 if (comparer.Compare(lookup_value, value))
1194 {
1195 //ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
1196 //second_tmp_Results.Add(_tmp_result);
1197 //_tmp_result = null; // free memory
1198 //SearchArgs.Results.RemoveAt(i);
1199 SearchArgs.Results[i].Value = comparer.Value;
1200 second_tmp_Results.Add(SearchArgs.Results[i]);
1201 }
1202 comparer = null; // free memory
1203 }
1204 break;
1205 #endregion
1206 #region case SearchDataTypes._16bits:
1207 case SearchDataTypes._16bits:
1208 if (SearchArgs.IsUnsignedDataType)
1209 {
1210 ushort lookup_value = r_ms.ReadUInt16();
1211 _16bit_unsigned_comparer_ comparer = new _16bit_unsigned_comparer_(SearchArgs, address);
1212 ushort value = 0;
1213 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1214 {
1215 value = Convert.ToUInt16(SearchArgs.Results[i].Value);
1216 comparer.Value = value;
1217 }
1218 else
1219 {
1220 value = Convert.ToUInt16(SearchArgs.CompareStartValue);
1221 comparer.Value = value;
1222 }
1223 if (comparer.Compare(lookup_value, value))
1224 {
1225 //ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
1226 //second_tmp_Results.Add(_tmp_result);
1227 //_tmp_result = null; // free memory
1228 //SearchArgs.Results.RemoveAt(i);
1229 SearchArgs.Results[i].Value = comparer.Value;
1230 second_tmp_Results.Add(SearchArgs.Results[i]);
1231 }
1232 comparer = null; // free memory
1233 }
1234 else
1235 {
1236 short lookup_value = r_ms.ReadInt16();
1237 _16bit_signed_comparer_ comparer = new _16bit_signed_comparer_(SearchArgs, address);
1238 short value = 0;
1239 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1240 {
1241 value = Convert.ToInt16(SearchArgs.Results[i].Value);
1242 }
1243 else
1244 {
1245 value = Convert.ToInt16(SearchArgs.CompareStartValue);
1246 }
1247 if (comparer.Compare(lookup_value, value))
1248 {
1249 //ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
1250 //second_tmp_Results.Add(_tmp_result);
1251 //_tmp_result = null; // free memory
1252 //SearchArgs.Results.RemoveAt(i);
1253 SearchArgs.Results[i].Value = comparer.Value;
1254 second_tmp_Results.Add(SearchArgs.Results[i]);
1255 }
1256 comparer = null; // free memory
1257 }
1258 break;
1259 #endregion
1260 #region case SearchDataTypes._32bits:
1261 case SearchDataTypes._32bits:
1262 if (SearchArgs.IsUnsignedDataType)
1263 {
1264 uint lookup_value = r_ms.ReadUInt32();
1265 _32bit_unsigned_comparer_ comparer = new _32bit_unsigned_comparer_(SearchArgs, address);
1266 uint value = 0;
1267 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1268 {
1269 value = Convert.ToUInt32(SearchArgs.Results[i].Value);
1270 comparer.Value = value;
1271 }
1272 else
1273 {
1274 value = Convert.ToUInt32(SearchArgs.CompareStartValue);
1275 comparer.Value = value;
1276 }
1277 if (comparer.Compare(lookup_value, value))
1278 {
1279 //ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
1280 //second_tmp_Results.Add(_tmp_result);
1281 //_tmp_result = null; // free memory
1282 //SearchArgs.Results.RemoveAt(i);
1283 SearchArgs.Results[i].Value = comparer.Value;
1284 second_tmp_Results.Add(SearchArgs.Results[i]);
1285 }
1286 comparer = null; // free memory
1287 }
1288 else
1289 {
1290 int lookup_value = r_ms.ReadInt32();
1291 _32bit_signed_comparer_ comparer = new _32bit_signed_comparer_(SearchArgs, address);
1292 int value = 0;
1293 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1294 {
1295 value = Convert.ToInt32(SearchArgs.Results[i].Value);
1296 }
1297 else
1298 {
1299 value = Convert.ToInt32(SearchArgs.CompareStartValue);
1300 }
1301 if (comparer.Compare(lookup_value, value))
1302 {
1303 //ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
1304 //second_tmp_Results.Add(_tmp_result);
1305 //_tmp_result = null; // free memory
1306 //SearchArgs.Results.RemoveAt(i);
1307 SearchArgs.Results[i].Value = comparer.Value;
1308 second_tmp_Results.Add(SearchArgs.Results[i]);
1309 }
1310 comparer = null; // free memory
1311 }
1312 break;
1313 #endregion
1314 #region case SearchDataTypes._64bits:
1315 case SearchDataTypes._64bits:
1316 if (SearchArgs.IsUnsignedDataType)
1317 {
1318 ulong lookup_value = r_ms.ReadUInt64();
1319 _64bit_unsigned_comparer_ comparer = new _64bit_unsigned_comparer_(SearchArgs, address);
1320 ulong value = 0;
1321 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1322 {
1323 value = Convert.ToUInt64(SearchArgs.Results[i].Value);
1324 comparer.Value = value;
1325 }
1326 else
1327 {
1328 value = Convert.ToUInt64(SearchArgs.CompareStartValue);
1329 comparer.Value = value;
1330 }
1331 if (comparer.Compare(lookup_value, value))
1332 {
1333 //ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
1334 //second_tmp_Results.Add(_tmp_result);
1335 //_tmp_result = null; // free memory
1336 //SearchArgs.Results.RemoveAt(i);
1337 SearchArgs.Results[i].Value = comparer.Value;
1338 second_tmp_Results.Add(SearchArgs.Results[i]);
1339 }
1340 comparer = null; // free memory
1341 }
1342 else
1343 {
1344 long lookup_value = r_ms.ReadInt64();
1345 _64bit_signed_comparer_ comparer = new _64bit_signed_comparer_(SearchArgs, address);
1346 long value = 0;
1347 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1348 {
1349 value = Convert.ToInt64(SearchArgs.Results[i].Value);
1350 }
1351 else
1352 {
1353 value = Convert.ToInt64(SearchArgs.CompareStartValue);
1354 }
1355 if (comparer.Compare(lookup_value, value))
1356 {
1357 //ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
1358 //second_tmp_Results.Add(_tmp_result);
1359 //_tmp_result = null; // free memory
1360 //SearchArgs.Results.RemoveAt(i);
1361 SearchArgs.Results[i].Value = comparer.Value;
1362 second_tmp_Results.Add(SearchArgs.Results[i]);
1363 }
1364 comparer = null; // free memory
1365 }
1366 break;
1367 #endregion
1368 #endregion
1369 }
1370
1371 double double_percent_done = 100.0 * (double)((double)i / (double)SearchArgs.Results.Count);
1372 int int_percent_done = (int)double_percent_done;
1373 if (int_percent_done != Last_Whole_Percent_Done && i % ElementsBeforeDisplay == 0)
1374 {
1375 resultsprogress.Value = int_percent_done;
1376 resultsprogress.Message = string.Format(" -> Reading Address: 0x{0:x8}", i);
1377 Last_Whole_Percent_Done = int_percent_done;
1378 //Application.DoEvents();
1379 }
1380
1381 }
1382 st_nonrange_search.Stop();
1383 logger.Profiler.WriteLine("Non-Ranged search took a total of {0} seconds to complete.", st_nonrange_search.Elapsed.TotalSeconds);
1384 #endregion
1385 }
1386 #region Ranged Searches
1387 #if !DONOT_HAVE_RANGED_SEARCH_SUPPORT
1388 if (SearchArgs.CompareType == SearchCompareTypes.Between || SearchArgs.CompareType == SearchCompareTypes.NotBetween)
1389 {
1390 st_ranged_search.Start();
1391 object start, end;
1392
1393 start = SearchArgs.CompareStartValue;
1394 end = SearchArgs.CompareEndValue;
1395 for (int i = 0; i < SearchArgs.Results.Count; i += 1)
1396 {
1397 uint address = SearchArgs.Results[i].Address;
1398 if (MemoryRangeStart > 0 && !SearchArgs.IsFirstSearch) { address = address - MemoryRangeStart; }
1399 r_ms.BaseStream.Seek(address, SeekOrigin.Begin);
1400 if (SearchArgs.CompareType == SearchCompareTypes.Between)
1401 {
1402 InRangeComparer comparer = new InRangeComparer(address, 0);
1403 if (comparer.Compare(start, end, SearchArgs.DataType, SearchArgs.IsUnsignedDataType, r_ms))
1404 {
1405 SearchArgs.Results[i].Value = comparer.Value;
1406 second_tmp_Results.Add(SearchArgs.Results[i]);
1407 }
1408 comparer = null;
1409 }
1410 else if (SearchArgs.CompareType == SearchCompareTypes.NotBetween)
1411 {
1412 NotInRangeComparer comparer = new NotInRangeComparer(address, 0);
1413 if (comparer.Compare(start, end, SearchArgs.DataType, SearchArgs.IsUnsignedDataType, r_ms))
1414 {
1415 SearchArgs.Results[i].Value = comparer.Value;
1416 second_tmp_Results.Add(SearchArgs.Results[i]);
1417 }
1418 comparer = null;
1419 }
1420 else
1421 {
1422 throw new InvalidOperationException("Encounted unkown range search type: " + SearchArgs.CompareType);
1423 }
1424 double double_percent_done = 100.0 * (double)((double)i / (double)SearchArgs.Results.Count);
1425 int int_percent_done = (int)double_percent_done;
1426 if (int_percent_done != Last_Whole_Percent_Done && i % ElementsBeforeDisplay == 0)
1427 {
1428 resultsprogress.Value = int_percent_done;
1429 resultsprogress.Message = string.Format(" -> Reading Address: 0x{0:x8}", i);
1430 Last_Whole_Percent_Done = int_percent_done;
1431 //Application.DoEvents();
1432 }
1433 }
1434 st_ranged_search.Stop();
1435 logger.Profiler.WriteLine("Ranged search took a total of {0} seconds to complete.", st_ranged_search.Elapsed.TotalSeconds);
1436 }
1437 #endif
1438 #endregion
1439
1440 }
1441 #endregion
1442 // leave SearchArgs.Results alone, if false
1443 if (NeedToCompare)
1444 {
1445 SearchArgs.Results = second_tmp_Results.GetRange(0, second_tmp_Results.Count);
1446 // fix addresses when memory start is not zero
1447 if (MemoryRangeStart > 0 && SearchArgs.IsFirstSearch) { for (int i = 0; i < SearchArgs.Results.Count; i++) { SearchArgs.Results[i].Address = SearchArgs.Results[i].Address + MemoryRangeStart; } }
1448 second_tmp_Results = null; // free memory
1449 }
1450
1451 r_ms.Close();
1452 }
1453 }
1454 }
1455
1456 private void SearchWorkerThread_ProgressChanged(object sender, ProgressChangedEventArgs e)
1457 {
1458 //if (SearchArgs.ProgressLogger != null)
1459 //{
1460 // resultsprogress.Value = e.ProgressPercentage;
1461 // //Application.DoEvents();
1462 //}
1463 }
1464
1465 private void SearchWorkerThread_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
1466 {
1467 if (!e.Cancelled)
1468 {
1469 Stopwatch st = (e.Result as Stopwatch);
1470 st.Stop();
1471 logger.Profiler.WriteLine("Search took {0} seconds, overall, to complete.", st.Elapsed.TotalSeconds);
1472 }
1473
1474 resultsprogress.Value = 100;
1475 logger.Debug.WriteLine(string.Format("Results Count -> 0x{0:x8}", SearchArgs.Results.Count));
1476
1477 if (SearchArgs.Results.Count == 1) // debug message for 1 result using 32bit unsigned
1478 logger.Debug.WriteLine(string.Format("Debug: Found 1 result -> Address: 0x{0:x8} Value: 0x{1:x8}", SearchArgs.Results[0].Address, SearchArgs.Results[0].Value));
1479
1480 logger.Info.WriteLine(string.Format("Found 0x{0:x8} results", SearchArgs.Results.Count));
1481
1482 if (SearchArgs.Results.Count <= MIN_NUMBER_OF_RESULTS_BEFORE_DISPLAY)
1483 {
1484 lstResults.Items.Clear();
1485 List<ResultItem> items = new List<ResultItem>();
1486 for (int i = 0; i < SearchArgs.Results.Count; i++)
1487 {
1488 ResultItem item = new ResultItem(0, false);
1489 //item.Text = string.Format("0x{0:x8}", SearchArgs.Results[i].Address);
1490 //item.SubItems.Add(string.Format("0x{0:x8}", SearchArgs.Results[i].Address));
1491 switch (SearchArgs.DataType)
1492 {
1493
1494 case SearchDataTypes._8bits:
1495 if (SearchArgs.IsUnsignedDataType) { item = new ResultItem(SearchArgs.Results[i].Address, false, Convert.ToByte(SearchArgs.Results[i].Value)); }
1496 else { item = new ResultItem(SearchArgs.Results[i].Address, false, Convert.ToSByte(SearchArgs.Results[i].Value)); }
1497 break;
1498 case SearchDataTypes._16bits:
1499 if (SearchArgs.IsUnsignedDataType) { item = new ResultItem(SearchArgs.Results[i].Address, false, Convert.ToUInt16(SearchArgs.Results[i].Value)); }
1500 else { item = new ResultItem(SearchArgs.Results[i].Address, false, Convert.ToInt16(SearchArgs.Results[i].Value)); }
1501 break;
1502 case SearchDataTypes._32bits:
1503 if (SearchArgs.IsUnsignedDataType) { item = new ResultItem(SearchArgs.Results[i].Address, false, Convert.ToUInt32(SearchArgs.Results[i].Value)); }
1504 else { item = new ResultItem(SearchArgs.Results[i].Address, false, Convert.ToInt32(SearchArgs.Results[i].Value)); }
1505 break;
1506 case SearchDataTypes._64bits:
1507 if (SearchArgs.IsUnsignedDataType) { item = new ResultItem(SearchArgs.Results[i].Address, false, Convert.ToUInt64(SearchArgs.Results[i].Value)); }
1508 else { item = new ResultItem(SearchArgs.Results[i].Address, false, Convert.ToInt64(SearchArgs.Results[i].Value)); }
1509 break;
1510 }
1511
1512 if (!items.Contains(item))
1513 items.Add(item);
1514 }
1515 lstResults.Items.AddRange(items.ToArray());
1516 }
1517
1518 this.DoSearchDoneSpecific();
1519 //System.Threading.Thread.Sleep(100);
1520 //if (_SEARCH_MODE != SearchMode.SEARCH_MODE_NORMAL_WITH_JOKER)
1521 this.ThawResultsUpdate();
1522 Application.DoEvents();
1523 }
1524 private void DoSearchDoneSpecific()
1525 {
1526 SearchWorkerThread.CancelAsync();
1527 if (lstResults.Items.Count > 0) { timer_update_results.Enabled = true; }
1528 else { timer_update_results.Enabled = false; }
1529
1530 search_progress_updater.Enabled = false;
1531
1532 btnCancel.Enabled = false;
1533 btnReset.Enabled = true;
1534 btnSearch.Enabled = true;
1535 grpCompareType.Enabled = true;
1536 grpCompareValue.Enabled = true;
1537 resultsprogress.Value = 0;
1538 resultsprogress.Message = "";
1539 grpDataType.Enabled = false;
1540 // resume process on reset, incase it was suspended
1541 ThreadControl.ResumeProcess(this.AcceptedProcess.Id);
1542 //Application.DoEvents();
1543 this.Refresh();
1544 }
1545
1546 private void DoCancelSpecific()
1547 {
1548 this.DoSearchDoneSpecific();
1549 }
1550 private void DoResetSpecific()
1551 {
1552 this.DoCancelSpecific();
1553 IsFirstSearch = true;
1554 grpDataType.Enabled = true;
1555 }
1556 private void search_progress_updater_Tick(object sender, EventArgs e)
1557 {
1558 if ((this.AcceptedProcess ==null) || Process.GetProcessById(this.AcceptedProcess.Id) == null)
1559 {
1560 SearchWorkerThread.CancelAsync();
1561 //JokerSearchWorker.CancelAsync();
1562 ResultsUpdateWorkerThread.CancelAsync();
1563 }
1564 }
1565
1566 #region Search Button
1567 private void btnSearch_Click(object sender, EventArgs e)
1568 {
1569 this.SearchInProgess = true;
1570 //btnCancel.Enabled = true;
1571 //btnReset.Enabled = false;
1572 //btnSearch.Enabled = false;
1573 this.FreezeResultsUpdate();
1574 this.handle_btnSearch_Click();
1575 }
1576 private void handle_btnSearch_Click()
1577 {
1578 //this.FreezeResultsUpdate();
1579 lstResults.Items.Clear();
1580
1581 if (lstResults.Items.Count > 0) { timer_update_results.Enabled = true; }
1582 else { timer_update_results.Enabled = false; }
1583
1584
1585 resultsprogress.Value = 0;
1586 bool _is_unsigned = chkUnsigned.Checked;
1587 SearchType search_type = new SearchType();
1588 SearchDataTypes _data_type = new SearchDataTypes();
1589 SearchCompareTypes _compare_type = new SearchCompareTypes();
1590 CompareValueTypes _compare_value_type = new CompareValueTypes();
1591 object start_value = 0;
1592 object end_value = 0;
1593 // get datatype
1594 if (radio_8bits.Checked) { _data_type = SearchDataTypes._8bits; }
1595 else if (radio_16bits.Checked) { _data_type = SearchDataTypes._16bits; }
1596 else if (radio_32bits.Checked) { _data_type = SearchDataTypes._32bits; }
1597 else if (radio_64bits.Checked) { _data_type = SearchDataTypes._64bits; }
1598 else { logger.Error.WriteLine("Could not determine search data type bit size. (was not 8/16/32/or 64bits)"); }
1599 // get compare type
1600 if (radiocompare_equal.Checked) { _compare_type = SearchCompareTypes.Equal; }
1601 else if (radiocompare_greaterthan.Checked) { _compare_type = SearchCompareTypes.GreaterThan; }
1602 else if (radiocompare_lessthan.Checked) { _compare_type = SearchCompareTypes.LessThan; }
1603 else if (radiocompare_greaterthan_orequal.Checked) { _compare_type = SearchCompareTypes.GreaterThanOrEqual; }
1604 else if (radiocompare_lessthan_orequal.Checked) { _compare_type = SearchCompareTypes.LessThanOrEqual; }
1605 else if (radiocompare_notequal.Checked) { _compare_type = SearchCompareTypes.NotEqual; }
1606 else if (radiocompare_between.Checked) { _compare_type = SearchCompareTypes.Between; }
1607 else if (radiocompare_notbetween.Checked) { _compare_type = SearchCompareTypes.NotBetween; }
1608 else { logger.Error.WriteLine("Could not determine search comparison type. (was not == > < >= <= != <> or !<>)"); }
1609 // get compare valure type
1610 if (radio_oldvalue.Checked) { _compare_value_type = CompareValueTypes.OldValue; }
1611 else if (radio_specificvalue.Checked) { _compare_value_type = CompareValueTypes.SpecificValue; }
1612 else { logger.Error.WriteLine("Could not determine search comparison type. (was not old or specific value"); }
1613
1614 if (_compare_value_type == CompareValueTypes.SpecificValue || (_compare_type == SearchCompareTypes.Between || _compare_type == SearchCompareTypes.NotBetween))
1615 {
1616
1617 switch (_data_type)
1618 {
1619 case SearchDataTypes._8bits:
1620 if (_is_unsigned) { start_value = txtStartAddr.ToByte(); }
1621 else { start_value = txtStartAddr.ToSByte(); }
1622 break;
1623 case SearchDataTypes._16bits:
1624 if (_is_unsigned) { start_value = txtStartAddr.ToUInt16(); }
1625 else { start_value = txtStartAddr.ToInt16(); }
1626 break;
1627 case SearchDataTypes._32bits:
1628 if (_is_unsigned) { start_value = txtStartAddr.ToUInt32(); }
1629 else { start_value = txtStartAddr.ToInt32(); }
1630 break;
1631 case SearchDataTypes._64bits:
1632 if (_is_unsigned) { start_value = txtStartAddr.ToUInt64(); }
1633 else { start_value = txtStartAddr.ToInt64(); }
1634 break;
1635 default: throw new InvalidOperationException("In SearchType(): Encounterd an Unkown Search Data Type.");
1636 }
1637 }
1638 if (_compare_type == SearchCompareTypes.Between || _compare_type == SearchCompareTypes.NotBetween)
1639 {
1640 switch (_data_type)
1641 {
1642 case SearchDataTypes._8bits:
1643 if (_is_unsigned) { end_value = txtEndAddr.ToByte(); }
1644 else { end_value = txtEndAddr.ToSByte(); }
1645 break;
1646 case SearchDataTypes._16bits:
1647 if (_is_unsigned) { end_value = txtEndAddr.ToUInt16(); }
1648 else { end_value = txtEndAddr.ToInt16(); }
1649 break;
1650 case SearchDataTypes._32bits:
1651 if (_is_unsigned) { end_value = txtEndAddr.ToUInt32(); }
1652 else { end_value = txtEndAddr.ToInt32(); }
1653 break;
1654 case SearchDataTypes._64bits:
1655 if (_is_unsigned) { end_value = txtEndAddr.ToUInt64(); }
1656 else { end_value = txtEndAddr.ToInt64(); }
1657 break;
1658 default: throw new InvalidOperationException("In SearchType(): Encounterd an Unkown Search Data Type.");
1659 }
1660 }
1661
1662 search_type = new SearchType(_data_type, _is_unsigned, _compare_type, _compare_value_type, start_value, end_value, resultsprogress);
1663
1664 //search_type.LogSearchOptions();
1665
1666 search_type.IsFirstSearch = IsFirstSearch;
1667
1668
1669
1670 DoSearch(search_type);
1671 IsFirstSearch = false;
1672 }
1673 private void DoSearch(SearchType args)
1674 {
1675 if (!args.IsFirstSearch && SearchArgs != null)
1676 {
1677 //args.Results.AddRange(SearchArgs.Results.ToArray());
1678 args.Results = SearchArgs.Results;
1679 }
1680 SearchArgs = args;
1681 #if DONOT_HAVE_RANGED_SEARCH_SUPPORT
1682 if (SearchArgs.CompareType == SearchCompareTypes.Between || SearchArgs.CompareType == SearchCompareTypes.NotBetween)
1683 {
1684 throw new NotImplementedException("Between and Not Between Range searches have not been implemented.");
1685 }
1686 #endif
1687 search_progress_updater.Enabled = true;
1688 //padPluginSelector.Enabled = false;
1689 //gsPluginSelector.Enabled = false;
1690 btnReset.Enabled = false;
1691 btnSearch.Enabled = false;
1692 btnCancel.Enabled = true;
1693 grpDataType.Enabled = false;
1694 grpCompareType.Enabled = false;
1695 grpCompareValue.Enabled = false;
1696 this.Refresh();
1697 Application.DoEvents();
1698 SearchWorkerThread.RunWorkerAsync();
1699 }
1700 #endregion
1701 private void btnReset_Click(object sender, EventArgs e)
1702 {
1703 this.SearchInProgess = false;
1704 //btnSearch.Enabled = true;
1705 //btnCancel.Enabled = false;
1706 this.DoResetSpecific();
1707 lstResults.Items.Clear();
1708 try { SearchArgs.Results = new List<ResultType<object>>(); }
1709 catch { }
1710 }
1711
1712 private void btnCancel_Click(object sender, EventArgs e)
1713 {
1714 this.SearchInProgess = false;
1715 //btnCancel.Enabled = false;
1716 //btnSearch.Enabled = true;
1717 //btnReset.Enabled = true;
1718 this.DoCancelSpecific();
1719 }
1720
1721 private void mnuItemPatchListViewMemoryRegion_Click(object sender, EventArgs e)
1722 {
1723 List<ResultDataType> patch_list = new List<ResultDataType>();
1724 List<int> SelectedIndexes = new List<int>();
1725 foreach (int index in lstPatchList.SelectedIndices) { SelectedIndexes.Add(index); }
1726 foreach (int index in SelectedIndexes)
1727 {
1728 ListViewItem item = lstPatchList.Items[index];
1729 ResultDataType rdt = (ResultDataType)item.Tag;
1730 ViewMemoryRegion(rdt);
1731 break; // only get the fist item
1732 }
1733 }
1734
1735 private void mnuItemResultsListViewMemoryRegion_Click(object sender, EventArgs e)
1736 {
1737 List<ResultDataType> patch_list = new List<ResultDataType>();
1738 List<int> SelectedIndexes = new List<int>();
1739 foreach (int index in lstResults.SelectedIndices) { SelectedIndexes.Add(index); }
1740 foreach (int index in SelectedIndexes)
1741 {
1742 ListViewItem item = lstResults.Items[index];
1743 ResultDataType rdt = (ResultDataType)item.Tag;
1744 ViewMemoryRegion(rdt);
1745 break; // only get the fist item
1746 }
1747 }
1748 private void ViewMemoryRegion(ResultDataType rdt)
1749 {
1750 if (OnBrowseMemoryRegion != null)
1751 OnBrowseMemoryRegion(new BrowseMemoryRegionEvent(this, rdt.Address));
1752 }
1753
1754 private void mnuAddedResults_Opening(object sender, CancelEventArgs e)
1755 {
1756 if (!(lstPatchList.Items.Count > 0)) { mnuItemRemoveResult.Visible = false; e.Cancel = true; }
1757 if (!(lstPatchList.Items.Count > 0)) { mnuItemPatchSelectedEntry.Visible = false; e.Cancel = true; }
1758 if (e.Cancel) return;
1759 if (lstPatchList.Items.Count > 0) mnuItemRemoveResult.Visible = true;
1760 if (lstPatchList.Items.Count > 0) mnuItemPatchSelectedEntry.Visible = true;
1761
1762 if (!(lstPatchList.Items.Count > 0)) { mnuItemFreezeSelectedPatches.Visible = false; e.Cancel = true; }
1763 if (!(lstPatchList.Items.Count > 0)) { mnuItemThawSelectedPatches.Visible = false; e.Cancel = true; }
1764 if (e.Cancel) return;
1765
1766 if (lstPatchList.Items.Count > 0) mnuItemFreezeSelectedPatches.Visible = true;
1767 if (lstPatchList.Items.Count > 0) mnuItemThawSelectedPatches.Visible = true;
1768
1769 if (lstPatchList.SelectedItems.Count == 0) e.Cancel = true;
1770 if (e.Cancel) return;
1771
1772 }
1773
1774 private void mnuResults_Opening(object sender, CancelEventArgs e)
1775 {
1776 if (!(lstResults.Items.Count > 0)) e.Cancel = true;
1777 if (lstResults.SelectedItems.Count == 0) e.Cancel = true;
1778 if (SearchArgs == null) e.Cancel = true;
1779 if (e.Cancel) return;
1780 }
1781
1782 private void chkMemoryRangeExpertMode_CheckedChanged(object sender, EventArgs e)
1783 {
1784 txtMemoryRangeStart.ReadOnly = !chkMemoryRangeExpertMode.Checked;
1785 txtMemoryRangeSize.ReadOnly = !chkMemoryRangeExpertMode.Checked;
1786 }
1787
1788 private void txtMemoryRangeStart_ValueChanged(object sender, ValueChangedEventArgs e) { this.MemoryRangeStart = Convert.ToUInt32(e.NewValue); }
1789 private void txtMemoryRangeSize_ValueChanged(object sender, ValueChangedEventArgs e) { this.MemoryRangeSize = Convert.ToUInt32(e.NewValue); }
1790
1791 }
1792 }