Parent Directory
|
Revision Log
|
Patch
--- trunk/RomCheater/Docking/FloatingRamDumperDialog.cs 2012/05/28 07:49:48 164 +++ trunk/RomCheater/Docking/FloatingRamDumperDialog.cs 2012/05/31 07:13:43 198 @@ -15,7 +15,7 @@ namespace RomCheater.Docking { - public partial class FloatingRamDumperDialog : DockContent, IProcessConfig + public partial class FloatingRamDumperDialog : DockContent, IProcessConfig, IAcceptsPlugin<IConfigPlugin> { #region sub-classes private const int BYTE_CORRECTION_VALUE = 23; @@ -40,33 +40,17 @@ } - #region IProcessConfig Members' + #region IProcessConfig Members public Process AcceptedProcess { get; set; } #endregion #region IAcceptsPlugin<IConfigPlugin> Members public IConfigPlugin AcceptedPlugin { get; set; } #endregion - - private void radioBTNBytes_CheckedChanged(object sender, EventArgs e) - { - dumpSize = DumpSize.Bytes; - } - - private void radioBTNKiloBytes_CheckedChanged(object sender, EventArgs e) - { - dumpSize = DumpSize.KiloBytes; - } - - private void radioBTNMegaBytes_CheckedChanged(object sender, EventArgs e) - { - dumpSize = DumpSize.MegaBytes; - } - - private void radioBTNGigaBytes_CheckedChanged(object sender, EventArgs e) - { - dumpSize = DumpSize.GigaBytes; - } - + #region ram-dump specific + private void radioBTNBytes_CheckedChanged(object sender, EventArgs e) { dumpSize = DumpSize.Bytes; } + private void radioBTNKiloBytes_CheckedChanged(object sender, EventArgs e) { dumpSize = DumpSize.KiloBytes; } + private void radioBTNMegaBytes_CheckedChanged(object sender, EventArgs e) { dumpSize = DumpSize.MegaBytes; } + private void radioBTNGigaBytes_CheckedChanged(object sender, EventArgs e) { dumpSize = DumpSize.GigaBytes; } private void btnCalcEndAddr_Click(object sender, EventArgs e) { ulong start = 0; @@ -75,24 +59,23 @@ 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; } } - private void btnCalcStartAddr_Click(object sender, EventArgs e) { long start = 0; @@ -102,15 +85,15 @@ { case DumpSize.Bytes: start = (long)((double)end - (Convert.ToDouble(txtDumpSize.Text) * 1.0)) + BYTE_CORRECTION_VALUE; - txtStart.Value = (ulong)start;; + txtStart.Value = (ulong)start; ; break; case DumpSize.KiloBytes: start = (long)((double)end - (Convert.ToDouble(txtDumpSize.Text) * 1000.0)) + BYTE_CORRECTION_VALUE; - txtStart.Value = (ulong)start;; + txtStart.Value = (ulong)start; ; break; case DumpSize.MegaBytes: start = (long)((double)end - (Convert.ToDouble(txtDumpSize.Text) * 1000000.0)) + BYTE_CORRECTION_VALUE; - txtStart.Value = (ulong)start;; + txtStart.Value = (ulong)start; ; break; case DumpSize.GigaBytes: start = (long)((double)end - (Convert.ToDouble(txtDumpSize.Text) * 1000000000.0)) + BYTE_CORRECTION_VALUE; @@ -118,7 +101,6 @@ break; } } - private void btnCalcDumpSize_Click(object sender, EventArgs e) { ulong start = txtStart.Value; @@ -140,7 +122,6 @@ break; } } - private void btnDumpRam_Click(object sender, EventArgs e) { if (this.AcceptedProcess == null) @@ -152,27 +133,29 @@ if (result != DialogResult.OK) return; DumpRam(txtStart.Value, txtEnd.Value, dumpsaver.FileName); } - + #endregion #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) - //{ + string arch = ProcessorAssemblyArchitecture.GetProcessorArchitecture(typeof(FloatingRamDumperDialog).Assembly); + if (arch == ProcessorAssemblyArchitecture.x86) + { + // intptr is 4 bytes on 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 - //} - + logger.Warn.WriteLine("Warning: DumpRam(): ending address is greater than 0x{0:x8} and we are running x86, this will exceed the max value for IntPtr", int.MaxValue); + } + else if (arch == ProcessorAssemblyArchitecture.x64) + { + // inptr is 8 bytes on x64 + if (end > uint.MaxValue) + logger.Warn.WriteLine("Warning: DumpRam(): ending address is greater than 0x{0:x8} and we are running x64, this will exceed the max value for UIntPtr", int.MaxValue); + } + else + { + throw new InvalidProgramException(string.Format("Unexcepted processor aritecture: expected x86 or x64 but we have: {0}", arch)); + } DumpRam(start, byte_count, filename); } private void DumpRam(ulong start, uint count, string filename) @@ -182,7 +165,14 @@ reader.ReadProcess = this.AcceptedProcess; reader.OpenProcess(); int bytesReadSize; - reader.DumpMemory(filename, (uint)start, count, out bytesReadSize); + if (reader.WriteProcessMemoryToFile(filename, (uint)start, count, out bytesReadSize)) + { + MessageBox.Show(string.Format("Succefully dumped memory (0x{0:x8}-0x{1:x8}) from pid=({3}) to file {2}", start, start + count, filename, string.Format("0x{0:x4} {1}.exe", this.AcceptedProcess.Id, AcceptedProcess.ProcessName)), "", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show(string.Format("Failed to dump memory (0x{0:x8}-0x{1:x8}) from pid=({3}) to file {2}", start, start + count, filename, string.Format("0x{0:x4} {1}.exe", this.AcceptedProcess.Id, AcceptedProcess.ProcessName)), "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } reader.CloseHandle(); } #endregion
ViewVC Help | |
Powered by ViewVC 1.1.22 |