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