//钩子回调 private unsafe int Hook(int nCode, int wParam, int lParam) { try { IntPtr p = new IntPtr(lParam); CWPSTRUCT m = (CWPSTRUCT)Marshal.PtrToStructure(p, typeof(CWPSTRUCT)); if (m.message == 74) { COPYDATASTRUCT entries = (COPYDATASTRUCT)Marshal.PtrToStructure((IntPtr)m.lparam, typeof(COPYDATASTRUCT)); IPC_Buffer entries1 = (IPC_Buffer)Marshal.PtrToStructure((IntPtr)entries.lpData, typeof(IPC_Buffer)); IntPtr intp = new IntPtr(entries1.cbBuffer); string str = new string((sbyte *)intp); SetUI(str); Debug.Log("json数据:" + str); } if (CallNextProc) { return(CallNextHookEx(idHook, nCode, wParam, lParam)); } else { //return 1; return(CallNextHookEx(idHook, nCode, wParam, lParam)); } } catch (Exception ex) { Debug.Log(ex.Message); return(0); } }
protected int WndHook(int ncode, IntPtr wParam, IntPtr lParam) { HookInfo hInfo = GetInfoByThread(); int res; CWPSTRUCT hookStr = (CWPSTRUCT)Marshal.PtrToStructure(lParam, typeof(CWPSTRUCT)); Control ctrl = null; try { if (!hInfo.inHook && lParam != IntPtr.Zero) { try { ctrl = Control.FromHandle(hookStr.hwnd); hInfo.inHook = true; res = InternalPreFilterMessage(hInfo, hookStr.message, ctrl, hookStr.hwnd, hookStr.wParam, hookStr.lParam) ? 1 : 0; } finally { hInfo.inHook = false; } } else { return(CallNextHookEx(hInfo.wndHookHandle, ncode, wParam, lParam)); } res = CallNextHookEx(hInfo.wndHookHandle, ncode, wParam, lParam); } finally { InternalPostFilterMessage(hInfo, hookStr.message, ctrl, hookStr.hwnd, hookStr.wParam, hookStr.lParam); } return(res); }
/// <summary> /// Handle messages for context menu /// </summary> private void WindowsHookInvoked(object sender, HookEventArgs e) { CWPSTRUCT cwp = (CWPSTRUCT)Marshal.PtrToStructure(e.lParam, typeof(CWPSTRUCT)); if (_oContextMenu2 != null && (cwp.message == (int)WM.INITMENUPOPUP || cwp.message == (int)WM.MEASUREITEM || cwp.message == (int)WM.DRAWITEM)) { if (_oContextMenu2.HandleMenuMsg((uint)cwp.message, cwp.wparam, cwp.lparam) == S_OK) { return; } } if (_oContextMenu3 != null && cwp.message == (int)WM.MENUCHAR) { if (_oContextMenu3.HandleMenuMsg2((uint)cwp.message, cwp.wparam, cwp.lparam, IntPtr.Zero) == S_OK) { return; } } return; }
//钩子回调 private unsafe int Hook(int nCode, int wParam, int lParam) { try { IntPtr p = new IntPtr(lParam); CWPSTRUCT m = (CWPSTRUCT)Marshal.PtrToStructure(p, typeof(CWPSTRUCT)); if (m.message == 74) { COPYDATASTRUCT entries = (COPYDATASTRUCT)Marshal.PtrToStructure((IntPtr)m.lparam, typeof(COPYDATASTRUCT)); IPC_Buffer entries1 = (IPC_Buffer)Marshal.PtrToStructure((IntPtr)entries.lpData, typeof(IPC_Buffer)); IntPtr intp = new IntPtr(entries1.cbBuffer); string str = new string((sbyte *)intp); OnReceived(str); } return(DataUtility.CallNextHookEx(idHook, nCode, wParam, lParam)); } catch (Exception ex) { if (OnError != null) { OnError(ex.Message); } return(0); } }
private IntPtr HookProcImpl(int code, IntPtr wParam, IntPtr lParam) { try { if (code >= 0) { CWPSTRUCT w = (CWPSTRUCT)Marshal.PtrToStructure(lParam, typeof(CWPSTRUCT)); if (w.msg == 1) { StringBuilder stringBuilder = new StringBuilder(128); int num = GetClassName(w.hwnd, stringBuilder, stringBuilder.Capacity); if (num != 0 && stringBuilder.ToString() == DIALOG_BOX) { int capacity = GetWindowTextLength(new HandleRef(this, w.hwnd)) * 2; StringBuilder stringBuilder2 = new StringBuilder(capacity); GetWindowText(new HandleRef(this, w.hwnd), stringBuilder2, stringBuilder2.Capacity); string caption = stringBuilder2.ToString(); if (caption == "File Modification Detected" || caption == "Обнаружено изменение в файле") { ShowWindow(w.hwnd, SHOW); keybd_event(TAB, 0, 0, 0); keybd_event(RETURN, 0, 0, 0); } } } } } catch (Exception e) { Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Exception: {0}", e.Message), "FMDKiller"); } GC.KeepAlive(this); return(CallNextHookEx(IntPtr.Zero, code, wParam, lParam)); }
internal CallWndProcHookEventArgs(IntPtr wparam, IntPtr lparam) { sentFromCurrentProcess = wparam != IntPtr.Zero; CWPSTRUCT cwp = (CWPSTRUCT)Marshal.PtrToStructure(lparam, typeof(CWPSTRUCT)); message = Message.Create(cwp.hwnd, cwp.message, cwp.wparam, cwp.lparam); }
private void NotifyCallWndProcEvent(IntPtr wParam, IntPtr lParam) { CWPSTRUCT cwp = (CWPSTRUCT)Marshal.PtrToStructure(lParam, typeof(CWPSTRUCT)); Message msg = Message.Create(cwp.hWnd, cwp.msg, cwp.wParam, cwp.lParam); foreach (IMessageListener listener in this.listeners) { if ((listener.DesiredHook & InstalledHook.CallWndProc) == InstalledHook.CallWndProc) { listener.PreviewWndProc(msg); } } }
public static int WindowMsgHook(int nCode, int wParam, IntPtr lParam) { if (nCode >= 0) { //CWPSTRUCT cwps = (CWPSTRUCT)Marshal.PtrToStructure(lParam, typeof(CWPSTRUCT)); CWPSTRUCT cwps = *(CWPSTRUCT *)lParam; switch (cwps.message) { case WM_MOVE: int lp = cwps.lparam.ToInt32(); myWindowX = lp & 0xFFFF; myWindowY = (int)(lp & 0xFFFF0000) >> 16; break; } } return(CallNextHookEx(myMsgHookHandle, nCode, wParam, lParam)); }
private int hookproc(int code, IntPtr wparam, ref CWPSTRUCT cwp) { if (code == 0) { switch (cwp.message) { case (int)MessageEnum.Register: { var value = (IntPtr)cwp.wparam; if (!this.SendList.Contains(value)) { this.SendList.Add(value); } break; } } } return(CallNextHookEx(hookHandle, code, wparam, ref cwp)); }
protected int CoreHookProc(int code, IntPtr wParam, IntPtr lParam) { if (code < 0) { return(CallNextHookEx(IntPtr.Zero, code, wParam, lParam));// } //Debug.Log( // "hook code =" + code.ToString() + // " lparam=" + lParam.ToString() + // " wparam=" + wParam.ToString()); CWPSTRUCT d = (CWPSTRUCT)Marshal.PtrToStructure(lParam, typeof(CWPSTRUCT)); if (d.Msg == WM_DEVICECHANGE) { switch (d.WParam.ToInt32()) // Check the W parameter to see if a device was inserted or removed { case DEVICE_ARRIVAL: // inserted //SendMessage("Msg_Device_Arrival", SendMessageOptions.DontRequireReceiver); if (Evt_DeviceArrived != null) { Evt_DeviceArrived(); } //++mMsgArrivedNum; break; case DEVICE_REMOVECOMPLETE: // removed //Debug.Log("DEVICE_REMOVECOMPLETE"); if (Evt_DeviceRemoved != null) { Evt_DeviceRemoved(); } break; } } //// Yield to the next hook in the chain return(CallNextHookEx(IntPtr.Zero, code, wParam, lParam)); }
private int HookCallBack(int nCode, int wParam, ref CWPSTRUCT lParam) { if(lParam.message == NativeFunctions.WM_SYSKEYDOWN) { //m_DotNetBar.OnSysKeyDown(lParam.hwnd,lParam.wParam,lParam.lParam); } else if(lParam.message == NativeFunctions.WM_SYSKEYUP) { //m_DotNetBar.OnSysKeyUp(lParam.hwnd,lParam.wParam,lParam.lParam); } else if(lParam.message == NativeFunctions.WM_KEYDOWN) { //m_DotNetBar.OnKeyDown(lParam.hwnd,lParam.wParam,lParam.lParam); } else if(lParam.message == NativeFunctions.WM_LBUTTONDOWN || lParam.message==NativeFunctions.WM_NCLBUTTONDOWN || lParam.message==NativeFunctions.WM_RBUTTONDOWN || lParam.message==NativeFunctions.WM_MBUTTONDOWN || lParam.message==NativeFunctions.WM_NCMBUTTONDOWN || lParam.message==NativeFunctions.WM_NCRBUTTONDOWN) { //m_DotNetBar.OnMouseDown(lParam.hwnd,lParam.wParam,lParam.lParam); } return CallNextHookEx(m_HookHandle,nCode,wParam,ref lParam); }
private unsafe IntPtr GetHookProc(int code, IntPtr wparam, ref CWPSTRUCT cwp) { if (CurrentProcess == 0) { CurrentProcess = GetCurrentProcess(); int hdwd = findwin(_windowName); IntPtr PID = (IntPtr)pid(hdwd); PID = (IntPtr)OpenProcess(PROCESS_ALL_ACCESS, false, (int)PID); hdwd = (int)PID; // if (hdwd == CurrentProcess || PID ==(IntPtr) CurrentProcess) //{ MEMORY_BASIC_INFORMATION mbi = new MEMORY_BASIC_INFORMATION(); IntPtr dwOldProtect = IntPtr.Zero; pfnMsgBox = GetProcAddress(LoadLibrary("ws2_32.dll"), "send"); VirtualQuery(pfnMsgBox, out mbi, 255); VirtualProtect(pfnMsgBox, 8, PAGE_READWRITE, dwOldProtect); ReadProcessMemory(PID, pfnMsgBox, add_old, sizeof(uint) * 2, IntPtr.Zero); GetSend mb = new GetSend(MySend); IntPtr new_add = Marshal.GetFunctionPointerForDelegate(mb); byte[] b = BitConverter.GetBytes((int)new_add); addr_new[1] = b[0]; addr_new[2] = b[1]; addr_new[3] = b[2]; addr_new[4] = b[3]; WriteProcessMemory(PID, pfnMsgBox, addr_new, sizeof(uint) * 2, IntPtr.Zero); // VirtualProtect(pfnMsgBox, 8, mbi.Protect, IntPtr.Zero); VirtualProtect(pfnMsgBox, 8, PAGE_READWRITE, dwOldProtect); } //当调用这个函数的时候就跳到我的函数上面了 // } return(CallNextHookEx(_nextHookPtr, code, wparam, cwp)); // return (IntPtr)0; }
private IntPtr CwpHookCallBack(int nCode, IntPtr wParam, ref CWPSTRUCT lParam) { if (nCode < 0) { return(User32.CallNextHookEx(m_gmHookHandle, nCode, wParam, ref lParam)); } if (true) //(wParam.ToInt32() == PM_NOREMOVE) { if (lParam.hwnd == this.m_windowHandle) { WindowListenerEventArgs eventArgs = new WindowListenerEventArgs(); eventArgs.handled = false; eventArgs.message = (int)lParam.message; eventArgs.lparam = lParam.lParam; eventArgs.wparam = lParam.wParam; Msgs wmMessage = (Msgs)lParam.message; switch (wmMessage) { case Msgs.WM_KILLFOCUS: if (LostFocus != null) { LostFocus(this, eventArgs); } break; case Msgs.WM_SETFOCUS: if (GetFocus != null) { GetFocus(this, eventArgs); } break; case Msgs.WM_WINDOWPOSCHANGING: if (PositionChanging != null) { PositionChanging(this, eventArgs); } break; case Msgs.WM_PAINT: if (this.Paint != null) { Paint(this, eventArgs); } break; default: if (OtherMessage != null) { OtherMessage(this, eventArgs); } break; } if (eventArgs.handled) { lParam.message = (uint)Msgs.WM_NULL; lParam.lParam = 0; lParam.wParam = 0; return((IntPtr)1); } } } return(User32.CallNextHookEx(m_cwpHookHandle, nCode, wParam, ref lParam)); }
public static extern int CallNextHookEx(IntPtr hookHandle, int code, IntPtr wparam, ref CWPSTRUCT cwp);
private static extern int CallNextHookEx(int CurrentHookHandle, int nCode, int wParam, ref CWPSTRUCT lParam);
public static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, ref CWPSTRUCT lParam);
static extern IntPtr CallNextHookEx(IntPtr hhook, int code, IntPtr wparam, CWPSTRUCT cwp);