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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 472 - (show annotations) (download)
Mon Jun 3 07:39:39 2013 UTC (7 years, 4 months ago) by william
File size: 142286 byte(s)

1 #region Logging Defines
2 // include this any class or method that required logging, and comment-out what is not needed
3
4 #region Enabled logging levels
5 #define LOGGING_ENABLE_INFO
6 #define LOGGING_ENABLE_WARN
7 #define LOGGING_ENABLE_DEBUG
8 #define LOGGING_ENABLE_VERBOSEDEBUG
9 #define LOGGING_ENABLE_ERROR
10 #define LOGGING_ENABLE_VERBOSEERROR
11 #define LOGGING_ENABLE_PROFILER
12 #endregion
13 #endregion
14 //#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
15 #if !USE_AUTOMATIC_MEMORY_SEARCH_RANGE
16 #define FORCE_USE_OF_MEMORYSIZECONSTANTS // when defined wil force the use of the constants defined in MemorySizeConstants for memory search range
17 #endif
18 #define DONOT_HAVE_RANGED_SEARCH_SUPPORT // when defined, indicates that ranged searches have not been implemented
19 #define INCREASE_NUMBER_OF_RESULTS_BEFORE_DISPLAY // when defined will set MIN RESULTS to 0x2701 otherwise 0x03e8
20 //#define DO_NOT_SUSPEND_RESUME_THREAD_ON_FREEZE // when defined will not freeze/resume thread on freeze
21 using System;
22 using System.Collections.Generic;
23 using System.ComponentModel;
24 using System.Data;
25 using System.Drawing;
26 using System.Linq;
27 using System.Text;
28 using System.Windows.Forms;
29 using WeifenLuo.WinFormsUI.Docking;
30 using RomCheater.PluginFramework.Interfaces;
31 using System.Diagnostics;
32 using RomCheater.Docking.MemorySearch;
33 using libWin32.Win32.Threading;
34 using System.Threading;
35 using RomCheater.Logging;
36 using System.IO;
37 using Sojaner.MemoryScanner.MemoryProviers;
38 using RomCheater.PluginFramework.Events;
39 using System.Reflection;
40 using Sojaner.MemoryScanner;
41 using System.Collections;
42 using RomCheater.Serialization;
43
44 namespace RomCheater.Docking
45 {
46 public partial class FloatingMemorySearcher : DockContent,
47 IAcceptsPlugin<IConfigPlugin>,
48 IAcceptsProcess,
49 IAcceptsProcessAndConfig,
50 ISearchInProgress,
51 IAcceptsBrowseMemoryRegion,
52 IAcceptsMemoryRange
53 {
54 #if INCREASE_NUMBER_OF_RESULTS_BEFORE_DISPLAY
55 const int MIN_NUMBER_OF_RESULTS_BEFORE_DISPLAY = 0x2701; // 10,000 results
56 #else
57 const int MIN_NUMBER_OF_RESULTS_BEFORE_DISPLAY = 0x03e8; // 1,000 results
58 #endif
59
60 const bool USE_OLD_SEARCH_RESULTS_COMPRATOR_CODE = false;
61 const bool USE_NONRANGE_SEARCH_RESULT_READER = false;
62 private bool DefaultUnsignedState = true; // set unsigned to true
63 public FloatingMemorySearcher() { InitializeComponent(); this.AcceptedPlugin = null; OnBrowseMemoryRegion = null; this.ProcessPID = 0; SearchInProgess = false; Reload(); }
64 public FloatingMemorySearcher(IConfigPlugin config) : this() { this.AcceptedPlugin = config; }
65 public FloatingMemorySearcher(IConfigPlugin config, int pid) : this() { this.AcceptedPlugin = config; this.ProcessPID = pid; }
66
67 //new Action<int, string>(UpdateProgress) to use this as a delegate
68 private void UpdateProgress(int value, string message)
69 {
70 resultsprogress.Value = value;
71 resultsprogress.Message = message;
72 }
73
74 #region IAcceptsProcess<Process> Members
75 private int _ProcessPID;
76 public int ProcessPID { get { return _ProcessPID; } set { _ProcessPID = value; UpdateProcessPID(value); } }
77 #endregion
78 #region IAcceptsPlugin<IConfigPlugin> Members
79 private IConfigPlugin _AcceptedPlugin;
80 public IConfigPlugin AcceptedPlugin { get { return _AcceptedPlugin; } set { _AcceptedPlugin = value; UpdateAcceptedPlugin(value); } }
81 #endregion
82 #region IAcceptsBrowseMemoryRegion members
83 public event BaseEventHandler<BrowseMemoryRegionEvent> OnBrowseMemoryRegion;
84 #endregion
85
86 private void UpdateAcceptedPlugin(IConfigPlugin config)
87 {
88 this.lstResults.AcceptedPlugin = config;
89 this.lstPatchList.AcceptedPlugin = config;
90 if (config != null)
91 {
92 MemoryRangeStart = AcceptedPlugin.MemoryRangeStart;
93 MemoryRangeSize = AcceptedPlugin.MemoryRangeStart + AcceptedPlugin.MemoryRangeSize;
94 }
95 }
96 private void UpdateProcessPID(int pid)
97 {
98 this.lstResults.ProcessPID = pid;
99 this.lstPatchList.ProcessPID = pid;
100 #if USE_AUTOMATIC_MEMORY_SEARCH_RANGE && FORCE_USE_OF_MEMORYSIZECONSTANTS
101 logger.Warn.WriteLine("FloatingMemorySearcher.UpdateAcceptedProcessAndConfig(IConfigPlugin config, Process process):");
102 logger.Warn.WriteLine("Both USE_AUTOMATIC_MEMORY_SEARCH_RANGE and FORCE_USE_OF_MEMORYSIZECONSTANTS are defined");
103 logger.Warn.WriteLine("FORCE_USE_OF_MEMORYSIZECONSTANTS will take precedence and will ignore the values supplied in the memeory search range");
104 #endif
105 #if FORCE_USE_OF_MEMORYSIZECONSTANTS
106 // force use of MemorySizeConstants
107 txtMemoryRangeStart.Value = MemorySizeConstants.MinimumSearchAddress;
108 txtMemoryRangeSize.Value = MemorySizeConstants.MinimumSearchAddress + MemorySizeConstants.MaximumSearchSize;
109 #endif
110 #if USE_AUTOMATIC_MEMORY_SEARCH_RANGE && !FORCE_USE_OF_MEMORYSIZECONSTANTS
111 ////// code to automatically choose the best starting memory address and size
112 //if (process != null)
113 //{
114 // string filename = process.MainModule.FileName;
115 // //string filename = @"c:\Windows\notepad.exe";
116 // PEReader peReader = new PEReader(filename);
117 //}
118 //else
119 //{
120 //txtMemoryRangeStart.Value = MemorySizeConstants.MinimumSearchAddress;
121 //txtMemoryRangeSize.Value = MemorySizeConstants.MinimumSearchAddress + MemorySizeConstants.MaximumSearchSize;
122 //}
123 if (AcceptedPlugin != null)
124 {
125 MemoryRangeStart = AcceptedPlugin.MemoryRangeStart;
126 MemoryRangeSize = AcceptedPlugin.MemoryRangeStart + AcceptedPlugin.MemoryRangeSize;
127 }
128
129 #endif
130
131 }
132 #region ISearchInProgress members
133 private bool _SearchInProgess;
134 public bool SearchInProgess
135 {
136 get { return _SearchInProgess; }
137 private set
138 {
139 _SearchInProgess = value;
140 if (this.AcceptedPlugin != null)
141 this.AcceptedPlugin.SetMemorySearchReference(this);
142 }
143 }
144 private Guid _SearchGuid;
145 public Guid SearchGuid
146 {
147 get { return _SearchGuid; }
148 private set { _SearchGuid = value; }
149 }
150 #endregion
151
152 #region IAcceptsMemoryRange
153 #if !FORCE_USE_OF_MEMORYSIZECONSTANTS
154 private uint _MemoryRangeStart;
155 private uint _MemoryRangeSize;
156 #endif
157 public uint MemoryRangeStart
158 {
159 get
160 {
161 #if FORCE_USE_OF_MEMORYSIZECONSTANTS
162 return MemorySizeConstants.MinimumSearchAddress;
163 #else
164 return _MemoryRangeStart;
165 #endif
166 }
167 set
168 {
169 #if !FORCE_USE_OF_MEMORYSIZECONSTANTS
170 _MemoryRangeStart = value;
171 txtMemoryRangeStart.Value = value;
172 #endif
173 }
174 }
175 public uint MemoryRangeSize
176 {
177 get
178 {
179 #if FORCE_USE_OF_MEMORYSIZECONSTANTS
180 return MemorySizeConstants.MinimumSearchAddress + MemorySizeConstants.MaximumSearchSize;
181 #else
182 return _MemoryRangeSize;
183 #endif
184 }
185 set
186 {
187 #if !FORCE_USE_OF_MEMORYSIZECONSTANTS
188 _MemoryRangeSize = value;
189 txtMemoryRangeSize.Value = value;
190 #endif
191 }
192 }
193 #endregion
194
195 public void Reload()
196 {
197 chkUnsigned.Checked = DefaultUnsignedState;
198 radio_8bits.Checked = true;
199 radiocompare_equal.Checked = true;
200 radio_oldvalue.Checked = true;
201 chkRefreshResults.Checked = true;
202 }
203 public enum eListViewResults
204 {
205 SEARCH_RESULTS_LIST = 0x3000,
206 PATCH_RESULTS_LIST = 0x3001,
207 UKNOWN_RESULTS_LIST = 0x3001
208 }
209 bool IsFirstSearch = true;
210 SearchType SearchArgs;
211 static int col_Found_Address = 1;
212 static int col_Found_Value = 2;
213 //static int col_Found_Frozen = 3; /* unused */
214 static int col_Added_Address = 1;
215 static int col_Added_Value = 2;
216 //static int col_Added_Frozen = 3; /* unused */
217 List<ListViewItem> ResultItems = new List<ListViewItem>();
218 List<ListViewItem> AddedItems = new List<ListViewItem>();
219 private bool _PatchedValue_NeedsUpdate;
220 bool PatchedValue_NeedsUpdate
221 {
222 get { if (_PatchedValue_NeedsUpdate) this.ThawResultsUpdate(); return _PatchedValue_NeedsUpdate; }
223 set { _PatchedValue_NeedsUpdate = value; if (value) this.ThawResultsUpdate(); }
224 }
225 private delegate ListViewItem ThreadSafe_GetResultItem(int index, int lv_type);
226 private ListViewItem GetResultItem(int index, int lv_type)
227 {
228 try
229 {
230 AddressValuePairList lv = null;
231 switch (lv_type)
232 {
233 case (int)eListViewResults.SEARCH_RESULTS_LIST: lv = lstResults; break;
234 case (int)eListViewResults.PATCH_RESULTS_LIST: lv = lstPatchList; break;
235 default: throw new IndexOutOfRangeException("Detected: " + Enum.GetName(typeof(eListViewResults), eListViewResults.UKNOWN_RESULTS_LIST) + " with value: " + lv_type.ToString("x4"));
236 }
237 ListViewItem item = new ListViewItem();
238 item = (ListViewItem)lv.Items[index].Clone();
239 return item;
240 }
241 catch (Exception)
242 {
243 return null;
244 }
245 }
246 private void radiocompare_equal_CheckedChanged(object sender, EventArgs e)
247 {
248 //if (!radiocompare_between.Checked && !radiocompare_notbetween.Checked)
249 //{
250 if (radio_oldvalue.Checked)
251 {
252 txtStartAddr.ReadOnly = true;
253 txtEndAddr.ReadOnly = true;
254 }
255 if (radio_specificvalue.Checked)
256 {
257 txtStartAddr.ReadOnly = false;
258 txtEndAddr.ReadOnly = true;
259 }
260 //}
261 }
262
263 private void radiocompare_between_CheckedChanged(object sender, EventArgs e)
264 {
265 if (!radiocompare_equal.Checked &&
266 !radiocompare_greaterthan.Checked &&
267 !radiocompare_greaterthan.Checked &&
268 !radiocompare_lessthan.Checked &&
269 !radiocompare_greaterthan_orequal.Checked &&
270 !radiocompare_lessthan_orequal.Checked &&
271 !radiocompare_notequal.Checked)
272 if (radiocompare_between.Checked)
273 {
274 txtStartAddr.ReadOnly = false;
275 txtEndAddr.ReadOnly = false;
276 return;
277 }
278 if (!radiocompare_between.Checked && !radiocompare_notbetween.Checked)
279 {
280 if (radio_oldvalue.Checked)
281 {
282 txtStartAddr.ReadOnly = true;
283 txtEndAddr.ReadOnly = true;
284 }
285 if (radio_specificvalue.Checked)
286 {
287 txtStartAddr.ReadOnly = false;
288 txtEndAddr.ReadOnly = true;
289 }
290 }
291 }
292
293 private void radiocompare_notbetween_CheckedChanged(object sender, EventArgs e)
294 {
295 if (!radiocompare_equal.Checked &&
296 !radiocompare_greaterthan.Checked &&
297 !radiocompare_greaterthan.Checked &&
298 !radiocompare_lessthan.Checked &&
299 !radiocompare_greaterthan_orequal.Checked &&
300 !radiocompare_lessthan_orequal.Checked &&
301 !radiocompare_notequal.Checked)
302 if (radiocompare_notbetween.Checked)
303 {
304 txtStartAddr.ReadOnly = false;
305 txtEndAddr.ReadOnly = false;
306 return;
307 }
308 if (!radiocompare_between.Checked && !radiocompare_notbetween.Checked)
309 {
310 if (radio_oldvalue.Checked)
311 {
312 txtStartAddr.ReadOnly = true;
313 txtEndAddr.ReadOnly = true;
314 }
315 if (radio_specificvalue.Checked)
316 {
317 txtStartAddr.ReadOnly = false;
318 txtEndAddr.ReadOnly = true;
319 }
320 }
321 }
322
323 private void radio_8bits_CheckedChanged(object sender, EventArgs e)
324 {
325 if (chkUnsigned.Checked)
326 {
327 txtStartAddr.CreateTypeSize<byte>();
328 txtEndAddr.CreateTypeSize<byte>();
329 }
330 else
331 {
332 txtStartAddr.CreateTypeSize<sbyte>();
333 txtEndAddr.CreateTypeSize<sbyte>();
334 }
335 }
336
337 private void radio_16bits_CheckedChanged(object sender, EventArgs e)
338 {
339 if (chkUnsigned.Checked)
340 {
341 txtStartAddr.CreateTypeSize<ushort>();
342 txtEndAddr.CreateTypeSize<ushort>();
343 }
344 else
345 {
346 txtStartAddr.CreateTypeSize<short>();
347 txtEndAddr.CreateTypeSize<short>();
348 }
349 }
350
351 private void radio_32bits_CheckedChanged(object sender, EventArgs e)
352 {
353
354 if (chkUnsigned.Checked)
355 {
356 txtStartAddr.CreateTypeSize<uint>();
357 txtEndAddr.CreateTypeSize<uint>();
358 }
359 else
360 {
361 txtStartAddr.CreateTypeSize<int>();
362 txtEndAddr.CreateTypeSize<int>();
363 }
364 }
365
366 private void radio_64bits_CheckedChanged(object sender, EventArgs e)
367 {
368
369 if (chkUnsigned.Checked)
370 {
371 txtStartAddr.CreateTypeSize<ulong>();
372 txtEndAddr.CreateTypeSize<ulong>();
373 }
374 else
375 {
376 txtStartAddr.CreateTypeSize<long>();
377 txtEndAddr.CreateTypeSize<long>();
378 }
379 }
380
381 private void radio_oldvalue_CheckedChanged(object sender, EventArgs e)
382 {
383 if (!radiocompare_between.Checked && !radiocompare_notbetween.Checked)
384 {
385 txtStartAddr.ReadOnly = true;
386 txtEndAddr.ReadOnly = true;
387 }
388 }
389
390 private void radio_specificvalue_CheckedChanged(object sender, EventArgs e)
391 {
392 if (!radiocompare_between.Checked && !radiocompare_notbetween.Checked)
393 {
394 txtStartAddr.ReadOnly = false;
395 txtEndAddr.ReadOnly = true;
396 }
397 }
398
399 private void chkRefreshResults_CheckedChanged(object sender, EventArgs e)
400 {
401 if (chkRefreshResults.Checked)
402 {
403 timer_update_results.Enabled = true;
404 }
405 else
406 {
407 timer_update_results.Enabled = false;
408 ResultsUpdateWorkerThread.CancelAsync();
409 }
410 }
411
412 private void timer_update_results_Tick(object sender, EventArgs e)
413 {
414 if (chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy)
415 {
416 ResultsUpdateWorkerThread.RunWorkerAsync();
417 }
418 }
419 private bool ShouldUpdateResults()
420 {
421 if (this.ProcessPID == 0) return false;
422 if (SearchWorkerThread.IsBusy) return false;
423 //if (JokerSearchWorker.IsBusy) return false;
424 if (this.IsResultsUpdateFrozen) return false;
425 if (mnuAddedResults.Visible) return false;
426 if (mnuResults.Visible) return false;
427 if (Process.GetProcessById(this.ProcessPID) == null) return false;
428 if (lstResults.Items.Count > 0) return true;
429 if (lstPatchList.Items.Count > 0) return true;
430 return false;
431 }
432 private void ResultsUpdateWorkerThread_DoWork(object sender, DoWorkEventArgs e)
433 {
434 Thread.Sleep(250); // keep thread from blocking
435 if (!this.ShouldUpdateResults()) return;
436 ////if (SearchArgs == null) return;
437 ////if (this.IsResultsUpdateFrozen) return;
438 ////// put thread to sleep for 500ms
439 ////System.Threading.Thread.Sleep(500);
440 //PCSX2MemoryProvider provider = new PCSX2MemoryProvider(this.SearchPCSX2ProcessPID, resultslog);
441 //byte[] buffered_mem = provider.GetMemory();
442 //MemoryStream ms = new MemoryStream(buffered_mem);
443 //BinaryReader r_ms = new BinaryReader(ms);
444
445 #region Update Results List
446 ResultItems = new List<ListViewItem>();
447 //r_ms.BaseStream.Seek(0, SeekOrigin.Begin);
448 for (int i = 0; i < lstResults.Items.Count; i++)
449 {
450 if (this.lstResults.InvokeRequired)
451 {
452 ThreadSafe_GetResultItem _get_item = new ThreadSafe_GetResultItem(GetResultItem);
453 object item = this.lstResults.Invoke(_get_item, new object[] { i, (int)eListViewResults.SEARCH_RESULTS_LIST });
454 if (item != null)
455 ResultItems.Add((ListViewItem)item);
456 }
457 else
458 {
459 ResultItems.Add(lstResults.Items[i]);
460 }
461
462 }
463 for (int i = 0; i < ResultItems.Count; i++)
464 {
465 if (ResultsUpdateWorkerThread.CancellationPending == true)
466 {
467 e.Cancel = true;
468 return;
469 }
470 int Address = 0;
471 ResultDataType _result = (ResultDataType)ResultItems[i].Tag;
472
473 Address = Convert.ToInt32(ResultItems[i].SubItems[col_Found_Address].Text, 16);
474 //r_ms.BaseStream.Seek(Address, SeekOrigin.Begin);
475 using (GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
476 {
477 provider.OpenProvider();
478 int bytesReadSize;
479 byte[] data;
480 uint bytesToRead = 0;
481 switch (_result.ValueType)
482 {
483 case SearchDataTypes._8bits:
484 bytesToRead = 1;
485 break;
486 case SearchDataTypes._16bits:
487 bytesToRead = 2;
488 break;
489 case SearchDataTypes._32bits:
490 bytesToRead = 4;
491 break;
492 case SearchDataTypes._64bits:
493 bytesToRead = 8;
494 break;
495 }
496 provider.ReadProcessMemory(Address, bytesToRead, out bytesReadSize, out data);
497 using (MemoryStream ms = new MemoryStream(data))
498 {
499 using (BinaryReader r_ms = new BinaryReader(ms))
500 {
501 switch (_result.ValueType)
502 {
503 case SearchDataTypes._8bits:
504 if (_result.IsUnsigned) { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x2}", r_ms.ReadByte()); }
505 else { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x2}", r_ms.ReadSByte()); }
506 break;
507 case SearchDataTypes._16bits:
508 if (_result.IsUnsigned) { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x4}", r_ms.ReadUInt16()); }
509 else { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x4}", r_ms.ReadInt16()); }
510 break;
511 case SearchDataTypes._32bits:
512 if (_result.IsUnsigned) { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x8}", r_ms.ReadUInt32()); }
513 else { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x8}", r_ms.ReadInt32()); }
514 break;
515 case SearchDataTypes._64bits:
516 if (_result.IsUnsigned) { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x16}", r_ms.ReadUInt64()); }
517 else { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x16}", r_ms.ReadInt64()); }
518 break;
519 }
520 r_ms.Close();
521 }
522 }
523 provider.CloseProvider();
524 }
525 //Application.DoEvents();
526 }
527 #endregion
528
529 #region Update Added Results List
530 AddedItems = new List<ListViewItem>();
531 //r_ms.BaseStream.Seek(0, SeekOrigin.Begin);
532 for (int i = 0; i < lstPatchList.Items.Count; i++)
533 {
534 if (this.lstResults.InvokeRequired)
535 {
536 ThreadSafe_GetResultItem _get_item = new ThreadSafe_GetResultItem(GetResultItem);
537 object item = this.lstResults.Invoke(_get_item, new object[] { i, (int)eListViewResults.PATCH_RESULTS_LIST });
538 if (item != null)
539 AddedItems.Add((ListViewItem)item);
540 }
541 else
542 {
543 AddedItems.Add(lstPatchList.Items[i]);
544 }
545
546 }
547 for (int i = 0; i < AddedItems.Count; i++)
548 {
549 if (ResultsUpdateWorkerThread.CancellationPending == true)
550 {
551 e.Cancel = true;
552 return;
553 }
554 int Address = 0;
555 ResultDataType _result = (ResultDataType)AddedItems[i].Tag;
556 Address = Convert.ToInt32(AddedItems[i].SubItems[col_Added_Address].Text, 16);
557 using (GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
558 {
559 provider.OpenProvider();
560 int bytesReadSize;
561 byte[] data;
562 uint bytesToRead = 0;
563 switch (_result.ValueType)
564 {
565 case SearchDataTypes._8bits:
566 bytesToRead = 1;
567 break;
568 case SearchDataTypes._16bits:
569 bytesToRead = 2;
570 break;
571 case SearchDataTypes._32bits:
572 bytesToRead = 4;
573 break;
574 case SearchDataTypes._64bits:
575 bytesToRead = 8;
576 break;
577 }
578 provider.ReadProcessMemory(Address, bytesToRead, out bytesReadSize, out data);
579 provider.CloseProvider();
580 using (MemoryStream ms = new MemoryStream(data))
581 {
582 using (BinaryReader r_ms = new BinaryReader(ms))
583 {
584 switch (_result.ValueType)
585 {
586 case SearchDataTypes._8bits:
587 if (_result.IsUnsigned) { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x2}", r_ms.ReadByte()); }
588 else { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x2}", r_ms.ReadSByte()); }
589 break;
590 case SearchDataTypes._16bits:
591 if (_result.IsUnsigned) { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x4}", r_ms.ReadUInt16()); }
592 else { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x4}", r_ms.ReadInt16()); }
593 break;
594 case SearchDataTypes._32bits:
595 if (_result.IsUnsigned) { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x8}", r_ms.ReadUInt32()); }
596 else { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x8}", r_ms.ReadInt32()); }
597 break;
598 case SearchDataTypes._64bits:
599 if (_result.IsUnsigned) { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x16}", r_ms.ReadUInt64()); }
600 else { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x16}", r_ms.ReadInt64()); }
601 break;
602 }
603 r_ms.Close();
604 }
605 }
606 }
607 //Application.DoEvents();
608 }
609 #endregion
610
611
612 }
613
614 private void ResultsUpdateWorkerThread_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
615 {
616 try
617 {
618 //if ((lstResults.SelectedItems.Count > 0) && !PatchedValue_NeedsUpdate ) return;
619 //if ((lstPatchList.SelectedItems.Count > 0) && !PatchedValue_NeedsUpdate) return;
620 if (!this.ShouldUpdateResults()) return;
621 if (ResultItems.Count > 0)
622 {
623 //lstResults.Items.Clear();
624 //lstResults.Items.AddRange(ResultItems.ToArray());
625
626 for (int i = 0; i < ResultItems.Count; i++)
627 {
628 lstResults.Items[i].SubItems[new AVPColumnText(AVPColumnType.VALUE).ColumnIndex].Text =
629 ResultItems[i].SubItems[new AVPColumnText(AVPColumnType.VALUE).ColumnIndex].Text;
630 }
631
632 }
633 if (AddedItems.Count > 0)
634 {
635 //lstPatchList.Items.Clear();
636 //lstPatchList.Items.AddRange(AddedItems.ToArray());
637
638 for (int i = 0; i < AddedItems.Count; i++)
639 {
640 lstPatchList.Items[i].SubItems[new AVPColumnText(AVPColumnType.VALUE).ColumnIndex].Text =
641 AddedItems[i].SubItems[new AVPColumnText(AVPColumnType.VALUE).ColumnIndex].Text;
642 }
643
644 }
645 PatchedValue_NeedsUpdate = false;
646 }
647 catch { }
648 }
649
650 private void btnImportFile_Click(object sender, EventArgs e)
651 {
652 this.FreezeResultsUpdate();
653 if (!lstPatchList.ImportFromFile())
654 {
655 MessageBox.Show("Failed to Import Patch List from File.", "Import Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
656 this.ThawResultsUpdate();
657 return;
658 }
659 else
660 {
661 MessageBox.Show("Succesfully Imported Patch List from File.", "Import Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
662 this.ThawResultsUpdate();
663 return;
664 }
665 }
666 bool g_isFrozen = false;
667 private bool IsResultsUpdateFrozen
668 {
669 get { return g_isFrozen; }
670 set { g_isFrozen = value; }
671 }
672 private void ThawResultsUpdate()
673 {
674 this.IsResultsUpdateFrozen = false;
675 if (this.ProcessPID != 0)
676 {
677 #if !DO_NOT_SUSPEND_RESUME_THREAD_ON_FREEZE
678 ThreadControl.ResumeProcess(this.ProcessPID);
679 #endif
680 }
681 }
682
683 private void FreezeResultsUpdate()
684 {
685 this.IsResultsUpdateFrozen = true;
686 //this.IsResultsUpdateFrozen = false;
687 if (this.ProcessPID != 0)
688 {
689 #if !DO_NOT_SUSPEND_RESUME_THREAD_ON_FREEZE
690 ThreadControl.SuspendProcess(this.ProcessPID);
691 #endif
692 }
693 }
694
695 private void btnExportFile_Click(object sender, EventArgs e)
696 {
697 this.FreezeResultsUpdate();
698 if (!lstPatchList.ExportToFile())
699 {
700 MessageBox.Show("Failed to Export Patch List to File.", "Export Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
701 this.ThawResultsUpdate();
702 return;
703 }
704 else
705 {
706 MessageBox.Show("Succesfully Exported Patch List to File.", "Export Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
707 this.ThawResultsUpdate();
708 return;
709 }
710 }
711
712 private void btnImportClipboard_Click(object sender, EventArgs e)
713 {
714 this.FreezeResultsUpdate();
715 if (!lstPatchList.ImportFromClipboard())
716 {
717 MessageBox.Show("Failed to Import Patch List from Clipboard.", "Import Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
718 this.ThawResultsUpdate();
719 return;
720 }
721 else
722 {
723 MessageBox.Show("Succesfully Import Patch List from Clipboard.", "Import Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
724 this.ThawResultsUpdate();
725 }
726 }
727
728 private void btnExportClipboard_Click(object sender, EventArgs e)
729 {
730 this.FreezeResultsUpdate();
731 if (!lstPatchList.ExportToClipboard())
732 {
733 MessageBox.Show("Failed to Export Patch List to Clipboard.", "Export Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
734 this.ThawResultsUpdate();
735 return;
736 }
737 else
738 {
739 MessageBox.Show("Succesfully Exported Patch List to Clipboard.", "Export Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
740 this.ThawResultsUpdate();
741 return;
742 }
743 }
744
745 private void btnAddPatchAddress_Click(object sender, EventArgs e)
746 {
747 PatchAdder adder = new PatchAdder((IAcceptsProcessAndConfig)this);
748 adder.ShowDialog();
749 if (adder.WasAPatchAdded) AddToPatchList(adder.AddedPatchValue);
750 }
751
752 private void btnAddAddressRange_Click(object sender, EventArgs e)
753 {
754 PatchRangeAdder adder = new PatchRangeAdder((IAcceptsProcessAndConfig)this);
755 adder.ShowDialog();
756 if (adder.WasAPatchAdded) AddToPatchList(adder.AddedPatchValue);
757 }
758 private void AddToPatchList(List<ResultDataType> item) { foreach (ResultDataType data in item) { AddToPatchList(data); } }
759 private void AddToPatchList(ResultDataType item)
760 {
761 ResultItem item2 = null;
762 switch (item.ValueType)
763 {
764 case SearchDataTypes._8bits:
765 if (item.IsUnsigned) { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToByte(item.Value)); }
766 else { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToSByte(item.Value)); }
767 break;
768 case SearchDataTypes._16bits:
769 if (item.IsUnsigned) { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToUInt16(item.Value)); }
770 else { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToInt16(item.Value)); }
771 break;
772 case SearchDataTypes._32bits:
773 if (item.IsUnsigned) { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToUInt32(item.Value)); }
774 else { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToInt32(item.Value)); }
775 break;
776 case SearchDataTypes._64bits:
777 if (item.IsUnsigned) { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToUInt64(item.Value)); }
778 else { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToInt64(item.Value)); }
779 break;
780 }
781 this.AddToPatchList(item2);
782 }
783 private void AddToPatchList(ListViewItem item)
784 {
785 try
786 {
787 ResultDataType _result = (ResultDataType)item.Tag;
788 this.AddToPatchList(_result);
789 }
790 catch (InvalidCastException ex)
791 {
792 // unable to cast
793 MessageBox.Show(ex.Message, "Invalid Cast Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
794 }
795 catch (Exception ex)
796 {
797 // other exception
798 MessageBox.Show(ex.Message, "Unhandled Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
799 }
800 }
801 private void AddToPatchList(ResultItem item)
802 {
803 if (!lstPatchList.Items.Contains(item)) lstPatchList.Items.Add(item);
804 }
805 private void AddToPatchList(string address, SearchDataTypes bitsize, bool IsUnsigned)
806 {
807 ResultItemState state = new ResultItemState(address, bitsize, IsUnsigned, (IAcceptsProcessAndConfig)this);
808 ResultItem item = new ResultItem(state.Address, state.Value, state.Frozen, state.ValueType, state.IsUnsigned);
809 this.AddToPatchList(item);
810 }
811
812 private void mnuItemAddToPatchList_Click(object sender, EventArgs e)
813 {
814 if (!(lstResults.SelectedItems.Count > 0)) return;
815 //if (SearchArgs == null) return;
816
817 try
818 {
819 for (int i = 0; i < lstResults.SelectedIndices.Count; i++)
820 {
821 //ResultDataType result = (ResultDataType)lstResults.Items[selected_index].Tag;
822 ListViewItem item = lstResults.Items[lstResults.SelectedIndices[i]];
823 this.AddToPatchList(item);
824 }
825 }
826 catch (Exception ex)
827 {
828 logger.Error.WriteLine(ex.ToString());
829 }
830 }
831
832 private void mnuItemRemoveResult_Click(object sender, EventArgs e)
833 {
834 if (!(lstPatchList.SelectedItems.Count > 0)) return;
835 //if (SearchArgs == null) return;
836 try
837 {
838 this.FreezeResultsUpdate();
839 for (int i = 0; i < lstPatchList.SelectedIndices.Count; i++)
840 {
841 //lstPatchList.ThawItem(lstPatchList.SelectedIndices[i]);
842 lstPatchList.Items[lstPatchList.SelectedIndices[i]].Remove();
843 }
844 this.ThawResultsUpdate();
845 }
846 catch (Exception ex)
847 {
848 Debug.WriteLine(ex.ToString());
849 }
850 }
851 private void PatchRange(bool SingleEntry)
852 {
853 //if (SearchArgs == null) return;
854 #region Patch Selected Address
855 // stop ResultsUpdate Thread
856 ResultsUpdateWorkerThread.CancelAsync();
857
858 List<ResultDataType> patch_list = new List<ResultDataType>();
859 List<int> SelectedIndexes = new List<int>();
860
861 if (SingleEntry)
862 {
863 SelectedIndexes.Add(lstPatchList.SelectedIndices[0]);
864 }
865 else
866 {
867 foreach (int index in lstPatchList.SelectedIndices)
868 {
869 SelectedIndexes.Add(index);
870 }
871 }
872 //PCSX2MemoryProvider provider = new PCSX2MemoryProvider(this.SearchPCSX2ProcessPID, resultslog);
873 foreach (int index in SelectedIndexes)
874 {
875 if (SingleEntry)
876 {
877 SearchPatcher patcher = null;
878 uint Address = 0;
879 ListViewItem item = lstPatchList.Items[index];
880 ResultDataType _result = (ResultDataType)item.Tag;
881 Address = Convert.ToUInt32(item.SubItems[col_Found_Address].Text, 16);
882 switch (_result.ValueType)
883 {
884 case SearchDataTypes._8bits:
885 if (_result.IsUnsigned)
886 {
887 byte value = Convert.ToByte(item.SubItems[col_Found_Value].Text, 16);
888 patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
889 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 else
897 {
898 sbyte value = Convert.ToSByte(item.SubItems[col_Found_Value].Text, 16);
899 patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
900 timer_update_results.Enabled = false;
901 patcher.ShowDialog();
902 timer_update_results.Enabled = true;
903 PatchedValue_NeedsUpdate = true;
904 if (!chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy)
905 ResultsUpdateWorkerThread.RunWorkerAsync();
906 }
907 break;
908 case SearchDataTypes._16bits:
909 if (_result.IsUnsigned)
910 {
911 ushort value = Convert.ToUInt16(item.SubItems[col_Found_Value].Text, 16);
912 patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
913 timer_update_results.Enabled = false;
914 patcher.ShowDialog();
915 timer_update_results.Enabled = true;
916 PatchedValue_NeedsUpdate = true;
917 if (!chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy)
918 ResultsUpdateWorkerThread.RunWorkerAsync();
919 }
920 else
921 {
922 short value = Convert.ToInt16(item.SubItems[col_Found_Value].Text, 16);
923 patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
924 timer_update_results.Enabled = false;
925 patcher.ShowDialog();
926 timer_update_results.Enabled = true;
927 PatchedValue_NeedsUpdate = true;
928 if (!chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy)
929 ResultsUpdateWorkerThread.RunWorkerAsync();
930 }
931 break;
932 case SearchDataTypes._32bits:
933 if (_result.IsUnsigned)
934 {
935 uint value = Convert.ToUInt32(item.SubItems[col_Found_Value].Text, 16);
936 patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
937 timer_update_results.Enabled = false;
938 patcher.ShowDialog();
939 timer_update_results.Enabled = true;
940 PatchedValue_NeedsUpdate = true;
941 if (!chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy)
942 ResultsUpdateWorkerThread.RunWorkerAsync();
943 }
944 else
945 {
946 int value = Convert.ToInt32(item.SubItems[col_Found_Value].Text, 16);
947 patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
948 timer_update_results.Enabled = false;
949 patcher.ShowDialog();
950 timer_update_results.Enabled = true;
951 PatchedValue_NeedsUpdate = true;
952 if (!chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy)
953 ResultsUpdateWorkerThread.RunWorkerAsync();
954 }
955 break;
956 case SearchDataTypes._64bits:
957 if (_result.IsUnsigned)
958 {
959 ulong value = Convert.ToUInt32(item.SubItems[col_Found_Value].Text, 16);
960 patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
961 timer_update_results.Enabled = false;
962 patcher.ShowDialog();
963 timer_update_results.Enabled = true;
964 PatchedValue_NeedsUpdate = true;
965 if (!chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy)
966 ResultsUpdateWorkerThread.RunWorkerAsync();
967 }
968 else
969 {
970 long value = Convert.ToInt32(item.SubItems[col_Found_Value].Text, 16);
971 patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
972 timer_update_results.Enabled = false;
973 patcher.ShowDialog();
974 timer_update_results.Enabled = true;
975 PatchedValue_NeedsUpdate = true;
976 if (!chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy)
977 ResultsUpdateWorkerThread.RunWorkerAsync();
978 }
979 break;
980 }
981 }
982 else
983 {
984
985 ListViewItem item = lstPatchList.Items[index];
986 ResultDataType _result = (ResultDataType)item.Tag;
987 patch_list.Add(_result);
988 }
989 }
990
991 if (patch_list.Count > 0)
992 {
993 SearchRangePatcher rangePatcher = new SearchRangePatcher((IAcceptsProcessAndConfig)this, patch_list);
994 rangePatcher.ShowDialog();
995 }
996
997 #endregion
998 }
999 private void mnuItemPatchSelectedEntry_Click(object sender, EventArgs e)
1000 {
1001 if (!(lstPatchList.SelectedItems.Count == 1)) return;
1002 PatchRange(true);
1003 }
1004
1005 private void mnuItemPatchSelectedRange_Click(object sender, EventArgs e)
1006 {
1007 if (!(lstPatchList.SelectedItems.Count >= 1)) return;
1008 PatchRange(false);
1009 }
1010
1011 private void mnuItemFreezeSelectedPatches_Click(object sender, EventArgs e)
1012 {
1013 if (!(lstPatchList.SelectedItems.Count > 0)) return;
1014 //if (SearchArgs == null) return;
1015 try
1016 {
1017 lstPatchList.ProcessID = this.ProcessPID;
1018 this.FreezeResultsUpdate();
1019 for (int i = 0; i < lstPatchList.SelectedIndices.Count; i++)
1020 {
1021 lstPatchList.FreezeItem(lstPatchList.SelectedIndices[i]);
1022 }
1023 // force thaw and update
1024 this.ThawResultsUpdate();
1025 this.Update();
1026 }
1027 catch (Exception ex)
1028 {
1029 Debug.WriteLine(ex.ToString());
1030 }
1031 }
1032
1033 private void mnuItemThawSelectedPatches_Click(object sender, EventArgs e)
1034 {
1035 if (!(lstPatchList.SelectedItems.Count > 0)) return;
1036 //if (SearchArgs == null) return;
1037 try
1038 {
1039 lstPatchList.ProcessID = this.ProcessPID;
1040 this.FreezeResultsUpdate();
1041 for (int i = 0; i < lstPatchList.SelectedIndices.Count; i++)
1042 {
1043 lstPatchList.ThawItem(lstPatchList.SelectedIndices[i]);
1044 }
1045 // force thaw and update
1046 this.ThawResultsUpdate();
1047 this.Update();
1048 }
1049 catch (Exception ex)
1050 {
1051 Debug.WriteLine(ex.ToString());
1052 }
1053 }
1054 private void search_provider_OnBytesRead(OnBytesReadEventArgs e)
1055 {
1056 if (SearchWorkerThread.CancellationPending) { e.Canceled = true; return; }
1057 SearchDataTypes sdt = SearchArgs.DataType;
1058 bool unsigned = SearchArgs.IsUnsignedDataType;
1059 int Last_Whole_Percent_Done = 0;
1060 uint CurrentIndex = e.CurrentIndex;
1061 if (e.UserState != null)
1062 {
1063 SearchResultWriter writer = (e.UserState as SearchResultWriter);
1064 if (writer == null)
1065 throw new InvalidOperationException("writer cannot be null");
1066 using (MemoryStream ms = new MemoryStream(e.Data))
1067 {
1068 using (BinaryReader br = new BinaryReader(ms))
1069 {
1070 while (br.BaseStream.Position < br.BaseStream.Length)
1071 {
1072 try
1073 {
1074 switch (sdt)
1075 {
1076 case SearchDataTypes._8bits:
1077 if (unsigned)
1078 {
1079 #region 8bits - unsigned
1080 var Value = br.ReadByte();
1081 using (_8bit_unsigned_comparer_ comparer = new _8bit_unsigned_comparer_(SearchArgs, CurrentIndex))
1082 {
1083 byte value = 0;
1084 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1085 {
1086 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1087 {
1088 try
1089 {
1090 gmp.OpenProvider();
1091 gmp.ReadMemory(CurrentIndex, out value);
1092 gmp.CloseProvider();
1093 }
1094 catch (Exception ex)
1095 {
1096 logger.VerboseError.WriteLine(ex.ToString());
1097 }
1098 }
1099 comparer.Value = value;
1100 }
1101 else
1102 {
1103 value = Convert.ToByte(SearchArgs.CompareStartValue);
1104 comparer.Value = value;
1105 }
1106 if (comparer.Compare(Convert.ToByte(Value), value))
1107 {
1108 writer.WriteResult<byte>(comparer.Address, comparer.Value);
1109 }
1110 }
1111 #endregion
1112 }
1113 else
1114 {
1115 #region 8bits - signed
1116 var Value = br.ReadSByte();
1117 using (_8bit_signed_comparer_ comparer = new _8bit_signed_comparer_(SearchArgs, CurrentIndex))
1118 {
1119 sbyte value = 0;
1120 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1121 {
1122 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1123 {
1124 try
1125 {
1126 gmp.OpenProvider();
1127 gmp.ReadMemory(CurrentIndex, out value);
1128 gmp.CloseProvider();
1129 }
1130 catch (Exception ex)
1131 {
1132 logger.VerboseError.WriteLine(ex.ToString());
1133 }
1134 }
1135 comparer.Value = value;
1136 }
1137 else
1138 {
1139 value = Convert.ToSByte(SearchArgs.CompareStartValue);
1140 comparer.Value = value;
1141 }
1142 if (comparer.Compare(Convert.ToSByte(Value), value))
1143 {
1144 writer.WriteResult<sbyte>(comparer.Address, comparer.Value);
1145 }
1146 }
1147 #endregion
1148 } break;
1149 case SearchDataTypes._16bits:
1150 if (unsigned)
1151 {
1152 #region 16bits - unsigned
1153 var Value = br.ReadUInt16();
1154 using (_16bit_unsigned_comparer_ comparer = new _16bit_unsigned_comparer_(SearchArgs, CurrentIndex))
1155 {
1156 ushort value = 0;
1157 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1158 {
1159 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1160 {
1161 try
1162 {
1163 gmp.OpenProvider();
1164 gmp.ReadMemory(CurrentIndex, out value);
1165 gmp.CloseProvider();
1166 }
1167 catch (Exception ex)
1168 {
1169 logger.VerboseError.WriteLine(ex.ToString());
1170 }
1171 }
1172 comparer.Value = value;
1173 }
1174 else
1175 {
1176 value = Convert.ToUInt16(SearchArgs.CompareStartValue);
1177 comparer.Value = value;
1178 }
1179 if (comparer.Compare(Convert.ToUInt16(Value), value))
1180 {
1181 writer.WriteResult<ushort>(comparer.Address, comparer.Value);
1182 }
1183 }
1184 #endregion
1185 writer.WriteResult<ushort>(CurrentIndex, br.ReadUInt16());
1186 }
1187 else
1188 {
1189 #region 16bits - signed
1190 var Value = br.ReadInt16();
1191 using (_16bit_signed_comparer_ comparer = new _16bit_signed_comparer_(SearchArgs, CurrentIndex))
1192 {
1193 short value = 0;
1194 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1195 {
1196 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1197 {
1198 try
1199 {
1200 gmp.OpenProvider();
1201 gmp.ReadMemory(CurrentIndex, out value);
1202 gmp.CloseProvider();
1203 }
1204 catch (Exception ex)
1205 {
1206 logger.VerboseError.WriteLine(ex.ToString());
1207 }
1208 }
1209 comparer.Value = value;
1210 }
1211 else
1212 {
1213 value = Convert.ToInt16(SearchArgs.CompareStartValue);
1214 comparer.Value = value;
1215 }
1216 if (comparer.Compare(Convert.ToSByte(Value), value))
1217 {
1218 writer.WriteResult<short>(comparer.Address, comparer.Value);
1219 }
1220 }
1221 #endregion
1222 } break;
1223 case SearchDataTypes._32bits:
1224 if (unsigned)
1225 {
1226 #region 32bits - unsigned
1227 var Value = br.ReadUInt32();
1228 using (_32bit_unsigned_comparer_ comparer = new _32bit_unsigned_comparer_(SearchArgs, CurrentIndex))
1229 {
1230 uint value = 0;
1231 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1232 {
1233 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1234 {
1235 try
1236 {
1237 gmp.OpenProvider();
1238 gmp.ReadMemory(CurrentIndex, out value);
1239 gmp.CloseProvider();
1240 }
1241 catch (Exception ex)
1242 {
1243 logger.VerboseError.WriteLine(ex.ToString());
1244 }
1245 }
1246 comparer.Value = value;
1247 }
1248 else
1249 {
1250 value = Convert.ToUInt32(SearchArgs.CompareStartValue);
1251 comparer.Value = value;
1252 }
1253 if (comparer.Compare(Convert.ToUInt32(Value), value))
1254 {
1255 writer.WriteResult<uint>(comparer.Address, comparer.Value);
1256 }
1257 }
1258 #endregion
1259 }
1260 else
1261 {
1262 #region 32bits - signed
1263 var Value = br.ReadInt32();
1264 using (_32bit_signed_comparer_ comparer = new _32bit_signed_comparer_(SearchArgs, CurrentIndex))
1265 {
1266 int value = 0;
1267 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1268 {
1269 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1270 {
1271 try
1272 {
1273 gmp.OpenProvider();
1274 gmp.ReadMemory(CurrentIndex, out value);
1275 gmp.CloseProvider();
1276 }
1277 catch (Exception ex)
1278 {
1279 logger.VerboseError.WriteLine(ex.ToString());
1280 }
1281 }
1282 comparer.Value = value;
1283 }
1284 else
1285 {
1286 value = Convert.ToInt32(SearchArgs.CompareStartValue);
1287 comparer.Value = value;
1288 }
1289 if (comparer.Compare(Convert.ToInt32(Value), value))
1290 {
1291 writer.WriteResult<int>(comparer.Address, comparer.Value);
1292 }
1293 }
1294 #endregion
1295 } break;
1296 case SearchDataTypes._64bits:
1297 if (unsigned)
1298 {
1299 #region 64bits - unsigned
1300 var Value = br.ReadUInt64();
1301 using (_64bit_unsigned_comparer_ comparer = new _64bit_unsigned_comparer_(SearchArgs, CurrentIndex))
1302 {
1303 ulong value = 0;
1304 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1305 {
1306 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1307 {
1308 try
1309 {
1310 gmp.OpenProvider();
1311 gmp.ReadMemory(CurrentIndex, out value);
1312 gmp.CloseProvider();
1313 }
1314 catch (Exception ex)
1315 {
1316 logger.VerboseError.WriteLine(ex.ToString());
1317 }
1318 }
1319 comparer.Value = value;
1320 }
1321 else
1322 {
1323 value = Convert.ToUInt64(SearchArgs.CompareStartValue);
1324 comparer.Value = value;
1325 }
1326 if (comparer.Compare(Convert.ToUInt64(Value), value))
1327 {
1328 writer.WriteResult<ulong>(comparer.Address, comparer.Value);
1329 }
1330 }
1331 #endregion
1332 }
1333 else
1334 {
1335 #region 64bits - signed
1336 var Value = br.ReadInt64();
1337 using (_64bit_signed_comparer_ comparer = new _64bit_signed_comparer_(SearchArgs, CurrentIndex))
1338 {
1339 long value = 0;
1340 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1341 {
1342 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1343 {
1344 try
1345 {
1346 gmp.OpenProvider();
1347 gmp.ReadMemory(CurrentIndex, out value);
1348 gmp.CloseProvider();
1349 }
1350 catch (Exception ex)
1351 {
1352 logger.VerboseError.WriteLine(ex.ToString());
1353 }
1354 }
1355 comparer.Value = value;
1356 }
1357 else
1358 {
1359 value = Convert.ToInt64(SearchArgs.CompareStartValue);
1360 comparer.Value = value;
1361 }
1362 if (comparer.Compare(Convert.ToInt64(Value), value))
1363 {
1364 writer.WriteResult<long>(comparer.Address, comparer.Value);
1365 }
1366 }
1367 #endregion
1368 } break;
1369 }
1370 if (SearchWorkerThread.CancellationPending) { e.Canceled = true; return; }
1371 }
1372 catch (EndOfStreamException) { }
1373 double double_percent_done = 100.0 * (double)((double)CurrentIndex / (double)e.TotalCount);
1374 int int_percent_done = (int)double_percent_done;
1375 if (int_percent_done != Last_Whole_Percent_Done && CurrentIndex % 100000 == 0)
1376 {
1377 if (int_percent_done <= 100)
1378 {
1379 new Action<int, string>(UpdateProgress).Invoke(int_percent_done, string.Format(" -> Reading Address: 0x{0:x8}", (CurrentIndex + MemoryRangeStart)));
1380 Last_Whole_Percent_Done = int_percent_done;
1381 }
1382 if (SearchWorkerThread.CancellationPending) { e.Canceled = true; return; }
1383 }
1384 switch (sdt)
1385 {
1386 case SearchDataTypes._8bits:
1387 CurrentIndex += sizeof(byte);
1388 break;
1389 case SearchDataTypes._16bits:
1390 CurrentIndex += sizeof(ushort);
1391 break;
1392 case SearchDataTypes._32bits:
1393 CurrentIndex += sizeof(uint);
1394 break;
1395 case SearchDataTypes._64bits:
1396 CurrentIndex += sizeof(ulong);
1397 break;
1398 }
1399 }
1400
1401 }
1402 }
1403 }
1404 if (SearchWorkerThread.CancellationPending) { e.Canceled = true; return; }
1405 }
1406 private void SearchWorkerThread_DoWork(object sender, DoWorkEventArgs e)
1407 {
1408 try
1409 {
1410 Stopwatch st = new Stopwatch();
1411 st.Start();
1412
1413 Stopwatch st_first_search = new Stopwatch();
1414 Stopwatch st_nonrange_search = new Stopwatch();
1415 Stopwatch st_ranged_search = new Stopwatch();
1416
1417 e.Result = st;
1418 //List<ResultType<object>> tmp_Results = new List<ResultType<object>>();
1419 List<ResultType<object>> second_tmp_Results = new List<ResultType<object>>();
1420 //const int ElementsBeforeDisplay = 100;
1421 SearchArgs.LogSearchOptions();
1422 uint STEP_SIZE = (uint)SearchArgs.DataType / 8;
1423
1424 bool unsigned = SearchArgs.IsUnsignedDataType;
1425 SearchDataTypes sdt = SearchArgs.DataType;
1426 //byte[] buffered_mem = new byte[(MemoryRangeSize - MemoryRangeStart)]; // throws OutOfMemoryException if size is over 2G
1427 logger.Debug.WriteLine(string.Format("Buffered Memory Size -> 0x{0:x8}", MemoryRangeSize - MemoryRangeStart));
1428 new Action<int, string>(UpdateProgress).Invoke(0, string.Format("Search is Warming Up...Please Wait..."));
1429 Stopwatch provider_st = new Stopwatch();
1430 provider_st.Start();
1431 using (GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1432 {
1433
1434 if (SearchArgs.IsFirstSearch)
1435 {
1436 provider.OpenProvider();
1437 int count = (int)((MemoryRangeSize - MemoryRangeStart) / STEP_SIZE);
1438 SearchResultWriter writer = new SearchResultWriter((int)(count), SearchGuid);
1439 provider.OnBytesRead += new BaseEventHandler<OnBytesReadEventArgs>(search_provider_OnBytesRead);
1440 provider.ReadProcessMemoryAtOnce(MemoryRangeStart, (MemoryRangeSize - MemoryRangeStart), writer);
1441 if (SearchWorkerThread.CancellationPending)
1442 {
1443 provider_st.Stop();
1444 st.Stop();
1445 writer.CancelRequest();
1446 writer.Dispose();
1447 writer = null;
1448 e.Result = true;
1449 provider.CloseProvider();
1450 return;
1451 }
1452 writer.Dispose();
1453 writer = null;
1454 provider.CloseProvider();
1455 }
1456 else
1457 {
1458 // need to get the address list
1459 using (SearchResultReader reader = new SearchResultReader(SearchGuid))
1460 {
1461 byte[] guid = SearchGuid.ToByteArray();
1462 guid[guid.Length - 1]++; // increment the search guid by 1
1463 Guid new_SearchGuid = new Guid(guid);
1464 //provider.OnBytesRead += new BaseEventHandler<OnBytesReadEventArgs>(search_provider_OnBytesRead);
1465 int count = 0;
1466 //int Last_Whole_Percent_Done = 0;
1467 //var results = reader.GetResults(SearchArgs.IsUnsignedDataType, SearchArgs.DataType, new Action<int, string>(UpdateProgress));
1468
1469 //reader.WriteUpdatedEntries(new_SearchGuid, SearchArgs.IsUnsignedDataType, SearchArgs.DataType, new Action<int, string>(UpdateProgress));
1470
1471 using (SearchResultWriter writer = new SearchResultWriter((int)(reader.ResultCount), new_SearchGuid))
1472 {
1473 for (int i = 0; i < reader.ResultCount; i++)
1474 {
1475 var item = reader.GetResultAtIndex(i, SearchArgs.IsUnsignedDataType, SearchArgs.DataType, new Action<int, string>(UpdateProgress));
1476 provider.OpenProvider();
1477 int bytesRead = 0;
1478 byte[] data = new byte[STEP_SIZE];
1479 provider.ReadProcessMemory(item.Address, STEP_SIZE, out bytesRead, out data);
1480 BaseEventHandler<OnBytesReadEventArgs> t = new BaseEventHandler<OnBytesReadEventArgs>(search_provider_OnBytesRead);
1481 OnBytesReadEventArgs t_args = new OnBytesReadEventArgs(this, writer, data, item.Address, (uint)reader.ResultCount);
1482 t.Invoke(t_args);
1483 t = null;
1484 t_args = null;
1485 double percent_done = 100.0 * ((double)count / (double)reader.ResultCount);
1486 new Action<int, string>(UpdateProgress).Invoke((int)percent_done, string.Format(" -> Reading Address: 0x{0:x8}", item.Address));
1487 count++;
1488 data = null;
1489 provider.CloseProvider();
1490 }
1491 }
1492 SearchGuid = new_SearchGuid;
1493 }
1494 }
1495 }
1496 provider_st.Stop();
1497 logger.Profiler.WriteLine("It took a total of {0} seconds for the memory provider to complete it's operation(s).", provider_st.Elapsed.TotalSeconds);
1498 //if (buffered_mem.Length == 0) { logger.Warn.WriteLine("Buffered Memory is Zero Length."); return; }
1499 //int Last_Whole_Percent_Done = 0;
1500
1501
1502 #region Subsequent Searches
1503 //r_ms.BaseStream.Seek(0, SeekOrigin.Begin);
1504
1505
1506 // hack to help with OutOfMemory Exceptions (OldValue and Equal compare will always add all found search results)
1507 bool NeedToCompare = true;
1508 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue &&
1509 SearchArgs.CompareType == SearchCompareTypes.Equal &&
1510 SearchArgs.IsFirstSearch)
1511 {
1512 NeedToCompare = false;
1513 //second_tmp_Results = null; // Free Memory
1514 }
1515
1516 if (NeedToCompare)
1517 {
1518 if (SearchArgs.CompareType != SearchCompareTypes.Between && SearchArgs.CompareType != SearchCompareTypes.NotBetween)
1519 {
1520 #region Non-Range Searches
1521 if (USE_NONRANGE_SEARCH_RESULT_READER)
1522 {
1523 st_nonrange_search.Start();
1524 //second_tmp_Results = new List<ResultType<object>>(SearchArgs.Results.Count * 1024);
1525 ////second_tmp_Results.c
1526 try
1527 {
1528 using (SearchResultReader reader = new SearchResultReader(SearchGuid))
1529 {
1530 try
1531 {
1532
1533 #region new comparator-support
1534 second_tmp_Results = new List<ResultType<object>>(reader.GetResults(SearchArgs.IsUnsignedDataType, SearchArgs.DataType, new Action<int, string>(UpdateProgress)));
1535 #endregion
1536
1537 #region USE_OLD_SEARCH_RESULTS_COMPRATOR_CODE
1538 if (USE_OLD_SEARCH_RESULTS_COMPRATOR_CODE)
1539 {
1540 for (int i = 0; i < reader.ResultCount; i += 1)
1541 {
1542 object result_value = 0;
1543 uint address = 0;
1544 #region switch (SearchArgs.DataType)
1545 switch (SearchArgs.DataType)
1546 {
1547 case SearchDataTypes._8bits: if (unsigned)
1548 {
1549 using (ResultType<byte> result = reader.GetNextResult<byte>())
1550 {
1551 address = result.Address;
1552 result_value = result.Value;
1553 }
1554 }
1555 else
1556 {
1557 using (ResultType<sbyte> result = reader.GetNextResult<sbyte>())
1558 {
1559 address = result.Address;
1560 result_value = result.Value;
1561 }
1562 } break;
1563 case SearchDataTypes._16bits: if (unsigned)
1564 {
1565 using (ResultType<ushort> result = reader.GetNextResult<ushort>())
1566 {
1567 address = result.Address;
1568 result_value = result.Value;
1569 }
1570 }
1571 else
1572 {
1573 using (ResultType<short> result = reader.GetNextResult<short>())
1574 {
1575 address = result.Address;
1576 result_value = result.Value;
1577 }
1578 } break;
1579 case SearchDataTypes._32bits: if (unsigned)
1580 {
1581 using (ResultType<uint> result = reader.GetNextResult<uint>())
1582 {
1583 address = result.Address;
1584 result_value = result.Value;
1585 }
1586 }
1587 else
1588 {
1589 using (ResultType<int> result = reader.GetNextResult<int>())
1590 {
1591 address = result.Address;
1592 result_value = result.Value;
1593 }
1594 } break;
1595 case SearchDataTypes._64bits: if (unsigned)
1596 {
1597 using (ResultType<ulong> result = reader.GetNextResult<ulong>())
1598 {
1599 address = result.Address;
1600 result_value = result.Value;
1601 }
1602 }
1603 else
1604 {
1605 using (ResultType<long> result = reader.GetNextResult<long>())
1606 {
1607 address = result.Address;
1608 result_value = result.Value;
1609 }
1610 } break;
1611 }
1612 #endregion
1613 if (MemoryRangeStart > 0 && !SearchArgs.IsFirstSearch) { address = address - MemoryRangeStart; }
1614 try
1615 {
1616 //r_ms.BaseStream.Seek(address, SeekOrigin.Begin);
1617 }
1618 catch (Exception)
1619 {
1620 throw;
1621 }
1622 switch (SearchArgs.DataType)
1623 {
1624 #region Comparer Support
1625 #region case SearchDataTypes._8bits:
1626 case SearchDataTypes._8bits:
1627 if (SearchArgs.IsUnsignedDataType)
1628 {
1629 byte lookup_value = 0;
1630 //using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this)) { gmp.OpenProvider(); gmp.ReadMemory(address, out lookup_value); gmp.CloseProvider(); }
1631 lookup_value = Convert.ToByte(result_value);
1632 using (_8bit_unsigned_comparer_ comparer = new _8bit_unsigned_comparer_(SearchArgs, address))
1633 {
1634 byte value = 0;
1635 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1636 {
1637 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1638 {
1639 try
1640 {
1641 gmp.OpenProvider();
1642 gmp.ReadMemory(address, out value);
1643 gmp.CloseProvider();
1644 }
1645 catch (Exception ex)
1646 {
1647 logger.VerboseError.WriteLine(ex.ToString());
1648 }
1649 }
1650 comparer.Value = value;
1651 }
1652 else
1653 {
1654 value = Convert.ToByte(SearchArgs.CompareStartValue);
1655 comparer.Value = value;
1656 }
1657 if (comparer.Compare(lookup_value, value))
1658 {
1659 second_tmp_Results.Add(new ResultType<object>(comparer.Address, comparer.Value));
1660 }
1661 }
1662 }
1663 else
1664 {
1665 sbyte lookup_value = 0;
1666 //using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this)) { gmp.OpenProvider(); gmp.ReadMemory(address, out lookup_value); gmp.CloseProvider(); }
1667 lookup_value = Convert.ToSByte(result_value);
1668 using (_8bit_signed_comparer_ comparer = new _8bit_signed_comparer_(SearchArgs, address))
1669 {
1670 sbyte value = 0;
1671 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1672 {
1673 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1674 {
1675 try
1676 {
1677 gmp.OpenProvider();
1678 gmp.ReadMemory(address, out value);
1679 gmp.CloseProvider();
1680 }
1681 catch (Exception ex)
1682 {
1683 logger.VerboseError.WriteLine(ex.ToString());
1684 }
1685 }
1686 comparer.Value = value;
1687 }
1688 else
1689 {
1690 value = Convert.ToSByte(SearchArgs.CompareStartValue);
1691 }
1692 if (comparer.Compare(lookup_value, value))
1693 {
1694 second_tmp_Results.Add(new ResultType<object>(comparer.Address, comparer.Value));
1695 }
1696 }
1697 }
1698 break;
1699 #endregion
1700 #region case SearchDataTypes._16bits:
1701 case SearchDataTypes._16bits:
1702 if (SearchArgs.IsUnsignedDataType)
1703 {
1704 ushort lookup_value = 0;
1705 //using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this)) { gmp.OpenProvider(); gmp.ReadMemory(address, out lookup_value); gmp.CloseProvider(); }
1706 lookup_value = Convert.ToUInt16(result_value);
1707 using (_16bit_unsigned_comparer_ comparer = new _16bit_unsigned_comparer_(SearchArgs, address))
1708 {
1709 ushort value = 0;
1710 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1711 {
1712 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1713 {
1714 try
1715 {
1716 gmp.OpenProvider();
1717 gmp.ReadMemory(address, out value);
1718 gmp.CloseProvider();
1719 }
1720 catch (Exception ex)
1721 {
1722 logger.VerboseError.WriteLine(ex.ToString());
1723 }
1724 }
1725 comparer.Value = value;
1726 }
1727 else
1728 {
1729 value = Convert.ToUInt16(SearchArgs.CompareStartValue);
1730 comparer.Value = value;
1731 }
1732 if (comparer.Compare(lookup_value, value))
1733 {
1734 second_tmp_Results.Add(new ResultType<object>(comparer.Address, comparer.Value));
1735 }
1736 }
1737 }
1738 else
1739 {
1740 short lookup_value = 0;
1741 //using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this)) { gmp.OpenProvider(); gmp.ReadMemory(address, out lookup_value); gmp.CloseProvider(); }
1742 lookup_value = Convert.ToInt16(result_value);
1743 using (_16bit_signed_comparer_ comparer = new _16bit_signed_comparer_(SearchArgs, address))
1744 {
1745 short value = 0;
1746 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1747 {
1748 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1749 {
1750 try
1751 {
1752 gmp.OpenProvider();
1753 gmp.ReadMemory(address, out value);
1754 gmp.CloseProvider();
1755 }
1756 catch (Exception ex)
1757 {
1758 logger.VerboseError.WriteLine(ex.ToString());
1759 }
1760 }
1761 comparer.Value = value;
1762 }
1763 else
1764 {
1765 value = Convert.ToInt16(SearchArgs.CompareStartValue);
1766 }
1767 if (comparer.Compare(lookup_value, value))
1768 {
1769 second_tmp_Results.Add(new ResultType<object>(comparer.Address, comparer.Value));
1770 }
1771 }
1772 }
1773 break;
1774 #endregion
1775 #region case SearchDataTypes._32bits:
1776 case SearchDataTypes._32bits:
1777 if (SearchArgs.IsUnsignedDataType)
1778 {
1779 uint lookup_value = 0;
1780 //using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this)) { gmp.OpenProvider(); gmp.ReadMemory(address, out lookup_value); gmp.CloseProvider(); }
1781 lookup_value = Convert.ToUInt32(result_value);
1782 using (_32bit_unsigned_comparer_ comparer = new _32bit_unsigned_comparer_(SearchArgs, address))
1783 {
1784 uint value = 0;
1785 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1786 {
1787 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1788 {
1789 try
1790 {
1791 gmp.OpenProvider();
1792 gmp.ReadMemory(address, out value);
1793 gmp.CloseProvider();
1794 }
1795 catch (Exception ex)
1796 {
1797 logger.VerboseError.WriteLine(ex.ToString());
1798 }
1799 }
1800 comparer.Value = value;
1801 }
1802 else
1803 {
1804 value = Convert.ToUInt32(SearchArgs.CompareStartValue);
1805 comparer.Value = value;
1806 }
1807 if (comparer.Compare(lookup_value, value))
1808 {
1809 second_tmp_Results.Add(new ResultType<object>(comparer.Address, comparer.Value));
1810 }
1811 }
1812 }
1813 else
1814 {
1815 int lookup_value = 0;
1816 //using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this)) { gmp.OpenProvider(); gmp.ReadMemory(address, out lookup_value); gmp.CloseProvider(); }
1817 lookup_value = Convert.ToInt32(result_value);
1818 using (_32bit_signed_comparer_ comparer = new _32bit_signed_comparer_(SearchArgs, address))
1819 {
1820 int value = 0;
1821 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1822 {
1823 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1824 {
1825 try
1826 {
1827 gmp.OpenProvider();
1828 gmp.ReadMemory(address, out value);
1829 gmp.CloseProvider();
1830 }
1831 catch (Exception ex)
1832 {
1833 logger.VerboseError.WriteLine(ex.ToString());
1834 }
1835 }
1836 comparer.Value = value;
1837 }
1838 else
1839 {
1840 value = Convert.ToInt32(SearchArgs.CompareStartValue);
1841 }
1842 if (comparer.Compare(lookup_value, value))
1843 {
1844 second_tmp_Results.Add(new ResultType<object>(comparer.Address, comparer.Value));
1845 }
1846 }
1847 }
1848 break;
1849 #endregion
1850 #region case SearchDataTypes._64bits:
1851 case SearchDataTypes._64bits:
1852 if (SearchArgs.IsUnsignedDataType)
1853 {
1854 ulong lookup_value = 0;
1855 //using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this)) { gmp.OpenProvider(); gmp.ReadMemory(address, out lookup_value); gmp.CloseProvider(); }
1856 lookup_value = Convert.ToUInt64(result_value);
1857 using (_64bit_unsigned_comparer_ comparer = new _64bit_unsigned_comparer_(SearchArgs, address))
1858 {
1859 ulong value = 0;
1860 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1861 {
1862 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1863 {
1864 try
1865 {
1866 gmp.OpenProvider();
1867 gmp.ReadMemory(address, out value);
1868 gmp.CloseProvider();
1869 }
1870 catch (Exception ex)
1871 {
1872 logger.VerboseError.WriteLine(ex.ToString());
1873 }
1874 }
1875 comparer.Value = value;
1876 }
1877 else
1878 {
1879 value = Convert.ToUInt64(SearchArgs.CompareStartValue);
1880 comparer.Value = value;
1881 }
1882 if (comparer.Compare(lookup_value, value))
1883 {
1884 second_tmp_Results.Add(new ResultType<object>(comparer.Address, comparer.Value));
1885 }
1886 }
1887 }
1888 else
1889 {
1890 long lookup_value = 0;
1891 //using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this)) { gmp.OpenProvider(); gmp.ReadMemory(address, out lookup_value); gmp.CloseProvider(); }
1892 lookup_value = Convert.ToInt64(result_value);
1893 using (_64bit_signed_comparer_ comparer = new _64bit_signed_comparer_(SearchArgs, address))
1894 {
1895 long value = 0;
1896 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
1897 {
1898 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
1899 {
1900 try
1901 {
1902 gmp.OpenProvider();
1903 gmp.ReadMemory(address, out value);
1904 gmp.CloseProvider();
1905 }
1906 catch (Exception ex)
1907 {
1908 logger.VerboseError.WriteLine(ex.ToString());
1909 }
1910 }
1911 comparer.Value = value;
1912 }
1913 else
1914 {
1915 value = Convert.ToInt64(SearchArgs.CompareStartValue);
1916 }
1917 if (comparer.Compare(lookup_value, value))
1918 {
1919 second_tmp_Results.Add(new ResultType<object>(comparer.Address, comparer.Value));
1920 }
1921 }
1922 }
1923 break;
1924 #endregion
1925 #endregion
1926 }
1927 double double_percent_done = 100.0 * (double)((double)i / (double)reader.ResultCount);
1928 int int_percent_done = (int)double_percent_done;
1929 //if (int_percent_done != Last_Whole_Percent_Done && i % 100000 == 0)
1930 //{
1931 if (int_percent_done <= 100)
1932 {
1933 //Last_Whole_Percent_Done = int_percent_done;
1934 new Action<int, string>(UpdateProgress).Invoke(int_percent_done, string.Format(" -> Reading Address: 0x{0:x8}", i + MemoryRangeStart));
1935 }
1936 //}
1937 //this.Refresh();
1938 }
1939 }
1940 #endregion
1941 }
1942 catch (Exception ex)
1943 {
1944 throw ex;
1945 }
1946 }
1947 }
1948 catch (Exception ex)
1949 {
1950 throw ex;
1951 }
1952 st_nonrange_search.Stop();
1953 logger.Profiler.WriteLine("Non-Ranged search took a total of {0} seconds to complete.", st_nonrange_search.Elapsed.TotalSeconds);
1954 //Last_Whole_Percent_Done = 0;
1955 }
1956 #endregion
1957 }
1958 #region Ranged Searches
1959 #if !DONOT_HAVE_RANGED_SEARCH_SUPPORT
1960 if (SearchArgs.CompareType == SearchCompareTypes.Between || SearchArgs.CompareType == SearchCompareTypes.NotBetween)
1961 {
1962 st_ranged_search.Start();
1963 object start, end;
1964
1965 start = SearchArgs.CompareStartValue;
1966 end = SearchArgs.CompareEndValue;
1967 using (SearchResultReader reader = new SearchResultReader(SearchGuid))
1968 {
1969 for (int i = 0; i < reader.ResultCount; i += 1)
1970 {
1971 uint address = 0;
1972 #region switch (SearchArgs.DataType)
1973 switch (SearchArgs.DataType)
1974 {
1975 case SearchDataTypes._8bits: if (unsigned) { using (ResultType<byte> result = reader.GetNextResult<byte>()) { address = result.Address; } }
1976 else { using (ResultType<sbyte> result = reader.GetNextResult<sbyte>()) { address = result.Address; } } break;
1977 case SearchDataTypes._16bits: if (unsigned) { using (ResultType<ushort> result = reader.GetNextResult<ushort>()) { address = result.Address; } }
1978 else { using (ResultType<short> result = reader.GetNextResult<short>()) { address = result.Address; } } break;
1979 case SearchDataTypes._32bits: if (unsigned) { using (ResultType<uint> result = reader.GetNextResult<uint>()) { address = result.Address; } }
1980 else { using (ResultType<int> result = reader.GetNextResult<int>()) { address = result.Address; } } break;
1981 case SearchDataTypes._64bits: if (unsigned) { using (ResultType<ulong> result = reader.GetNextResult<ulong>()) { address = result.Address; } }
1982 else { using (ResultType<long> result = reader.GetNextResult<long>()) { address = result.Address; } } break;
1983 }
1984 #endregion
1985
1986 if (MemoryRangeStart > 0 && !SearchArgs.IsFirstSearch) { address = address - MemoryRangeStart; }
1987 //r_ms.BaseStream.Seek(address, SeekOrigin.Begin);
1988 if (SearchArgs.CompareType == SearchCompareTypes.Between)
1989 {
1990 using (InRangeComparer comparer = new InRangeComparer(address, 0))
1991 {
1992 if (comparer.Compare(start, end, SearchArgs.DataType, SearchArgs.IsUnsignedDataType, (IAcceptsProcessAndConfig)this))
1993 {
1994 using (ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value))
1995 {
1996 second_tmp_Results.Add(_tmp_result);
1997 }
1998 }
1999 }
2000 }
2001 else if (SearchArgs.CompareType == SearchCompareTypes.NotBetween)
2002 {
2003 using (NotInRangeComparer comparer = new NotInRangeComparer(address, 0))
2004 {
2005 if (comparer.Compare(start, end, SearchArgs.DataType, SearchArgs.IsUnsignedDataType, (IAcceptsProcessAndConfig)this))
2006 {
2007 using (ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value))
2008 {
2009 second_tmp_Results.Add(_tmp_result);
2010 }
2011 }
2012 }
2013 }
2014 else
2015 {
2016 throw new InvalidOperationException("Encounted unkown range search type: " + SearchArgs.CompareType);
2017 }
2018 double double_percent_done = 100.0 * (double)((double)i / (double)reader.ResultCount);
2019 int int_percent_done = (int)double_percent_done;
2020 if (int_percent_done != Last_Whole_Percent_Done)
2021 {
2022 if (int_percent_done <= 100)
2023 {
2024 resultsprogress.Value = int_percent_done;
2025 resultsprogress.Message = string.Format(" -> Reading Address: 0x{0:x8}", i + MemoryRangeStart);
2026 Last_Whole_Percent_Done = int_percent_done;
2027 }
2028 }
2029 }
2030 }
2031 st_ranged_search.Stop();
2032 logger.Profiler.WriteLine("Ranged search took a total of {0} seconds to complete.", st_ranged_search.Elapsed.TotalSeconds);
2033 }
2034 #endif
2035 #endregion
2036
2037 }
2038 #endregion
2039 //// leave SearchArgs.Results alone, if false
2040 //if (NeedToCompare)
2041 //{
2042 // // fix addresses when memory start is not zero
2043 // if (MemoryRangeStart > 0 && SearchArgs.IsFirstSearch) { for (int i = 0; i < second_tmp_Results.Count; i++) { second_tmp_Results[i].Address = second_tmp_Results[i].Address + MemoryRangeStart; } }
2044 // using (SearchResultWriter writer = new SearchResultWriter(second_tmp_Results.Count, SearchGuid))
2045 // {
2046 // for (int i = 0; i < second_tmp_Results.Count; i++)
2047 // {
2048 // switch (sdt)
2049 // {
2050 // case SearchDataTypes._8bits:
2051 // if (unsigned) { writer.WriteResult<Byte>(second_tmp_Results[i].Address, Convert.ToByte(second_tmp_Results[i].Value)); }
2052 // else { writer.WriteResult<SByte>(second_tmp_Results[i].Address, Convert.ToSByte(second_tmp_Results[i].Value)); } break;
2053 // case SearchDataTypes._16bits:
2054 // if (unsigned) { writer.WriteResult<UInt16>(second_tmp_Results[i].Address, Convert.ToUInt16(second_tmp_Results[i].Value)); }
2055 // else { writer.WriteResult<Int16>(second_tmp_Results[i].Address, Convert.ToInt16(second_tmp_Results[i].Value)); } break;
2056 // case SearchDataTypes._32bits:
2057 // if (unsigned) { writer.WriteResult<UInt32>(second_tmp_Results[i].Address, Convert.ToUInt32(second_tmp_Results[i].Value)); }
2058 // else { writer.WriteResult<Int32>(second_tmp_Results[i].Address, Convert.ToInt32(second_tmp_Results[i].Value)); } break;
2059 // case SearchDataTypes._64bits:
2060 // if (unsigned) { writer.WriteResult<UInt64>(second_tmp_Results[i].Address, Convert.ToUInt64(second_tmp_Results[i].Value)); }
2061 // else { writer.WriteResult<Int64>(second_tmp_Results[i].Address, Convert.ToInt64(second_tmp_Results[i].Value)); } break;
2062 // }
2063 // }
2064 // }
2065 // second_tmp_Results = null; // free memory
2066 //}
2067 }
2068 catch (Exception ex)
2069 {
2070 throw ex;
2071 }
2072 }
2073
2074
2075
2076 private void SearchWorkerThread_ProgressChanged(object sender, ProgressChangedEventArgs e)
2077 {
2078 //if (SearchArgs.ProgressLogger != null)
2079 //{
2080 // resultsprogress.Value = e.ProgressPercentage;
2081 // //Application.DoEvents();
2082 //}
2083 }
2084
2085 private void SearchWorkerThread_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
2086 {
2087 try { if ((bool)e.Result) { logger.Warn.WriteLine("Search operation was cancelled.");
2088 new Action<int, string>(UpdateProgress).Invoke(0, string.Empty);
2089 return; }
2090 }
2091 catch (InvalidCastException) { }
2092 try
2093 {
2094 Stopwatch st = (Stopwatch)e.Result;
2095 st.Stop();
2096 logger.Profiler.WriteLine("Search took {0} seconds, overall, to complete.", st.Elapsed.TotalSeconds);
2097 }
2098 catch (InvalidCastException) { }
2099 catch (Exception ex) { throw ex; }
2100
2101 new Action<int, string>(UpdateProgress).Invoke(100, string.Empty);
2102 bool unsigned = SearchArgs.IsUnsignedDataType;
2103 using (SearchResultReader reader = new SearchResultReader(SearchGuid))
2104 {
2105 logger.Info.WriteLine(string.Format("Found 0x{0:x8} results", reader.ResultCount));
2106
2107 if (reader.ResultCount <= MIN_NUMBER_OF_RESULTS_BEFORE_DISPLAY)
2108 {
2109 lstResults.Items.Clear();
2110 //List<ResultItem> items = new List<ResultItem>();
2111 //for (int i = 0; i < reader.ResultCount; i++)
2112 //{
2113 // ResultItem item = new ResultItem(0, false);
2114 // //item.Text = string.Format("0x{0:x8}", SearchArgs.Results[i].Address);
2115 // //item.SubItems.Add(string.Format("0x{0:x8}", SearchArgs.Results[i].Address));
2116 // switch (SearchArgs.DataType)
2117 // {
2118 // case SearchDataTypes._8bits:
2119 // if (SearchArgs.IsUnsignedDataType) { ResultType<byte> result = new ResultType<byte>(); item = new ResultItem(result.Address, false, result.Value); }
2120 // else { ResultType<sbyte> result = reader.GetNextResult<sbyte>(); item = new ResultItem(result.Address, false, result.Value); }
2121 // break;
2122 // case SearchDataTypes._16bits:
2123 // if (SearchArgs.IsUnsignedDataType) { ResultType<ushort> result = reader.GetNextResult<ushort>(); item = new ResultItem(result.Address, false, result.Value); }
2124 // else { ResultType<short> result = reader.GetNextResult<short>(); item = new ResultItem(result.Address, false, result.Value); }
2125 // break;
2126 // case SearchDataTypes._32bits:
2127 // if (SearchArgs.IsUnsignedDataType) { ResultType<uint> result = reader.GetNextResult<uint>(); item = new ResultItem(result.Address, false, result.Value); }
2128 // else { ResultType<int> result = reader.GetNextResult<int>(); item = new ResultItem(result.Address, false, result.Value); }
2129 // break;
2130 // case SearchDataTypes._64bits:
2131 // if (SearchArgs.IsUnsignedDataType) { ResultType<ulong> result = reader.GetNextResult<ulong>(); item = new ResultItem(result.Address, false, result.Value); }
2132 // else { ResultType<long> result = reader.GetNextResult<long>(); item = new ResultItem(result.Address, false, result.Value); }
2133 // break;
2134 // }
2135 // if (!items.Contains(item))
2136 // items.Add(item);
2137 //}
2138 lstResults.Items.AddRange(reader.GetResultItems(SearchArgs.IsUnsignedDataType, SearchArgs.DataType, new Action<int, string>(UpdateProgress)));
2139 }
2140 }
2141
2142 this.DoSearchDoneSpecific();
2143 //System.Threading.Thread.Sleep(100);
2144 //if (_SEARCH_MODE != SearchMode.SEARCH_MODE_NORMAL_WITH_JOKER)
2145 this.ThawResultsUpdate();
2146 Application.DoEvents();
2147 }
2148 private void DoSearchDoneSpecific()
2149 {
2150 SearchWorkerThread.CancelAsync();
2151 if (lstResults.Items.Count > 0) { timer_update_results.Enabled = true; }
2152 else { timer_update_results.Enabled = false; }
2153
2154 search_progress_updater.Enabled = false;
2155
2156 btnCancel.Enabled = false;
2157 btnReset.Enabled = true;
2158 btnSearch.Enabled = true;
2159 grpCompareType.Enabled = true;
2160 grpCompareValue.Enabled = true;
2161 new Action<int, string>(UpdateProgress).Invoke(0, string.Empty);
2162 grpDataType.Enabled = false;
2163 // resume process on reset, incase it was suspended
2164 ThreadControl.ResumeProcess(this.ProcessPID);
2165 //Application.DoEvents();
2166 this.Refresh();
2167 }
2168
2169 private void DoCancelSpecific()
2170 {
2171 this.DoSearchDoneSpecific();
2172 }
2173 private void DoResetSpecific()
2174 {
2175 this.DoCancelSpecific();
2176 IsFirstSearch = true;
2177 grpDataType.Enabled = true;
2178 btnReset.Enabled = false;
2179
2180 // delete any temporary search result files
2181 SearchResultWriter.CleanupTemporarySearchResultFiles();
2182
2183 }
2184 private void search_progress_updater_Tick(object sender, EventArgs e)
2185 {
2186 if ((this.ProcessPID == 0) || Process.GetProcessById(this.ProcessPID) == null)
2187 {
2188 SearchWorkerThread.CancelAsync();
2189 //JokerSearchWorker.CancelAsync();
2190 ResultsUpdateWorkerThread.CancelAsync();
2191 }
2192 }
2193
2194 #region Search Button
2195 private void btnSearch_Click(object sender, EventArgs e)
2196 {
2197 if (this.SearchGuid == Guid.Empty)
2198 this.SearchGuid = Guid.NewGuid();
2199 this.SearchInProgess = true;
2200 btnCancel.Enabled = true;
2201 btnReset.Enabled = true;
2202 btnSearch.Enabled = false;
2203 this.FreezeResultsUpdate();
2204 this.handle_btnSearch_Click();
2205 }
2206 private void handle_btnSearch_Click()
2207 {
2208 //this.FreezeResultsUpdate();
2209 lstResults.Items.Clear();
2210
2211 if (lstResults.Items.Count > 0) { timer_update_results.Enabled = true; }
2212 else { timer_update_results.Enabled = false; }
2213 new Action<int, string>(UpdateProgress).Invoke(0, string.Empty);
2214 bool _is_unsigned = chkUnsigned.Checked;
2215 SearchType search_type = new SearchType();
2216 SearchDataTypes _data_type = new SearchDataTypes();
2217 SearchCompareTypes _compare_type = new SearchCompareTypes();
2218 CompareValueTypes _compare_value_type = new CompareValueTypes();
2219 object start_value = 0;
2220 object end_value = 0;
2221 // get datatype
2222 if (radio_8bits.Checked) { _data_type = SearchDataTypes._8bits; }
2223 else if (radio_16bits.Checked) { _data_type = SearchDataTypes._16bits; }
2224 else if (radio_32bits.Checked) { _data_type = SearchDataTypes._32bits; }
2225 else if (radio_64bits.Checked) { _data_type = SearchDataTypes._64bits; }
2226 else { logger.Error.WriteLine("Could not determine search data type bit size. (was not 8/16/32/or 64bits)"); }
2227 // get compare type
2228 if (radiocompare_equal.Checked) { _compare_type = SearchCompareTypes.Equal; }
2229 else if (radiocompare_greaterthan.Checked) { _compare_type = SearchCompareTypes.GreaterThan; }
2230 else if (radiocompare_lessthan.Checked) { _compare_type = SearchCompareTypes.LessThan; }
2231 else if (radiocompare_greaterthan_orequal.Checked) { _compare_type = SearchCompareTypes.GreaterThanOrEqual; }
2232 else if (radiocompare_lessthan_orequal.Checked) { _compare_type = SearchCompareTypes.LessThanOrEqual; }
2233 else if (radiocompare_notequal.Checked) { _compare_type = SearchCompareTypes.NotEqual; }
2234 else if (radiocompare_between.Checked) { _compare_type = SearchCompareTypes.Between; }
2235 else if (radiocompare_notbetween.Checked) { _compare_type = SearchCompareTypes.NotBetween; }
2236 else { logger.Error.WriteLine("Could not determine search comparison type. (was not == > < >= <= != <> or !<>)"); }
2237 // get compare valure type
2238 if (radio_oldvalue.Checked) { _compare_value_type = CompareValueTypes.OldValue; }
2239 else if (radio_specificvalue.Checked) { _compare_value_type = CompareValueTypes.SpecificValue; }
2240 else { logger.Error.WriteLine("Could not determine search comparison type. (was not old or specific value"); }
2241
2242 if (_compare_value_type == CompareValueTypes.SpecificValue || (_compare_type == SearchCompareTypes.Between || _compare_type == SearchCompareTypes.NotBetween))
2243 {
2244
2245 switch (_data_type)
2246 {
2247 case SearchDataTypes._8bits:
2248 if (_is_unsigned) { start_value = txtStartAddr.ToByte(); }
2249 else { start_value = txtStartAddr.ToSByte(); }
2250 break;
2251 case SearchDataTypes._16bits:
2252 if (_is_unsigned) { start_value = txtStartAddr.ToUInt16(); }
2253 else { start_value = txtStartAddr.ToInt16(); }
2254 break;
2255 case SearchDataTypes._32bits:
2256 if (_is_unsigned) { start_value = txtStartAddr.ToUInt32(); }
2257 else { start_value = txtStartAddr.ToInt32(); }
2258 break;
2259 case SearchDataTypes._64bits:
2260 if (_is_unsigned) { start_value = txtStartAddr.ToUInt64(); }
2261 else { start_value = txtStartAddr.ToInt64(); }
2262 break;
2263 default: throw new InvalidOperationException("In SearchType(): Encounterd an Unkown Search Data Type.");
2264 }
2265 }
2266 if (_compare_type == SearchCompareTypes.Between || _compare_type == SearchCompareTypes.NotBetween)
2267 {
2268 switch (_data_type)
2269 {
2270 case SearchDataTypes._8bits:
2271 if (_is_unsigned) { end_value = txtEndAddr.ToByte(); }
2272 else { end_value = txtEndAddr.ToSByte(); }
2273 break;
2274 case SearchDataTypes._16bits:
2275 if (_is_unsigned) { end_value = txtEndAddr.ToUInt16(); }
2276 else { end_value = txtEndAddr.ToInt16(); }
2277 break;
2278 case SearchDataTypes._32bits:
2279 if (_is_unsigned) { end_value = txtEndAddr.ToUInt32(); }
2280 else { end_value = txtEndAddr.ToInt32(); }
2281 break;
2282 case SearchDataTypes._64bits:
2283 if (_is_unsigned) { end_value = txtEndAddr.ToUInt64(); }
2284 else { end_value = txtEndAddr.ToInt64(); }
2285 break;
2286 default: throw new InvalidOperationException("In SearchType(): Encounterd an Unkown Search Data Type.");
2287 }
2288 }
2289
2290 search_type = new SearchType(_data_type, _is_unsigned, _compare_type, _compare_value_type, start_value, end_value, resultsprogress);
2291
2292 //search_type.LogSearchOptions();
2293
2294 search_type.IsFirstSearch = IsFirstSearch;
2295
2296
2297
2298 DoSearch(search_type);
2299 IsFirstSearch = false;
2300 }
2301 private void DoSearch(SearchType args)
2302 {
2303 if (!args.IsFirstSearch && SearchArgs != null)
2304 {
2305 //args.Results.AddRange(SearchArgs.Results.ToArray());
2306 //args.Results = SearchArgs.Results;
2307 }
2308 SearchArgs = args;
2309 #if DONOT_HAVE_RANGED_SEARCH_SUPPORT
2310 if (SearchArgs.CompareType == SearchCompareTypes.Between || SearchArgs.CompareType == SearchCompareTypes.NotBetween)
2311 {
2312 throw new NotImplementedException("Between and Not Between Range searches have not been implemented.");
2313 }
2314 #endif
2315 search_progress_updater.Enabled = true;
2316 //padPluginSelector.Enabled = false;
2317 //gsPluginSelector.Enabled = false;
2318 btnReset.Enabled = true;
2319 btnSearch.Enabled = false;
2320 btnCancel.Enabled = true;
2321 grpDataType.Enabled = false;
2322 grpCompareType.Enabled = false;
2323 grpCompareValue.Enabled = false;
2324 this.Refresh();
2325 Application.DoEvents();
2326 SearchWorkerThread.RunWorkerAsync();
2327 }
2328 #endregion
2329 private void btnReset_Click(object sender, EventArgs e)
2330 {
2331 this.SearchGuid = Guid.Empty;
2332 this.SearchInProgess = false;
2333 btnSearch.Enabled = true;
2334 btnReset.Enabled = false;
2335 btnCancel.Enabled = false;
2336 this.DoResetSpecific();
2337 lstResults.Items.Clear();
2338 //try { SearchArgs.Results = new List<ResultType<object>>(); }
2339 //catch { }
2340 }
2341
2342 private void btnCancel_Click(object sender, EventArgs e)
2343 {
2344 this.SearchInProgess = false;
2345 btnCancel.Enabled = false;
2346 btnSearch.Enabled = true;
2347 btnReset.Enabled = true;
2348 this.DoCancelSpecific();
2349 }
2350
2351 private void mnuItemPatchListViewMemoryRegion_Click(object sender, EventArgs e)
2352 {
2353 List<ResultDataType> patch_list = new List<ResultDataType>();
2354 List<int> SelectedIndexes = new List<int>();
2355 foreach (int index in lstPatchList.SelectedIndices) { SelectedIndexes.Add(index); }
2356 foreach (int index in SelectedIndexes)
2357 {
2358 ListViewItem item = lstPatchList.Items[index];
2359 ResultDataType rdt = (ResultDataType)item.Tag;
2360 ViewMemoryRegion(rdt);
2361 break; // only get the fist item
2362 }
2363 }
2364
2365 private void mnuItemResultsListViewMemoryRegion_Click(object sender, EventArgs e)
2366 {
2367 List<ResultDataType> patch_list = new List<ResultDataType>();
2368 List<int> SelectedIndexes = new List<int>();
2369 foreach (int index in lstResults.SelectedIndices) { SelectedIndexes.Add(index); }
2370 foreach (int index in SelectedIndexes)
2371 {
2372 ListViewItem item = lstResults.Items[index];
2373 ResultDataType rdt = (ResultDataType)item.Tag;
2374 ViewMemoryRegion(rdt);
2375 break; // only get the fist item
2376 }
2377 }
2378 private void ViewMemoryRegion(ResultDataType rdt)
2379 {
2380 if (OnBrowseMemoryRegion != null)
2381 OnBrowseMemoryRegion(new BrowseMemoryRegionEvent(this, rdt.Address));
2382 }
2383
2384 private void mnuAddedResults_Opening(object sender, CancelEventArgs e)
2385 {
2386 if (!(lstPatchList.Items.Count > 0)) { mnuItemRemoveResult.Visible = false; e.Cancel = true; }
2387 if (!(lstPatchList.Items.Count > 0)) { mnuItemPatchSelectedEntry.Visible = false; e.Cancel = true; }
2388 if (e.Cancel) return;
2389 if (lstPatchList.Items.Count > 0) mnuItemRemoveResult.Visible = true;
2390 if (lstPatchList.Items.Count > 0) mnuItemPatchSelectedEntry.Visible = true;
2391
2392 if (!(lstPatchList.Items.Count > 0)) { mnuItemFreezeSelectedPatches.Visible = false; e.Cancel = true; }
2393 if (!(lstPatchList.Items.Count > 0)) { mnuItemThawSelectedPatches.Visible = false; e.Cancel = true; }
2394 if (e.Cancel) return;
2395
2396 if (lstPatchList.Items.Count > 0) mnuItemFreezeSelectedPatches.Visible = true;
2397 if (lstPatchList.Items.Count > 0) mnuItemThawSelectedPatches.Visible = true;
2398
2399 if (lstPatchList.SelectedItems.Count == 0) e.Cancel = true;
2400 if (e.Cancel) return;
2401
2402 }
2403
2404 private void mnuResults_Opening(object sender, CancelEventArgs e)
2405 {
2406 if (!(lstResults.Items.Count > 0)) e.Cancel = true;
2407 if (lstResults.SelectedItems.Count == 0) e.Cancel = true;
2408 if (SearchArgs == null) e.Cancel = true;
2409 if (e.Cancel) return;
2410 }
2411
2412 private void chkMemoryRangeExpertMode_CheckedChanged(object sender, EventArgs e)
2413 {
2414 txtMemoryRangeStart.ReadOnly = !chkMemoryRangeExpertMode.Checked;
2415 txtMemoryRangeSize.ReadOnly = !chkMemoryRangeExpertMode.Checked;
2416 }
2417
2418 private void txtMemoryRangeStart_ValueChanged(object sender, ValueChangedEventArgs e) { this.MemoryRangeStart = Convert.ToUInt32(e.NewValue); }
2419 private void txtMemoryRangeSize_ValueChanged(object sender, ValueChangedEventArgs e) { this.MemoryRangeSize = Convert.ToUInt32(e.NewValue); }
2420
2421 }
2422 }

  ViewVC Help
Powered by ViewVC 1.1.22