/// <summary> /// Initializes a new instance of the <see cref="MemoryDump"/> class. /// </summary> /// <param name="selected">The selected.</param> /// <param name="module">The module.</param> /// <param name="data">The data.</param> public MemoryDump(AllocationInformation selected, string module, XDocument data) : this() { Selected = selected; Title = string.Format("Displaying memory dump of \"{0}\" | Address: {1} - Bytes: {2} (0x{3:x8})", new object[] { module, selected.BaseAddressInHex, selected.RegionSize, selected.RegionSize }); memDump = data.ToString(); }
/// <summary> /// Reads the process memory. /// </summary> /// <param name="processName">Name of the process.</param> /// <param name="selected">The selected.</param> /// <returns></returns> public static XDocument ReadProcessMemory(string processName, AllocationInformation selected) { XDocument retval = null; StringBuilder infoAsXml = new StringBuilder(MAXCHARS + 1); int result = ReadMemory(processName, infoAsXml, infoAsXml.Capacity, selected.BaseAddressInDec, selected.RegionSize); if (result == 0 && (retval = infoAsXml.GetXDocument()) != null && infoAsXml.GetXDocument().Element("memoryDump").DescendantNodes().Count() == 0) { retval = null; } return(retval); }
/// <summary> /// Handles the Clicked event of the menuItem control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param> private void menuItem_Clicked(object sender, RoutedEventArgs e) { XDocument dump = null; AllocationInformation selected = lstMemAllocations.SelectedItem as AllocationInformation; using (BackgroundWorker worker = new BackgroundWorker()) { // Work to do worker.DoWork += delegate(object a, DoWorkEventArgs b) { Dispatcher.Invoke(new Action(() => { ((MainWindow)App.Current.MainWindow).ManageVisualState(MainWindow.AnimationState.Loading); })); if (selected != null && (dump = DataExchange.ReadProcessMemory(ProcessNameOrId, selected)) != null) { b.Result = dump; } }; // Code executed when Backgroundworker is completed worker.RunWorkerCompleted += delegate(object a, RunWorkerCompletedEventArgs b) { XDocument dumpAsXml = b.Result as XDocument; Dispatcher.Invoke(new Action(() => { ((MainWindow)App.Current.MainWindow).ManageVisualState(MainWindow.AnimationState.Loaded); })); if (dumpAsXml != null) { (new MemoryDump(selected, Module, dump) { Owner = this.Owner }).ShowDialog(); } else { System.Windows.MessageBox.Show("Unable to read the specified memory region", "Information", MessageBoxButton.OK, MessageBoxImage.Information); } }; worker.RunWorkerAsync(); } }