ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/RomCheater/trunk/RomCheater/Main.cs
Revision: 267
Committed: Sun Jun 3 19:52:12 2012 UTC (11 years, 6 months ago) by william
File size: 14079 byte(s)
Log Message:
load_plugins(): update config and process for memoryview and memorysearch

File Contents

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