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 88 by william, Wed May 9 20:52:20 2012 UTC vs.
Revision 156 by william, Mon May 28 04:14:03 2012 UTC

--- trunk/Win32/Sojaner.MemoryScanner/MemoryScanner.cs	2012/05/09 20:52:20	88
+++ trunk/Win32/Sojaner.MemoryScanner/MemoryScanner.cs	2012/05/28 04:14:03	156
@@ -4,6 +4,7 @@ using System.Text;
 using System.Diagnostics;
 using System.Threading;
 using System.Runtime.InteropServices;
+using RomCheater.Logging;
 
 namespace Sojaner.MemoryScanner
 {
@@ -67,14 +68,29 @@ namespace Sojaner.MemoryScanner
 
         public byte[] ReadProcessMemory(IntPtr MemoryAddress, uint bytesToRead, out int bytesRead)
         {
-            byte[] buffer = new byte[bytesToRead];
+            try
+            {
+                byte[] buffer = new byte[bytesToRead - 1];
 
-            IntPtr ptrBytesRead;
-            ProcessMemoryReaderApi.ReadProcessMemory(m_hProcess, MemoryAddress, buffer, bytesToRead, out ptrBytesRead);
+                IntPtr ptrBytesRead;
+                ProcessMemoryReaderApi.ReadProcessMemory(m_hProcess, MemoryAddress, buffer, bytesToRead, out ptrBytesRead);
 
-            bytesRead = ptrBytesRead.ToInt32();
+                bytesRead = ptrBytesRead.ToInt32();
 
-            return buffer;
+                return buffer;
+            }
+            catch (OutOfMemoryException ex)
+            {
+                logger.Error.WriteLine("ReadProcessMemory(): OutOfMemoryException");
+                logger.Error.WriteLine(ex.ToString());
+            }
+            catch (Exception ex)
+            {
+                logger.Error.WriteLine("ReadProcessMemory(): Exception");
+                logger.Error.WriteLine(ex.ToString());
+            }
+            bytesRead = 0; 
+            return new byte[] { };
         }
 
         public void WriteProcessMemory(IntPtr MemoryAddress, byte[] bytesToWrite, out int bytesWritten)