/[RomCheater]/trunk/RomCheater/Main.cs
ViewVC logotype

Annotation of /trunk/RomCheater/Main.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 335 - (hide annotations) (download)
Thu Jun 7 21:11:51 2012 UTC (9 years ago) by william
File size: 20149 byte(s)

1 william 99 #define FORCE_ALL_LOGGING_FLAGS // when defined will force logging flags to ALL
2 william 158 #define SHOW_DEBUG_MENU // when defined will show the debug menu or else it will be hidden
3 william 99 using System;
4 william 5 using System.Collections.Generic;
5     using System.ComponentModel;
6     using System.Data;
7     using System.Drawing;
8     using System.Linq;
9     using System.Text;
10     using System.Windows.Forms;
11 william 17 using RomCheater.Logging;
12 william 34 using RomCheater.Properties;
13     using RomCheater.UserSettingsSupport;
14 william 83 using RomCheater.PluginFramework.Core;
15 william 86 using System.Diagnostics;
16 william 87 using RomCheater.PluginFramework.Interfaces;
17 william 144 using WeifenLuo.WinFormsUI.Docking;
18 william 146 using RomCheater.Docking;
19 william 152 using System.IO;
20 william 159 using Sojaner.MemoryScanner;
21 william 196 using RomCheater.PluginFramework.Events;
22 william 5
23     namespace RomCheater
24     {
25 william 13 public partial class Main : Form
26 william 5 {
27 william 152 private bool m_bSaveLayout = true;
28 william 196 private Process SelectedProcess = null;
29 william 144 private DeserializeDockContent m_deserializeDockContent;
30     private FloatingLogWindow m_LogWindow = new FloatingLogWindow();
31 william 147 private FloatingAboutBox m_AboutBox = new FloatingAboutBox();
32 william 148 private FloatingRamDumperDialog m_RamDump = new FloatingRamDumperDialog();
33     private PIDSelector m_PIDSelector = new PIDSelector();
34 william 196 private FloatingMemoryView m_memoryview = new FloatingMemoryView();
35 william 218 private FloatingDataTypeConverter m_typeconverter = new FloatingDataTypeConverter();
36 william 227 private FloatingMemorySearcher m_memsearcher = new FloatingMemorySearcher();
37 william 318 private FloatingPEViewer m_peviewer = new FloatingPEViewer();
38 william 144 //private bool log_window_expanded = false;
39     //private double log_window_splitter_default_position = 1.4045;
40 william 86 PluginLoader loader = null;
41 william 87 IConfigPlugin ConfigPlugin = null;
42     IInputPlugin InputPlugin = null;
43     IWindowPlugin WindowPlugin = null;
44 william 146 static Main() { SettingSubscriber.AddSubscriber(new Main(), Settings.Default); }
45 william 20 private const string t = "RomCheater";
46 william 17 #region LogWriterSupport
47     static LogWriter _LoggerInstance;
48     static LogWriter LoggerInstance
49     {
50     get { return _LoggerInstance; }
51     set { _LoggerInstance = value; }
52     }
53     #endregion
54    
55    
56 william 196 private void OnProcessChanged(ProcessChangedEventArgs e)
57 william 151 {
58 william 228 if (m_memsearcher.SearchInProgess)
59     {
60     DialogResult result = MessageBox.Show("Do you want to start a new search with the selected process?", "A memory search is currently in progress", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button3);
61     if (result != DialogResult.Yes || result != DialogResult.OK) { return; }
62     m_memsearcher = null; //free memory used by the memory searcher
63     m_memsearcher = new FloatingMemorySearcher();
64     }
65 william 153 SelectedProcess = Process.GetProcessById(e.ProcessID);
66 william 196 m_RamDump.AcceptedPlugin = this.ConfigPlugin;
67 william 245 m_RamDump.AcceptedProcess = SelectedProcess;
68 william 196
69 william 244 m_memoryview.AcceptedPlugin = this.ConfigPlugin;
70 william 196 m_memoryview.AcceptedProcess = SelectedProcess;
71 william 227
72 william 244 m_memsearcher.AcceptedPlugin = this.ConfigPlugin;
73 william 227 m_memsearcher.AcceptedProcess = SelectedProcess;
74 william 275 m_memsearcher.OnBrowseMemoryRegion += new BaseEventHandler<BrowseMemoryRegionEvent>(OnBrowseMemoryRegion);
75 william 318
76     m_peviewer.AcceptedPlugin = this.ConfigPlugin;
77     m_peviewer.AcceptedProcess = SelectedProcess;
78 william 323 m_peviewer.OnPEDataUpdated += new BaseEventHandler<PEViewerDataUpdatedEvent>(OnPEDataUpdated);
79 william 318
80 william 151 }
81 william 323
82     void OnPEDataUpdated(PEViewerDataUpdatedEvent e)
83     {
84     m_memoryview.SetPEViewerData(e.PEData);
85     }
86 william 275 private void OnBrowseMemoryRegion(BrowseMemoryRegionEvent e)
87     {
88 william 276 m_memoryview.BrowseMemoryRegion(e.MemoryRegion);
89 william 275 }
90 william 151
91 william 144 #region Dock Support
92 william 313 void AddDockToWindowList(object sender, EventArgs e)
93     {
94     DockContent dc;
95 william 315 TypeBinder.Bind(sender, out dc);
96 william 314 ToolStripMenuItem tsmi = new ToolStripMenuItem(dc.Text);
97     tsmi.Name = dc.Name;
98     tsmi.Tag = dc;
99 william 315 tsmi.Click += new EventHandler(tsmi_Click);
100 william 314 mnuWindows.DropDownItems.Add(tsmi);
101 william 313 }
102 william 314 void tsmi_Click(object sender, EventArgs e)
103     {
104     ToolStripMenuItem tsmi;
105 william 315 TypeBinder.Bind(sender, out tsmi);
106 william 314 DockContent dc;
107 william 315 TypeBinder.Bind(tsmi.Tag, out dc);
108 william 314 dc.Activate();
109     }
110 william 313 void RemoveDockFromWindowList(object sender, FormClosedEventArgs e)
111     {
112     DockContent dc;
113 william 315 TypeBinder.Bind(sender, out dc);
114 william 314 mnuWindows.DropDownItems.RemoveByKey(dc.Name);
115 william 313 }
116 william 144 private IDockContent GetContentFromPersistString(string persistString)
117     {
118 william 228 if (persistString == typeof(FloatingLogWindow).ToString()) { return m_LogWindow; }
119     if (persistString == typeof(FloatingRamDumperDialog).ToString()) { return m_RamDump; }
120     if (persistString == typeof(PIDSelector).ToString()) { return m_PIDSelector; }
121     if (persistString == typeof(FloatingMemoryView).ToString()) { return m_memoryview; }
122     if (persistString == typeof(FloatingDataTypeConverter).ToString()) { return m_typeconverter; }
123     if (persistString == typeof(FloatingMemorySearcher).ToString()) { return m_memsearcher; }
124 william 318 if (persistString == typeof(FloatingPEViewer).ToString()) { return m_peviewer; }
125 william 228 else { return null; }
126 william 144 }
127     public void SetupDocks()
128     {
129     m_LogWindow = new FloatingLogWindow();
130 william 147 m_AboutBox = new FloatingAboutBox();
131 william 148 m_RamDump = new FloatingRamDumperDialog();
132     m_PIDSelector = new PIDSelector();
133 william 196 m_PIDSelector.OnSelectedProcessChanged += new BaseEventHandler<ProcessChangedEventArgs>(OnProcessChanged);
134     m_memoryview = new FloatingMemoryView();
135 william 218 m_typeconverter = new FloatingDataTypeConverter();
136 william 227 m_memsearcher = new FloatingMemorySearcher();
137 william 275 m_memsearcher.OnBrowseMemoryRegion += new BaseEventHandler<BrowseMemoryRegionEvent>(OnBrowseMemoryRegion);
138 william 318 m_peviewer = new FloatingPEViewer();
139 william 323 m_peviewer.OnPEDataUpdated+=new BaseEventHandler<PEViewerDataUpdatedEvent>(OnPEDataUpdated);
140 william 144 m_deserializeDockContent = new DeserializeDockContent(GetContentFromPersistString);
141     }
142 william 313 #region SetupDockWindowHandler support
143     public void SetupDockWindowHandler()
144     {
145     SetupLogWindowHandler();
146     SetupRamDumpWindowHandler();
147     SetupMemoryViewWindowHandler();
148     SetupPIDSelectorWindowHandler();
149     SetupDataTypeConverterWindowHandler();
150     SetupMemorySearchWindowHandler();
151 william 318 SetupPEViewerWindowHandler();
152 william 313 }
153     private void SetupLogWindowHandler()
154     {
155     if (m_LogWindow == null) return;
156     m_LogWindow.Shown += new EventHandler(AddDockToWindowList);
157 william 335 m_LogWindow.FormClosed += new FormClosedEventHandler(RemoveDockFromWindowList);
158 william 314 m_LogWindow.Activate();
159 william 313 }
160     private void SetupRamDumpWindowHandler()
161     {
162     if (m_RamDump == null) return;
163     m_RamDump.Shown += new EventHandler(AddDockToWindowList);
164     m_RamDump.FormClosed += new FormClosedEventHandler(RemoveDockFromWindowList);
165 william 335 m_RamDump.AcceptedPlugin = ConfigPlugin;
166 william 314 m_RamDump.Activate();
167 william 313 }
168     private void SetupMemoryViewWindowHandler()
169     {
170     if (m_memoryview == null) return;
171     m_memoryview.Shown += new EventHandler(AddDockToWindowList);
172     m_memoryview.FormClosed += new FormClosedEventHandler(RemoveDockFromWindowList);
173 william 335 m_memoryview.AcceptedPlugin = ConfigPlugin;
174 william 314 m_memoryview.Activate();
175 william 313 }
176     private void SetupPIDSelectorWindowHandler()
177     {
178     if (m_PIDSelector == null) return;
179     m_PIDSelector.Shown += new EventHandler(AddDockToWindowList);
180     m_PIDSelector.FormClosed += new FormClosedEventHandler(RemoveDockFromWindowList);
181 william 335 m_PIDSelector.AcceptedPlugin = ConfigPlugin;
182 william 314 m_PIDSelector.Activate();
183 william 313 }
184     private void SetupDataTypeConverterWindowHandler()
185     {
186     if (m_typeconverter == null) return;
187     m_typeconverter.Shown += new EventHandler(AddDockToWindowList);
188     m_typeconverter.FormClosed += new FormClosedEventHandler(RemoveDockFromWindowList);
189 william 314 m_typeconverter.Activate();
190 william 313 }
191     private void SetupMemorySearchWindowHandler()
192     {
193     if (m_memsearcher == null) return;
194     m_memsearcher.Shown += new EventHandler(AddDockToWindowList);
195     m_memsearcher.FormClosed += new FormClosedEventHandler(RemoveDockFromWindowList);
196 william 314 m_memsearcher.Activate();
197 william 313 }
198 william 318 private void SetupPEViewerWindowHandler()
199     {
200     if (m_peviewer == null) return;
201     m_peviewer.Shown += new EventHandler(AddDockToWindowList);
202     m_peviewer.FormClosed += new FormClosedEventHandler(RemoveDockFromWindowList);
203 william 335 m_PIDSelector.AcceptedPlugin = ConfigPlugin;
204 william 318 m_peviewer.Activate();
205     }
206 william 313 #endregion
207 william 144 public void ShowDocks()
208     {
209     ShowLogWindow();
210 william 313 SetupLogWindowHandler();
211 william 152 //ShowAboutBox();
212 william 148 ShowRamDump();
213 william 313 SetupRamDumpWindowHandler();
214 william 196 ShowMemoryView();
215 william 313 SetupMemoryViewWindowHandler();
216 william 148 ShowPidSelector();
217 william 313 SetupPIDSelectorWindowHandler();
218 william 218 ShowDataTypeConverter();
219 william 313 SetupDataTypeConverterWindowHandler();
220 william 227 ShowMemorySearch();
221 william 313 SetupMemorySearchWindowHandler();
222 william 318 ShowPEViewer();
223     SetupPEViewerWindowHandler();
224 william 144 }
225     public void ShowLogWindow()
226 william 218 {
227     if (m_LogWindow == null || m_LogWindow.IsDisposed) { m_LogWindow = new FloatingLogWindow(); }
228 william 263 LoggerInstance = m_LogWindow.Logwriter;
229 william 264 LoggerInstance.CreateNewLog(false);
230 william 313 m_LogWindow.Show(dockPanel, DockState.DockBottom);
231 william 144 }
232 william 147 public void ShowAboutBox()
233     {
234 william 218 if (m_AboutBox == null || m_AboutBox.IsDisposed) { m_AboutBox = new FloatingAboutBox(); }
235 william 148 m_AboutBox.ShowDialog();
236 william 147 }
237 william 148 public void ShowRamDump()
238     {
239 william 218 load_plugins();
240 william 153 m_RamDump = new FloatingRamDumperDialog(ConfigPlugin);
241 william 201 m_RamDump.AcceptedProcess = SelectedProcess;
242 william 313 m_RamDump.Show(dockPanel);
243     }
244 william 196 public void ShowMemoryView()
245     {
246 william 218 load_plugins();
247 william 196 m_memoryview = new FloatingMemoryView(ConfigPlugin);
248 william 201 m_memoryview.AcceptedProcess = SelectedProcess;
249 william 196 m_memoryview.Show(dockPanel);
250     }
251 william 148 public void ShowPidSelector()
252     {
253 william 218 load_plugins();
254 william 148 //List<Process> procs = ConfigPlugin.ValidProcessesForPlugin;
255     m_PIDSelector = new PIDSelector(ConfigPlugin);
256 william 196 m_PIDSelector.OnSelectedProcessChanged += new BaseEventHandler<ProcessChangedEventArgs>(OnProcessChanged);
257 william 148 m_PIDSelector.Show(dockPanel);
258     }
259 william 218 public void ShowDataTypeConverter()
260     {
261     if (m_typeconverter == null || m_typeconverter.IsDisposed) { m_typeconverter = new FloatingDataTypeConverter(); }
262 william 313 m_typeconverter.Show(dockPanel, DockState.DockRightAutoHide);
263 william 218 }
264 william 227 public void ShowMemorySearch()
265     {
266     load_plugins();
267     m_memsearcher = new FloatingMemorySearcher(ConfigPlugin);
268     m_memsearcher.AcceptedProcess = SelectedProcess;
269 william 275 m_memsearcher.OnBrowseMemoryRegion += new BaseEventHandler<BrowseMemoryRegionEvent>(OnBrowseMemoryRegion);
270 william 227 m_memsearcher.Show(dockPanel);
271     }
272 william 318 public void ShowPEViewer()
273     {
274     load_plugins();
275     m_peviewer = new FloatingPEViewer(ConfigPlugin);
276     m_peviewer.AcceptedProcess = SelectedProcess;
277 william 323 m_peviewer.OnPEDataUpdated +=new BaseEventHandler<PEViewerDataUpdatedEvent>(OnPEDataUpdated);
278 william 318 m_peviewer.Show(dockPanel);
279     }
280 william 313
281 william 144 #endregion
282    
283    
284 william 117 public Main() : this(false) { }
285     public Main(bool no_console_redirect)
286 william 5 {
287     InitializeComponent();
288 william 158 #if SHOW_DEBUG_MENU
289     mnuDebug.Visible = true;
290     #else
291     mnuDebug.Visible = false;
292     #endif
293 william 83 load_loggerflags();
294 william 144 SetupDocks();
295     LoggerInstance = m_LogWindow.Logwriter;
296 william 23 LoggerInstance.CreateNewLog(false);
297 william 112 logger.ForceLog.Info.WriteLine("LoggingFlags = 0x{0:x4} ({1})", logger.GetLoggingFlags().Value, logger.GetLoggingFlags().Name);
298 william 87 load_plugins();
299 william 117 if (no_console_redirect)
300     LoggerInstance.RedirectConsoleOutput = false;
301 william 158
302    
303 william 144
304 william 5 }
305 william 83 private void load_loggerflags()
306     {
307 william 111 logger.SetLoggingFlags(Logging.Properties.Settings.Default.LoggingFlags);
308 william 99 #if FORCE_ALL_LOGGING_FLAGS
309     logger.SetLoggingFlags(loggerflags.ALL);
310     #endif
311 william 83 }
312 william 87 private void load_plugins()
313     {
314     loader = new PluginLoader();
315     loader.LoadPlugins();
316 william 83
317 william 87 ConfigPlugin = loader.GetConfigPlugin(RomCheater.Properties.Settings.Default.LastConfigPlugin);
318     if (ConfigPlugin != null)
319     logger.Info.WriteLine("Loaded Config Plugin: {0}", ConfigPlugin.ToString());
320     InputPlugin = loader.GetInputPlugin(RomCheater.Properties.Settings.Default.LastInputPlugin);
321     if (InputPlugin != null)
322     logger.Info.WriteLine("Loaded Input Plugin: {0}", InputPlugin.ToString());
323     WindowPlugin = loader.GetWindowPlugin(RomCheater.Properties.Settings.Default.LastWindowPlugin);
324     if (WindowPlugin != null)
325     logger.Info.WriteLine("Loaded Window Plugin: {0}", WindowPlugin.ToString());
326    
327 william 153 m_PIDSelector.AcceptedPlugin = ConfigPlugin;
328     m_RamDump.AcceptedPlugin = ConfigPlugin;
329 william 267 m_memoryview.AcceptedPlugin = ConfigPlugin;
330     m_memsearcher.AcceptedPlugin = ConfigPlugin;
331 william 335 m_PIDSelector.AcceptedPlugin = ConfigPlugin;
332 william 153 if (this.SelectedProcess != null)
333 william 267 {
334 william 153 m_RamDump.AcceptedProcess = SelectedProcess;
335 william 267 m_memoryview.AcceptedProcess = SelectedProcess;
336     m_memsearcher.AcceptedProcess = SelectedProcess;
337     }
338 william 152
339 william 87 }
340    
341 william 14 private void mnuItemExit_Click(object sender, EventArgs e)
342     {
343     this.Close();
344     }
345 william 16
346 william 17
347     private void Main_Load(object sender, EventArgs e)
348 william 144 {
349 william 152
350 william 17 }
351 william 63
352     private void mnuItemConfig_Click(object sender, EventArgs e)
353     {
354 william 86 RomCheaterConfigDialog dlg = new RomCheaterConfigDialog(loader);
355 william 63 dlg.ShowDialog();
356 william 270 logger.ForceLog.Info.WriteLine("LoggingFlags = 0x{0:x4} ({1})", logger.GetLoggingFlags().Value, logger.GetLoggingFlags().Name);
357 william 92 // reload plugins
358     load_plugins();
359 william 270
360 william 63 }
361 william 69
362     private void mnuItemOpenProcess_Click(object sender, EventArgs e)
363     {
364 william 148 ////List<Process> procs = ConfigPlugin.ValidProcessesForPlugin;
365     //PIDSelector selector = new PIDSelector(ConfigPlugin);
366     //selector.ShowDialog();
367 william 69 }
368 william 104
369 william 144 private void Main_Shown(object sender, EventArgs e)
370 william 104 {
371 william 152 //dockPanel.SuspendLayout(true);
372     //ShowDocks();
373     string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "DockPanel.config");
374     if (File.Exists(configFile))
375     {
376     try
377     {
378     dockPanel.LoadFromXml(configFile, m_deserializeDockContent);
379 william 313 SetupDockWindowHandler();
380 william 152 }
381 william 177 catch (Exception)
382 william 152 {
383     this.Controls.Remove(dockPanel);
384     dockPanel = new DockPanel();
385     dockPanel.Dock = DockStyle.Fill;
386     dockPanel.DocumentStyle = DocumentStyle.DockingWindow;
387     this.Controls.Add(dockPanel);
388     ShowDocks();
389     }
390     }
391     else
392     {
393     ShowDocks();
394     }
395    
396     //dockPanel.ResumeLayout(true, true);
397 william 104 }
398 william 144
399     private void mnuItemShowLogWindow_Click(object sender, EventArgs e)
400     {
401     ShowLogWindow();
402     }
403 william 147
404     private void mnuItemHelpAbout_Click(object sender, EventArgs e)
405     {
406     ShowAboutBox();
407     }
408 william 148
409     private void mnuItemShowRamDumpDialog_Click(object sender, EventArgs e)
410     {
411     ShowRamDump();
412     }
413    
414     private void mnuItemShowPIDSelector_Click(object sender, EventArgs e)
415     {
416     ShowPidSelector();
417     }
418 william 201 private void mnuItemShowMemoryView_Click(object sender, EventArgs e)
419     {
420     ShowMemoryView();
421     }
422 william 152 private void Main_FormClosing(object sender, FormClosingEventArgs e)
423     {
424     string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "DockPanel.config");
425     if (m_bSaveLayout)
426     dockPanel.SaveAsXml(configFile);
427     else if (File.Exists(configFile))
428     File.Delete(configFile);
429     }
430 william 158
431     private void mnuTestExeParse_Click(object sender, EventArgs e)
432     {
433 william 159 PEReader reader = new PEReader(@"C:\Windows\System32\notepad.exe");
434 william 158 }
435 william 201
436     private void mnuItemFindMaxNonNegativeHexValue_Click(object sender, EventArgs e)
437     {
438    
439     //uint start = 0xf0000000;
440     uint end = uint.MaxValue;
441     //for (uint i = start; i < end; i++)
442     //{
443     ulong value = Convert.ToUInt64(end.ToString(), 16);
444     //}
445     }
446 william 218
447     private void mnuItemShowDataTypeConverter_Click(object sender, EventArgs e)
448     {
449     ShowDataTypeConverter();
450     }
451 william 227
452     private void mnuItemShowMemorySearch_Click(object sender, EventArgs e)
453     {
454     ShowMemorySearch();
455     }
456 william 260
457     private void mnuItemDateShift_Click(object sender, EventArgs e)
458     {
459     DateTime t = DateTime.Now;
460     int year = Convert.ToInt32(t.ToString("yy"));
461     int y = year << 9;
462     int m = t.Month << 5;
463     int d = t.Day;
464    
465     ushort v1 = (ushort)(y | m | d);
466    
467     t = t.AddDays(1);
468     year = Convert.ToInt32(t.ToString("yy"));
469     y = year << 9;
470     m = t.Month << 5;
471     d = t.Day;
472     ushort v2 = (ushort)(y | m | d);
473    
474     t = t.AddDays(1);
475     year = Convert.ToInt32(t.ToString("yy"));
476     y = year << 9;
477     m = t.Month << 5;
478     d = t.Day;
479     ushort v3 = (ushort)(y | m | d);
480    
481     t = new DateTime(9999,12,31);
482     year = Convert.ToInt32(t.ToString("yy"));
483     y = year << 9;
484     m = t.Month << 5;
485     d = t.Day;
486     ushort v4 = (ushort)(y | m | d);
487     }
488 william 318
489     private void mnuItemShowPEViewer_Click(object sender, EventArgs e)
490     {
491     ShowPEViewer();
492     }
493    
494 william 201
495 william 5 }
496     }

  ViewVC Help
Powered by ViewVC 1.1.22