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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.22