private void dumpToolStripMenuItem_Click(object sender, EventArgs e) { Func <SaveFileDialog> createDialogFn; Action <IRemoteMemoryReader, Stream> dumpFn; if (GetToolStripSourceControl(sender) == modulesDataGridView) { var module = GetSelectedModule(); if (module == null) { return; } createDialogFn = () => new SaveFileDialog { FileName = $"{Path.GetFileNameWithoutExtension(module.Name)}_Dumped{Path.GetExtension(module.Name)}", InitialDirectory = Path.GetDirectoryName(module.Path) }; dumpFn = (reader, stream) => { Dumper.DumpModule(reader, module, stream); MessageBox.Show("Module successfully dumped.", Constants.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Information); }; } else { var section = GetSelectedSection(); if (section == null) { return; } createDialogFn = () => new SaveFileDialog { FileName = $"Section_{section.Start.ToString("X")}_{section.End.ToString("X")}.dat" }; dumpFn = (reader, stream) => { Dumper.DumpSection(reader, section, stream); MessageBox.Show("Section successfully dumped.", Constants.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Information); }; } using var sfd = createDialogFn(); sfd.Filter = "All|*.*"; if (sfd.ShowDialog() != DialogResult.OK) { return; } try { using var stream = sfd.OpenFile(); dumpFn(process, stream); } catch (Exception ex) { Program.ShowException(ex); } }
private void dumpToolStripMenuItem_Click(object sender, EventArgs e) { bool isModule; string fileName; var initialDirectory = string.Empty; IntPtr address; int size; if (GetToolStripSourceControl(sender) == modulesDataGridView) { var module = GetSelectedModule(); if (module == null) { return; } isModule = true; fileName = $"{Path.GetFileNameWithoutExtension(module.Name)}_Dumped{Path.GetExtension(module.Name)}"; initialDirectory = Path.GetDirectoryName(module.Path); address = module.Start; size = module.Size.ToInt32(); } else { var section = GetSelectedSection(); if (section == null) { return; } isModule = false; fileName = $"Section_{section.Start.ToString("X")}_{section.End.ToString("X")}.dat"; address = section.Start; size = section.Size.ToInt32(); } using (var sfd = new SaveFileDialog()) { sfd.FileName = fileName; sfd.Filter = "All|*.*"; sfd.InitialDirectory = initialDirectory; if (sfd.ShowDialog() == DialogResult.OK) { var dumper = new Dumper(process); try { using (var stream = sfd.OpenFile()) { if (isModule) { dumper.DumpModule(address, size, stream); } else { dumper.DumpSection(address, size, stream); } MessageBox.Show("Module successfully dumped.", Constants.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { Program.ShowException(ex); } } } }