/[RomCheater]/trunk/Win32/Sojaner.MemoryScanner/MemoryScanner.cs
ViewVC logotype

Diff of /trunk/Win32/Sojaner.MemoryScanner/MemoryScanner.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/Win32/Sojaner.MemoryScanner/MemoryScanner.cs	2012/06/08 04:39:37	349
+++ trunk/Win32/Sojaner.MemoryScanner/MemoryScanner.cs	2012/06/09 20:07:18	350
@@ -139,8 +139,14 @@
             //			SIZE_T nSize,                 // number of bytes to read
             //			SIZE_T * lpNumberOfBytesRead  // number of bytes read
             //			);
-            [DllImport("kernel32.dll")]
-            public static extern Int32 ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [In, Out] byte[] buffer, UInt32 size, out IntPtr lpNumberOfBytesRead);
+            [DllImport("kernel32.dll", SetLastError = true)]
+            public static extern bool ReadProcessMemory(
+              IntPtr hProcess,
+              IntPtr lpBaseAddress,
+              [Out] byte[] lpBuffer,
+              uint dwSize,
+              out int lpNumberOfBytesRead
+             );
 
             //		BOOL WriteProcessMemory(
             //			HANDLE hProcess,                // handle to process
@@ -149,8 +155,13 @@
             //			SIZE_T nSize,                   // count of bytes to write
             //			SIZE_T * lpNumberOfBytesWritten // count of bytes written
             //			);
-            [DllImport("kernel32.dll")]
-            public static extern Int32 WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [In, Out] byte[] buffer, UInt32 size, out IntPtr lpNumberOfBytesWritten);
+            [DllImport("kernel32.dll", SetLastError = true)]
+            public static extern bool WriteProcessMemory(
+                IntPtr hProcess,
+                IntPtr lpBaseAddress, 
+                byte[] lpBuffer, 
+                uint nSize, 
+                out UIntPtr lpNumberOfBytesWritten);
 
 
         }
@@ -242,12 +253,14 @@
         #region public void ReadProcessMemory(int MemoryAddress, uint bytesToRead, out int bytesRead, out byte[] data)
         public void ReadProcessMemory(int MemoryAddress, uint bytesToRead, out int bytesRead, out byte[] data)
         {
+            ReadProcessMemory((uint)MemoryAddress, bytesToRead, out bytesRead, out data);
+        }
+        public void ReadProcessMemory(uint MemoryAddress, uint bytesToRead, out int bytesRead, out byte[] data)
+        {
             try
             {
                 byte[] buffer = new byte[bytesToRead];
-                IntPtr ptrBytesRead;
-                ProcessMemoryReader.ProcessMemoryReaderApi.ReadProcessMemory(m_hProcess, (IntPtr)MemoryAddress, buffer, bytesToRead, out ptrBytesRead);
-                bytesRead = ptrBytesRead.ToInt32();
+                ProcessMemoryReader.ProcessMemoryReaderApi.ReadProcessMemory(m_hProcess, (IntPtr)MemoryAddress, buffer, bytesToRead, out bytesRead);
                 data = buffer;
             }
             catch (SEHException ex)
@@ -269,6 +282,10 @@
         #region IMemoryWriter Members
         #region public void WriteProcessMemory(uint MemoryAddress, byte byteToWrite, out int bytesWritten)
         public void WriteProcessMemory(int MemoryAddress, byte byteToWrite, out int bytesWritten)
+        {            
+            WriteProcessMemory(MemoryAddress, new byte[] { byteToWrite }, out bytesWritten);            
+        }
+        public void WriteProcessMemory(uint MemoryAddress, byte byteToWrite, out uint bytesWritten)
         {
             WriteProcessMemory(MemoryAddress, new byte[] { byteToWrite }, out bytesWritten);
         }
@@ -276,11 +293,17 @@
         #region public void WriteProcessMemory(uint MemoryAddress, byte[] bytesToWrite, out int bytesWritten)
         public void WriteProcessMemory(int MemoryAddress, byte[] bytesToWrite, out int bytesWritten)
         {
+            uint _bytesWritten = 0;
+            WriteProcessMemory((uint)MemoryAddress, bytesToWrite, out _bytesWritten);
+            bytesWritten = (int)_bytesWritten;
+        }
+        public void WriteProcessMemory(uint MemoryAddress, byte[] bytesToWrite, out uint bytesWritten)
+        {
             try
             {
-                IntPtr ptrBytesWritten;
+                UIntPtr ptrBytesWritten;
                 ProcessMemoryReaderApi.WriteProcessMemory(m_hProcess, (IntPtr)MemoryAddress, bytesToWrite, (uint)bytesToWrite.Length, out ptrBytesWritten);
-                bytesWritten = ptrBytesWritten.ToInt32();
+                bytesWritten = ptrBytesWritten.ToUInt32();
             }
             catch (SEHException ex)
             {

 

  ViewVC Help
Powered by ViewVC 1.1.22