/[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/03 15:28:16	248
+++ trunk/Win32/Sojaner.MemoryScanner/MemoryScanner.cs	2012/06/03 16:09:05	249
@@ -14,7 +14,7 @@
     #region ProcessMemoryReader class
     //Thanks goes to Arik Poznanski for P/Invokes and methods needed to read and write the Memory
     //For more information refer to "Minesweeper, Behind the scenes" article by Arik Poznanski at Codeproject.com
-    internal class ProcessMemoryReader : IMemoryReader, IMemoryWriter, IFileWriter
+    public class ProcessMemoryReader : IMemoryReader, IMemoryWriter, IFileWriter
     {
 
         public ProcessMemoryReader()
@@ -133,7 +133,7 @@
             //			SIZE_T * lpNumberOfBytesRead  // number of bytes read
             //			);
             [DllImport("kernel32.dll")]
-            public static extern Int32 ReadProcessMemory(IntPtr hProcess, UIntPtr lpBaseAddress, [In, Out] byte[] buffer, UInt32 size, out IntPtr lpNumberOfBytesRead);
+            public static extern Int32 ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [In, Out] byte[] buffer, UInt32 size, out IntPtr lpNumberOfBytesRead);
 
             //		BOOL WriteProcessMemory(
             //			HANDLE hProcess,                // handle to process
@@ -143,20 +143,21 @@
             //			SIZE_T * lpNumberOfBytesWritten // count of bytes written
             //			);
             [DllImport("kernel32.dll")]
-            public static extern Int32 WriteProcessMemory(IntPtr hProcess, UIntPtr lpBaseAddress, [In, Out] byte[] buffer, UInt32 size, out IntPtr lpNumberOfBytesWritten);
+            public static extern Int32 WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [In, Out] byte[] buffer, UInt32 size, out IntPtr lpNumberOfBytesWritten);
 
 
         }
 
         #region IMemoryReader Members
-        public bool ReadFirstNonZeroByte(uint MemoryAddress, uint bytesToRead, out uint address)
+        #region public bool ReadFirstNonZeroByte(uint MemoryAddress, uint bytesToRead, out int address)
+        public bool ReadFirstNonZeroByte(int MemoryAddress, uint bytesToRead, out int address)
         {
             //logger.Info.WriteLine("Dumping memory (0x{0:x8}-0x{1:x8}) from pid=({2})", MemoryAddress, MemoryAddress + bytesToRead, string.Format("0x{0:x4} {1}.exe", ppid.Id, ppid.ProcessName));
             address = 0;
             uint byte_alignment = 1;
             // get common init parameters
             //InitMemoryDump(out byte_alignment);
-            uint mem_address = MemoryAddress;
+            int mem_address = MemoryAddress;
             uint _bytesToRead = bytesToRead;
             byte[] buffer = new byte[] { };
             try
@@ -188,12 +189,12 @@
                     if (_bytesToRead < byte_alignment)
                     {
                         i += _bytesToRead;
-                        mem_address += (uint)_bytesToRead;
+                        mem_address += (int)_bytesToRead;
                     }
                     else
                     {
                         i += byte_alignment;
-                        mem_address += (uint)byte_alignment;
+                        mem_address += (int)byte_alignment;
                     }
                     for (uint j = 0; j < buffer.Length; j++)
                     {
@@ -230,13 +231,15 @@
             }
             return false;
         }
-        public void ReadProcessMemory(uint MemoryAddress, uint bytesToRead, out int bytesRead, out byte[] data)
+        #endregion
+        #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)
         {
             try
             {
                 byte[] buffer = new byte[] { };
                 IntPtr ptrBytesRead;
-                ProcessMemoryReader.ProcessMemoryReaderApi.ReadProcessMemory(m_hProcess, (UIntPtr)MemoryAddress, buffer, bytesToRead, out ptrBytesRead);
+                ProcessMemoryReader.ProcessMemoryReaderApi.ReadProcessMemory(m_hProcess, (IntPtr)MemoryAddress, buffer, bytesToRead, out ptrBytesRead);
                 bytesRead = ptrBytesRead.ToInt32();
                 data = buffer;
             }
@@ -254,18 +257,22 @@
             }
         }
         #endregion
+        #endregion
 
         #region IMemoryWriter Members
-        public void WriteProcessMemory(uint MemoryAddress, byte byteToWrite, out int bytesWritten)
+        #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[] bytesToWrite, out int bytesWritten)
+        #endregion
+        #region public void WriteProcessMemory(uint MemoryAddress, byte[] bytesToWrite, out int bytesWritten)
+        public void WriteProcessMemory(int MemoryAddress, byte[] bytesToWrite, out int bytesWritten)
         {
             try
             {
                 IntPtr ptrBytesWritten;
-                ProcessMemoryReaderApi.WriteProcessMemory(m_hProcess, (UIntPtr)MemoryAddress, bytesToWrite, (uint)bytesToWrite.Length, out ptrBytesWritten);
+                ProcessMemoryReaderApi.WriteProcessMemory(m_hProcess, (IntPtr)MemoryAddress, bytesToWrite, (uint)bytesToWrite.Length, out ptrBytesWritten);
                 bytesWritten = ptrBytesWritten.ToInt32();
             }
             catch (SEHException ex)
@@ -283,16 +290,17 @@
                 throw ex;
             }
         }
+         #endregion
         #endregion
 
         #region IFileWriter Members
-
-        public bool WriteProcessMemoryToFile(string filename, uint MemoryAddress, uint bytesToRead, out int bytesRead)
+        #region public bool WriteProcessMemoryToFile(string filename, uint MemoryAddress, uint bytesToRead, out int bytesRead)
+        public bool WriteProcessMemoryToFile(string filename, int MemoryAddress, uint bytesToRead, out int bytesRead)
         {
             //logger.Info.WriteLine("Dumping memory (0x{0:x8}-0x{1:x8}) from pid=({3}) to file {2}", MemoryAddress, MemoryAddress + bytesToRead, filename, string.Format("0x{0:x4} {1}.exe", ppid.Id, ppid.ProcessName));
             bytesRead = 0;
             uint byte_alignment = 102400;
-            uint address = MemoryAddress;
+            int address = MemoryAddress;
             uint _bytesToRead = bytesToRead;
             byte[] buffer = new byte[] { };
             try
@@ -324,12 +332,12 @@
                         if (_bytesToRead < byte_alignment)
                         {
                             i += _bytesToRead;
-                            address += (uint)_bytesToRead;
+                            address += (int)_bytesToRead;
                         }
                         else
                         {
                             i += byte_alignment;
-                            address += (uint)byte_alignment;
+                            address += (int)byte_alignment;
                         }
 
 
@@ -358,7 +366,7 @@
             }
             return false;
         }
-
+        #endregion
         #endregion
     }
     #endregion

 

  ViewVC Help
Powered by ViewVC 1.1.22