--- trunk/RomCheater/Docking/FloatingRamDumperDialog.cs 2012/05/28 03:04:05 154 +++ trunk/RomCheater/Docking/FloatingRamDumperDialog.cs 2012/05/28 08:13:31 165 @@ -9,6 +9,9 @@ using WeifenLuo.WinFormsUI.Docking; using RomCheater.PluginFramework.Interfaces; using System.Diagnostics; +using System.IO; +using RomCheater.Logging; +using System.Reflection; namespace RomCheater.Docking { @@ -72,19 +75,19 @@ switch (dumpSize) { case DumpSize.Bytes: - end = (ulong)(Convert.ToDouble(txtDumpSize.Text) * 1.0 + start) - BYTE_CORRECTION_VALUE; + end = (ulong)(Convert.ToDouble(txtDumpSize.Text) * 1.0 + (double)start) + BYTE_CORRECTION_VALUE; txtEnd.Value = end; break; case DumpSize.KiloBytes: - end = (ulong)(Convert.ToDouble(txtDumpSize.Text) * 1000.0 + start) - BYTE_CORRECTION_VALUE; + end = (ulong)(Convert.ToDouble(txtDumpSize.Text) * 1000.0 + (double)start) + BYTE_CORRECTION_VALUE; txtEnd.Value = end; break; case DumpSize.MegaBytes: - end = (ulong)(Convert.ToDouble(txtDumpSize.Text) * 1000000.0 + start) - BYTE_CORRECTION_VALUE; + end = (ulong)(Convert.ToDouble(txtDumpSize.Text) * 1000000.0 + (double)start) + BYTE_CORRECTION_VALUE; txtEnd.Value = end; break; case DumpSize.GigaBytes: - end = (ulong)(Convert.ToDouble(txtDumpSize.Text) * 1000000000.0 + start) - BYTE_CORRECTION_VALUE; + end = (ulong)(Convert.ToDouble(txtDumpSize.Text) * 1000000000.0 + (double)start) + BYTE_CORRECTION_VALUE; txtEnd.Value = end; break; } @@ -137,5 +140,51 @@ 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); + + //string arch = ProcessorAssemblyArchitecture.GetProcessorArchitecture(typeof(FloatingRamDumperDialog).Assembly); + //if (arch == ProcessorAssemblyArchitecture.x86) + //{ + if (end > int.MaxValue) + logger.Warn.WriteLine("Warning: DumpRam(): ending address is greater than 0x{0:x8} and we are running x86, this will exceed the ", int.MaxValue); + //} + //else if (arch == ProcessorAssemblyArchitecture.x64) + //{ + //} + //else + //{ + // // don't know + //} + + 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; + reader.DumpMemory(filename, (uint)start, count, out bytesReadSize); + reader.CloseHandle(); + } + #endregion } }