private void BroadcastMessage(SystemWin32.WindowMessage wmsg) { foreach (IntPtr sink in Sinks) { SystemWin32.PostMessage(sink, wmsg.msg, wmsg.wParam, wmsg.lParam); } }
static void Main(string[] args) { if (args.Length == 1 && args[0] == "-c") { SystemWin32.AllocConsole(); } RunGui(); }
private void MessageDispatcher(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam) { if (BroadcastKeys.Contains((Keys)wParam)) { foreach (IntPtr sink in Sinks) { SystemWin32.PostMessage(sink, msg, wParam, lParam); } } }
public void DetourWndProc() { WndProcPatchInstance = WndProcPatch; IntPtr hwnd = Process.GetCurrentProcess().MainWindowHandle; IntPtr originalWndProcAddress = (IntPtr)SystemWin32.GetWindowLong(hwnd, SystemWin32.GWL_WNDPROC); originalWndProc = Marshal.GetDelegateForFunctionPointer <SystemWin32.WndProc>(originalWndProcAddress); SystemWin32.SetWindowLong(hwnd, SystemWin32.GWL_WNDPROC, Marshal.GetFunctionPointerForDelegate(WndProcPatchInstance)); }
private void PatchVirtualProtect() { IntPtr vpAddress = SystemWin32.GetProcAddress(SystemWin32.GetModuleHandle("kernel32.dll"), "VirtualProtect"); originalVirtualProtect = Marshal.GetDelegateForFunctionPointer <SystemWin32.VirtualProtectDelegate>(vpAddress); virtualProtectPatch = LocalHook.Create( vpAddress, new SystemWin32.VirtualProtectDelegate(VirtualProtectPatchHandler), this); virtualProtectPatch.ThreadACL.SetExclusiveACL(new Int32[] { }); }
public void Dispose() { DestroyLuaEventFrameHandler(); if (originalWndProc != null) { /* restore original wnd proc if hooked */ SystemWin32.SetWindowLong( Process.GetCurrentProcess().MainWindowHandle, SystemWin32.GWL_WNDPROC, Marshal.GetFunctionPointerForDelegate(originalWndProc)); } }
public PageCheckHook(Memory memory, PageCheck pageCheckHandlerInstance, IntPtr targetAddress) { this.memory = memory; this.pageCheckHandlerInstance = pageCheckHandlerInstance; IntPtr hookAddress = Marshal.GetFunctionPointerForDelegate(pageCheckHandlerInstance); IntPtr endAddress = targetAddress + Offset.PageCheckReturnOffset; uint oldProtect = 0; SystemWin32.VirtualProtect(targetAddress, (UIntPtr)jmpShellcode.Length, SystemWin32.MemoryProtection.PAGE_EXECUTE_READWRITE, ref oldProtect); codeCaveAddress = Marshal.AllocHGlobal(PageCheckShellCode_Length); SystemWin32.VirtualProtect(codeCaveAddress, (UIntPtr)PageCheckShellCode_Length, SystemWin32.MemoryProtection.PAGE_EXECUTE_READWRITE, ref oldProtect); int hookJumpOffset = hookAddress.ToInt32() - codeCaveAddress.ToInt32() - PageCheckShellCode_CallHookOffset; int endJumpOffset = endAddress.ToInt32() - codeCaveAddress.ToInt32() - PageCheckShellCode_Length; byte[] pageCheckShellcodeAssembly = PageCheckShellCode(hookJumpOffset, endJumpOffset); memory.Write(codeCaveAddress, pageCheckShellcodeAssembly); int offsetCodeCave = codeCaveAddress.ToInt32() - targetAddress.ToInt32() - jmpShellcode.Length; byte[] offsetCodeCaveBytes = BitConverter.GetBytes(offsetCodeCave); jmpShellcode[0] = 0xE9; // JMP jmpShellcode[1] = offsetCodeCaveBytes[0]; jmpShellcode[2] = offsetCodeCaveBytes[1]; jmpShellcode[3] = offsetCodeCaveBytes[2]; jmpShellcode[4] = offsetCodeCaveBytes[3]; originalPageCheckBytes = memory.Read(targetAddress, jmpShellcode.Length); memory.Write(targetAddress, jmpShellcode); }
public void YieldWindowFocusHandler(IntPtr target) { SystemWin32.SwitchToThisWindow(target, true); }