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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 305 - (hide annotations) (download)
Tue Jun 5 13:42:37 2012 UTC (8 years, 4 months ago) by william
File size: 85565 byte(s)
+ split config and process updates into seperate methods

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

  ViewVC Help
Powered by ViewVC 1.1.22