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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 398 - (show annotations) (download)
Wed Jun 20 12:16:34 2012 UTC (8 years, 4 months ago) by william
File size: 92702 byte(s)
MemmoryProvider: using statements

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

  ViewVC Help
Powered by ViewVC 1.1.22