/[RomCheater]/trunk/RomCheater/Docking/FloatingRamDumperDialog.cs
ViewVC logotype

Diff of /trunk/RomCheater/Docking/FloatingRamDumperDialog.cs

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

--- trunk/RomCheater/Docking/FloatingRamDumperDialog.cs	2012/05/28 03:04:05	154
+++ trunk/RomCheater/Docking/FloatingRamDumperDialog.cs	2012/05/28 04:20:13	157
@@ -9,6 +9,7 @@
 using WeifenLuo.WinFormsUI.Docking;
 using RomCheater.PluginFramework.Interfaces;
 using System.Diagnostics;
+using System.IO;
 
 namespace RomCheater.Docking
 {
@@ -137,5 +138,43 @@
                     break;
             }
         }
+
+        private void btnDumpRam_Click(object sender, EventArgs e)
+        {
+            if (this.AcceptedProcess == null)
+            {
+                MessageBox.Show("Please select a process to dump memory from", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
+                return;
+            }
+            DialogResult result = dumpsaver.ShowDialog();
+            if (result != DialogResult.OK) return;
+            DumpRam(txtStart.Value, txtEnd.Value, dumpsaver.FileName);
+        }
+
+
+        #region memory support
+        private void DumpRam(ulong start, ulong end, string filename)
+        {
+            uint byte_count = (uint)(end - start);
+            DumpRam(start, byte_count, filename);
+        }
+        private void DumpRam(ulong start, uint count, string filename)
+        {
+            if (this.AcceptedProcess == null) return;
+            Sojaner.MemoryScanner.ProcessMemoryReader reader = new Sojaner.MemoryScanner.ProcessMemoryReader();
+            reader.ReadProcess = this.AcceptedProcess;
+            reader.OpenProcess();
+            int bytesReadSize;
+            byte[] data = reader.ReadProcessMemory((IntPtr)(uint)start, count, out bytesReadSize);
+            reader.CloseHandle();
+            using (FileStream fs = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite))
+            {
+                BinaryWriter bw = new BinaryWriter(fs);
+                foreach (byte b in data) { bw.Write(b); }
+                bw.Flush();
+                bw.Close();
+            }
+        }
+        #endregion
     }
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22