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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.22