/[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/09 20:52:19	351
+++ trunk/Win32/Sojaner.MemoryScanner/MemoryScanner.cs	2012/06/09 21:11:02	352
@@ -305,16 +305,6 @@
         #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 @@
         {
             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)
             {

 

  ViewVC Help
Powered by ViewVC 1.1.22