/[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

revision 407 by william, Thu Jun 21 12:51:57 2012 UTC revision 408 by william, Thu Jun 21 18:10:21 2012 UTC
# Line 11  using Microsoft.Win32.SafeHandles; Line 11  using Microsoft.Win32.SafeHandles;
11  using Microsoft.Win32.Interop;  using Microsoft.Win32.Interop;
12  using System.ComponentModel;  using System.ComponentModel;
13  using ManagedWinapi;  using ManagedWinapi;
14    using RomCheater.PluginFramework.Events;
15    
16  namespace Sojaner.MemoryScanner  namespace Sojaner.MemoryScanner
17  {  {
# Line 18  namespace Sojaner.MemoryScanner Line 19  namespace Sojaner.MemoryScanner
19      #region ProcessMemoryReader class      #region ProcessMemoryReader class
20      //Thanks goes to Arik Poznanski for P/Invokes and methods needed to read and write the Memory      //Thanks goes to Arik Poznanski for P/Invokes and methods needed to read and write the Memory
21      //For more information refer to "Minesweeper, Behind the scenes" article by Arik Poznanski at Codeproject.com      //For more information refer to "Minesweeper, Behind the scenes" article by Arik Poznanski at Codeproject.com
22      internal class ProcessMemoryReader : IMemoryReader, IMemoryWriter, IFileWriter, IPatchMemory,IReadMemory      internal class ProcessMemoryReader : IMemoryReader, IMemoryWriter, IFileWriter, IPatchMemory,IReadMemory, IAcceptsBytesReadEvent
23      {      {
24          // constants information can be found in <winnt.h>          // constants information can be found in <winnt.h>
25          [Flags]          [Flags]
# Line 68  namespace Sojaner.MemoryScanner Line 69  namespace Sojaner.MemoryScanner
69          public ProcessMemoryReader()          public ProcessMemoryReader()
70          {          {
71          }          }
72            public event BaseEventHandler<OnBytesReadEventArgs> OnBytesRead;
73          /// <summary>            /// <summary>  
74          /// Process from which to read                    /// Process from which to read          
75          /// </summary>          /// </summary>
# Line 153  namespace Sojaner.MemoryScanner Line 154  namespace Sojaner.MemoryScanner
154          /// </summary>          /// </summary>
155          private class ProcessMemoryReaderApi          private class ProcessMemoryReaderApi
156          {          {
             
           
157              [DllImport("kernel32.dll")]              [DllImport("kernel32.dll")]
158              public static extern int VirtualQueryEx(IntPtr hProcess, IntPtr lpAddress, out MEMORY_BASIC_INFORMATION lpBuffer, uint dwLength);              public static extern int VirtualQueryEx(IntPtr hProcess, IntPtr lpAddress, out MEMORY_BASIC_INFORMATION lpBuffer, uint dwLength);
159    
# Line 293  namespace Sojaner.MemoryScanner Line 292  namespace Sojaner.MemoryScanner
292          }          }
293          #endregion          #endregion
294    
295            public void ReadProcessMemoryAtOnce(uint MemoryAddress, uint bytesToRead,object UserState)
296            {
297                uint size = 1024 * 128;
298                for (uint j = MemoryAddress; j < bytesToRead; j += size)
299                {
300                    ProcessMemoryChunk mem = new ProcessMemoryChunk(m_ReadProcess, (IntPtr)j, (int)size);
301                    byte[] bigMem = mem.Read();
302                    if (this.OnBytesRead != null)
303                        this.OnBytesRead.Invoke(new OnBytesReadEventArgs(this, UserState, bigMem, j, bytesToRead));
304                    bigMem = null;
305                }
306                
307            }
308          public void ReadProcessMemoryAtOnce(uint MemoryAddress, uint bytesToRead, out int bytesRead, out byte[] data)          public void ReadProcessMemoryAtOnce(uint MemoryAddress, uint bytesToRead, out int bytesRead, out byte[] data)
309          {          {
310              Stopwatch st = new Stopwatch();              Stopwatch st = new Stopwatch();

Legend:
Removed from v.407  
changed lines
  Added in v.408

  ViewVC Help
Powered by ViewVC 1.1.22