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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.22