ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/RomCheater/trunk/Win32/Sojaner.MemoryScanner/MemoryScanner.cs
(Generate patch)

Comparing trunk/Win32/Sojaner.MemoryScanner/MemoryScanner.cs (file contents):
Revision 349 by william, Tue Jun 5 02:19:13 2012 UTC vs.
Revision 350 by william, Sat Jun 9 20:07:18 2012 UTC

# Line 139 | Line 139 | namespace Sojaner.MemoryScanner
139              //                  SIZE_T nSize,                 // number of bytes to read
140              //                  SIZE_T * lpNumberOfBytesRead  // number of bytes read
141              //                  );
142 <            [DllImport("kernel32.dll")]
143 <            public static extern Int32 ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [In, Out] byte[] buffer, UInt32 size, out IntPtr lpNumberOfBytesRead);
142 >            [DllImport("kernel32.dll", SetLastError = true)]
143 >            public static extern bool ReadProcessMemory(
144 >              IntPtr hProcess,
145 >              IntPtr lpBaseAddress,
146 >              [Out] byte[] lpBuffer,
147 >              uint dwSize,
148 >              out int lpNumberOfBytesRead
149 >             );
150  
151              //          BOOL WriteProcessMemory(
152              //                  HANDLE hProcess,                // handle to process
# Line 149 | Line 155 | namespace Sojaner.MemoryScanner
155              //                  SIZE_T nSize,                   // count of bytes to write
156              //                  SIZE_T * lpNumberOfBytesWritten // count of bytes written
157              //                  );
158 <            [DllImport("kernel32.dll")]
159 <            public static extern Int32 WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [In, Out] byte[] buffer, UInt32 size, out IntPtr lpNumberOfBytesWritten);
158 >            [DllImport("kernel32.dll", SetLastError = true)]
159 >            public static extern bool WriteProcessMemory(
160 >                IntPtr hProcess,
161 >                IntPtr lpBaseAddress,
162 >                byte[] lpBuffer,
163 >                uint nSize,
164 >                out UIntPtr lpNumberOfBytesWritten);
165  
166  
167          }
# Line 242 | Line 253 | namespace Sojaner.MemoryScanner
253          #region public void ReadProcessMemory(int MemoryAddress, uint bytesToRead, out int bytesRead, out byte[] data)
254          public void ReadProcessMemory(int MemoryAddress, uint bytesToRead, out int bytesRead, out byte[] data)
255          {
256 +            ReadProcessMemory((uint)MemoryAddress, bytesToRead, out bytesRead, out data);
257 +        }
258 +        public void ReadProcessMemory(uint MemoryAddress, uint bytesToRead, out int bytesRead, out byte[] data)
259 +        {
260              try
261              {
262                  byte[] buffer = new byte[bytesToRead];
263 <                IntPtr ptrBytesRead;
249 <                ProcessMemoryReader.ProcessMemoryReaderApi.ReadProcessMemory(m_hProcess, (IntPtr)MemoryAddress, buffer, bytesToRead, out ptrBytesRead);
250 <                bytesRead = ptrBytesRead.ToInt32();
263 >                ProcessMemoryReader.ProcessMemoryReaderApi.ReadProcessMemory(m_hProcess, (IntPtr)MemoryAddress, buffer, bytesToRead, out bytesRead);
264                  data = buffer;
265              }
266              catch (SEHException ex)
# Line 269 | Line 282 | namespace Sojaner.MemoryScanner
282          #region IMemoryWriter Members
283          #region public void WriteProcessMemory(uint MemoryAddress, byte byteToWrite, out int bytesWritten)
284          public void WriteProcessMemory(int MemoryAddress, byte byteToWrite, out int bytesWritten)
285 +        {            
286 +            WriteProcessMemory(MemoryAddress, new byte[] { byteToWrite }, out bytesWritten);            
287 +        }
288 +        public void WriteProcessMemory(uint MemoryAddress, byte byteToWrite, out uint bytesWritten)
289          {
290              WriteProcessMemory(MemoryAddress, new byte[] { byteToWrite }, out bytesWritten);
291          }
# Line 276 | Line 293 | namespace Sojaner.MemoryScanner
293          #region public void WriteProcessMemory(uint MemoryAddress, byte[] bytesToWrite, out int bytesWritten)
294          public void WriteProcessMemory(int MemoryAddress, byte[] bytesToWrite, out int bytesWritten)
295          {
296 +            uint _bytesWritten = 0;
297 +            WriteProcessMemory((uint)MemoryAddress, bytesToWrite, out _bytesWritten);
298 +            bytesWritten = (int)_bytesWritten;
299 +        }
300 +        public void WriteProcessMemory(uint MemoryAddress, byte[] bytesToWrite, out uint bytesWritten)
301 +        {
302              try
303              {
304 <                IntPtr ptrBytesWritten;
304 >                UIntPtr ptrBytesWritten;
305                  ProcessMemoryReaderApi.WriteProcessMemory(m_hProcess, (IntPtr)MemoryAddress, bytesToWrite, (uint)bytesToWrite.Length, out ptrBytesWritten);
306 <                bytesWritten = ptrBytesWritten.ToInt32();
306 >                bytesWritten = ptrBytesWritten.ToUInt32();
307              }
308              catch (SEHException ex)
309              {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines