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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.22