ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/RomCheater/trunk/Win32/Sojaner.MemoryScanner/MemoryScanner.cs
(Generate patch)

Comparing trunk/Win32/Sojaner.MemoryScanner/MemoryScanner.cs (file contents):
Revision 351 by william, Sat Jun 9 20:52:19 2012 UTC vs.
Revision 352 by william, Sat Jun 9 21:11:02 2012 UTC

--- trunk/Win32/Sojaner.MemoryScanner/MemoryScanner.cs	2012/06/09 20:52:19	351
+++ trunk/Win32/Sojaner.MemoryScanner/MemoryScanner.cs	2012/06/09 21:11:02	352
@@ -305,16 +305,6 @@ namespace Sojaner.MemoryScanner
         #endregion
 
         #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);
-        }
-        #endregion
         #region public void WriteProcessMemory(uint MemoryAddress, byte[] bytesToWrite, out int bytesWritten)
         public void WriteProcessMemory(int MemoryAddress, byte[] bytesToWrite, out int bytesWritten)
         {
@@ -326,23 +316,17 @@ namespace Sojaner.MemoryScanner
         {
             try
             {
-                UIntPtr ptrBytesWritten;
-                ProcessMemoryReaderApi.WriteProcessMemory(m_hProcess, (IntPtr)MemoryAddress, bytesToWrite, (uint)bytesToWrite.Length, out ptrBytesWritten);
-                bytesWritten = ptrBytesWritten.ToUInt32();
-                int LastWin32Error = Marshal.GetLastWin32Error();
-                if (LastWin32Error != ResultWin32.ERROR_SUCCESS)
+                uint _bytesWritten = 0;
+                uint _MemoryAddress = MemoryAddress;
+                for (int i = 0; i < bytesToWrite.Length; i++)
                 {
-                    string error = ResultWin32.GetErrorName(LastWin32Error);
-                    throw new Win32Exception(LastWin32Error, "Unable to read process memory");
+                    UIntPtr _ptrBytesWritten = UIntPtr.Zero;
+                    byte[] buffer = new byte[] { bytesToWrite[i] };
+                    ProcessMemoryReaderApi.WriteProcessMemory(m_hProcess, (IntPtr)_MemoryAddress, buffer, (uint)buffer.Length, out _ptrBytesWritten);
+                    _MemoryAddress++;
+                    _bytesWritten++;
                 }
-            }
-            catch (Win32Exception ex)
-            {
-                string error_name = ResultWin32.GetErrorName(ex.ErrorCode);
-                error_name = (error_name == string.Empty) ? "undefined" : error_name;
-                logger.Error.WriteLine("WriteProcessMemory() Win32Exception was thrown: ErrorCode:{0} - {1}", string.Format("0x{0:x8}", ex.ErrorCode, error_name), ex.Message);
-                logger.Error.WriteLine(ex.ToString());
-                throw ex;
+                bytesWritten = _bytesWritten;
             }
             catch (SEHException ex)
             {