1 |
william |
229 |
using System; |
2 |
|
|
using System.Collections.Generic; |
3 |
|
|
using System.Linq; |
4 |
|
|
using System.Text; |
5 |
|
|
using System.Windows.Forms; |
6 |
|
|
using System.IO; |
7 |
|
|
using System.Diagnostics; |
8 |
|
|
using RomCheater.Logging; |
9 |
william |
240 |
using Sojaner.MemoryScanner.MemoryProviers; |
10 |
william |
245 |
using RomCheater.PluginFramework.Interfaces; |
11 |
william |
229 |
|
12 |
|
|
namespace RomCheater.Docking.MemorySearch |
13 |
|
|
{ |
14 |
|
|
[Serializable] |
15 |
william |
245 |
public class ResultItemState : |
16 |
|
|
IAcceptsPlugin<IConfigPlugin>, |
17 |
|
|
IAcceptsProcess<Process>, |
18 |
|
|
IAcceptsProcessAndConfig |
19 |
william |
229 |
{ |
20 |
|
|
#region Implicit Conversion |
21 |
|
|
public static implicit operator ResultDataType(ResultItemState state) |
22 |
|
|
{ |
23 |
|
|
ResultDataType _result = null; |
24 |
|
|
bool frozen = false; |
25 |
|
|
switch (state.Frozen.ToLower()) |
26 |
|
|
{ |
27 |
|
|
case "true": frozen = true; break; |
28 |
|
|
case "false": frozen = false; break; |
29 |
|
|
} |
30 |
|
|
|
31 |
william |
378 |
uint Address = Convert.ToUInt32(state.Address, 16); |
32 |
william |
229 |
switch (state.ValueType) |
33 |
|
|
{ |
34 |
|
|
case SearchDataTypes._8bits: |
35 |
|
|
if (state.IsUnsigned) { _result = new ResultDataType(Address, frozen, Convert.ToByte(state.Value, 16)); } |
36 |
|
|
else { _result = new ResultDataType(Address, frozen, Convert.ToSByte(state.Value)); } |
37 |
|
|
break; |
38 |
|
|
case SearchDataTypes._16bits: |
39 |
|
|
if (state.IsUnsigned) { _result = new ResultDataType(Address, frozen, Convert.ToUInt16(state.Value, 16)); } |
40 |
|
|
else { _result = new ResultDataType(Address, frozen, Convert.ToInt16(state.Value, 16)); } |
41 |
|
|
break; |
42 |
|
|
case SearchDataTypes._32bits: |
43 |
|
|
if (state.IsUnsigned) { _result = new ResultDataType(Address, frozen, Convert.ToUInt32(state.Value, 16)); } |
44 |
|
|
else { _result = new ResultDataType(Address, frozen, Convert.ToInt32(state.Value, 16)); } |
45 |
|
|
break; |
46 |
|
|
case SearchDataTypes._64bits: |
47 |
|
|
if (state.IsUnsigned) { _result = new ResultDataType(Address, frozen, Convert.ToUInt64(state.Value, 16)); } |
48 |
|
|
else { _result = new ResultDataType(Address, frozen, Convert.ToInt64(state.Value, 16)); } |
49 |
|
|
break; |
50 |
|
|
} |
51 |
|
|
return _result; |
52 |
|
|
} |
53 |
|
|
#endregion |
54 |
william |
245 |
#region IAcceptsProcess<Process> Members |
55 |
|
|
public Process AcceptedProcess { get; set; } |
56 |
|
|
#endregion |
57 |
|
|
#region IAcceptsPlugin<IConfigPlugin> Members |
58 |
|
|
public IConfigPlugin AcceptedPlugin { get; set; } |
59 |
|
|
#endregion |
60 |
|
|
public ResultItemState() : this(null) { } |
61 |
|
|
public ResultItemState(IAcceptsProcessAndConfig pconfig) |
62 |
william |
229 |
{ |
63 |
|
|
this.IconKey = ""; |
64 |
|
|
this.Address = (0).ToString("x8"); |
65 |
|
|
this.Value = (0).ToString("x8"); |
66 |
|
|
this.Frozen = false.ToString(); |
67 |
|
|
this.ValueType = SearchDataTypes._32bits; |
68 |
|
|
this.IsUnsigned = true; |
69 |
william |
245 |
|
70 |
|
|
this.AcceptedPlugin = pconfig.AcceptedPlugin; |
71 |
|
|
this.AcceptedProcess = pconfig.AcceptedProcess; |
72 |
william |
229 |
} |
73 |
william |
245 |
public ResultItemState(string address, SearchDataTypes bitsize, bool IsUnsigned, IAcceptsProcessAndConfig pconfig) |
74 |
|
|
: this(AVPIconKeys.NOTFROZEN, address, "", false.ToString(), bitsize, IsUnsigned, pconfig) |
75 |
william |
229 |
{ |
76 |
william |
249 |
int Address = 0; |
77 |
william |
398 |
Address = Convert.ToInt32(this.Address, 16); |
78 |
william |
229 |
int bytesReadSize; |
79 |
william |
398 |
uint bytesToRead = 0; |
80 |
william |
229 |
switch (bitsize) |
81 |
|
|
{ |
82 |
|
|
case SearchDataTypes._8bits: |
83 |
|
|
bytesToRead = 1; |
84 |
|
|
break; |
85 |
|
|
case SearchDataTypes._16bits: |
86 |
|
|
bytesToRead = 2; |
87 |
|
|
break; |
88 |
|
|
case SearchDataTypes._32bits: |
89 |
|
|
bytesToRead = 4; |
90 |
|
|
break; |
91 |
|
|
case SearchDataTypes._64bits: |
92 |
|
|
bytesToRead = 8; |
93 |
|
|
break; |
94 |
|
|
} |
95 |
william |
398 |
byte[] data = new byte[bytesToRead]; |
96 |
|
|
using (GenericMemoryProvider provider = new GenericMemoryProvider(pconfig)) |
97 |
william |
229 |
{ |
98 |
william |
398 |
provider.OpenProvider(); |
99 |
|
|
provider.ReadProcessMemory(Address, bytesToRead, out bytesReadSize, out data); |
100 |
william |
423 |
//provider.CloseProvider(); |
101 |
william |
229 |
} |
102 |
william |
398 |
using (MemoryStream ms = new MemoryStream(data)) |
103 |
|
|
{ |
104 |
|
|
using (BinaryReader r_ms = new BinaryReader(ms)) |
105 |
|
|
{ |
106 |
|
|
|
107 |
|
|
//r_ms.BaseStream.Seek(Address, SeekOrigin.Begin); |
108 |
|
|
//int val = 0; |
109 |
|
|
switch (bitsize) |
110 |
|
|
{ |
111 |
|
|
case SearchDataTypes._8bits: |
112 |
|
|
if (IsUnsigned) { this.Value = string.Format("0x{0:x2}", r_ms.ReadByte()); } |
113 |
|
|
else { this.Value = string.Format("0x{0:x2}", r_ms.ReadSByte()); } |
114 |
|
|
break; |
115 |
|
|
case SearchDataTypes._16bits: |
116 |
|
|
if (IsUnsigned) { this.Value = string.Format("0x{0:x4}", r_ms.ReadUInt16()); } |
117 |
|
|
else { this.Value = string.Format("0x{0:x4}", r_ms.ReadInt16()); } |
118 |
|
|
break; |
119 |
|
|
case SearchDataTypes._32bits: |
120 |
|
|
if (IsUnsigned) { this.Value = string.Format("0x{0:x8}", r_ms.ReadUInt32()); } |
121 |
|
|
else { this.Value = string.Format("0x{0:x8}", r_ms.ReadInt32()); } |
122 |
|
|
break; |
123 |
|
|
case SearchDataTypes._64bits: |
124 |
|
|
if (IsUnsigned) { this.Value = string.Format("0x{0:x16}", r_ms.ReadUInt64()); } |
125 |
|
|
else { this.Value = string.Format("0x{0:x16}", r_ms.ReadInt64()); } |
126 |
|
|
break; |
127 |
|
|
} |
128 |
|
|
} |
129 |
|
|
} |
130 |
william |
229 |
} |
131 |
william |
245 |
public ResultItemState(string IconKey, string address, string value, string frozen, SearchDataTypes bitsize, bool IsUnsigned, IAcceptsProcessAndConfig pconfig) |
132 |
|
|
: this(pconfig) |
133 |
william |
229 |
{ |
134 |
|
|
this.IconKey = IconKey; |
135 |
|
|
this.Address = address; |
136 |
|
|
this.Value = value; |
137 |
|
|
this.Frozen = frozen; |
138 |
|
|
this.ValueType = bitsize; |
139 |
|
|
this.IsUnsigned = IsUnsigned; |
140 |
|
|
} |
141 |
|
|
|
142 |
|
|
|
143 |
|
|
private string _IconKey; |
144 |
|
|
private string _Address; |
145 |
|
|
private string _Value; |
146 |
|
|
private string _Frozen; |
147 |
|
|
|
148 |
|
|
public string IconKey { get { return _IconKey; } set { _IconKey = value; } } |
149 |
|
|
public string Address { get { return _Address; } set { _Address = value; } } |
150 |
|
|
public string Value { get { return _Value; } set { _Value = value; } } |
151 |
|
|
public string Frozen { get { return _Frozen; } set { _Frozen = value; } } |
152 |
|
|
|
153 |
|
|
|
154 |
|
|
private bool _IsUnsigned; |
155 |
|
|
public bool IsUnsigned { get { return _IsUnsigned; } set { _IsUnsigned = value; } } |
156 |
|
|
private SearchDataTypes _ValueType; |
157 |
|
|
public SearchDataTypes ValueType { get { return _ValueType; } set { _ValueType = value; } } |
158 |
|
|
} |
159 |
|
|
} |