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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 288 - (hide annotations) (download)
Tue Jun 5 09:01:43 2012 UTC (8 years, 4 months ago) by william
File size: 84875 byte(s)

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

  ViewVC Help
Powered by ViewVC 1.1.22