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