Example #1
0
 // Write an object's data to the process memory at ptr.
 public void Write(object obj, int size, IntPtr ptr)
 {
     using (LP_Pinner pin = new LP_Pinner(obj))
     {
         uint bytesWritten = 0;
         if (!WriteProcessMemory(hProcess, ptr, pin.Ptr, size, ref bytesWritten))
         {
             int    err = GetLastError();
             string s   = "Write failed; err=" + err + "; bytesWritten=" + bytesWritten;
             throw new ApplicationException(s);
         }
     }
 }
Example #2
0
 // Reads an object's data from the process memory at ptr.
 public void Read(object obj, IntPtr ptr)
 {
     using (LP_Pinner pin = new LP_Pinner(obj))
     {
         uint bytesRead = 0;
         int  size      = Marshal.SizeOf(obj);
         if (!ReadProcessMemory(hProcess, ptr, pin.Ptr, size, ref bytesRead))
         {
             int    err = GetLastError();
             string s   = "Read failed; err=" + err + "; bytesRead=" + bytesRead;
             throw new ApplicationException(s);
         }
     }
 }