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 350 by william, Sat Jun 9 20:07:18 2012 UTC vs.
Revision 351 by william, Sat Jun 9 20:52:19 2012 UTC

# Line 8 | Line 8 | using RomCheater.Logging;
8   using System.IO;
9   using Sojaner.MemoryScanner.MemoryProviers;
10   using Microsoft.Win32.SafeHandles;
11 + using Microsoft.Win32.Interop;
12 + using System.ComponentModel;
13  
14   namespace Sojaner.MemoryScanner
15   {
# Line 259 | Line 261 | namespace Sojaner.MemoryScanner
261          {
262              try
263              {
264 <                byte[] buffer = new byte[bytesToRead];
265 <                ProcessMemoryReader.ProcessMemoryReaderApi.ReadProcessMemory(m_hProcess, (IntPtr)MemoryAddress, buffer, bytesToRead, out bytesRead);
266 <                data = buffer;
264 >                bytesRead = 0;
265 >
266 >                List<byte> buffer_list = new List<byte>();
267 >                uint _MemoryAddress = MemoryAddress;
268 >                for (int i = 0; i < bytesToRead; i++)
269 >                {
270 >                    byte[] buffer = new byte[1];
271 >                    int _bytesRead = 0;
272 >                    ProcessMemoryReader.ProcessMemoryReaderApi.ReadProcessMemory(m_hProcess, (IntPtr)_MemoryAddress, buffer, 1, out _bytesRead);
273 >                    if (_bytesRead > 0)
274 >                    {
275 >                        foreach (byte b in buffer)
276 >                        {
277 >                            buffer_list.Add(b);
278 >                        }
279 >                        _MemoryAddress += (uint)buffer.Length;
280 >                    }
281 >                    else
282 >                    {
283 >                        buffer_list.Add(0);
284 >                        _MemoryAddress++;
285 >                    }
286 >                    
287 >                }
288 >                bytesRead = buffer_list.Count;
289 >                data = buffer_list.ToArray();
290              }
291              catch (SEHException ex)
292              {
# Line 304 | Line 329 | namespace Sojaner.MemoryScanner
329                  UIntPtr ptrBytesWritten;
330                  ProcessMemoryReaderApi.WriteProcessMemory(m_hProcess, (IntPtr)MemoryAddress, bytesToWrite, (uint)bytesToWrite.Length, out ptrBytesWritten);
331                  bytesWritten = ptrBytesWritten.ToUInt32();
332 +                int LastWin32Error = Marshal.GetLastWin32Error();
333 +                if (LastWin32Error != ResultWin32.ERROR_SUCCESS)
334 +                {
335 +                    string error = ResultWin32.GetErrorName(LastWin32Error);
336 +                    throw new Win32Exception(LastWin32Error, "Unable to read process memory");
337 +                }
338 +            }
339 +            catch (Win32Exception ex)
340 +            {
341 +                string error_name = ResultWin32.GetErrorName(ex.ErrorCode);
342 +                error_name = (error_name == string.Empty) ? "undefined" : error_name;
343 +                logger.Error.WriteLine("WriteProcessMemory() Win32Exception was thrown: ErrorCode:{0} - {1}", string.Format("0x{0:x8}", ex.ErrorCode, error_name), ex.Message);
344 +                logger.Error.WriteLine(ex.ToString());
345 +                throw ex;
346              }
347              catch (SEHException ex)
348              {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines