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 |
|
|
|
10 |
|
|
namespace RomCheater.Docking.MemorySearch |
11 |
|
|
{ |
12 |
|
|
[Serializable] |
13 |
|
|
public class ResultItemState |
14 |
|
|
{ |
15 |
|
|
#region Implicit Conversion |
16 |
|
|
public static implicit operator ResultDataType(ResultItemState state) |
17 |
|
|
{ |
18 |
|
|
ResultDataType _result = null; |
19 |
|
|
bool frozen = false; |
20 |
|
|
switch (state.Frozen.ToLower()) |
21 |
|
|
{ |
22 |
|
|
case "true": frozen = true; break; |
23 |
|
|
case "false": frozen = false; break; |
24 |
|
|
} |
25 |
|
|
|
26 |
|
|
uint Address = Convert.ToUInt32(state.Address, 16); |
27 |
|
|
switch (state.ValueType) |
28 |
|
|
{ |
29 |
|
|
case SearchDataTypes._8bits: |
30 |
|
|
if (state.IsUnsigned) { _result = new ResultDataType(Address, frozen, Convert.ToByte(state.Value, 16)); } |
31 |
|
|
else { _result = new ResultDataType(Address, frozen, Convert.ToSByte(state.Value)); } |
32 |
|
|
break; |
33 |
|
|
case SearchDataTypes._16bits: |
34 |
|
|
if (state.IsUnsigned) { _result = new ResultDataType(Address, frozen, Convert.ToUInt16(state.Value, 16)); } |
35 |
|
|
else { _result = new ResultDataType(Address, frozen, Convert.ToInt16(state.Value, 16)); } |
36 |
|
|
break; |
37 |
|
|
case SearchDataTypes._32bits: |
38 |
|
|
if (state.IsUnsigned) { _result = new ResultDataType(Address, frozen, Convert.ToUInt32(state.Value, 16)); } |
39 |
|
|
else { _result = new ResultDataType(Address, frozen, Convert.ToInt32(state.Value, 16)); } |
40 |
|
|
break; |
41 |
|
|
case SearchDataTypes._64bits: |
42 |
|
|
if (state.IsUnsigned) { _result = new ResultDataType(Address, frozen, Convert.ToUInt64(state.Value, 16)); } |
43 |
|
|
else { _result = new ResultDataType(Address, frozen, Convert.ToInt64(state.Value, 16)); } |
44 |
|
|
break; |
45 |
|
|
} |
46 |
|
|
return _result; |
47 |
|
|
} |
48 |
|
|
#endregion |
49 |
|
|
|
50 |
|
|
public ResultItemState() |
51 |
|
|
{ |
52 |
|
|
this.IconKey = ""; |
53 |
|
|
this.Address = (0).ToString("x8"); |
54 |
|
|
this.Value = (0).ToString("x8"); |
55 |
|
|
this.Frozen = false.ToString(); |
56 |
|
|
this.ValueType = SearchDataTypes._32bits; |
57 |
|
|
this.IsUnsigned = true; |
58 |
|
|
} |
59 |
|
|
public ResultItemState(string address, SearchDataTypes bitsize, bool IsUnsigned, int pid) |
60 |
|
|
: this(AVPIconKeys.NOTFROZEN, address, "", false.ToString(), bitsize, IsUnsigned) |
61 |
|
|
{ |
62 |
|
|
uint Address = 0; |
63 |
|
|
Address = Convert.ToUInt32(this.Address, 16); |
64 |
|
|
Sojaner.MemoryScanner.ProcessMemoryReader reader = new Sojaner.MemoryScanner.ProcessMemoryReader(); |
65 |
|
|
reader.ReadProcess = Process.GetProcessById(pid); |
66 |
|
|
if (reader.ReadProcess == null) { logger.Error.WriteLine("Could not attach to process: {0}", pid); return; } |
67 |
|
|
reader.OpenProcess(); |
68 |
|
|
int bytesReadSize; |
69 |
|
|
byte[] data; |
70 |
|
|
uint bytesToRead=0; |
71 |
|
|
switch (bitsize) |
72 |
|
|
{ |
73 |
|
|
case SearchDataTypes._8bits: |
74 |
|
|
bytesToRead = 1; |
75 |
|
|
break; |
76 |
|
|
case SearchDataTypes._16bits: |
77 |
|
|
bytesToRead = 2; |
78 |
|
|
break; |
79 |
|
|
case SearchDataTypes._32bits: |
80 |
|
|
bytesToRead = 4; |
81 |
|
|
break; |
82 |
|
|
case SearchDataTypes._64bits: |
83 |
|
|
bytesToRead = 8; |
84 |
|
|
break; |
85 |
|
|
} |
86 |
|
|
|
87 |
|
|
reader.ReadProcessMemory(Address, bytesToRead, out bytesReadSize, out data); |
88 |
|
|
MemoryStream ms = new MemoryStream(data); |
89 |
|
|
BinaryReader r_ms = new BinaryReader(ms); |
90 |
|
|
|
91 |
|
|
//r_ms.BaseStream.Seek(Address, SeekOrigin.Begin); |
92 |
|
|
//int val = 0; |
93 |
|
|
switch (bitsize) |
94 |
|
|
{ |
95 |
|
|
case SearchDataTypes._8bits: |
96 |
|
|
if (IsUnsigned) { this.Value = string.Format("0x{0:x2}", r_ms.ReadByte()); } |
97 |
|
|
else { this.Value = string.Format("0x{0:x2}", r_ms.ReadSByte()); } |
98 |
|
|
break; |
99 |
|
|
case SearchDataTypes._16bits: |
100 |
|
|
if (IsUnsigned) { this.Value = string.Format("0x{0:x4}", r_ms.ReadUInt16()); } |
101 |
|
|
else { this.Value = string.Format("0x{0:x4}", r_ms.ReadInt16()); } |
102 |
|
|
break; |
103 |
|
|
case SearchDataTypes._32bits: |
104 |
|
|
if (IsUnsigned) { this.Value = string.Format("0x{0:x8}", r_ms.ReadUInt32()); } |
105 |
|
|
else { this.Value = string.Format("0x{0:x8}", r_ms.ReadInt32()); } |
106 |
|
|
break; |
107 |
|
|
case SearchDataTypes._64bits: |
108 |
|
|
if (IsUnsigned) { this.Value = string.Format("0x{0:x16}", r_ms.ReadUInt64()); } |
109 |
|
|
else { this.Value = string.Format("0x{0:x16}", r_ms.ReadInt64()); } |
110 |
|
|
break; |
111 |
|
|
} |
112 |
|
|
} |
113 |
|
|
//public ResultItemState(string address, SearchDataTypes bitsize, bool IsUnsigned) |
114 |
|
|
// : this(AVPIconKeys.NOTFROZEN, address, "", false.ToString(), bitsize, IsUnsigned) |
115 |
|
|
//{ |
116 |
|
|
// //PCSX2MemoryProvider provider = new PCSX2MemoryProvider(pcsx2_pid, null); |
117 |
|
|
// //byte[] buffered_mem = provider.GetMemory(); |
118 |
|
|
// //MemoryStream ms = new MemoryStream(buffered_mem); |
119 |
|
|
// //BinaryReader r_ms = new BinaryReader(ms); |
120 |
|
|
// uint Address = 0; |
121 |
|
|
// Address = Convert.ToUInt32(this.Address, 16); |
122 |
|
|
// //r_ms.BaseStream.Seek(Address, SeekOrigin.Begin); |
123 |
|
|
// int val = 0; |
124 |
|
|
// switch (bitsize) |
125 |
|
|
// { |
126 |
|
|
// case SearchDataTypes._8bits: |
127 |
|
|
// if (IsUnsigned) { this.Value = string.Format("0x{0:x2}", val); } |
128 |
|
|
// else { this.Value = string.Format("0x{0:x2}", val); } |
129 |
|
|
// break; |
130 |
|
|
// case SearchDataTypes._16bits: |
131 |
|
|
// if (IsUnsigned) { this.Value = string.Format("0x{0:x4}", val); } |
132 |
|
|
// else { this.Value = string.Format("0x{0:x4}", val); } |
133 |
|
|
// break; |
134 |
|
|
// case SearchDataTypes._32bits: |
135 |
|
|
// if (IsUnsigned) { this.Value = string.Format("0x{0:x8}", val); } |
136 |
|
|
// else { this.Value = string.Format("0x{0:x8}", val); } |
137 |
|
|
// break; |
138 |
|
|
// case SearchDataTypes._64bits: |
139 |
|
|
// if (IsUnsigned) { this.Value = string.Format("0x{0:x16}", val); } |
140 |
|
|
// else { this.Value = string.Format("0x{0:x16}", val); } |
141 |
|
|
// break; |
142 |
|
|
// } |
143 |
|
|
//} |
144 |
|
|
public ResultItemState(string IconKey, string address, string value, string frozen, SearchDataTypes bitsize, bool IsUnsigned) |
145 |
|
|
{ |
146 |
|
|
this.IconKey = IconKey; |
147 |
|
|
this.Address = address; |
148 |
|
|
this.Value = value; |
149 |
|
|
this.Frozen = frozen; |
150 |
|
|
this.ValueType = bitsize; |
151 |
|
|
this.IsUnsigned = IsUnsigned; |
152 |
|
|
} |
153 |
|
|
|
154 |
|
|
|
155 |
|
|
private string _IconKey; |
156 |
|
|
private string _Address; |
157 |
|
|
private string _Value; |
158 |
|
|
private string _Frozen; |
159 |
|
|
|
160 |
|
|
public string IconKey { get { return _IconKey; } set { _IconKey = value; } } |
161 |
|
|
public string Address { get { return _Address; } set { _Address = value; } } |
162 |
|
|
public string Value { get { return _Value; } set { _Value = value; } } |
163 |
|
|
public string Frozen { get { return _Frozen; } set { _Frozen = value; } } |
164 |
|
|
|
165 |
|
|
|
166 |
|
|
private bool _IsUnsigned; |
167 |
|
|
public bool IsUnsigned { get { return _IsUnsigned; } set { _IsUnsigned = value; } } |
168 |
|
|
private SearchDataTypes _ValueType; |
169 |
|
|
public SearchDataTypes ValueType { get { return _ValueType; } set { _ValueType = value; } } |
170 |
|
|
} |
171 |
|
|
} |