/[RomCheater]/trunk/RomCheater/Docking/MemorySearch/InRangeComparer.cs
ViewVC logotype

Contents of /trunk/RomCheater/Docking/MemorySearch/InRangeComparer.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 424 - (show annotations) (download)
Tue May 28 12:03:10 2013 UTC (7 years, 2 months ago) by william
File size: 5389 byte(s)
revert r423
+  do not close provider - keep it open for shared access

1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.IO;
6 using RomCheater.PluginFramework.Interfaces;
7 using Sojaner.MemoryScanner.MemoryProviers;
8
9 namespace RomCheater.Docking.MemorySearch
10 {
11 public class InRangeComparer : RangedComparer<object>, IRangeComparer<object>
12 {
13 public InRangeComparer(uint address, object value)
14 : base(address, value)
15 {
16 }
17 #region IRangeComparer<object> Members
18 public bool Compare(object Start, object End, SearchDataTypes bitsize, bool unsigned, IAcceptsProcessAndConfig pconfig)
19 {
20 //reader.BaseStream.Seek(this.Address, SeekOrigin.Begin);
21
22 ulong start_value, end_value;
23 start_value = new DataTypeConverter(Start).ToUInt64();
24 end_value = new DataTypeConverter(End).ToUInt64();
25 DataTypeConverter lookup_value;
26 if (bitsize == SearchDataTypes._8bits)
27 {
28 if (unsigned)
29 {
30 byte val = 0;
31 using (GenericMemoryProvider gmp = new GenericMemoryProvider(pconfig)) { gmp.OpenProvider(); gmp.ReadMemory(Address, out val); gmp.CloseProvider(); }
32 lookup_value = new DataTypeConverter(val);
33 if (lookup_value.ToByte() >= (byte)start_value && lookup_value.ToByte() <= (byte)end_value) { this.Value = lookup_value.Value; return true; }
34 }
35 else
36 {
37 sbyte val = 0;
38 using (GenericMemoryProvider gmp = new GenericMemoryProvider(pconfig)) { gmp.OpenProvider(); gmp.ReadMemory(Address, out val); gmp.CloseProvider(); }
39 lookup_value = new DataTypeConverter(val);
40 if (lookup_value.ToSByte() >= (sbyte)start_value && lookup_value.ToSByte() <= (sbyte)end_value) { this.Value = lookup_value.Value; return true; }
41 }
42 }
43 else if (bitsize == SearchDataTypes._16bits)
44 {
45 if (unsigned)
46 {
47 ushort val = 0;
48 using (GenericMemoryProvider gmp = new GenericMemoryProvider(pconfig)) { gmp.OpenProvider(); gmp.ReadMemory(Address, out val); gmp.CloseProvider(); }
49 lookup_value = new DataTypeConverter(val);
50 if (lookup_value.ToUInt16() >= (ushort)start_value && lookup_value.ToUInt16() <= (ushort)end_value) { this.Value = lookup_value.Value; return true; }
51 }
52 else
53 {
54 short val = 0;
55 using (GenericMemoryProvider gmp = new GenericMemoryProvider(pconfig)) { gmp.OpenProvider(); gmp.ReadMemory(Address, out val); gmp.CloseProvider(); }
56 lookup_value = new DataTypeConverter(val);
57 if (lookup_value.ToInt16() >= (short)start_value && lookup_value.ToInt16() <= (short)end_value) { this.Value = lookup_value.Value; return true; }
58 }
59 }
60 else if (bitsize == SearchDataTypes._32bits)
61 {
62 if (unsigned)
63 {
64 uint val = 0;
65 using (GenericMemoryProvider gmp = new GenericMemoryProvider(pconfig)) { gmp.OpenProvider(); gmp.ReadMemory(Address, out val); gmp.CloseProvider(); }
66 lookup_value = new DataTypeConverter(val);
67 if (lookup_value.ToUInt32() >= (uint)start_value && lookup_value.ToUInt32() <= (uint)end_value) { this.Value = lookup_value.Value; return true; }
68 }
69 else
70 {
71 int val = 0;
72 using (GenericMemoryProvider gmp = new GenericMemoryProvider(pconfig)) { gmp.OpenProvider(); gmp.ReadMemory(Address, out val); gmp.CloseProvider(); }
73 lookup_value = new DataTypeConverter(val);
74 if (lookup_value.ToInt32() >= (int)start_value && lookup_value.ToInt32() <= (int)end_value) { this.Value = lookup_value.Value; return true; }
75 }
76 }
77 else if (bitsize == SearchDataTypes._64bits)
78 {
79 if (unsigned)
80 {
81 ulong val = 0;
82 using (GenericMemoryProvider gmp = new GenericMemoryProvider(pconfig)) { gmp.OpenProvider(); gmp.ReadMemory(Address, out val); gmp.CloseProvider(); }
83 lookup_value = new DataTypeConverter(val);
84 if (lookup_value.ToUInt64() >= (ulong)start_value && lookup_value.ToUInt64() <= (ulong)end_value) { this.Value = lookup_value.Value; return true; }
85 }
86 else
87 {
88 long val = 0;
89 using (GenericMemoryProvider gmp = new GenericMemoryProvider(pconfig)) { gmp.OpenProvider(); gmp.ReadMemory(Address, out val); gmp.CloseProvider(); }
90 lookup_value = new DataTypeConverter(val);
91 if (lookup_value.ToInt64() >= (long)start_value && lookup_value.ToInt64() <= (long)end_value) { this.Value = lookup_value.Value; return true; }
92 }
93 }
94 return false;
95 }
96 #endregion
97 }
98 }

  ViewVC Help
Powered by ViewVC 1.1.22