/[RomCheater]/trunk/RomCheater.PluginFramework/Core/PluginBase.cs
ViewVC logotype

Diff of /trunk/RomCheater.PluginFramework/Core/PluginBase.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/RomCheater.PluginFramework/Core/PluginBase.cs	2013/06/17 09:31:52	686
+++ trunk/RomCheater.PluginFramework/Core/PluginBase.cs	2013/06/17 09:43:16	687
@@ -4,6 +4,8 @@
 using System.Text;
 using System.Diagnostics;
 using RomCheater.Core;
+using Sojaner.MemoryScanner.MemoryProviers;
+using ManagedWinapi;
 
 namespace RomCheater.PluginFramework.Core
 {
@@ -24,16 +26,69 @@
             {
                 bytesRead = 0x00;
                 data = new byte[bytesToRead];
-
-                
-
+                if (this.AcceptedConfig == null || this.AcceptedProcess == null) { return; }
+                IConfigPlugin config = this.AcceptedConfig;
+                Process proc = this.AcceptedProcess;
+                using (GenericMemoryProvider provider = new GenericMemoryProvider(config, proc))
+                {
+                    provider.OpenProvider();
+                    provider.ReadProcessMemory(MemoryAddress, bytesToRead, out bytesRead, out data);
+                    provider.CloseProvider();
+                }
             }
             catch (Exception ex)
             {
                 throw ex;
             }
         }
-
+        protected void WriteProcessMemory(long MemoryAddress, byte[] bytesToWrite, out ulong bytesWritten)
+        {
+            try
+            {
+                bytesWritten = 0;
+                if (this.AcceptedConfig == null || this.AcceptedProcess == null) { return; }
+                IConfigPlugin config = this.AcceptedConfig;
+                Process proc = this.AcceptedProcess;
+                using (GenericMemoryProvider provider = new GenericMemoryProvider(config, proc))
+                {
+                    provider.OpenProvider();
+                    provider.WriteProcessMemory(MemoryAddress, bytesToWrite, out bytesWritten);
+                    provider.CloseProvider();
+                }
+            }
+            catch (Exception ex)
+            {
+                throw ex;
+            }
+        }
+        protected List<MEMORY_REGION_INFORMATION> QueryMemoryRegions()
+        {
+            if (this.AcceptedConfig == null || this.AcceptedProcess == null) { return new List<MEMORY_REGION_INFORMATION>(); }
+            IConfigPlugin config = this.AcceptedConfig;
+            Process proc = this.AcceptedProcess;
+            List<MEMORY_REGION_INFORMATION> MemoryRegions = new List<MEMORY_REGION_INFORMATION>();
+            using (GenericMemoryProvider provider = new GenericMemoryProvider(config, proc))
+            {
+                provider.OpenProvider();
+                if (this.peData != null)
+                {
+                    if (this.peData.Is32bitAssembly())
+                    {
+                        MemoryRegions = provider.QueryMemoryRegions(MemorySizeConstants.MinimumAddress, MemorySizeConstants.MaximumAddressSize_x86);
+                    }
+                    else
+                    {
+                        MemoryRegions = provider.QueryMemoryRegions(MemorySizeConstants.MinimumAddress, MemorySizeConstants.MaximumAddressSize_x64);
+                    }
+                }
+                else
+                {
+                    MemoryRegions = provider.QueryMemoryRegions(MemorySizeConstants.MinimumAddress, MemorySizeConstants.MaximumAddressSize_x86);
+                }                
+                provider.CloseProvider();
+            }
+            return MemoryRegions;
+        }
         #region IPluginBase Members
         public abstract Guid ID { get; }
         public abstract string Name { get; }

 

  ViewVC Help
Powered by ViewVC 1.1.22