/[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 477 - (show annotations) (download)
Mon Jun 3 18:35:45 2013 UTC (7 years, 3 months ago) by william
File size: 7174 byte(s)
revert r471: pass process informatin by using the process's PID, instead of passing the process as a reference

+ pass the process instead
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
12 namespace RomCheater.Docking.MemorySearch
13 {
14 [Serializable]
15 public class ResultItemState :
16 IAcceptsPlugin<IConfigPlugin>,
17 IAcceptsProcess<Process>,
18 IAcceptsProcessAndConfig
19 {
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 uint Address = Convert.ToUInt32(state.Address, 16);
32 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 #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 {
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
70 this.AcceptedPlugin = pconfig.AcceptedPlugin;
71 this.AcceptedProcess = pconfig.AcceptedProcess;
72 }
73 public ResultItemState(string address, SearchDataTypes bitsize, bool IsUnsigned, IAcceptsProcessAndConfig pconfig)
74 : this(AVPIconKeys.NOTFROZEN, address, "", false.ToString(), bitsize, IsUnsigned, pconfig)
75 {
76 int Address = 0;
77 Address = Convert.ToInt32(this.Address, 16);
78 int bytesReadSize;
79 uint bytesToRead = 0;
80 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 byte[] data = new byte[bytesToRead];
96 using (GenericMemoryProvider provider = new GenericMemoryProvider(pconfig))
97 {
98 provider.OpenProvider();
99 provider.ReadProcessMemory(Address, bytesToRead, out bytesReadSize, out data);
100 provider.CloseProvider();
101 }
102 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 }
131 public ResultItemState(string IconKey, string address, string value, string frozen, SearchDataTypes bitsize, bool IsUnsigned, IAcceptsProcessAndConfig pconfig)
132 : this(pconfig)
133 {
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 }

  ViewVC Help
Powered by ViewVC 1.1.22