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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 356 - (show annotations) (download)
Sat Jun 9 22:23:15 2012 UTC (8 years, 4 months ago) by william
File size: 85720 byte(s)

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

  ViewVC Help
Powered by ViewVC 1.1.22