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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.22