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

Contents of /trunk/RomCheater.Core/Docking/FloatingRamDumperDialog.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 892 - (show annotations) (download)
Wed Sep 17 05:56:41 2014 UTC (6 years, 10 months ago) by william
File size: 10099 byte(s)
+ alot of dang work to force an icon to be shown on the docked panels
  ** when it was as simple as setting: DockPanel.ShowDocumentIcon to true

1 #region Logging Defines
2 // include this any class or method that required logging, and comment-out what is not needed
3
4 #region Enabled logging levels
5 #define LOGGING_ENABLE_INFO
6 #define LOGGING_ENABLE_WARN
7 #define LOGGING_ENABLE_DEBUG
8 #define LOGGING_ENABLE_VERBOSEDEBUG
9 #define LOGGING_ENABLE_ERROR
10 #define LOGGING_ENABLE_VERBOSEERROR
11 #define LOGGING_ENABLE_PROFILER
12 #endregion
13 #endregion
14 using System;
15 using System.Collections.Generic;
16 using System.ComponentModel;
17 using System.Data;
18 using System.Drawing;
19 using System.Linq;
20 using System.Text;
21 using System.Windows.Forms;
22 using WeifenLuo.WinFormsUI.Docking;
23 using System.Diagnostics;
24 using System.IO;
25 using RomCheater.Logging;
26 using System.Reflection;
27 using Sojaner.MemoryScanner.MemoryProviers;
28 using Sojaner.MemoryScanner;
29 using RomCheater.Interfaces;
30
31 namespace RomCheater.Core.Docking
32 {
33 public partial class FloatingRamDumperDialog : DockContent,
34 IAcceptsPlugin<IConfigPlugin>,
35 IAcceptsProcess<Process>,
36 IAcceptsProcessAndConfig,
37 IAcceptPEData
38 {
39 #region sub-classes
40 private const int BYTE_CORRECTION_VALUE = 23;
41 public enum DumpSize
42 {
43 Bytes,
44 KiloBytes,
45 MegaBytes,
46 GigaBytes,
47 }
48 #endregion
49 private DumpSize dumpSize = DumpSize.Bytes;
50
51 public FloatingRamDumperDialog() { InitializeComponent(); this.AcceptedPlugin = null; this.AcceptedProcess = null; }
52 public FloatingRamDumperDialog(IConfigPlugin config) : this() { this.AcceptedPlugin = config; }
53 public FloatingRamDumperDialog(IConfigPlugin config, Process process) : this() { this.AcceptedPlugin = config; this.AcceptedProcess = process; }
54
55 private void FloatingRamDumperDialog_Load(object sender, EventArgs e)
56 {
57 txtStart.Value = MemorySizeConstants.MinimumAddress;
58 if (this.PEData != null)
59 {
60 if (this.PEData.Is32bitAssembly())
61 {
62 txtEnd.Value = MemorySizeConstants.MinimumAddress + MemorySizeConstants.MaximumAddressSize_x86;
63 }
64 else
65 {
66 txtEnd.Value = MemorySizeConstants.MinimumAddress + MemorySizeConstants.MaximumAddressSize_x64;
67 }
68 }
69 else
70 {
71 txtEnd.Value = MemorySizeConstants.MinimumAddress + MemorySizeConstants.MaximumAddressSize_x86;
72 }
73
74 }
75
76
77 #region IAcceptsProcess<Process> Members
78 public Process AcceptedProcess { get; set; }
79 #endregion
80 #region IAcceptsPlugin<IConfigPlugin> Members
81 public IConfigPlugin AcceptedPlugin { get; set; }
82 #endregion
83 #region ram-dump specific
84 private void radioBTNBytes_CheckedChanged(object sender, EventArgs e) { dumpSize = DumpSize.Bytes; }
85 private void radioBTNKiloBytes_CheckedChanged(object sender, EventArgs e) { dumpSize = DumpSize.KiloBytes; }
86 private void radioBTNMegaBytes_CheckedChanged(object sender, EventArgs e) { dumpSize = DumpSize.MegaBytes; }
87 private void radioBTNGigaBytes_CheckedChanged(object sender, EventArgs e) { dumpSize = DumpSize.GigaBytes; }
88 private void btnCalcEndAddr_Click(object sender, EventArgs e)
89 {
90 ulong start = 0;
91 ulong end = 0;
92 start = txtStart.Value;
93 switch (dumpSize)
94 {
95 case DumpSize.Bytes:
96 end = (ulong)(Convert.ToDouble(txtDumpSize.Text) * 1.0 + (double)start) + BYTE_CORRECTION_VALUE;
97 txtEnd.Value = end;
98 break;
99 case DumpSize.KiloBytes:
100 end = (ulong)(Convert.ToDouble(txtDumpSize.Text) * 1000.0 + (double)start) + BYTE_CORRECTION_VALUE;
101 txtEnd.Value = end;
102 break;
103 case DumpSize.MegaBytes:
104 end = (ulong)(Convert.ToDouble(txtDumpSize.Text) * 1000000.0 + (double)start) + BYTE_CORRECTION_VALUE;
105 txtEnd.Value = end;
106 break;
107 case DumpSize.GigaBytes:
108 end = (ulong)(Convert.ToDouble(txtDumpSize.Text) * 1000000000.0 + (double)start) + BYTE_CORRECTION_VALUE;
109 txtEnd.Value = end;
110 break;
111 }
112 }
113 private void btnCalcStartAddr_Click(object sender, EventArgs e)
114 {
115 long start = 0;
116 long end = 0;
117 end = txtEnd.ToInt64();
118 switch (dumpSize)
119 {
120 case DumpSize.Bytes:
121 start = (long)((double)end - (Convert.ToDouble(txtDumpSize.Text) * 1.0)) + BYTE_CORRECTION_VALUE;
122 txtStart.Value = (ulong)start;
123 break;
124 case DumpSize.KiloBytes:
125 start = (long)((double)end - (Convert.ToDouble(txtDumpSize.Text) * 1000.0)) + BYTE_CORRECTION_VALUE;
126 txtStart.Value = (ulong)start;
127 break;
128 case DumpSize.MegaBytes:
129 start = (long)((double)end - (Convert.ToDouble(txtDumpSize.Text) * 1000000.0)) + BYTE_CORRECTION_VALUE;
130 txtStart.Value = (ulong)start;
131 break;
132 case DumpSize.GigaBytes:
133 start = (long)((double)end - (Convert.ToDouble(txtDumpSize.Text) * 1000000000.0)) + BYTE_CORRECTION_VALUE;
134 txtStart.Value = (ulong)start;
135 break;
136 }
137 }
138 private void btnCalcDumpSize_Click(object sender, EventArgs e)
139 {
140 ulong start = txtStart.Value;
141 ulong end = txtEnd.Value;
142 ulong byte_diff = (end - start) + BYTE_CORRECTION_VALUE;
143 switch (dumpSize)
144 {
145 case DumpSize.Bytes:
146 txtDumpSize.Text = string.Format("{0:n2}", (double)byte_diff);
147 break;
148 case DumpSize.KiloBytes:
149 txtDumpSize.Text = string.Format("{0:n3}", (double)byte_diff / 1000.0);
150 break;
151 case DumpSize.MegaBytes:
152 txtDumpSize.Text = string.Format("{0:n6}", (double)byte_diff / 1000000.0);
153 break;
154 case DumpSize.GigaBytes:
155 txtDumpSize.Text = string.Format("{0:n9}", (double)byte_diff / 1000000000.0);
156 break;
157 }
158 }
159 private void btnDumpRam_Click(object sender, EventArgs e)
160 {
161 if (this.AcceptedProcess == null)
162 {
163 MessageBox.Show("Please select a process to dump memory from", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
164 return;
165 }
166 DialogResult result = dumpsaver.ShowDialog();
167 if (result != DialogResult.OK) return;
168
169
170 if(txtEnd.Value < txtStart.Value)
171 {
172 MessageBox.Show("Failed to dump memory...end address cannot be less than start address.", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
173 return;
174 }
175 ulong count = (txtEnd.Value - txtStart.Value) + 1; // add one to get the last address included
176 DumpRam(txtStart.Value, count, dumpsaver.FileName);
177 }
178 #endregion
179
180 #region memory support
181 private void DumpRam(ulong start, ulong count, string filename)
182 {
183 if (this.AcceptedProcess == null) return;
184 ulong bytesReadSize;
185 using (GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
186 {
187 provider.OpenProvider();
188 if (provider.WriteProcessMemoryToFile(filename, (ulong)start, count, out bytesReadSize))
189 {
190 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);
191 }
192 else
193 {
194 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);
195 }
196 provider.CloseProvider();
197 }
198
199 //ProcessMemoryReader provider = new ProcessMemoryReader();
200 //provider.ReadProcess = this.AcceptedProcess;
201 //provider.OpenProcess();
202 //provider.WriteProcessMemoryToFile(filename, (int)start, count, out bytesReadSize);
203 //provider.CloseHandle();
204
205 }
206 #endregion
207
208 private IPEDData _PEData;
209 private IPEDData PEData { get { return _PEData; } set { _PEData = value; } }
210 public void SetPEViewerData(IPEDData peData)
211 {
212 this.PEData = peData;
213 txtStart.Value = MemorySizeConstants.MinimumAddress;
214 if (this.PEData != null)
215 {
216 if (this.PEData.Is32bitAssembly())
217 {
218 txtEnd.Value = MemorySizeConstants.MinimumAddress + MemorySizeConstants.MaximumAddressSize_x86;
219 }
220 else
221 {
222 txtEnd.Value = MemorySizeConstants.MinimumAddress + MemorySizeConstants.MaximumAddressSize_x64;
223 }
224 }
225 else
226 {
227 txtEnd.Value = MemorySizeConstants.MinimumAddress + MemorySizeConstants.MaximumAddressSize_x86;
228 }
229 }
230 }
231 }

  ViewVC Help
Powered by ViewVC 1.1.22