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

Contents of /trunk/RomCheater/Main.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 227 - (show annotations) (download)
Sat Jun 2 15:48:25 2012 UTC (8 years, 4 months ago) by william
File size: 12626 byte(s)
+ add initial support for memory search

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

  ViewVC Help
Powered by ViewVC 1.1.22