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

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

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

--- trunk/Win32/Sojaner.MemoryScanner/MemoryScanner.cs	2012/05/31 09:08:24	204
+++ trunk/Win32/Sojaner.MemoryScanner/MemoryScanner-r204.cs	2012/06/03 16:32:58	251
@@ -8,7 +8,7 @@
 using RomCheater.Core;
 using System.IO;
 
-namespace Sojaner.MemoryScanner
+namespace Sojaner.MemoryScanner.r204
 {
     // code borrowed from: http://www.codeproject.com/KB/cs/sojaner_memory_scanner.aspx    
     #region ProcessMemoryReader class
@@ -69,7 +69,7 @@
         }
 
         #region WriteProcessMemoryToFile
-        public bool WriteProcessMemoryToFile(string filename, uint MemoryAddress, uint bytesToRead, out int bytesRead)
+        public bool WriteProcessMemoryToFile(string filename, int MemoryAddress, uint bytesToRead, out int bytesRead)
         {
             RamDumper dumper = new RamDumper();
             return dumper.DumpMemoryToFile(ReadProcess, filename, MemoryAddress, bytesToRead, out bytesRead);
@@ -77,7 +77,12 @@
         #endregion
 
         #region ReadProcessMemory
-        public byte[] ReadProcessMemory(uint MemoryAddress, uint bytesToRead, out int bytesRead)
+        public void ReadProcessMemory(int MemoryAddress, uint bytesToRead, out int bytesRead, out byte[] data)
+        {
+            RamDumper dumper = new RamDumper();
+            data = dumper.DumpMemoryToByteArray(ReadProcess, MemoryAddress, bytesToRead, out bytesRead);
+        }
+        public byte[] ReadProcessMemory(int MemoryAddress, uint bytesToRead, out int bytesRead)
         {
             RamDumper dumper = new RamDumper();
             return dumper.DumpMemoryToByteArray(ReadProcess, MemoryAddress, bytesToRead, out bytesRead);
@@ -85,21 +90,21 @@
         #endregion
 
         #region ReadProcessMemory
-        public bool ReadFirstNonZeroByte(uint MemoryAddress, uint bytesToRead, out uint address)
+        public bool ReadFirstNonZeroByte(int MemoryAddress, uint bytesToRead, out int address)
         {
             RamDumper dumper = new RamDumper();
             return dumper.ReadFirstNonZeroByte(ReadProcess, MemoryAddress, bytesToRead, out address);
         }
         #endregion
         #region WriteProcessMemory
-        public void WriteProcessMemory(UIntPtr 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(UIntPtr MemoryAddress, byte[] bytesToWrite, out int bytesWritten)
+        public void WriteProcessMemory(int MemoryAddress, byte[] bytesToWrite, out int bytesWritten)
         {
             IntPtr ptrBytesWritten;
-            ProcessMemoryReaderApi.WriteProcessMemory(m_hProcess, MemoryAddress, bytesToWrite, (uint)bytesToWrite.Length, out ptrBytesWritten);
+            ProcessMemoryReaderApi.WriteProcessMemory(m_hProcess, (IntPtr)MemoryAddress, bytesToWrite, (uint)bytesToWrite.Length, out ptrBytesWritten);
             bytesWritten = ptrBytesWritten.ToInt32();
         }
         #endregion
@@ -107,8 +112,8 @@
         #region RamDumper
         private interface IRamDumper
         {
-           bool DumpMemoryToFile(Process ppid, string filename, uint MemoryAddress, uint bytesToRead, out int bytesRead);
-           byte[] DumpMemoryToByteArray(Process ppid, uint MemoryAddress, uint bytesToRead, out int bytesRead);
+           bool DumpMemoryToFile(Process ppid, string filename, int MemoryAddress, uint bytesToRead, out int bytesRead);
+           byte[] DumpMemoryToByteArray(Process ppid, int MemoryAddress, uint bytesToRead, out int bytesRead);
         }
         private class RamDumper : IRamDumper
         {
@@ -119,14 +124,14 @@
             }
             #region IRamDumper members
             #region DumpMemoryToFile
-            public bool DumpMemoryToFile(Process ppid, string filename, uint MemoryAddress, uint bytesToRead, out int bytesRead)
+            public bool DumpMemoryToFile(Process ppid, 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 = 0;
                 // get common init parameters
                 InitMemoryDump(out byte_alignment);
-                uint address = MemoryAddress;
+                int address = MemoryAddress;
                 uint _bytesToRead = bytesToRead;
                 byte[] buffer = new byte[] { };
                 try
@@ -153,7 +158,7 @@
                             }
                             IntPtr ptrBytesRead;
 
-                            ProcessMemoryReader.ProcessMemoryReaderApi.ReadProcessMemory(m_hProcess, (UIntPtr)address, buffer, _bytesToRead, out ptrBytesRead);
+                            ProcessMemoryReader.ProcessMemoryReaderApi.ReadProcessMemory(m_hProcess, (IntPtr)address, buffer, _bytesToRead, out ptrBytesRead);
                             bytesRead = ptrBytesRead.ToInt32();
                             bw.Write(buffer);
                             bw.Flush();
@@ -161,12 +166,12 @@
                             if (_bytesToRead < byte_alignment)
                             {
                                 i += _bytesToRead;
-                                address += _bytesToRead;
+                                address += (int)_bytesToRead;
                             }
                             else
                             {
                                 i += byte_alignment;
-                                address += byte_alignment;
+                                address += (int)byte_alignment;
                             }
 
 
@@ -192,14 +197,14 @@
             }
             #endregion
             #region DumpMemoryToByteArray
-            public byte[] DumpMemoryToByteArray(Process ppid, uint MemoryAddress, uint bytesToRead, out int bytesRead)
+            public byte[] DumpMemoryToByteArray(Process ppid, int MemoryAddress, uint bytesToRead, out int bytesRead)
             {
                 //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));
                 bytesRead = 0;
                 uint byte_alignment = 1;
                 // get common init parameters
                 //InitMemoryDump(out byte_alignment);
-                uint address = MemoryAddress;
+                int address = MemoryAddress;
                 uint _bytesToRead = bytesToRead;
                 byte[] buffer = new byte[] { };
                 try
@@ -209,7 +214,7 @@
                         BinaryWriter bw = new BinaryWriter(ms);
                         //foreach (byte b in data) { bw.Write(b); }
 
-                        for (uint i = 0; i <= bytesToRead; )
+                        for (int i = 0; i <= bytesToRead; )
                         {
                             if (_bytesToRead < byte_alignment)
                             {
@@ -223,20 +228,20 @@
                             }
                             IntPtr ptrBytesRead;
 
-                            ProcessMemoryReader.ProcessMemoryReaderApi.ReadProcessMemory(m_hProcess, (UIntPtr)address, buffer, _bytesToRead, out ptrBytesRead);
+                            ProcessMemoryReader.ProcessMemoryReaderApi.ReadProcessMemory(m_hProcess, (IntPtr)address, buffer, _bytesToRead, out ptrBytesRead);
                             bytesRead = ptrBytesRead.ToInt32();
                             bw.Write(buffer);
                             bw.Flush();
 
                             if (_bytesToRead < byte_alignment)
                             {
-                                i += _bytesToRead;
-                                address += _bytesToRead;
+                                i += (int)_bytesToRead;
+                                address += (int)_bytesToRead;
                             }
                             else
                             {
-                                i += byte_alignment;
-                                address += byte_alignment;
+                                i += (int)byte_alignment;
+                                address += (int)byte_alignment;
                             }
 
 
@@ -264,14 +269,14 @@
             #endregion
 
             #region ReadFirstNonZeroByte
-            public bool ReadFirstNonZeroByte(Process ppid, uint MemoryAddress, uint bytesToRead, out uint address)
+            public bool ReadFirstNonZeroByte(Process ppid, 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
@@ -293,24 +298,24 @@
                                 buffer = new byte[byte_alignment];
                             }
                             IntPtr ptrBytesRead;
-                            ProcessMemoryReader.ProcessMemoryReaderApi.ReadProcessMemory(m_hProcess, (UIntPtr)mem_address, buffer, _bytesToRead, out ptrBytesRead);
+                            ProcessMemoryReader.ProcessMemoryReaderApi.ReadProcessMemory(m_hProcess, (IntPtr)mem_address, buffer, _bytesToRead, out ptrBytesRead);
                             //bw.Write(buffer);
                             //bw.Flush();
                             if (_bytesToRead < byte_alignment)
                             {
                                 i += _bytesToRead;
-                                mem_address += _bytesToRead;
+                                mem_address += (int)_bytesToRead;
                             }
                             else
                             {
                                 i += byte_alignment;
-                                mem_address += byte_alignment;
+                                mem_address += (int)byte_alignment;
                             }
                             for (uint j = 0; j < buffer.Length; j++)
                             {
                                 if (buffer[j] != 0)
                                 {
-                                    address = mem_address;
+                                    address = (int)mem_address;
                                     break;
                                 }
                             }
@@ -385,7 +390,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
@@ -395,7 +400,7 @@
             //			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);
 
 
         }

 

  ViewVC Help
Powered by ViewVC 1.1.22