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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 397 - (show annotations) (download)
Wed Jun 20 11:18:56 2012 UTC (8 years, 4 months ago) by william
File size: 87904 byte(s)
+ major speed boost on first search

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 GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this);
436 provider.OpenProvider();
437 int bytesReadSize;
438 byte[] data;
439 uint bytesToRead = 0;
440 switch (_result.ValueType)
441 {
442 case SearchDataTypes._8bits:
443 bytesToRead = 1;
444 break;
445 case SearchDataTypes._16bits:
446 bytesToRead = 2;
447 break;
448 case SearchDataTypes._32bits:
449 bytesToRead = 4;
450 break;
451 case SearchDataTypes._64bits:
452 bytesToRead = 8;
453 break;
454 }
455 provider.ReadProcessMemory(Address, bytesToRead, out bytesReadSize, out data);
456 MemoryStream ms = new MemoryStream(data);
457 BinaryReader r_ms = new BinaryReader(ms);
458 switch (_result.ValueType)
459 {
460 case SearchDataTypes._8bits:
461 if (_result.IsUnsigned) { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x2}", r_ms.ReadByte()); }
462 else { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x2}", r_ms.ReadSByte()); }
463 break;
464 case SearchDataTypes._16bits:
465 if (_result.IsUnsigned) { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x4}", r_ms.ReadUInt16()); }
466 else { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x4}", r_ms.ReadInt16()); }
467 break;
468 case SearchDataTypes._32bits:
469 if (_result.IsUnsigned) { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x8}", r_ms.ReadUInt32()); }
470 else { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x8}", r_ms.ReadInt32()); }
471 break;
472 case SearchDataTypes._64bits:
473 if (_result.IsUnsigned) { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x16}", r_ms.ReadUInt64()); }
474 else { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x16}", r_ms.ReadInt64()); }
475 break;
476 }
477 r_ms.Close();
478 provider.CloseProvider();
479 Application.DoEvents();
480 }
481 #endregion
482
483 #region Update Added Results List
484 AddedItems = new List<ListViewItem>();
485 //r_ms.BaseStream.Seek(0, SeekOrigin.Begin);
486 for (int i = 0; i < lstPatchList.Items.Count; i++)
487 {
488 if (this.lstResults.InvokeRequired)
489 {
490 ThreadSafe_GetResultItem _get_item = new ThreadSafe_GetResultItem(GetResultItem);
491 object item = this.lstResults.Invoke(_get_item, new object[] { i, (int)eListViewResults.PATCH_RESULTS_LIST });
492 if (item != null)
493 AddedItems.Add((ListViewItem)item);
494 }
495 else
496 {
497 AddedItems.Add(lstPatchList.Items[i]);
498 }
499
500 }
501 for (int i = 0; i < AddedItems.Count; i++)
502 {
503 if (ResultsUpdateWorkerThread.CancellationPending == true)
504 {
505 e.Cancel = true;
506 return;
507 }
508 int Address = 0;
509 ResultDataType _result = (ResultDataType)AddedItems[i].Tag;
510 Address = Convert.ToInt32(AddedItems[i].SubItems[col_Added_Address].Text, 16);
511 GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this);
512 provider.OpenProvider();
513 int bytesReadSize;
514 byte[] data;
515 uint bytesToRead = 0;
516 switch (_result.ValueType)
517 {
518 case SearchDataTypes._8bits:
519 bytesToRead = 1;
520 break;
521 case SearchDataTypes._16bits:
522 bytesToRead = 2;
523 break;
524 case SearchDataTypes._32bits:
525 bytesToRead = 4;
526 break;
527 case SearchDataTypes._64bits:
528 bytesToRead = 8;
529 break;
530 }
531 provider.ReadProcessMemory(Address, bytesToRead, out bytesReadSize, out data);
532 MemoryStream ms = new MemoryStream(data);
533 BinaryReader r_ms = new BinaryReader(ms);
534 switch (_result.ValueType)
535 {
536 case SearchDataTypes._8bits:
537 if (_result.IsUnsigned) { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x2}", r_ms.ReadByte()); }
538 else { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x2}", r_ms.ReadSByte()); }
539 break;
540 case SearchDataTypes._16bits:
541 if (_result.IsUnsigned) { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x4}", r_ms.ReadUInt16()); }
542 else { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x4}", r_ms.ReadInt16()); }
543 break;
544 case SearchDataTypes._32bits:
545 if (_result.IsUnsigned) { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x8}", r_ms.ReadUInt32()); }
546 else { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x8}", r_ms.ReadInt32()); }
547 break;
548 case SearchDataTypes._64bits:
549 if (_result.IsUnsigned) { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x16}", r_ms.ReadUInt64()); }
550 else { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x16}", r_ms.ReadInt64()); }
551 break;
552 }
553 r_ms.Close();
554 provider.CloseProvider();
555 Application.DoEvents();
556 }
557 #endregion
558
559
560 }
561
562 private void ResultsUpdateWorkerThread_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
563 {
564 try
565 {
566 //if ((lstResults.SelectedItems.Count > 0) && !PatchedValue_NeedsUpdate ) return;
567 //if ((lstPatchList.SelectedItems.Count > 0) && !PatchedValue_NeedsUpdate) return;
568 if (!this.ShouldUpdateResults()) return;
569 if (ResultItems.Count > 0)
570 {
571 //lstResults.Items.Clear();
572 //lstResults.Items.AddRange(ResultItems.ToArray());
573
574 for (int i = 0; i < ResultItems.Count; i++)
575 {
576 lstResults.Items[i].SubItems[new AVPColumnText(AVPColumnType.VALUE).ColumnIndex].Text =
577 ResultItems[i].SubItems[new AVPColumnText(AVPColumnType.VALUE).ColumnIndex].Text;
578 }
579
580 }
581 if (AddedItems.Count > 0)
582 {
583 //lstPatchList.Items.Clear();
584 //lstPatchList.Items.AddRange(AddedItems.ToArray());
585
586 for (int i = 0; i < AddedItems.Count; i++)
587 {
588 lstPatchList.Items[i].SubItems[new AVPColumnText(AVPColumnType.VALUE).ColumnIndex].Text =
589 AddedItems[i].SubItems[new AVPColumnText(AVPColumnType.VALUE).ColumnIndex].Text;
590 }
591
592 }
593 PatchedValue_NeedsUpdate = false;
594 }
595 catch { }
596 }
597
598 private void btnImportFile_Click(object sender, EventArgs e)
599 {
600 this.FreezeResultsUpdate();
601 if (!lstPatchList.ImportFromFile())
602 {
603 MessageBox.Show("Failed to Import Patch List from File.", "Import Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
604 this.ThawResultsUpdate();
605 return;
606 }
607 else
608 {
609 MessageBox.Show("Succesfully Imported Patch List from File.", "Import Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
610 this.ThawResultsUpdate();
611 return;
612 }
613 }
614 bool g_isFrozen = false;
615 private bool IsResultsUpdateFrozen
616 {
617 get { return g_isFrozen; }
618 set { g_isFrozen = value; }
619 }
620 private void ThawResultsUpdate()
621 {
622 this.IsResultsUpdateFrozen = false;
623 if (this.AcceptedProcess != null)
624 {
625 #if !DO_NOT_SUSPEND_RESUME_THREAD_ON_FREEZE
626 ThreadControl.ResumeProcess(this.AcceptedProcess.Id);
627 #endif
628 }
629 }
630
631 private void FreezeResultsUpdate()
632 {
633 this.IsResultsUpdateFrozen = true;
634 //this.IsResultsUpdateFrozen = false;
635 if (this.AcceptedProcess != null)
636 {
637 #if !DO_NOT_SUSPEND_RESUME_THREAD_ON_FREEZE
638 ThreadControl.SuspendProcess(this.AcceptedProcess.Id);
639 #endif
640 }
641 }
642
643 private void btnExportFile_Click(object sender, EventArgs e)
644 {
645 this.FreezeResultsUpdate();
646 if (!lstPatchList.ExportToFile())
647 {
648 MessageBox.Show("Failed to Export Patch List to File.", "Export Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
649 this.ThawResultsUpdate();
650 return;
651 }
652 else
653 {
654 MessageBox.Show("Succesfully Exported Patch List to File.", "Export Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
655 this.ThawResultsUpdate();
656 return;
657 }
658 }
659
660 private void btnImportClipboard_Click(object sender, EventArgs e)
661 {
662 this.FreezeResultsUpdate();
663 if (!lstPatchList.ImportFromClipboard())
664 {
665 MessageBox.Show("Failed to Import Patch List from Clipboard.", "Import Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
666 this.ThawResultsUpdate();
667 return;
668 }
669 else
670 {
671 MessageBox.Show("Succesfully Import Patch List from Clipboard.", "Import Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
672 this.ThawResultsUpdate();
673 }
674 }
675
676 private void btnExportClipboard_Click(object sender, EventArgs e)
677 {
678 this.FreezeResultsUpdate();
679 if (!lstPatchList.ExportToClipboard())
680 {
681 MessageBox.Show("Failed to Export Patch List to Clipboard.", "Export Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
682 this.ThawResultsUpdate();
683 return;
684 }
685 else
686 {
687 MessageBox.Show("Succesfully Exported Patch List to Clipboard.", "Export Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
688 this.ThawResultsUpdate();
689 return;
690 }
691 }
692
693 private void btnAddPatchAddress_Click(object sender, EventArgs e)
694 {
695 PatchAdder adder = new PatchAdder((IAcceptsProcessAndConfig)this);
696 adder.ShowDialog();
697 if (adder.WasAPatchAdded) AddToPatchList(adder.AddedPatchValue);
698 }
699
700 private void btnAddAddressRange_Click(object sender, EventArgs e)
701 {
702 PatchRangeAdder adder = new PatchRangeAdder((IAcceptsProcessAndConfig)this);
703 adder.ShowDialog();
704 if (adder.WasAPatchAdded) AddToPatchList(adder.AddedPatchValue);
705 }
706 private void AddToPatchList(List<ResultDataType> item) { foreach (ResultDataType data in item) { AddToPatchList(data); } }
707 private void AddToPatchList(ResultDataType item)
708 {
709 ResultItem item2 = null;
710 switch (item.ValueType)
711 {
712 case SearchDataTypes._8bits:
713 if (item.IsUnsigned) { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToByte(item.Value)); }
714 else { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToSByte(item.Value)); }
715 break;
716 case SearchDataTypes._16bits:
717 if (item.IsUnsigned) { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToUInt16(item.Value)); }
718 else { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToInt16(item.Value)); }
719 break;
720 case SearchDataTypes._32bits:
721 if (item.IsUnsigned) { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToUInt32(item.Value)); }
722 else { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToInt32(item.Value)); }
723 break;
724 case SearchDataTypes._64bits:
725 if (item.IsUnsigned) { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToUInt64(item.Value)); }
726 else { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToInt64(item.Value)); }
727 break;
728 }
729 this.AddToPatchList(item2);
730 }
731 private void AddToPatchList(ListViewItem item)
732 {
733 try
734 {
735 ResultDataType _result = (ResultDataType)item.Tag;
736 this.AddToPatchList(_result);
737 }
738 catch (InvalidCastException ex)
739 {
740 // unable to cast
741 MessageBox.Show(ex.Message, "Invalid Cast Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
742 }
743 catch (Exception ex)
744 {
745 // other exception
746 MessageBox.Show(ex.Message, "Unhandled Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
747 }
748 }
749 private void AddToPatchList(ResultItem item)
750 {
751 if (!lstPatchList.Items.Contains(item)) lstPatchList.Items.Add(item);
752 }
753 private void AddToPatchList(string address, SearchDataTypes bitsize, bool IsUnsigned)
754 {
755 ResultItemState state = new ResultItemState(address, bitsize, IsUnsigned, (IAcceptsProcessAndConfig)this);
756 ResultItem item = new ResultItem(state.Address, state.Value, state.Frozen, state.ValueType, state.IsUnsigned);
757 this.AddToPatchList(item);
758 }
759
760 private void mnuItemAddToPatchList_Click(object sender, EventArgs e)
761 {
762 if (!(lstResults.SelectedItems.Count > 0)) return;
763 //if (SearchArgs == null) return;
764
765 try
766 {
767 for (int i = 0; i < lstResults.SelectedIndices.Count; i++)
768 {
769 //ResultDataType result = (ResultDataType)lstResults.Items[selected_index].Tag;
770 ListViewItem item = lstResults.Items[lstResults.SelectedIndices[i]];
771 this.AddToPatchList(item);
772 }
773 }
774 catch (Exception ex)
775 {
776 logger.Error.WriteLine(ex.ToString());
777 }
778 }
779
780 private void mnuItemRemoveResult_Click(object sender, EventArgs e)
781 {
782 if (!(lstPatchList.SelectedItems.Count > 0)) return;
783 //if (SearchArgs == null) return;
784 try
785 {
786 this.FreezeResultsUpdate();
787 for (int i = 0; i < lstPatchList.SelectedIndices.Count; i++)
788 {
789 //lstPatchList.ThawItem(lstPatchList.SelectedIndices[i]);
790 lstPatchList.Items[lstPatchList.SelectedIndices[i]].Remove();
791 }
792 this.ThawResultsUpdate();
793 }
794 catch (Exception ex)
795 {
796 Debug.WriteLine(ex.ToString());
797 }
798 }
799 private void PatchRange(bool SingleEntry)
800 {
801 //if (SearchArgs == null) return;
802 #region Patch Selected Address
803 // stop ResultsUpdate Thread
804 ResultsUpdateWorkerThread.CancelAsync();
805
806 List<ResultDataType> patch_list = new List<ResultDataType>();
807 List<int> SelectedIndexes = new List<int>();
808
809 if (SingleEntry)
810 {
811 SelectedIndexes.Add(lstPatchList.SelectedIndices[0]);
812 }
813 else
814 {
815 foreach (int index in lstPatchList.SelectedIndices)
816 {
817 SelectedIndexes.Add(index);
818 }
819 }
820 //PCSX2MemoryProvider provider = new PCSX2MemoryProvider(this.SearchPCSX2ProcessPID, resultslog);
821 foreach (int index in SelectedIndexes)
822 {
823 if (SingleEntry)
824 {
825 SearchPatcher patcher = null;
826 uint Address = 0;
827 ListViewItem item = lstPatchList.Items[index];
828 ResultDataType _result = (ResultDataType)item.Tag;
829 Address = Convert.ToUInt32(item.SubItems[col_Found_Address].Text, 16);
830 switch (_result.ValueType)
831 {
832 case SearchDataTypes._8bits:
833 if (_result.IsUnsigned)
834 {
835 byte value = Convert.ToByte(item.SubItems[col_Found_Value].Text, 16);
836 patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
837 timer_update_results.Enabled = false;
838 patcher.ShowDialog();
839 timer_update_results.Enabled = true;
840 PatchedValue_NeedsUpdate = true;
841 if (!chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy)
842 ResultsUpdateWorkerThread.RunWorkerAsync();
843 }
844 else
845 {
846 sbyte value = Convert.ToSByte(item.SubItems[col_Found_Value].Text, 16);
847 patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
848 timer_update_results.Enabled = false;
849 patcher.ShowDialog();
850 timer_update_results.Enabled = true;
851 PatchedValue_NeedsUpdate = true;
852 if (!chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy)
853 ResultsUpdateWorkerThread.RunWorkerAsync();
854 }
855 break;
856 case SearchDataTypes._16bits:
857 if (_result.IsUnsigned)
858 {
859 ushort value = Convert.ToUInt16(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 short value = Convert.ToInt16(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._32bits:
881 if (_result.IsUnsigned)
882 {
883 uint value = Convert.ToUInt32(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 int value = Convert.ToInt32(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._64bits:
905 if (_result.IsUnsigned)
906 {
907 ulong 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 long 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 }
929 }
930 else
931 {
932
933 ListViewItem item = lstPatchList.Items[index];
934 ResultDataType _result = (ResultDataType)item.Tag;
935 patch_list.Add(_result);
936 }
937 }
938
939 if (patch_list.Count > 0)
940 {
941 SearchRangePatcher rangePatcher = new SearchRangePatcher((IAcceptsProcessAndConfig)this, patch_list);
942 rangePatcher.ShowDialog();
943 }
944
945 #endregion
946 }
947 private void mnuItemPatchSelectedEntry_Click(object sender, EventArgs e)
948 {
949 if (!(lstPatchList.SelectedItems.Count == 1)) return;
950 PatchRange(true);
951 }
952
953 private void mnuItemPatchSelectedRange_Click(object sender, EventArgs e)
954 {
955 if (!(lstPatchList.SelectedItems.Count >= 1)) return;
956 PatchRange(false);
957 }
958
959 private void mnuItemFreezeSelectedPatches_Click(object sender, EventArgs e)
960 {
961 if (!(lstPatchList.SelectedItems.Count > 0)) return;
962 //if (SearchArgs == null) return;
963 try
964 {
965 lstPatchList.ProcessID = this.AcceptedProcess.Id;
966 this.FreezeResultsUpdate();
967 for (int i = 0; i < lstPatchList.SelectedIndices.Count; i++)
968 {
969 lstPatchList.FreezeItem(lstPatchList.SelectedIndices[i]);
970 }
971 // force thaw and update
972 this.ThawResultsUpdate();
973 this.Update();
974 }
975 catch (Exception ex)
976 {
977 Debug.WriteLine(ex.ToString());
978 }
979 }
980
981 private void mnuItemThawSelectedPatches_Click(object sender, EventArgs e)
982 {
983 if (!(lstPatchList.SelectedItems.Count > 0)) return;
984 //if (SearchArgs == null) return;
985 try
986 {
987 lstPatchList.ProcessID = this.AcceptedProcess.Id;
988 this.FreezeResultsUpdate();
989 for (int i = 0; i < lstPatchList.SelectedIndices.Count; i++)
990 {
991 lstPatchList.ThawItem(lstPatchList.SelectedIndices[i]);
992 }
993 // force thaw and update
994 this.ThawResultsUpdate();
995 this.Update();
996 }
997 catch (Exception ex)
998 {
999 Debug.WriteLine(ex.ToString());
1000 }
1001 }
1002
1003 private void SearchWorkerThread_DoWork(object sender, DoWorkEventArgs e)
1004 {
1005 Stopwatch st = new Stopwatch();
1006 st.Start();
1007
1008 Stopwatch st_first_search = new Stopwatch();
1009 Stopwatch st_nonrange_search = new Stopwatch();
1010 Stopwatch st_ranged_search = new Stopwatch();
1011
1012 e.Result = st;
1013 //List<ResultType<object>> tmp_Results = new List<ResultType<object>>();
1014 List<ResultType<object>> second_tmp_Results = new List<ResultType<object>>();
1015 const int ElementsBeforeDisplay = 100;
1016 //const double _UPDATE_DELAY = 1024.0;
1017 //double UPDATE_DELAY = 1;
1018 //tmp_Results = SearchArgs.Results.GetRange(0,SearchArgs.Results.Count);
1019 //SearchArgs.Results = null;
1020 //SearchArgs.Results.Clear();
1021 // log options
1022 SearchArgs.LogSearchOptions();
1023 uint STEP_SIZE = (uint)SearchArgs.DataType / 8;
1024 GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this);
1025 provider.OpenProvider();
1026 int bytes_read = 0;
1027
1028 byte[] buffered_mem = new byte[(MemoryRangeSize - MemoryRangeStart)]; // throws OutOfMemoryException if size is over 2G
1029 provider.ReadProcessMemoryAtOnce(MemoryRangeStart, (MemoryRangeSize - MemoryRangeStart), out bytes_read, out buffered_mem);
1030 provider.CloseProvider();
1031
1032 if (buffered_mem.Length == 0) { logger.Warn.WriteLine("Buffered Memory is Zero Length."); return; }
1033 MemoryStream ms = new MemoryStream(buffered_mem);
1034 BinaryReader r_ms = new BinaryReader(ms);
1035 logger.Debug.WriteLine(string.Format("Buffered Memory Size -> 0x{0:x8}", buffered_mem.Length));
1036 int Last_Whole_Percent_Done = 0;
1037
1038 #region First Search
1039 if (SearchArgs.IsFirstSearch)
1040 {
1041 st_first_search.Start();
1042 SearchArgs.Results.Clear();
1043 r_ms.BaseStream.Seek(0, SeekOrigin.Begin);
1044 List<ResultType<object>> results_list = new List<ResultType<object>>();
1045 for (uint i = 0; i < buffered_mem.Length; i += STEP_SIZE)
1046 {
1047 ResultType<object> _tmp_result = new ResultType<object>();
1048 switch (SearchArgs.DataType)
1049 {
1050 case SearchDataTypes._8bits:
1051 if (SearchArgs.IsUnsignedDataType) { _tmp_result = new ResultType<object>(i, r_ms.ReadByte()); }
1052 else { _tmp_result = new ResultType<object>(i, r_ms.ReadSByte()); } break;
1053 case SearchDataTypes._16bits:
1054 if (SearchArgs.IsUnsignedDataType) { _tmp_result = new ResultType<object>(i, r_ms.ReadUInt16()); }
1055 else { _tmp_result = new ResultType<object>(i,r_ms.ReadInt16()); } break;
1056 case SearchDataTypes._32bits:
1057 if (SearchArgs.IsUnsignedDataType) { _tmp_result = new ResultType<object>(i, r_ms.ReadUInt32()); }
1058 else { _tmp_result = new ResultType<object>(i, r_ms.ReadInt32()); } break;
1059 case SearchDataTypes._64bits:
1060 if (SearchArgs.IsUnsignedDataType) { _tmp_result = new ResultType<object>(i, r_ms.ReadUInt64()); }
1061 else { _tmp_result = new ResultType<object>(i, r_ms.ReadInt64()); } break;
1062 }
1063 results_list.Add(_tmp_result);
1064 double double_percent_done = 100.0 * (double)((double)i / (double)buffered_mem.Length);
1065 int int_percent_done = (int)double_percent_done;
1066 if (int_percent_done != Last_Whole_Percent_Done && i % ElementsBeforeDisplay == 0)
1067 {
1068 resultsprogress.Value = int_percent_done;
1069 resultsprogress.Message = string.Format(" -> Reading Address: 0x{0:x8}", i);
1070 Last_Whole_Percent_Done = int_percent_done;
1071 //Application.DoEvents();
1072 }
1073
1074 if (SearchWorkerThread.CancellationPending == true)
1075 {
1076 e.Cancel = true;
1077 return;
1078 }
1079 //Application.DoEvents();
1080 }
1081 SearchArgs.Results.AddRange(results_list);
1082 resultsprogress.Value = 100;
1083 resultsprogress.Message = "";
1084 //Application.DoEvents();
1085 st_first_search.Stop();
1086 logger.Profiler.WriteLine("First search took a total of {0} seconds to complete.", st_first_search.Elapsed.TotalSeconds);
1087 }
1088 #endregion
1089
1090 #region Subsequent Searches
1091 r_ms.BaseStream.Seek(0, SeekOrigin.Begin);
1092
1093
1094 // hack to help with OutOfMemory Exceptions (OldValue and Equal compare will always add all found search results)
1095 bool NeedToCompare = true;
1096 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue &&
1097 SearchArgs.CompareType == SearchCompareTypes.Equal &&
1098 SearchArgs.IsFirstSearch)
1099 {
1100 NeedToCompare = false;
1101 second_tmp_Results = null; // Free Memory
1102 }
1103
1104 if (NeedToCompare)
1105 {
1106 if (SearchArgs.CompareType != SearchCompareTypes.Between && SearchArgs.CompareType != SearchCompareTypes.NotBetween)
1107 {
1108 #region Non-Range Searches
1109 st_nonrange_search.Start();
1110 //second_tmp_Results = new List<ResultType<object>>(SearchArgs.Results.Count * 1024);
1111 ////second_tmp_Results.c
1112 for (int i = 0; i < SearchArgs.Results.Count; i += 1)
1113 {
1114 uint address = SearchArgs.Results[i].Address;
1115 if (MemoryRangeStart > 0 && !SearchArgs.IsFirstSearch) { address = address - MemoryRangeStart; }
1116 r_ms.BaseStream.Seek(address, SeekOrigin.Begin);
1117 switch (SearchArgs.DataType)
1118 {
1119 #region Comparer Support
1120 #region case SearchDataTypes._8bits:
1121 case SearchDataTypes._8bits:
1122 if (SearchArgs.IsUnsignedDataType)
1123 {
1124 byte lookup_value = r_ms.ReadByte();
1125 _8bit_unsigned_comparer_ comparer = new _8bit_unsigned_comparer_(SearchArgs, address);
1126 byte value = 0;
1127 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1128 {
1129 value = Convert.ToByte(SearchArgs.Results[i].Value);
1130 comparer.Value = value;
1131 }
1132 else
1133 {
1134 value = Convert.ToByte(SearchArgs.CompareStartValue);
1135 comparer.Value = value;
1136 }
1137 if (comparer.Compare(lookup_value, value))
1138 {
1139 //ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
1140 //second_tmp_Results.Add(_tmp_result);
1141 //_tmp_result = null; // free memory
1142 //SearchArgs.Results.RemoveAt(i);
1143 SearchArgs.Results[i].Value = comparer.Value;
1144 second_tmp_Results.Add(SearchArgs.Results[i]);
1145 }
1146 comparer = null; // free memory
1147 }
1148 else
1149 {
1150 sbyte lookup_value = r_ms.ReadSByte();
1151 _8bit_signed_comparer_ comparer = new _8bit_signed_comparer_(SearchArgs, address);
1152 sbyte value = 0;
1153 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1154 {
1155 value = Convert.ToSByte(SearchArgs.Results[i].Value);
1156 }
1157 else
1158 {
1159 value = Convert.ToSByte(SearchArgs.CompareStartValue);
1160 }
1161 if (comparer.Compare(lookup_value, value))
1162 {
1163 //ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
1164 //second_tmp_Results.Add(_tmp_result);
1165 //_tmp_result = null; // free memory
1166 //SearchArgs.Results.RemoveAt(i);
1167 SearchArgs.Results[i].Value = comparer.Value;
1168 second_tmp_Results.Add(SearchArgs.Results[i]);
1169 }
1170 comparer = null; // free memory
1171 }
1172 break;
1173 #endregion
1174 #region case SearchDataTypes._16bits:
1175 case SearchDataTypes._16bits:
1176 if (SearchArgs.IsUnsignedDataType)
1177 {
1178 ushort lookup_value = r_ms.ReadUInt16();
1179 _16bit_unsigned_comparer_ comparer = new _16bit_unsigned_comparer_(SearchArgs, address);
1180 ushort value = 0;
1181 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1182 {
1183 value = Convert.ToUInt16(SearchArgs.Results[i].Value);
1184 comparer.Value = value;
1185 }
1186 else
1187 {
1188 value = Convert.ToUInt16(SearchArgs.CompareStartValue);
1189 comparer.Value = value;
1190 }
1191 if (comparer.Compare(lookup_value, value))
1192 {
1193 //ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
1194 //second_tmp_Results.Add(_tmp_result);
1195 //_tmp_result = null; // free memory
1196 //SearchArgs.Results.RemoveAt(i);
1197 SearchArgs.Results[i].Value = comparer.Value;
1198 second_tmp_Results.Add(SearchArgs.Results[i]);
1199 }
1200 comparer = null; // free memory
1201 }
1202 else
1203 {
1204 short lookup_value = r_ms.ReadInt16();
1205 _16bit_signed_comparer_ comparer = new _16bit_signed_comparer_(SearchArgs, address);
1206 short value = 0;
1207 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1208 {
1209 value = Convert.ToInt16(SearchArgs.Results[i].Value);
1210 }
1211 else
1212 {
1213 value = Convert.ToInt16(SearchArgs.CompareStartValue);
1214 }
1215 if (comparer.Compare(lookup_value, value))
1216 {
1217 //ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
1218 //second_tmp_Results.Add(_tmp_result);
1219 //_tmp_result = null; // free memory
1220 //SearchArgs.Results.RemoveAt(i);
1221 SearchArgs.Results[i].Value = comparer.Value;
1222 second_tmp_Results.Add(SearchArgs.Results[i]);
1223 }
1224 comparer = null; // free memory
1225 }
1226 break;
1227 #endregion
1228 #region case SearchDataTypes._32bits:
1229 case SearchDataTypes._32bits:
1230 if (SearchArgs.IsUnsignedDataType)
1231 {
1232 uint lookup_value = r_ms.ReadUInt32();
1233 _32bit_unsigned_comparer_ comparer = new _32bit_unsigned_comparer_(SearchArgs, address);
1234 uint value = 0;
1235 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1236 {
1237 value = Convert.ToUInt32(SearchArgs.Results[i].Value);
1238 comparer.Value = value;
1239 }
1240 else
1241 {
1242 value = Convert.ToUInt32(SearchArgs.CompareStartValue);
1243 comparer.Value = value;
1244 }
1245 if (comparer.Compare(lookup_value, value))
1246 {
1247 //ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
1248 //second_tmp_Results.Add(_tmp_result);
1249 //_tmp_result = null; // free memory
1250 //SearchArgs.Results.RemoveAt(i);
1251 SearchArgs.Results[i].Value = comparer.Value;
1252 second_tmp_Results.Add(SearchArgs.Results[i]);
1253 }
1254 comparer = null; // free memory
1255 }
1256 else
1257 {
1258 int lookup_value = r_ms.ReadInt32();
1259 _32bit_signed_comparer_ comparer = new _32bit_signed_comparer_(SearchArgs, address);
1260 int value = 0;
1261 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1262 {
1263 value = Convert.ToInt32(SearchArgs.Results[i].Value);
1264 }
1265 else
1266 {
1267 value = Convert.ToInt32(SearchArgs.CompareStartValue);
1268 }
1269 if (comparer.Compare(lookup_value, value))
1270 {
1271 //ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
1272 //second_tmp_Results.Add(_tmp_result);
1273 //_tmp_result = null; // free memory
1274 //SearchArgs.Results.RemoveAt(i);
1275 SearchArgs.Results[i].Value = comparer.Value;
1276 second_tmp_Results.Add(SearchArgs.Results[i]);
1277 }
1278 comparer = null; // free memory
1279 }
1280 break;
1281 #endregion
1282 #region case SearchDataTypes._64bits:
1283 case SearchDataTypes._64bits:
1284 if (SearchArgs.IsUnsignedDataType)
1285 {
1286 ulong lookup_value = r_ms.ReadUInt64();
1287 _64bit_unsigned_comparer_ comparer = new _64bit_unsigned_comparer_(SearchArgs, address);
1288 ulong value = 0;
1289 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1290 {
1291 value = Convert.ToUInt64(SearchArgs.Results[i].Value);
1292 comparer.Value = value;
1293 }
1294 else
1295 {
1296 value = Convert.ToUInt64(SearchArgs.CompareStartValue);
1297 comparer.Value = value;
1298 }
1299 if (comparer.Compare(lookup_value, value))
1300 {
1301 //ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
1302 //second_tmp_Results.Add(_tmp_result);
1303 //_tmp_result = null; // free memory
1304 //SearchArgs.Results.RemoveAt(i);
1305 SearchArgs.Results[i].Value = comparer.Value;
1306 second_tmp_Results.Add(SearchArgs.Results[i]);
1307 }
1308 comparer = null; // free memory
1309 }
1310 else
1311 {
1312 long lookup_value = r_ms.ReadInt64();
1313 _64bit_signed_comparer_ comparer = new _64bit_signed_comparer_(SearchArgs, address);
1314 long value = 0;
1315 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1316 {
1317 value = Convert.ToInt64(SearchArgs.Results[i].Value);
1318 }
1319 else
1320 {
1321 value = Convert.ToInt64(SearchArgs.CompareStartValue);
1322 }
1323 if (comparer.Compare(lookup_value, value))
1324 {
1325 //ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
1326 //second_tmp_Results.Add(_tmp_result);
1327 //_tmp_result = null; // free memory
1328 //SearchArgs.Results.RemoveAt(i);
1329 SearchArgs.Results[i].Value = comparer.Value;
1330 second_tmp_Results.Add(SearchArgs.Results[i]);
1331 }
1332 comparer = null; // free memory
1333 }
1334 break;
1335 #endregion
1336 #endregion
1337 }
1338
1339 double double_percent_done = 100.0 * (double)((double)i / (double)SearchArgs.Results.Count);
1340 int int_percent_done = (int)double_percent_done;
1341 if (int_percent_done != Last_Whole_Percent_Done && i % ElementsBeforeDisplay == 0)
1342 {
1343 resultsprogress.Value = int_percent_done;
1344 resultsprogress.Message = string.Format(" -> Reading Address: 0x{0:x8}", i);
1345 Last_Whole_Percent_Done = int_percent_done;
1346 //Application.DoEvents();
1347 }
1348
1349 }
1350 st_nonrange_search.Stop();
1351 logger.Profiler.WriteLine("Non-Ranged search took a total of {0} seconds to complete.", st_nonrange_search.Elapsed.TotalSeconds);
1352 #endregion
1353 }
1354 #region Ranged Searches
1355 #if !DONOT_HAVE_RANGED_SEARCH_SUPPORT
1356 if (SearchArgs.CompareType == SearchCompareTypes.Between || SearchArgs.CompareType == SearchCompareTypes.NotBetween)
1357 {
1358 st_ranged_search.Start();
1359 object start, end;
1360
1361 start = SearchArgs.CompareStartValue;
1362 end = SearchArgs.CompareEndValue;
1363 for (int i = 0; i < SearchArgs.Results.Count; i += 1)
1364 {
1365 uint address = SearchArgs.Results[i].Address;
1366 if (MemoryRangeStart > 0 && !SearchArgs.IsFirstSearch) { address = address - MemoryRangeStart; }
1367 r_ms.BaseStream.Seek(address, SeekOrigin.Begin);
1368 if (SearchArgs.CompareType == SearchCompareTypes.Between)
1369 {
1370 InRangeComparer comparer = new InRangeComparer(address, 0);
1371 if (comparer.Compare(start, end, SearchArgs.DataType, SearchArgs.IsUnsignedDataType, r_ms))
1372 {
1373 SearchArgs.Results[i].Value = comparer.Value;
1374 second_tmp_Results.Add(SearchArgs.Results[i]);
1375 }
1376 comparer = null;
1377 }
1378 else if (SearchArgs.CompareType == SearchCompareTypes.NotBetween)
1379 {
1380 NotInRangeComparer comparer = new NotInRangeComparer(address, 0);
1381 if (comparer.Compare(start, end, SearchArgs.DataType, SearchArgs.IsUnsignedDataType, r_ms))
1382 {
1383 SearchArgs.Results[i].Value = comparer.Value;
1384 second_tmp_Results.Add(SearchArgs.Results[i]);
1385 }
1386 comparer = null;
1387 }
1388 else
1389 {
1390 throw new InvalidOperationException("Encounted unkown range search type: " + SearchArgs.CompareType);
1391 }
1392 double double_percent_done = 100.0 * (double)((double)i / (double)SearchArgs.Results.Count);
1393 int int_percent_done = (int)double_percent_done;
1394 if (int_percent_done != Last_Whole_Percent_Done && i % ElementsBeforeDisplay == 0)
1395 {
1396 resultsprogress.Value = int_percent_done;
1397 resultsprogress.Message = string.Format(" -> Reading Address: 0x{0:x8}", i);
1398 Last_Whole_Percent_Done = int_percent_done;
1399 //Application.DoEvents();
1400 }
1401 }
1402 st_ranged_search.Stop();
1403 logger.Profiler.WriteLine("Ranged search took a total of {0} seconds to complete.", st_ranged_search.Elapsed.TotalSeconds);
1404 }
1405 #endif
1406 #endregion
1407
1408 }
1409 #endregion
1410 // leave SearchArgs.Results alone, if false
1411 if (NeedToCompare)
1412 {
1413 SearchArgs.Results = second_tmp_Results.GetRange(0, second_tmp_Results.Count);
1414 // fix addresses when memory start is not zero
1415 if (MemoryRangeStart > 0 && SearchArgs.IsFirstSearch) { for (int i = 0; i < SearchArgs.Results.Count; i++) { SearchArgs.Results[i].Address = SearchArgs.Results[i].Address + MemoryRangeStart; } }
1416 second_tmp_Results = null; // free memory
1417 }
1418
1419 r_ms.Close();
1420 }
1421
1422 private void SearchWorkerThread_ProgressChanged(object sender, ProgressChangedEventArgs e)
1423 {
1424 //if (SearchArgs.ProgressLogger != null)
1425 //{
1426 // resultsprogress.Value = e.ProgressPercentage;
1427 // //Application.DoEvents();
1428 //}
1429 }
1430
1431 private void SearchWorkerThread_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
1432 {
1433 if (!e.Cancelled)
1434 {
1435 Stopwatch st = (e.Result as Stopwatch);
1436 st.Stop();
1437 logger.Profiler.WriteLine("Search took {0} seconds, overall, to complete.", st.Elapsed.TotalSeconds);
1438 }
1439
1440 resultsprogress.Value = 100;
1441 logger.Debug.WriteLine(string.Format("Results Count -> 0x{0:x8}", SearchArgs.Results.Count));
1442
1443 if (SearchArgs.Results.Count == 1) // debug message for 1 result using 32bit unsigned
1444 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));
1445
1446 logger.Info.WriteLine(string.Format("Found 0x{0:x8} results", SearchArgs.Results.Count));
1447
1448 if (SearchArgs.Results.Count <= MIN_NUMBER_OF_RESULTS_BEFORE_DISPLAY)
1449 {
1450 lstResults.Items.Clear();
1451 List<ResultItem> items = new List<ResultItem>();
1452 for (int i = 0; i < SearchArgs.Results.Count; i++)
1453 {
1454 ResultItem item = new ResultItem(0, false);
1455 //item.Text = string.Format("0x{0:x8}", SearchArgs.Results[i].Address);
1456 //item.SubItems.Add(string.Format("0x{0:x8}", SearchArgs.Results[i].Address));
1457 switch (SearchArgs.DataType)
1458 {
1459
1460 case SearchDataTypes._8bits:
1461 if (SearchArgs.IsUnsignedDataType) { item = new ResultItem(SearchArgs.Results[i].Address, false, Convert.ToByte(SearchArgs.Results[i].Value)); }
1462 else { item = new ResultItem(SearchArgs.Results[i].Address, false, Convert.ToSByte(SearchArgs.Results[i].Value)); }
1463 break;
1464 case SearchDataTypes._16bits:
1465 if (SearchArgs.IsUnsignedDataType) { item = new ResultItem(SearchArgs.Results[i].Address, false, Convert.ToUInt16(SearchArgs.Results[i].Value)); }
1466 else { item = new ResultItem(SearchArgs.Results[i].Address, false, Convert.ToInt16(SearchArgs.Results[i].Value)); }
1467 break;
1468 case SearchDataTypes._32bits:
1469 if (SearchArgs.IsUnsignedDataType) { item = new ResultItem(SearchArgs.Results[i].Address, false, Convert.ToUInt32(SearchArgs.Results[i].Value)); }
1470 else { item = new ResultItem(SearchArgs.Results[i].Address, false, Convert.ToInt32(SearchArgs.Results[i].Value)); }
1471 break;
1472 case SearchDataTypes._64bits:
1473 if (SearchArgs.IsUnsignedDataType) { item = new ResultItem(SearchArgs.Results[i].Address, false, Convert.ToUInt64(SearchArgs.Results[i].Value)); }
1474 else { item = new ResultItem(SearchArgs.Results[i].Address, false, Convert.ToInt64(SearchArgs.Results[i].Value)); }
1475 break;
1476 }
1477
1478 if (!items.Contains(item))
1479 items.Add(item);
1480 }
1481 lstResults.Items.AddRange(items.ToArray());
1482 }
1483
1484 this.DoSearchDoneSpecific();
1485 //System.Threading.Thread.Sleep(100);
1486 //if (_SEARCH_MODE != SearchMode.SEARCH_MODE_NORMAL_WITH_JOKER)
1487 this.ThawResultsUpdate();
1488 Application.DoEvents();
1489 }
1490 private void DoSearchDoneSpecific()
1491 {
1492 SearchWorkerThread.CancelAsync();
1493 if (lstResults.Items.Count > 0) { timer_update_results.Enabled = true; }
1494 else { timer_update_results.Enabled = false; }
1495
1496 search_progress_updater.Enabled = false;
1497
1498 btnCancel.Enabled = false;
1499 btnReset.Enabled = true;
1500 btnSearch.Enabled = true;
1501 grpCompareType.Enabled = true;
1502 grpCompareValue.Enabled = true;
1503 resultsprogress.Value = 0;
1504 resultsprogress.Message = "";
1505 grpDataType.Enabled = false;
1506 // resume process on reset, incase it was suspended
1507 ThreadControl.ResumeProcess(this.AcceptedProcess.Id);
1508 //Application.DoEvents();
1509 this.Refresh();
1510 }
1511
1512 private void DoCancelSpecific()
1513 {
1514 this.DoSearchDoneSpecific();
1515 }
1516 private void DoResetSpecific()
1517 {
1518 this.DoCancelSpecific();
1519 IsFirstSearch = true;
1520 grpDataType.Enabled = true;
1521 }
1522 private void search_progress_updater_Tick(object sender, EventArgs e)
1523 {
1524 if ((this.AcceptedProcess ==null) || Process.GetProcessById(this.AcceptedProcess.Id) == null)
1525 {
1526 SearchWorkerThread.CancelAsync();
1527 //JokerSearchWorker.CancelAsync();
1528 ResultsUpdateWorkerThread.CancelAsync();
1529 }
1530 }
1531
1532 #region Search Button
1533 private void btnSearch_Click(object sender, EventArgs e)
1534 {
1535 this.SearchInProgess = true;
1536 //btnCancel.Enabled = true;
1537 //btnReset.Enabled = false;
1538 //btnSearch.Enabled = false;
1539 this.FreezeResultsUpdate();
1540 this.handle_btnSearch_Click();
1541 }
1542 private void handle_btnSearch_Click()
1543 {
1544 //this.FreezeResultsUpdate();
1545 lstResults.Items.Clear();
1546
1547 if (lstResults.Items.Count > 0) { timer_update_results.Enabled = true; }
1548 else { timer_update_results.Enabled = false; }
1549
1550
1551 resultsprogress.Value = 0;
1552 bool _is_unsigned = chkUnsigned.Checked;
1553 SearchType search_type = new SearchType();
1554 SearchDataTypes _data_type = new SearchDataTypes();
1555 SearchCompareTypes _compare_type = new SearchCompareTypes();
1556 CompareValueTypes _compare_value_type = new CompareValueTypes();
1557 object start_value = 0;
1558 object end_value = 0;
1559 // get datatype
1560 if (radio_8bits.Checked) { _data_type = SearchDataTypes._8bits; }
1561 else if (radio_16bits.Checked) { _data_type = SearchDataTypes._16bits; }
1562 else if (radio_32bits.Checked) { _data_type = SearchDataTypes._32bits; }
1563 else if (radio_64bits.Checked) { _data_type = SearchDataTypes._64bits; }
1564 else { logger.Error.WriteLine("Could not determine search data type bit size. (was not 8/16/32/or 64bits)"); }
1565 // get compare type
1566 if (radiocompare_equal.Checked) { _compare_type = SearchCompareTypes.Equal; }
1567 else if (radiocompare_greaterthan.Checked) { _compare_type = SearchCompareTypes.GreaterThan; }
1568 else if (radiocompare_lessthan.Checked) { _compare_type = SearchCompareTypes.LessThan; }
1569 else if (radiocompare_greaterthan_orequal.Checked) { _compare_type = SearchCompareTypes.GreaterThanOrEqual; }
1570 else if (radiocompare_lessthan_orequal.Checked) { _compare_type = SearchCompareTypes.LessThanOrEqual; }
1571 else if (radiocompare_notequal.Checked) { _compare_type = SearchCompareTypes.NotEqual; }
1572 else if (radiocompare_between.Checked) { _compare_type = SearchCompareTypes.Between; }
1573 else if (radiocompare_notbetween.Checked) { _compare_type = SearchCompareTypes.NotBetween; }
1574 else { logger.Error.WriteLine("Could not determine search comparison type. (was not == > < >= <= != <> or !<>)"); }
1575 // get compare valure type
1576 if (radio_oldvalue.Checked) { _compare_value_type = CompareValueTypes.OldValue; }
1577 else if (radio_specificvalue.Checked) { _compare_value_type = CompareValueTypes.SpecificValue; }
1578 else { logger.Error.WriteLine("Could not determine search comparison type. (was not old or specific value"); }
1579
1580 if (_compare_value_type == CompareValueTypes.SpecificValue || (_compare_type == SearchCompareTypes.Between || _compare_type == SearchCompareTypes.NotBetween))
1581 {
1582
1583 switch (_data_type)
1584 {
1585 case SearchDataTypes._8bits:
1586 if (_is_unsigned) { start_value = txtStartAddr.ToByte(); }
1587 else { start_value = txtStartAddr.ToSByte(); }
1588 break;
1589 case SearchDataTypes._16bits:
1590 if (_is_unsigned) { start_value = txtStartAddr.ToUInt16(); }
1591 else { start_value = txtStartAddr.ToInt16(); }
1592 break;
1593 case SearchDataTypes._32bits:
1594 if (_is_unsigned) { start_value = txtStartAddr.ToUInt32(); }
1595 else { start_value = txtStartAddr.ToInt32(); }
1596 break;
1597 case SearchDataTypes._64bits:
1598 if (_is_unsigned) { start_value = txtStartAddr.ToUInt64(); }
1599 else { start_value = txtStartAddr.ToInt64(); }
1600 break;
1601 default: throw new InvalidOperationException("In SearchType(): Encounterd an Unkown Search Data Type.");
1602 }
1603 }
1604 if (_compare_type == SearchCompareTypes.Between || _compare_type == SearchCompareTypes.NotBetween)
1605 {
1606 switch (_data_type)
1607 {
1608 case SearchDataTypes._8bits:
1609 if (_is_unsigned) { end_value = txtEndAddr.ToByte(); }
1610 else { end_value = txtEndAddr.ToSByte(); }
1611 break;
1612 case SearchDataTypes._16bits:
1613 if (_is_unsigned) { end_value = txtEndAddr.ToUInt16(); }
1614 else { end_value = txtEndAddr.ToInt16(); }
1615 break;
1616 case SearchDataTypes._32bits:
1617 if (_is_unsigned) { end_value = txtEndAddr.ToUInt32(); }
1618 else { end_value = txtEndAddr.ToInt32(); }
1619 break;
1620 case SearchDataTypes._64bits:
1621 if (_is_unsigned) { end_value = txtEndAddr.ToUInt64(); }
1622 else { end_value = txtEndAddr.ToInt64(); }
1623 break;
1624 default: throw new InvalidOperationException("In SearchType(): Encounterd an Unkown Search Data Type.");
1625 }
1626 }
1627
1628 search_type = new SearchType(_data_type, _is_unsigned, _compare_type, _compare_value_type, start_value, end_value, resultsprogress);
1629
1630 //search_type.LogSearchOptions();
1631
1632 search_type.IsFirstSearch = IsFirstSearch;
1633
1634
1635
1636 DoSearch(search_type);
1637 IsFirstSearch = false;
1638 }
1639 private void DoSearch(SearchType args)
1640 {
1641 if (!args.IsFirstSearch && SearchArgs != null)
1642 {
1643 //args.Results.AddRange(SearchArgs.Results.ToArray());
1644 args.Results = SearchArgs.Results;
1645 }
1646 SearchArgs = args;
1647 #if DONOT_HAVE_RANGED_SEARCH_SUPPORT
1648 if (SearchArgs.CompareType == SearchCompareTypes.Between || SearchArgs.CompareType == SearchCompareTypes.NotBetween)
1649 {
1650 throw new NotImplementedException("Between and Not Between Range searches have not been implemented.");
1651 }
1652 #endif
1653 search_progress_updater.Enabled = true;
1654 //padPluginSelector.Enabled = false;
1655 //gsPluginSelector.Enabled = false;
1656 btnReset.Enabled = false;
1657 btnSearch.Enabled = false;
1658 btnCancel.Enabled = true;
1659 grpDataType.Enabled = false;
1660 grpCompareType.Enabled = false;
1661 grpCompareValue.Enabled = false;
1662 this.Refresh();
1663 Application.DoEvents();
1664 SearchWorkerThread.RunWorkerAsync();
1665 }
1666 #endregion
1667 private void btnReset_Click(object sender, EventArgs e)
1668 {
1669 this.SearchInProgess = false;
1670 //btnSearch.Enabled = true;
1671 //btnCancel.Enabled = false;
1672 this.DoResetSpecific();
1673 lstResults.Items.Clear();
1674 try { SearchArgs.Results = new List<ResultType<object>>(); }
1675 catch { }
1676 }
1677
1678 private void btnCancel_Click(object sender, EventArgs e)
1679 {
1680 this.SearchInProgess = false;
1681 //btnCancel.Enabled = false;
1682 //btnSearch.Enabled = true;
1683 //btnReset.Enabled = true;
1684 this.DoCancelSpecific();
1685 }
1686
1687 private void mnuItemPatchListViewMemoryRegion_Click(object sender, EventArgs e)
1688 {
1689 List<ResultDataType> patch_list = new List<ResultDataType>();
1690 List<int> SelectedIndexes = new List<int>();
1691 foreach (int index in lstPatchList.SelectedIndices) { SelectedIndexes.Add(index); }
1692 foreach (int index in SelectedIndexes)
1693 {
1694 ListViewItem item = lstPatchList.Items[index];
1695 ResultDataType rdt = (ResultDataType)item.Tag;
1696 ViewMemoryRegion(rdt);
1697 break; // only get the fist item
1698 }
1699 }
1700
1701 private void mnuItemResultsListViewMemoryRegion_Click(object sender, EventArgs e)
1702 {
1703 List<ResultDataType> patch_list = new List<ResultDataType>();
1704 List<int> SelectedIndexes = new List<int>();
1705 foreach (int index in lstResults.SelectedIndices) { SelectedIndexes.Add(index); }
1706 foreach (int index in SelectedIndexes)
1707 {
1708 ListViewItem item = lstResults.Items[index];
1709 ResultDataType rdt = (ResultDataType)item.Tag;
1710 ViewMemoryRegion(rdt);
1711 break; // only get the fist item
1712 }
1713 }
1714 private void ViewMemoryRegion(ResultDataType rdt)
1715 {
1716 if (OnBrowseMemoryRegion != null)
1717 OnBrowseMemoryRegion(new BrowseMemoryRegionEvent(this, rdt.Address));
1718 }
1719
1720 private void mnuAddedResults_Opening(object sender, CancelEventArgs e)
1721 {
1722 if (!(lstPatchList.Items.Count > 0)) { mnuItemRemoveResult.Visible = false; e.Cancel = true; }
1723 if (!(lstPatchList.Items.Count > 0)) { mnuItemPatchSelectedEntry.Visible = false; e.Cancel = true; }
1724 if (e.Cancel) return;
1725 if (lstPatchList.Items.Count > 0) mnuItemRemoveResult.Visible = true;
1726 if (lstPatchList.Items.Count > 0) mnuItemPatchSelectedEntry.Visible = true;
1727
1728 if (!(lstPatchList.Items.Count > 0)) { mnuItemFreezeSelectedPatches.Visible = false; e.Cancel = true; }
1729 if (!(lstPatchList.Items.Count > 0)) { mnuItemThawSelectedPatches.Visible = false; e.Cancel = true; }
1730 if (e.Cancel) return;
1731
1732 if (lstPatchList.Items.Count > 0) mnuItemFreezeSelectedPatches.Visible = true;
1733 if (lstPatchList.Items.Count > 0) mnuItemThawSelectedPatches.Visible = true;
1734
1735 if (lstPatchList.SelectedItems.Count == 0) e.Cancel = true;
1736 if (e.Cancel) return;
1737
1738 }
1739
1740 private void mnuResults_Opening(object sender, CancelEventArgs e)
1741 {
1742 if (!(lstResults.Items.Count > 0)) e.Cancel = true;
1743 if (lstResults.SelectedItems.Count == 0) e.Cancel = true;
1744 if (SearchArgs == null) e.Cancel = true;
1745 if (e.Cancel) return;
1746 }
1747
1748 private void chkMemoryRangeExpertMode_CheckedChanged(object sender, EventArgs e)
1749 {
1750 txtMemoryRangeStart.ReadOnly = !chkMemoryRangeExpertMode.Checked;
1751 txtMemoryRangeSize.ReadOnly = !chkMemoryRangeExpertMode.Checked;
1752 }
1753
1754 private void txtMemoryRangeStart_ValueChanged(object sender, ValueChangedEventArgs e) { this.MemoryRangeStart = Convert.ToUInt32(e.NewValue); }
1755 private void txtMemoryRangeSize_ValueChanged(object sender, ValueChangedEventArgs e) { this.MemoryRangeSize = Convert.ToUInt32(e.NewValue); }
1756
1757 }
1758 }

  ViewVC Help
Powered by ViewVC 1.1.22