public bool PreFilterMessage(ref Message m) { switch (m.Msg) { case WM.MOUSEMOVE: if (MouseMoved != null) { MouseMoved(CursorPosition.GetCursorPosition()); } break; case WM.XBUTTONDOWN: if (XButtonDown != null) { var button = WindowMacro.HighWord(m.WParam.ToInt32()); if (button == 0x0001) { XButtonDown(MouseButtons.XButton1); } if (button == 0x0002) { XButtonDown(MouseButtons.XButton2); } } break; } // always allow message to continue to the next filter control return(false); }
public MainWindow() { InitializeComponent(); KeyWord.InitKeywords(); this.assemblies = new List <Assembly>(); this.CloseBtn.Click += (s, e) => this.Close(); this.MinimizeBtn.Click += (s, e) => this.WindowState = WindowState.Minimized; this.MaximizeBtn.Click += (s, e) => this.WindowState = this.WindowState == WindowState.Normal ? WindowState.Maximized : WindowState.Normal; this.CodeBox.KeyDown += (s, e) => { if (e.Key == Key.F && (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control) { if (this.searchForm == null || this.searchForm.IsDisposed) { this.searchForm = new SearchForm(this); this.searchForm.Show(); } else { this.searchForm.BringToFront(); } } }; this.AssemblyTree.SelectedItemChanged += (s, e) => Reflect(); #region TEST /*if (selName == t.Name) * { * this.selectedAssembly = a; * if (t.IsClass) * { * this.CodeBoxAppendText((t.IsPublic ? "public " : t.IsNestedAssembly ? "internal " : t.IsNestedFamily ? "protected " : "") + (t.IsSealed ? "static " : "") + " class " + t.Name + "\n{"); * * this.CodeBoxAppendText("\n"); * * foreach (FieldInfo fi in t.GetFields()) * { * string val = ""; * try * { * val = fi.GetRawConstantValue() != null ? " = " + fi.GetRawConstantValue().ToString() : ""; * } * catch { } * this.CodeBoxAppendText("\t" + (fi.IsPublic ? "public " : fi.IsPrivate ? "private " : fi.IsFamily ? "protected " : fi.IsAssembly ? "internal " : "") + (fi.IsStatic ? "static " : "") + fi.FieldType.Name + " " + fi.Name + val + ";\n"); * } * * this.CodeBoxAppendText("\n"); * * foreach (MethodInfo mi in t.GetMethods()) * { * string parameters = ""; * List<Type> ptypes = new List<Type>(); * foreach (var p in mi.GetParameters()) * { * parameters += $"{p.ParameterType.Name} {p.Name}, "; * ptypes.Add(p.ParameterType); * } * * if (parameters.Length > 0) * parameters = parameters.Substring(0, parameters.Length - 2); * * this.CodeBoxAppendText("\t" + (mi.IsPublic ? "public" : mi.IsFamily ? "protected" : mi.IsAssembly ? "internal" : mi.IsPrivate ? "private" : "???") + " " + (mi.IsStatic ? "static " : "") + (mi.IsAbstract ? "abstract " : "") + (mi.IsVirtual ? "virtual " : "") + (mi.IsFinal ? "readonly " : "") + mi.ReturnType.Name + " " + mi.Name + "(" + parameters + ")\n" + "\t{\n"); * * if (mi.GetMethodBody() != null) * { * List<Instruction> actionList = new List<Instruction>(); * byte[] IL = mi.GetMethodBody().GetILAsByteArray(); * //foreach (var ins in Disassembler.GetInstructions(mi)) * /*if (ins.OpCode.Name == "ret") * this.CodeBoxAppendText($"\t\treturn;\n"); * else if (ins.OpCode.Name == "nop") * { * if (actionList.Count == 0) * continue; * List<string> p = new List<string>(); * string csharped = ""; * foreach (Instruction instruction in actionList) * if (instruction.OpCode.Name == "ldsfld") * { * string op = instruction.Operand.ToString(); * try * { * csharped = op.Substring(op.IndexOf("[") + 1, op.IndexOf("]") - op.IndexOf("[") - 1) + "." + op.Split(' ')[op.Split(' ').Length - 1]; * } * catch { } * } * else if (instruction.OpCode.Name == "ldstr") * p.Add("\"" + instruction.Operand.ToString() + "\""); * else if (instruction.OpCode.Name == "call") * p.Add(instruction.Operand.ToString().Split(' ')[0] + "." + instruction.Operand.ToString().Split(' ')[1]); * else if (instruction.OpCode.Name == "newobj") * continue; * else if (instruction.OpCode.Name == "callvirt") * { * string pp = ""; * string op = instruction.Operand.ToString(); * foreach (string p_ in p) * pp += $"{p_}, "; * if (pp.Length != 0) * pp = pp.Substring(0, pp.Length - 2); * string tt = op.Substring(op.IndexOf("(") + 1, op.IndexOf(")") - op.IndexOf("(")); * csharped += "." + op.Split(' ')[1].Replace(tt, $"new {tt.Substring(0, tt.Length - 1)}({pp}))"); * } * * this.CodeBoxAppendText($"\t\t{csharped};\n"); * actionList.Clear(); * } * else if (ins.OpCode.Name == "ldsfld" || ins.OpCode.Name == "ldstr" || ins.OpCode.Name == "call" || ins.OpCode.Name == "newobj" || ins.OpCode.Name == "callvirt") * actionList.Add(ins); * } * this.CodeBoxAppendText("\t}\n\n"); * } * try * { * this.CodeBoxSetText(this.CodeBoxGetText().Substring(0, this.CodeBoxGetText().Length - 3)); * } * catch { } * this.CodeBoxAppendText("}"); * } * } * /*TextRange range = new TextRange(this.CodeBox.Document.ContentStart, this.CodeBox.Document.ContentEnd); * foreach (KeyWord k in KeyWord.KeyWords) * { * Regex rx = new Regex(k.Name); * foreach (Match index in rx.Matches(this.CodeBox.GetText())) * { * int x = index.Index; * try * { * TextRange innerRange = new TextRange(range.Start.GetPositionAtOffset(x), range.Start.GetPositionAtOffset(x + k.Name.Length)); * innerRange.ApplyPropertyValue(TextElement.ForegroundProperty, new SolidColorBrush(k.Color)); * } * catch (Exception ex) { } * } * }*/ #endregion TEST this.MSILCB.Click += (s, e) => { if (!(bool)this.MSILCB.IsChecked) { this.CodeBox.Width = this.MainPanel.Width / 10 * 7; this.MSILGrid.Width = this.MainPanel.Width / 10 * 3; } else { this.CodeBox.Width = this.MainPanel.Width; this.MSILGrid.Width = 0; } Reflect(); }; this.OpenAssemblyButton.Background = new ImageBrush() { ImageSource = BitmapFrame.Create(Application.GetResourceStream(new Uri("Images/OpenAssembly.png", UriKind.Relative)).Stream) }; this.SaveAssemblyButton.Background = new ImageBrush() { ImageSource = BitmapFrame.Create(Application.GetResourceStream(new Uri("Images/SaveIcon.png", UriKind.Relative)).Stream) }; this.OpenAssemblyButton.Click += (s, e) => { System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog() { Filter = "Assembly Files|*.exe;*.dll|EXE Files|*.exe|DLL Files|*.dll" }; if (ofd.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } this.AddAssembly(Assembly.LoadFile(ofd.FileName)); }; this.SaveAssemblyButton.Click += (s, e) => { }; var interopHelper = new WindowInteropHelper(Application.Current.MainWindow); var activeScreen = System.Windows.Forms.Screen.FromHandle(interopHelper.Handle); this.currentScreen = activeScreen.Bounds; this.TitleBar.MouseDown += (s, e) => { if (e.LeftButton != MouseButtonState.Pressed) { return; } if (this.Width == this.currentScreen.Width && this.Height == this.currentScreen.Height && !this.MaximizeBtn.IsPressed) { this.Width = 800; this.Height = 450; this.Left = CursorPosition.GetCursorPosition().X - 10; this.Top = 0; } DragMove(); if (e.ClickCount >= 2) { this.WindowState = this.WindowState == WindowState.Normal ? WindowState.Maximized : WindowState.Normal; } }; this.LocationChanged += (s, e) => { if (this.Top == 0) { this.WindowState = WindowState.Normal; } this.Resize(); }; this.SizeChanged += (s, e) => { this.Resize(); }; this.StateChanged += (s, e) => { this.Resize(); }; }