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