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

Contents of /trunk/RomCheater/Main.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 314 - (show annotations) (download)
Tue Jun 5 15:17:41 2012 UTC (9 years, 1 month ago) by william
File size: 18247 byte(s)
+ add support to list the currently opened windows and allow them to be selected (even if hidden)

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

  ViewVC Help
Powered by ViewVC 1.1.22