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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 579 - (show annotations) (download)
Thu Jun 6 08:21:11 2013 UTC (8 years, 5 months ago) by william
File size: 7193 byte(s)

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

  ViewVC Help
Powered by ViewVC 1.1.22