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