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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 389 - (show annotations) (download)
Tue Jun 19 12:47:26 2012 UTC (8 years, 4 months ago) by william
File size: 87438 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 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 e.Result = st;
1008 //List<ResultType<object>> tmp_Results = new List<ResultType<object>>();
1009 List<ResultType<object>> second_tmp_Results = new List<ResultType<object>>();
1010 const int ElementsBeforeDisplay = 100;
1011 //const double _UPDATE_DELAY = 1024.0;
1012 //double UPDATE_DELAY = 1;
1013 //tmp_Results = SearchArgs.Results.GetRange(0,SearchArgs.Results.Count);
1014 //SearchArgs.Results = null;
1015 //SearchArgs.Results.Clear();
1016 // log options
1017 SearchArgs.LogSearchOptions();
1018 uint STEP_SIZE = (uint)SearchArgs.DataType / 8;
1019 GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this);
1020 provider.OpenProvider();
1021 int bytes_read = 0;
1022
1023 byte[] buffered_mem = new byte[(MemoryRangeSize - MemoryRangeStart)]; // throws OutOfMemoryException if size is over 2G
1024 provider.ReadProcessMemoryAtOnce(MemoryRangeStart, (MemoryRangeSize - MemoryRangeStart), out bytes_read, out buffered_mem);
1025 provider.CloseProvider();
1026
1027 if (buffered_mem.Length == 0) { logger.Warn.WriteLine("Buffered Memory is Zero Length."); return; }
1028 //MemoryStream ms = new MemoryStream(buffered_mem);
1029 //BinaryReader r_ms = new BinaryReader(ms);
1030 logger.Debug.WriteLine(string.Format("Buffered Memory Size -> 0x{0:x8}", buffered_mem.Length));
1031 int Last_Whole_Percent_Done = 0;
1032
1033 #region First Search
1034 if (SearchArgs.IsFirstSearch)
1035 {
1036 SearchArgs.Results.Clear();
1037 //r_ms.BaseStream.Seek(0, SeekOrigin.Begin);
1038 for (uint i = 0; i < buffered_mem.Length; i += STEP_SIZE)
1039 {
1040 ResultType<object> _tmp_result = new ResultType<object>();
1041 switch (SearchArgs.DataType)
1042 {
1043 case SearchDataTypes._8bits:
1044 if (SearchArgs.IsUnsignedDataType) { _tmp_result = new ResultType<object>(i, buffered_mem[i]); }
1045 else { _tmp_result = new ResultType<object>(i, buffered_mem[i]); } break;
1046 case SearchDataTypes._16bits:
1047 if (SearchArgs.IsUnsignedDataType) { _tmp_result = new ResultType<object>(i, BitConverter.ToUInt16(buffered_mem,(int)i)); }
1048 else { _tmp_result = new ResultType<object>(i,BitConverter.ToInt16(buffered_mem,(int)i)); } break;
1049 case SearchDataTypes._32bits:
1050 if (SearchArgs.IsUnsignedDataType) { _tmp_result = new ResultType<object>(i, BitConverter.ToUInt32(buffered_mem,(int)i)); }
1051 else { _tmp_result = new ResultType<object>(i, BitConverter.ToInt32(buffered_mem,(int)i)); } break;
1052 case SearchDataTypes._64bits:
1053 if (SearchArgs.IsUnsignedDataType) { _tmp_result = new ResultType<object>(i, BitConverter.ToUInt64(buffered_mem,(int)i)); }
1054 else { _tmp_result = new ResultType<object>(i, BitConverter.ToInt64(buffered_mem,(int)i)); } break;
1055 }
1056 SearchArgs.Results.Add(_tmp_result);
1057 double double_percent_done = 100.0 * (double)((double)i / (double)buffered_mem.Length);
1058 int int_percent_done = (int)double_percent_done;
1059 if (int_percent_done != Last_Whole_Percent_Done && i % ElementsBeforeDisplay == 0)
1060 {
1061 resultsprogress.Value = int_percent_done;
1062 //resultsprogress.Message = string.Format(" -> Reading Address: 0x{0:x8}", i);
1063 Last_Whole_Percent_Done = int_percent_done;
1064 //Application.DoEvents();
1065 }
1066
1067 if (SearchWorkerThread.CancellationPending == true)
1068 {
1069 e.Cancel = true;
1070 return;
1071 }
1072 Application.DoEvents();
1073 }
1074 resultsprogress.Value = 100;
1075 resultsprogress.Message = "";
1076 //Application.DoEvents();
1077
1078 }
1079 #endregion
1080
1081 #region Subsequent Searches
1082 //r_ms.BaseStream.Seek(0, SeekOrigin.Begin);
1083
1084
1085 // hack to help with OutOfMemory Exceptions (OldValue and Equal compare will always add all found search results)
1086 bool NeedToCompare = true;
1087 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue &&
1088 SearchArgs.CompareType == SearchCompareTypes.Equal &&
1089 SearchArgs.IsFirstSearch)
1090 {
1091 NeedToCompare = false;
1092 second_tmp_Results = null; // Free Memory
1093 }
1094
1095 if (NeedToCompare)
1096 {
1097 if (SearchArgs.CompareType != SearchCompareTypes.Between && SearchArgs.CompareType != SearchCompareTypes.NotBetween)
1098 {
1099 #region Non-Range Searches
1100 //second_tmp_Results = new List<ResultType<object>>(SearchArgs.Results.Count * 1024);
1101 ////second_tmp_Results.c
1102 for (int i = 0; i < SearchArgs.Results.Count; i += 1)
1103 {
1104 //r_ms.BaseStream.Seek(SearchArgs.Results[i].Address, SeekOrigin.Begin);
1105 uint address = SearchArgs.Results[i].Address;
1106 if (MemoryRangeStart > 0 && !SearchArgs.IsFirstSearch) { address = address - MemoryRangeStart; }
1107 switch (SearchArgs.DataType)
1108 {
1109 #region Comparer Support
1110 #region case SearchDataTypes._8bits:
1111 case SearchDataTypes._8bits:
1112 if (SearchArgs.IsUnsignedDataType)
1113 {
1114 byte lookup_value = buffered_mem[address];
1115 _8bit_unsigned_comparer_ comparer = new _8bit_unsigned_comparer_(SearchArgs, SearchArgs.Results[i].Address);
1116 byte value = 0;
1117 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1118 {
1119 value = Convert.ToByte(SearchArgs.Results[i].Value);
1120 comparer.Value = value;
1121 }
1122 else
1123 {
1124 value = Convert.ToByte(SearchArgs.CompareStartValue);
1125 comparer.Value = value;
1126 }
1127 if (comparer.Compare(lookup_value, value))
1128 {
1129 //ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
1130 //second_tmp_Results.Add(_tmp_result);
1131 //_tmp_result = null; // free memory
1132 //SearchArgs.Results.RemoveAt(i);
1133 SearchArgs.Results[i].Value = comparer.Value;
1134 second_tmp_Results.Add(SearchArgs.Results[i]);
1135 }
1136 comparer = null; // free memory
1137 }
1138 else
1139 {
1140 sbyte lookup_value = (sbyte)buffered_mem[address];
1141 _8bit_signed_comparer_ comparer = new _8bit_signed_comparer_(SearchArgs, SearchArgs.Results[i].Address);
1142 sbyte value = 0;
1143 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1144 {
1145 value = Convert.ToSByte(SearchArgs.Results[i].Value);
1146 }
1147 else
1148 {
1149 value = Convert.ToSByte(SearchArgs.CompareStartValue);
1150 }
1151 if (comparer.Compare(lookup_value, value))
1152 {
1153 //ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
1154 //second_tmp_Results.Add(_tmp_result);
1155 //_tmp_result = null; // free memory
1156 //SearchArgs.Results.RemoveAt(i);
1157 SearchArgs.Results[i].Value = comparer.Value;
1158 second_tmp_Results.Add(SearchArgs.Results[i]);
1159 }
1160 comparer = null; // free memory
1161 }
1162 break;
1163 #endregion
1164 #region case SearchDataTypes._16bits:
1165 case SearchDataTypes._16bits:
1166 if (SearchArgs.IsUnsignedDataType)
1167 {
1168 ushort lookup_value = BitConverter.ToUInt16(buffered_mem,(int)address);
1169 _16bit_unsigned_comparer_ comparer = new _16bit_unsigned_comparer_(SearchArgs, SearchArgs.Results[i].Address);
1170 ushort value = 0;
1171 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1172 {
1173 value = Convert.ToUInt16(SearchArgs.Results[i].Value);
1174 comparer.Value = value;
1175 }
1176 else
1177 {
1178 value = Convert.ToUInt16(SearchArgs.CompareStartValue);
1179 comparer.Value = value;
1180 }
1181 if (comparer.Compare(lookup_value, value))
1182 {
1183 //ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
1184 //second_tmp_Results.Add(_tmp_result);
1185 //_tmp_result = null; // free memory
1186 //SearchArgs.Results.RemoveAt(i);
1187 SearchArgs.Results[i].Value = comparer.Value;
1188 second_tmp_Results.Add(SearchArgs.Results[i]);
1189 }
1190 comparer = null; // free memory
1191 }
1192 else
1193 {
1194 short lookup_value = BitConverter.ToInt16(buffered_mem,(int)address);
1195 _16bit_signed_comparer_ comparer = new _16bit_signed_comparer_(SearchArgs, SearchArgs.Results[i].Address);
1196 short value = 0;
1197 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1198 {
1199 value = Convert.ToInt16(SearchArgs.Results[i].Value);
1200 }
1201 else
1202 {
1203 value = Convert.ToInt16(SearchArgs.CompareStartValue);
1204 }
1205 if (comparer.Compare(lookup_value, value))
1206 {
1207 //ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
1208 //second_tmp_Results.Add(_tmp_result);
1209 //_tmp_result = null; // free memory
1210 //SearchArgs.Results.RemoveAt(i);
1211 SearchArgs.Results[i].Value = comparer.Value;
1212 second_tmp_Results.Add(SearchArgs.Results[i]);
1213 }
1214 comparer = null; // free memory
1215 }
1216 break;
1217 #endregion
1218 #region case SearchDataTypes._32bits:
1219 case SearchDataTypes._32bits:
1220 if (SearchArgs.IsUnsignedDataType)
1221 {
1222 uint lookup_value = BitConverter.ToUInt32(buffered_mem,(int)address);
1223 _32bit_unsigned_comparer_ comparer = new _32bit_unsigned_comparer_(SearchArgs, SearchArgs.Results[i].Address);
1224 uint value = 0;
1225 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1226 {
1227 value = Convert.ToUInt32(SearchArgs.Results[i].Value);
1228 comparer.Value = value;
1229 }
1230 else
1231 {
1232 value = Convert.ToUInt32(SearchArgs.CompareStartValue);
1233 comparer.Value = value;
1234 }
1235 if (comparer.Compare(lookup_value, value))
1236 {
1237 //ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
1238 //second_tmp_Results.Add(_tmp_result);
1239 //_tmp_result = null; // free memory
1240 //SearchArgs.Results.RemoveAt(i);
1241 SearchArgs.Results[i].Value = comparer.Value;
1242 second_tmp_Results.Add(SearchArgs.Results[i]);
1243 }
1244 comparer = null; // free memory
1245 }
1246 else
1247 {
1248 int lookup_value =BitConverter.ToInt32(buffered_mem,(int)address);
1249 _32bit_signed_comparer_ comparer = new _32bit_signed_comparer_(SearchArgs, SearchArgs.Results[i].Address);
1250 int value = 0;
1251 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1252 {
1253 value = Convert.ToInt32(SearchArgs.Results[i].Value);
1254 }
1255 else
1256 {
1257 value = Convert.ToInt32(SearchArgs.CompareStartValue);
1258 }
1259 if (comparer.Compare(lookup_value, value))
1260 {
1261 //ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
1262 //second_tmp_Results.Add(_tmp_result);
1263 //_tmp_result = null; // free memory
1264 //SearchArgs.Results.RemoveAt(i);
1265 SearchArgs.Results[i].Value = comparer.Value;
1266 second_tmp_Results.Add(SearchArgs.Results[i]);
1267 }
1268 comparer = null; // free memory
1269 }
1270 break;
1271 #endregion
1272 #region case SearchDataTypes._64bits:
1273 case SearchDataTypes._64bits:
1274 if (SearchArgs.IsUnsignedDataType)
1275 {
1276 ulong lookup_value = BitConverter.ToUInt64(buffered_mem,(int)address);
1277 _64bit_unsigned_comparer_ comparer = new _64bit_unsigned_comparer_(SearchArgs, SearchArgs.Results[i].Address);
1278 ulong value = 0;
1279 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1280 {
1281 value = Convert.ToUInt64(SearchArgs.Results[i].Value);
1282 comparer.Value = value;
1283 }
1284 else
1285 {
1286 value = Convert.ToUInt64(SearchArgs.CompareStartValue);
1287 comparer.Value = value;
1288 }
1289 if (comparer.Compare(lookup_value, value))
1290 {
1291 //ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
1292 //second_tmp_Results.Add(_tmp_result);
1293 //_tmp_result = null; // free memory
1294 //SearchArgs.Results.RemoveAt(i);
1295 SearchArgs.Results[i].Value = comparer.Value;
1296 second_tmp_Results.Add(SearchArgs.Results[i]);
1297 }
1298 comparer = null; // free memory
1299 }
1300 else
1301 {
1302 long lookup_value = BitConverter.ToInt64(buffered_mem,(int)address);
1303 _64bit_signed_comparer_ comparer = new _64bit_signed_comparer_(SearchArgs, SearchArgs.Results[i].Address);
1304 long value = 0;
1305 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1306 {
1307 value = Convert.ToInt64(SearchArgs.Results[i].Value);
1308 }
1309 else
1310 {
1311 value = Convert.ToInt64(SearchArgs.CompareStartValue);
1312 }
1313 if (comparer.Compare(lookup_value, value))
1314 {
1315 //ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
1316 //second_tmp_Results.Add(_tmp_result);
1317 //_tmp_result = null; // free memory
1318 //SearchArgs.Results.RemoveAt(i);
1319 SearchArgs.Results[i].Value = comparer.Value;
1320 second_tmp_Results.Add(SearchArgs.Results[i]);
1321 }
1322 comparer = null; // free memory
1323 }
1324 break;
1325 #endregion
1326 #endregion
1327 }
1328
1329 double double_percent_done = 100.0 * (double)((double)i / (double)SearchArgs.Results.Count);
1330 int int_percent_done = (int)double_percent_done;
1331 if (int_percent_done != Last_Whole_Percent_Done && i % ElementsBeforeDisplay == 0)
1332 {
1333 resultsprogress.Value = int_percent_done;
1334 //resultsprogress.Message = string.Format(" -> Reading Address: 0x{0:x8}", i);
1335 Last_Whole_Percent_Done = int_percent_done;
1336 //Application.DoEvents();
1337 }
1338
1339 }
1340 #endregion
1341 }
1342 #region Ranged Searches
1343 #if !DONOT_HAVE_RANGED_SEARCH_SUPPORT
1344 if (SearchArgs.CompareType == SearchCompareTypes.Between || SearchArgs.CompareType == SearchCompareTypes.NotBetween)
1345 {
1346 object start, end;
1347
1348 start = SearchArgs.CompareStartValue;
1349 end = SearchArgs.CompareEndValue;
1350 for (int i = 0; i < SearchArgs.Results.Count; i += 1)
1351 {
1352 uint address = SearchArgs.Results[i].Address;
1353 if (MemoryRangeStart > 0 && !SearchArgs.IsFirstSearch) { address = address - MemoryRangeStart; }
1354 //r_ms.BaseStream.Seek(SearchArgs.Results[i].Address, SeekOrigin.Begin);
1355 if (SearchArgs.CompareType == SearchCompareTypes.Between)
1356 {
1357 InRangeComparer comparer = new InRangeComparer(address, 0);
1358 if (comparer.Compare(start, end, SearchArgs.DataType, SearchArgs.IsUnsignedDataType, buffered_mem))
1359 {
1360 SearchArgs.Results[i].Value = comparer.Value;
1361 second_tmp_Results.Add(SearchArgs.Results[i]);
1362 }
1363 comparer = null;
1364 }
1365 else if (SearchArgs.CompareType == SearchCompareTypes.NotBetween)
1366 {
1367 NotInRangeComparer comparer = new NotInRangeComparer(address, 0);
1368 if (comparer.Compare(start, end, SearchArgs.DataType, SearchArgs.IsUnsignedDataType, buffered_mem))
1369 {
1370 SearchArgs.Results[i].Value = comparer.Value;
1371 second_tmp_Results.Add(SearchArgs.Results[i]);
1372 }
1373 comparer = null;
1374 }
1375 else
1376 {
1377 throw new InvalidOperationException("Encounted unkown range search type: " + SearchArgs.CompareType);
1378 }
1379 double double_percent_done = 100.0 * (double)((double)i / (double)SearchArgs.Results.Count);
1380 int int_percent_done = (int)double_percent_done;
1381 if (int_percent_done != Last_Whole_Percent_Done && i % ElementsBeforeDisplay == 0)
1382 {
1383 resultsprogress.Value = int_percent_done;
1384 //resultsprogress.Message = string.Format(" -> Reading Address: 0x{0:x8}", i);
1385 Last_Whole_Percent_Done = int_percent_done;
1386 //Application.DoEvents();
1387 }
1388 }
1389 }
1390 #endif
1391 #endregion
1392
1393 }
1394 #endregion
1395 // leave SearchArgs.Results alone, if false
1396 if (NeedToCompare)
1397 {
1398 SearchArgs.Results = second_tmp_Results.GetRange(0, second_tmp_Results.Count);
1399 // fix addresses when memory start is not zero
1400 if (MemoryRangeStart > 0 && SearchArgs.IsFirstSearch) { for (int i = 0; i < SearchArgs.Results.Count; i++) { SearchArgs.Results[i].Address = SearchArgs.Results[i].Address + MemoryRangeStart; } }
1401 second_tmp_Results = null; // free memory
1402 }
1403
1404 //r_ms.Close();
1405 }
1406
1407 private void SearchWorkerThread_ProgressChanged(object sender, ProgressChangedEventArgs e)
1408 {
1409 //if (SearchArgs.ProgressLogger != null)
1410 //{
1411 // resultsprogress.Value = e.ProgressPercentage;
1412 // //Application.DoEvents();
1413 //}
1414 }
1415
1416 private void SearchWorkerThread_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
1417 {
1418 if (!e.Cancelled)
1419 {
1420 Stopwatch st = (e.Result as Stopwatch);
1421 st.Stop();
1422 logger.Debug.WriteLine("Search took a total of {0} seconds", st.Elapsed.TotalSeconds);
1423 }
1424
1425 resultsprogress.Value = 100;
1426 logger.Debug.WriteLine(string.Format("Results Count -> 0x{0:x8}", SearchArgs.Results.Count));
1427
1428 if (SearchArgs.Results.Count == 1) // debug message for 1 result using 32bit unsigned
1429 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));
1430
1431 logger.Info.WriteLine(string.Format("Found 0x{0:x8} results", SearchArgs.Results.Count));
1432
1433 if (SearchArgs.Results.Count <= MIN_NUMBER_OF_RESULTS_BEFORE_DISPLAY)
1434 {
1435 lstResults.Items.Clear();
1436 List<ResultItem> items = new List<ResultItem>();
1437 for (int i = 0; i < SearchArgs.Results.Count; i++)
1438 {
1439 ResultItem item = new ResultItem(0, false);
1440 //item.Text = string.Format("0x{0:x8}", SearchArgs.Results[i].Address);
1441 //item.SubItems.Add(string.Format("0x{0:x8}", SearchArgs.Results[i].Address));
1442 switch (SearchArgs.DataType)
1443 {
1444
1445 case SearchDataTypes._8bits:
1446 if (SearchArgs.IsUnsignedDataType) { item = new ResultItem(SearchArgs.Results[i].Address, false, Convert.ToByte(SearchArgs.Results[i].Value)); }
1447 else { item = new ResultItem(SearchArgs.Results[i].Address, false, Convert.ToSByte(SearchArgs.Results[i].Value)); }
1448 break;
1449 case SearchDataTypes._16bits:
1450 if (SearchArgs.IsUnsignedDataType) { item = new ResultItem(SearchArgs.Results[i].Address, false, Convert.ToUInt16(SearchArgs.Results[i].Value)); }
1451 else { item = new ResultItem(SearchArgs.Results[i].Address, false, Convert.ToInt16(SearchArgs.Results[i].Value)); }
1452 break;
1453 case SearchDataTypes._32bits:
1454 if (SearchArgs.IsUnsignedDataType) { item = new ResultItem(SearchArgs.Results[i].Address, false, Convert.ToUInt32(SearchArgs.Results[i].Value)); }
1455 else { item = new ResultItem(SearchArgs.Results[i].Address, false, Convert.ToInt32(SearchArgs.Results[i].Value)); }
1456 break;
1457 case SearchDataTypes._64bits:
1458 if (SearchArgs.IsUnsignedDataType) { item = new ResultItem(SearchArgs.Results[i].Address, false, Convert.ToUInt64(SearchArgs.Results[i].Value)); }
1459 else { item = new ResultItem(SearchArgs.Results[i].Address, false, Convert.ToInt64(SearchArgs.Results[i].Value)); }
1460 break;
1461 }
1462
1463 if (!items.Contains(item))
1464 items.Add(item);
1465 }
1466 lstResults.Items.AddRange(items.ToArray());
1467 }
1468
1469 this.DoSearchDoneSpecific();
1470 //System.Threading.Thread.Sleep(100);
1471 //if (_SEARCH_MODE != SearchMode.SEARCH_MODE_NORMAL_WITH_JOKER)
1472 this.ThawResultsUpdate();
1473 Application.DoEvents();
1474 }
1475 private void DoSearchDoneSpecific()
1476 {
1477 SearchWorkerThread.CancelAsync();
1478 if (lstResults.Items.Count > 0) { timer_update_results.Enabled = true; }
1479 else { timer_update_results.Enabled = false; }
1480
1481 search_progress_updater.Enabled = false;
1482
1483 btnCancel.Enabled = false;
1484 btnReset.Enabled = true;
1485 btnSearch.Enabled = true;
1486 grpCompareType.Enabled = true;
1487 grpCompareValue.Enabled = true;
1488 resultsprogress.Value = 0;
1489 resultsprogress.Message = "";
1490 grpDataType.Enabled = false;
1491 // resume process on reset, incase it was suspended
1492 ThreadControl.ResumeProcess(this.AcceptedProcess.Id);
1493 //Application.DoEvents();
1494 this.Refresh();
1495 }
1496
1497 private void DoCancelSpecific()
1498 {
1499 this.DoSearchDoneSpecific();
1500 }
1501 private void DoResetSpecific()
1502 {
1503 this.DoCancelSpecific();
1504 IsFirstSearch = true;
1505 grpDataType.Enabled = true;
1506 }
1507 private void search_progress_updater_Tick(object sender, EventArgs e)
1508 {
1509 if ((this.AcceptedProcess ==null) || Process.GetProcessById(this.AcceptedProcess.Id) == null)
1510 {
1511 SearchWorkerThread.CancelAsync();
1512 //JokerSearchWorker.CancelAsync();
1513 ResultsUpdateWorkerThread.CancelAsync();
1514 }
1515 }
1516
1517 #region Search Button
1518 private void btnSearch_Click(object sender, EventArgs e)
1519 {
1520 this.SearchInProgess = true;
1521 //btnCancel.Enabled = true;
1522 //btnReset.Enabled = false;
1523 //btnSearch.Enabled = false;
1524 this.FreezeResultsUpdate();
1525 this.handle_btnSearch_Click();
1526 }
1527 private void handle_btnSearch_Click()
1528 {
1529 //this.FreezeResultsUpdate();
1530 lstResults.Items.Clear();
1531
1532 if (lstResults.Items.Count > 0) { timer_update_results.Enabled = true; }
1533 else { timer_update_results.Enabled = false; }
1534
1535
1536 resultsprogress.Value = 0;
1537 bool _is_unsigned = chkUnsigned.Checked;
1538 SearchType search_type = new SearchType();
1539 SearchDataTypes _data_type = new SearchDataTypes();
1540 SearchCompareTypes _compare_type = new SearchCompareTypes();
1541 CompareValueTypes _compare_value_type = new CompareValueTypes();
1542 object start_value = 0;
1543 object end_value = 0;
1544 // get datatype
1545 if (radio_8bits.Checked) { _data_type = SearchDataTypes._8bits; }
1546 else if (radio_16bits.Checked) { _data_type = SearchDataTypes._16bits; }
1547 else if (radio_32bits.Checked) { _data_type = SearchDataTypes._32bits; }
1548 else if (radio_64bits.Checked) { _data_type = SearchDataTypes._64bits; }
1549 else { logger.Error.WriteLine("Could not determine search data type bit size. (was not 8/16/32/or 64bits)"); }
1550 // get compare type
1551 if (radiocompare_equal.Checked) { _compare_type = SearchCompareTypes.Equal; }
1552 else if (radiocompare_greaterthan.Checked) { _compare_type = SearchCompareTypes.GreaterThan; }
1553 else if (radiocompare_lessthan.Checked) { _compare_type = SearchCompareTypes.LessThan; }
1554 else if (radiocompare_greaterthan_orequal.Checked) { _compare_type = SearchCompareTypes.GreaterThanOrEqual; }
1555 else if (radiocompare_lessthan_orequal.Checked) { _compare_type = SearchCompareTypes.LessThanOrEqual; }
1556 else if (radiocompare_notequal.Checked) { _compare_type = SearchCompareTypes.NotEqual; }
1557 else if (radiocompare_between.Checked) { _compare_type = SearchCompareTypes.Between; }
1558 else if (radiocompare_notbetween.Checked) { _compare_type = SearchCompareTypes.NotBetween; }
1559 else { logger.Error.WriteLine("Could not determine search comparison type. (was not == > < >= <= != <> or !<>)"); }
1560 // get compare valure type
1561 if (radio_oldvalue.Checked) { _compare_value_type = CompareValueTypes.OldValue; }
1562 else if (radio_specificvalue.Checked) { _compare_value_type = CompareValueTypes.SpecificValue; }
1563 else { logger.Error.WriteLine("Could not determine search comparison type. (was not old or specific value"); }
1564
1565 if (_compare_value_type == CompareValueTypes.SpecificValue || (_compare_type == SearchCompareTypes.Between || _compare_type == SearchCompareTypes.NotBetween))
1566 {
1567
1568 switch (_data_type)
1569 {
1570 case SearchDataTypes._8bits:
1571 if (_is_unsigned) { start_value = txtStartAddr.ToByte(); }
1572 else { start_value = txtStartAddr.ToSByte(); }
1573 break;
1574 case SearchDataTypes._16bits:
1575 if (_is_unsigned) { start_value = txtStartAddr.ToUInt16(); }
1576 else { start_value = txtStartAddr.ToInt16(); }
1577 break;
1578 case SearchDataTypes._32bits:
1579 if (_is_unsigned) { start_value = txtStartAddr.ToUInt32(); }
1580 else { start_value = txtStartAddr.ToInt32(); }
1581 break;
1582 case SearchDataTypes._64bits:
1583 if (_is_unsigned) { start_value = txtStartAddr.ToUInt64(); }
1584 else { start_value = txtStartAddr.ToInt64(); }
1585 break;
1586 default: throw new InvalidOperationException("In SearchType(): Encounterd an Unkown Search Data Type.");
1587 }
1588 }
1589 if (_compare_type == SearchCompareTypes.Between || _compare_type == SearchCompareTypes.NotBetween)
1590 {
1591 switch (_data_type)
1592 {
1593 case SearchDataTypes._8bits:
1594 if (_is_unsigned) { end_value = txtEndAddr.ToByte(); }
1595 else { end_value = txtEndAddr.ToSByte(); }
1596 break;
1597 case SearchDataTypes._16bits:
1598 if (_is_unsigned) { end_value = txtEndAddr.ToUInt16(); }
1599 else { end_value = txtEndAddr.ToInt16(); }
1600 break;
1601 case SearchDataTypes._32bits:
1602 if (_is_unsigned) { end_value = txtEndAddr.ToUInt32(); }
1603 else { end_value = txtEndAddr.ToInt32(); }
1604 break;
1605 case SearchDataTypes._64bits:
1606 if (_is_unsigned) { end_value = txtEndAddr.ToUInt64(); }
1607 else { end_value = txtEndAddr.ToInt64(); }
1608 break;
1609 default: throw new InvalidOperationException("In SearchType(): Encounterd an Unkown Search Data Type.");
1610 }
1611 }
1612
1613 search_type = new SearchType(_data_type, _is_unsigned, _compare_type, _compare_value_type, start_value, end_value, resultsprogress);
1614
1615 //search_type.LogSearchOptions();
1616
1617 search_type.IsFirstSearch = IsFirstSearch;
1618
1619
1620
1621 DoSearch(search_type);
1622 IsFirstSearch = false;
1623 }
1624 private void DoSearch(SearchType args)
1625 {
1626 if (!args.IsFirstSearch && SearchArgs != null)
1627 {
1628 //args.Results.AddRange(SearchArgs.Results.ToArray());
1629 args.Results = SearchArgs.Results;
1630 }
1631 SearchArgs = args;
1632 #if DONOT_HAVE_RANGED_SEARCH_SUPPORT
1633 if (SearchArgs.CompareType == SearchCompareTypes.Between || SearchArgs.CompareType == SearchCompareTypes.NotBetween)
1634 {
1635 throw new NotImplementedException("Between and Not Between Range searches have not been implemented.");
1636 }
1637 #endif
1638 search_progress_updater.Enabled = true;
1639 //padPluginSelector.Enabled = false;
1640 //gsPluginSelector.Enabled = false;
1641 btnReset.Enabled = false;
1642 btnSearch.Enabled = false;
1643 btnCancel.Enabled = true;
1644 grpDataType.Enabled = false;
1645 grpCompareType.Enabled = false;
1646 grpCompareValue.Enabled = false;
1647 this.Refresh();
1648 Application.DoEvents();
1649 SearchWorkerThread.RunWorkerAsync();
1650 }
1651 #endregion
1652 private void btnReset_Click(object sender, EventArgs e)
1653 {
1654 this.SearchInProgess = false;
1655 //btnSearch.Enabled = true;
1656 //btnCancel.Enabled = false;
1657 this.DoResetSpecific();
1658 lstResults.Items.Clear();
1659 try { SearchArgs.Results = new List<ResultType<object>>(); }
1660 catch { }
1661 }
1662
1663 private void btnCancel_Click(object sender, EventArgs e)
1664 {
1665 this.SearchInProgess = false;
1666 //btnCancel.Enabled = false;
1667 //btnSearch.Enabled = true;
1668 //btnReset.Enabled = true;
1669 this.DoCancelSpecific();
1670 }
1671
1672 private void mnuItemPatchListViewMemoryRegion_Click(object sender, EventArgs e)
1673 {
1674 List<ResultDataType> patch_list = new List<ResultDataType>();
1675 List<int> SelectedIndexes = new List<int>();
1676 foreach (int index in lstPatchList.SelectedIndices) { SelectedIndexes.Add(index); }
1677 foreach (int index in SelectedIndexes)
1678 {
1679 ListViewItem item = lstPatchList.Items[index];
1680 ResultDataType rdt = (ResultDataType)item.Tag;
1681 ViewMemoryRegion(rdt);
1682 break; // only get the fist item
1683 }
1684 }
1685
1686 private void mnuItemResultsListViewMemoryRegion_Click(object sender, EventArgs e)
1687 {
1688 List<ResultDataType> patch_list = new List<ResultDataType>();
1689 List<int> SelectedIndexes = new List<int>();
1690 foreach (int index in lstResults.SelectedIndices) { SelectedIndexes.Add(index); }
1691 foreach (int index in SelectedIndexes)
1692 {
1693 ListViewItem item = lstResults.Items[index];
1694 ResultDataType rdt = (ResultDataType)item.Tag;
1695 ViewMemoryRegion(rdt);
1696 break; // only get the fist item
1697 }
1698 }
1699 private void ViewMemoryRegion(ResultDataType rdt)
1700 {
1701 if (OnBrowseMemoryRegion != null)
1702 OnBrowseMemoryRegion(new BrowseMemoryRegionEvent(this, rdt.Address));
1703 }
1704
1705 private void mnuAddedResults_Opening(object sender, CancelEventArgs e)
1706 {
1707 if (!(lstPatchList.Items.Count > 0)) { mnuItemRemoveResult.Visible = false; e.Cancel = true; }
1708 if (!(lstPatchList.Items.Count > 0)) { mnuItemPatchSelectedEntry.Visible = false; e.Cancel = true; }
1709 if (e.Cancel) return;
1710 if (lstPatchList.Items.Count > 0) mnuItemRemoveResult.Visible = true;
1711 if (lstPatchList.Items.Count > 0) mnuItemPatchSelectedEntry.Visible = true;
1712
1713 if (!(lstPatchList.Items.Count > 0)) { mnuItemFreezeSelectedPatches.Visible = false; e.Cancel = true; }
1714 if (!(lstPatchList.Items.Count > 0)) { mnuItemThawSelectedPatches.Visible = false; e.Cancel = true; }
1715 if (e.Cancel) return;
1716
1717 if (lstPatchList.Items.Count > 0) mnuItemFreezeSelectedPatches.Visible = true;
1718 if (lstPatchList.Items.Count > 0) mnuItemThawSelectedPatches.Visible = true;
1719
1720 if (lstPatchList.SelectedItems.Count == 0) e.Cancel = true;
1721 if (e.Cancel) return;
1722
1723 }
1724
1725 private void mnuResults_Opening(object sender, CancelEventArgs e)
1726 {
1727 if (!(lstResults.Items.Count > 0)) e.Cancel = true;
1728 if (lstResults.SelectedItems.Count == 0) e.Cancel = true;
1729 if (SearchArgs == null) e.Cancel = true;
1730 if (e.Cancel) return;
1731 }
1732
1733 private void chkMemoryRangeExpertMode_CheckedChanged(object sender, EventArgs e)
1734 {
1735 txtMemoryRangeStart.ReadOnly = !chkMemoryRangeExpertMode.Checked;
1736 txtMemoryRangeSize.ReadOnly = !chkMemoryRangeExpertMode.Checked;
1737 }
1738
1739 private void txtMemoryRangeStart_ValueChanged(object sender, ValueChangedEventArgs e) { this.MemoryRangeStart = Convert.ToUInt32(e.NewValue); }
1740 private void txtMemoryRangeSize_ValueChanged(object sender, ValueChangedEventArgs e) { this.MemoryRangeSize = Convert.ToUInt32(e.NewValue); }
1741
1742 }
1743 }

  ViewVC Help
Powered by ViewVC 1.1.22