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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 384 - (hide annotations) (download)
Tue Jun 19 10:15:53 2012 UTC (8 years, 4 months ago) by william
File size: 86042 byte(s)

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

  ViewVC Help
Powered by ViewVC 1.1.22