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

Contents of /trunk/RomCheater/Main.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 276 - (show annotations) (download)
Sun Jun 3 22:04:37 2012 UTC (8 years, 3 months ago) by william
File size: 14622 byte(s)
+ rename members involved in BrowseMemoryRegion Contract

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 private IDockContent GetContentFromPersistString(string persistString)
82 {
83 if (persistString == typeof(FloatingLogWindow).ToString()) { return m_LogWindow; }
84 if (persistString == typeof(FloatingRamDumperDialog).ToString()) { return m_RamDump; }
85 if (persistString == typeof(PIDSelector).ToString()) { return m_PIDSelector; }
86 if (persistString == typeof(FloatingMemoryView).ToString()) { return m_memoryview; }
87 if (persistString == typeof(FloatingDataTypeConverter).ToString()) { return m_typeconverter; }
88 if (persistString == typeof(FloatingMemorySearcher).ToString()) { return m_memsearcher; }
89 else { return null; }
90 }
91 public void SetupDocks()
92 {
93 m_LogWindow = new FloatingLogWindow();
94 m_AboutBox = new FloatingAboutBox();
95 m_RamDump = new FloatingRamDumperDialog();
96 m_PIDSelector = new PIDSelector();
97 m_PIDSelector.OnSelectedProcessChanged += new BaseEventHandler<ProcessChangedEventArgs>(OnProcessChanged);
98 m_memoryview = new FloatingMemoryView();
99 m_typeconverter = new FloatingDataTypeConverter();
100 m_memsearcher = new FloatingMemorySearcher();
101 m_memsearcher.OnBrowseMemoryRegion += new BaseEventHandler<BrowseMemoryRegionEvent>(OnBrowseMemoryRegion);
102 m_deserializeDockContent = new DeserializeDockContent(GetContentFromPersistString);
103 }
104 public void ShowDocks()
105 {
106 ShowLogWindow();
107 //ShowAboutBox();
108 ShowRamDump();
109 ShowMemoryView();
110 ShowPidSelector();
111 ShowDataTypeConverter();
112 ShowMemorySearch();
113 }
114 public void ShowLogWindow()
115 {
116 if (m_LogWindow == null || m_LogWindow.IsDisposed) { m_LogWindow = new FloatingLogWindow(); }
117 LoggerInstance = m_LogWindow.Logwriter;
118 LoggerInstance.CreateNewLog(false);
119 m_LogWindow.Show(dockPanel, DockState.DockBottom);
120
121 }
122 public void ShowAboutBox()
123 {
124 if (m_AboutBox == null || m_AboutBox.IsDisposed) { m_AboutBox = new FloatingAboutBox(); }
125 m_AboutBox.ShowDialog();
126 }
127 public void ShowRamDump()
128 {
129 load_plugins();
130 m_RamDump = new FloatingRamDumperDialog(ConfigPlugin);
131 m_RamDump.AcceptedProcess = SelectedProcess;
132 m_RamDump.Show(dockPanel);
133 }
134 public void ShowMemoryView()
135 {
136 load_plugins();
137 m_memoryview = new FloatingMemoryView(ConfigPlugin);
138 m_memoryview.AcceptedProcess = SelectedProcess;
139 m_memoryview.Show(dockPanel);
140 }
141 public void ShowPidSelector()
142 {
143 load_plugins();
144 //List<Process> procs = ConfigPlugin.ValidProcessesForPlugin;
145 m_PIDSelector = new PIDSelector(ConfigPlugin);
146 m_PIDSelector.OnSelectedProcessChanged += new BaseEventHandler<ProcessChangedEventArgs>(OnProcessChanged);
147 m_PIDSelector.Show(dockPanel);
148 }
149 public void ShowDataTypeConverter()
150 {
151 if (m_typeconverter == null || m_typeconverter.IsDisposed) { m_typeconverter = new FloatingDataTypeConverter(); }
152 m_typeconverter.Show(dockPanel, DockState.DockRightAutoHide);
153 }
154 public void ShowMemorySearch()
155 {
156 load_plugins();
157 m_memsearcher = new FloatingMemorySearcher(ConfigPlugin);
158 m_memsearcher.AcceptedProcess = SelectedProcess;
159 m_memsearcher.OnBrowseMemoryRegion += new BaseEventHandler<BrowseMemoryRegionEvent>(OnBrowseMemoryRegion);
160 m_memsearcher.Show(dockPanel);
161 }
162 #endregion
163
164
165 public Main() : this(false) { }
166 public Main(bool no_console_redirect)
167 {
168 InitializeComponent();
169 #if SHOW_DEBUG_MENU
170 mnuDebug.Visible = true;
171 #else
172 mnuDebug.Visible = false;
173 #endif
174 load_loggerflags();
175 SetupDocks();
176 LoggerInstance = m_LogWindow.Logwriter;
177 LoggerInstance.CreateNewLog(false);
178 logger.ForceLog.Info.WriteLine("LoggingFlags = 0x{0:x4} ({1})", logger.GetLoggingFlags().Value, logger.GetLoggingFlags().Name);
179 load_plugins();
180 if (no_console_redirect)
181 LoggerInstance.RedirectConsoleOutput = false;
182
183
184
185 }
186 private void load_loggerflags()
187 {
188 logger.SetLoggingFlags(Logging.Properties.Settings.Default.LoggingFlags);
189 #if FORCE_ALL_LOGGING_FLAGS
190 logger.SetLoggingFlags(loggerflags.ALL);
191 #endif
192 }
193 private void load_plugins()
194 {
195 loader = new PluginLoader();
196 loader.LoadPlugins();
197
198 ConfigPlugin = loader.GetConfigPlugin(RomCheater.Properties.Settings.Default.LastConfigPlugin);
199 if (ConfigPlugin != null)
200 logger.Info.WriteLine("Loaded Config Plugin: {0}", ConfigPlugin.ToString());
201 InputPlugin = loader.GetInputPlugin(RomCheater.Properties.Settings.Default.LastInputPlugin);
202 if (InputPlugin != null)
203 logger.Info.WriteLine("Loaded Input Plugin: {0}", InputPlugin.ToString());
204 WindowPlugin = loader.GetWindowPlugin(RomCheater.Properties.Settings.Default.LastWindowPlugin);
205 if (WindowPlugin != null)
206 logger.Info.WriteLine("Loaded Window Plugin: {0}", WindowPlugin.ToString());
207
208 m_PIDSelector.AcceptedPlugin = ConfigPlugin;
209 m_RamDump.AcceptedPlugin = ConfigPlugin;
210 m_memoryview.AcceptedPlugin = ConfigPlugin;
211 m_memsearcher.AcceptedPlugin = ConfigPlugin;
212
213 if (this.SelectedProcess != null)
214 {
215 m_RamDump.AcceptedProcess = SelectedProcess;
216 m_memoryview.AcceptedProcess = SelectedProcess;
217 m_memsearcher.AcceptedProcess = SelectedProcess;
218 }
219
220 }
221
222 private void mnuItemExit_Click(object sender, EventArgs e)
223 {
224 this.Close();
225 }
226
227
228 private void Main_Load(object sender, EventArgs e)
229 {
230
231 }
232
233 private void mnuItemConfig_Click(object sender, EventArgs e)
234 {
235 RomCheaterConfigDialog dlg = new RomCheaterConfigDialog(loader);
236 dlg.ShowDialog();
237 logger.ForceLog.Info.WriteLine("LoggingFlags = 0x{0:x4} ({1})", logger.GetLoggingFlags().Value, logger.GetLoggingFlags().Name);
238 // reload plugins
239 load_plugins();
240
241 }
242
243 private void mnuItemOpenProcess_Click(object sender, EventArgs e)
244 {
245 ////List<Process> procs = ConfigPlugin.ValidProcessesForPlugin;
246 //PIDSelector selector = new PIDSelector(ConfigPlugin);
247 //selector.ShowDialog();
248 }
249
250 private void Main_Shown(object sender, EventArgs e)
251 {
252 //dockPanel.SuspendLayout(true);
253 //ShowDocks();
254 string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "DockPanel.config");
255 if (File.Exists(configFile))
256 {
257 try
258 {
259 dockPanel.LoadFromXml(configFile, m_deserializeDockContent);
260 }
261 catch (Exception)
262 {
263 this.Controls.Remove(dockPanel);
264 dockPanel = new DockPanel();
265 dockPanel.Dock = DockStyle.Fill;
266 dockPanel.DocumentStyle = DocumentStyle.DockingWindow;
267 this.Controls.Add(dockPanel);
268 ShowDocks();
269 }
270 }
271 else
272 {
273 ShowDocks();
274 }
275
276 //dockPanel.ResumeLayout(true, true);
277 }
278
279 private void mnuItemShowLogWindow_Click(object sender, EventArgs e)
280 {
281 ShowLogWindow();
282 }
283
284 private void mnuItemHelpAbout_Click(object sender, EventArgs e)
285 {
286 ShowAboutBox();
287 }
288
289 private void mnuItemShowRamDumpDialog_Click(object sender, EventArgs e)
290 {
291 ShowRamDump();
292 }
293
294 private void mnuItemShowPIDSelector_Click(object sender, EventArgs e)
295 {
296 ShowPidSelector();
297 }
298 private void mnuItemShowMemoryView_Click(object sender, EventArgs e)
299 {
300 ShowMemoryView();
301 }
302 private void Main_FormClosing(object sender, FormClosingEventArgs e)
303 {
304 string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "DockPanel.config");
305 if (m_bSaveLayout)
306 dockPanel.SaveAsXml(configFile);
307 else if (File.Exists(configFile))
308 File.Delete(configFile);
309 }
310
311 private void mnuTestExeParse_Click(object sender, EventArgs e)
312 {
313 PEReader reader = new PEReader(@"C:\Windows\System32\notepad.exe");
314 }
315
316 private void mnuItemFindMaxNonNegativeHexValue_Click(object sender, EventArgs e)
317 {
318
319 //uint start = 0xf0000000;
320 uint end = uint.MaxValue;
321 //for (uint i = start; i < end; i++)
322 //{
323 ulong value = Convert.ToUInt64(end.ToString(), 16);
324 //}
325 }
326
327 private void mnuItemShowDataTypeConverter_Click(object sender, EventArgs e)
328 {
329 ShowDataTypeConverter();
330 }
331
332 private void mnuItemShowMemorySearch_Click(object sender, EventArgs e)
333 {
334 ShowMemorySearch();
335 }
336
337 private void mnuItemDateShift_Click(object sender, EventArgs e)
338 {
339 DateTime t = DateTime.Now;
340 int year = Convert.ToInt32(t.ToString("yy"));
341 int y = year << 9;
342 int m = t.Month << 5;
343 int d = t.Day;
344
345 ushort v1 = (ushort)(y | m | d);
346
347 t = t.AddDays(1);
348 year = Convert.ToInt32(t.ToString("yy"));
349 y = year << 9;
350 m = t.Month << 5;
351 d = t.Day;
352 ushort v2 = (ushort)(y | m | d);
353
354 t = t.AddDays(1);
355 year = Convert.ToInt32(t.ToString("yy"));
356 y = year << 9;
357 m = t.Month << 5;
358 d = t.Day;
359 ushort v3 = (ushort)(y | m | d);
360
361 t = new DateTime(9999,12,31);
362 year = Convert.ToInt32(t.ToString("yy"));
363 y = year << 9;
364 m = t.Month << 5;
365 d = t.Day;
366 ushort v4 = (ushort)(y | m | d);
367 }
368
369 }
370 }

  ViewVC Help
Powered by ViewVC 1.1.22