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

Diff of /trunk/RomCheater/Docking/FloatingRamDumperDialog.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 154 by william, Mon May 28 03:04:05 2012 UTC revision 157 by william, Mon May 28 04:20:13 2012 UTC
# Line 9  using System.Windows.Forms; Line 9  using System.Windows.Forms;
9  using WeifenLuo.WinFormsUI.Docking;  using WeifenLuo.WinFormsUI.Docking;
10  using RomCheater.PluginFramework.Interfaces;  using RomCheater.PluginFramework.Interfaces;
11  using System.Diagnostics;  using System.Diagnostics;
12    using System.IO;
13    
14  namespace RomCheater.Docking  namespace RomCheater.Docking
15  {  {
# Line 137  namespace RomCheater.Docking Line 138  namespace RomCheater.Docking
138                      break;                      break;
139              }              }
140          }          }
141    
142            private void btnDumpRam_Click(object sender, EventArgs e)
143            {
144                if (this.AcceptedProcess == null)
145                {
146                    MessageBox.Show("Please select a process to dump memory from", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
147                    return;
148                }
149                DialogResult result = dumpsaver.ShowDialog();
150                if (result != DialogResult.OK) return;
151                DumpRam(txtStart.Value, txtEnd.Value, dumpsaver.FileName);
152            }
153    
154    
155            #region memory support
156            private void DumpRam(ulong start, ulong end, string filename)
157            {
158                uint byte_count = (uint)(end - start);
159                DumpRam(start, byte_count, filename);
160            }
161            private void DumpRam(ulong start, uint count, string filename)
162            {
163                if (this.AcceptedProcess == null) return;
164                Sojaner.MemoryScanner.ProcessMemoryReader reader = new Sojaner.MemoryScanner.ProcessMemoryReader();
165                reader.ReadProcess = this.AcceptedProcess;
166                reader.OpenProcess();
167                int bytesReadSize;
168                byte[] data = reader.ReadProcessMemory((IntPtr)(uint)start, count, out bytesReadSize);
169                reader.CloseHandle();
170                using (FileStream fs = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite))
171                {
172                    BinaryWriter bw = new BinaryWriter(fs);
173                    foreach (byte b in data) { bw.Write(b); }
174                    bw.Flush();
175                    bw.Close();
176                }
177            }
178            #endregion
179      }      }
180  }  }

Legend:
Removed from v.154  
changed lines
  Added in v.157

  ViewVC Help
Powered by ViewVC 1.1.22