/[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/05/28 04:10:38	155
+++ trunk/Win32/Sojaner.MemoryScanner/MemoryScanner.cs	2012/05/28 04:14:03	156
@@ -4,6 +4,7 @@
 using System.Diagnostics;
 using System.Threading;
 using System.Runtime.InteropServices;
+using RomCheater.Logging;
 
 namespace Sojaner.MemoryScanner
 {
@@ -67,14 +68,29 @@
 
         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)

 

  ViewVC Help
Powered by ViewVC 1.1.22