/[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

revision 162 by william, Mon May 28 07:12:37 2012 UTC revision 164 by william, Mon May 28 07:49:48 2012 UTC
# Line 72  namespace Sojaner.MemoryScanner Line 72  namespace Sojaner.MemoryScanner
72          public bool DumpMemory(string filename, uint MemoryAddress, uint bytesToRead, out int bytesRead)          public bool DumpMemory(string filename, uint MemoryAddress, uint bytesToRead, out int bytesRead)
73          {          {
74              bytesRead = 0;              bytesRead = 0;
75              uint byte_alignment = 512; // 4mb alignment              uint byte_alignment = 16; // 16 byte alignment
76              uint address = MemoryAddress;              uint address = MemoryAddress;
77              try              try
78              {              {
# Line 86  namespace Sojaner.MemoryScanner Line 86  namespace Sojaner.MemoryScanner
86                          byte[] buffer = new byte[byte_alignment];                          byte[] buffer = new byte[byte_alignment];
87                          uint bytes_to_read = byte_alignment;                          uint bytes_to_read = byte_alignment;
88                          IntPtr ptrBytesRead;                          IntPtr ptrBytesRead;
89                          ProcessMemoryReaderApi.ReadProcessMemory(m_hProcess, (IntPtr)address, buffer, bytes_to_read, out ptrBytesRead);                          ProcessMemoryReaderApi.ReadProcessMemory(m_hProcess, (UIntPtr)address, buffer, bytes_to_read, out ptrBytesRead);
90                          bytesRead = ptrBytesRead.ToInt32();                          bytesRead = ptrBytesRead.ToInt32();
91                          bw.Write(buffer);                          bw.Write(buffer);
92                          bw.Flush();                          bw.Flush();
# Line 124  namespace Sojaner.MemoryScanner Line 124  namespace Sojaner.MemoryScanner
124                      byte[] buffer = new byte[byte_alignment];                      byte[] buffer = new byte[byte_alignment];
125                      uint bytes_to_read = byte_alignment;                      uint bytes_to_read = byte_alignment;
126                      IntPtr ptrBytesRead;                      IntPtr ptrBytesRead;
127                      ProcessMemoryReaderApi.ReadProcessMemory(m_hProcess, (IntPtr)address, buffer, bytes_to_read, out ptrBytesRead);                      ProcessMemoryReaderApi.ReadProcessMemory(m_hProcess, (UIntPtr)address, buffer, bytes_to_read, out ptrBytesRead);
128                      bytesRead = ptrBytesRead.ToInt32();                      bytesRead = ptrBytesRead.ToInt32();
129                      aligned_array_list.Add(buffer);                                          aligned_array_list.Add(buffer);                    
130                      address += byte_alignment;                      address += byte_alignment;
# Line 148  namespace Sojaner.MemoryScanner Line 148  namespace Sojaner.MemoryScanner
148              return new byte[] { };              return new byte[] { };
149          }          }
150    
151          public void WriteProcessMemory(IntPtr MemoryAddress, byte[] bytesToWrite, out int bytesWritten)          public void WriteProcessMemory(UIntPtr MemoryAddress, byte[] bytesToWrite, out int bytesWritten)
152          {          {
153              IntPtr ptrBytesWritten;              IntPtr ptrBytesWritten;
154              ProcessMemoryReaderApi.WriteProcessMemory(m_hProcess, MemoryAddress, bytesToWrite, (uint)bytesToWrite.Length, out ptrBytesWritten);              ProcessMemoryReaderApi.WriteProcessMemory(m_hProcess, MemoryAddress, bytesToWrite, (uint)bytesToWrite.Length, out ptrBytesWritten);
# Line 203  namespace Sojaner.MemoryScanner Line 203  namespace Sojaner.MemoryScanner
203              //                  SIZE_T * lpNumberOfBytesRead  // number of bytes read              //                  SIZE_T * lpNumberOfBytesRead  // number of bytes read
204              //                  );              //                  );
205              [DllImport("kernel32.dll")]              [DllImport("kernel32.dll")]
206              public static extern Int32 ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [In, Out] byte[] buffer, UInt32 size, out IntPtr lpNumberOfBytesRead);              public static extern Int32 ReadProcessMemory(IntPtr hProcess, UIntPtr lpBaseAddress, [In, Out] byte[] buffer, UInt32 size, out IntPtr lpNumberOfBytesRead);
207    
208              //          BOOL WriteProcessMemory(              //          BOOL WriteProcessMemory(
209              //                  HANDLE hProcess,                // handle to process              //                  HANDLE hProcess,                // handle to process
# Line 213  namespace Sojaner.MemoryScanner Line 213  namespace Sojaner.MemoryScanner
213              //                  SIZE_T * lpNumberOfBytesWritten // count of bytes written              //                  SIZE_T * lpNumberOfBytesWritten // count of bytes written
214              //                  );              //                  );
215              [DllImport("kernel32.dll")]              [DllImport("kernel32.dll")]
216              public static extern Int32 WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [In, Out] byte[] buffer, UInt32 size, out IntPtr lpNumberOfBytesWritten);              public static extern Int32 WriteProcessMemory(IntPtr hProcess, UIntPtr lpBaseAddress, [In, Out] byte[] buffer, UInt32 size, out IntPtr lpNumberOfBytesWritten);
217    
218    
219          }          }

Legend:
Removed from v.162  
changed lines
  Added in v.164

  ViewVC Help
Powered by ViewVC 1.1.22