没有合适的资源?快使用搜索试试~ 我知道了~
开发应用层加密程序时常用到的钩子技术 可以以此作为编码参考
资源推荐
资源详情
资源评论
1 首先倒入所需要的windows函数,主要有三个,SetWindowsHookEX用来安装钩子,UnhookWindowsHookEX用来卸载钩子以及CallNextHookEX用来将hook信息传递到链表中下一个hook处理过程。
2 在安装全局钩子的时候,我们就要做替换了,将WH_MOUSE和WH_KEYBORAD分别换成WH_MOUSE_LL和WH_KEYBORAD_LL:
//SetWindowsHookEX 用于安装钩子
[DllImport(\"user32.dll\",CharSetCharSet=CharSet.Auto, CallingConventionCallingConvention=CallingConvention.StdCall,SetLastError=true)] private static extern int SetWindowsHookEx( intidHook, HookProclpfn, IntPtrhMod, intdwThreadId);
//UnHookWindowsHookEX 用于卸载钩子
[DllImport(\"user32.dll\",CharSetCharSet=CharSet.Auto, CallingConventionCallingConvention=CallingConvention.StdCall,SetLastError=true)] private static extern int UnhookWindowsHookEx(intidHook);
//CallNextHookEX 用于将hook信息传递到链表中下一个hook处理过程
[DllImport(\"user32.dll\",CharSetCharSet=CharSet.Auto, CallingConventionCallingConvention=CallingConvention.StdCall)] private static extern int CallNextHookEx( intidHook, intnCode, intwParam, IntPtrlParam);
//installhook 其中第一个参数WH_MOUSE_LL原来是WH_MOUSE
hMouseHook=SetWindowsHookEx(WH_MOUSE_LL,MouseHookProcedure,Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]),0);
//installhook 其中第一个参数WH_KEYBOARD_LL原来是WH_KEYBORAD
hKeyboardHook=SetWindowsHookEx(WH_KEYBOARD_LL,KeyboardHookProcedure,Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]), 0);
//下面是关于鼠标和键盘的两个Callback函数:
private int MouseHookProc(int nCode, int wParam, IntPtr lParam)
{ // if ok and someone listens to our events
if ((nCode >= 0) && (OnMouseActivity != null))
{
//Marshall the data from callback.
MouseLLHookStruct mouseHookStruct = (MouseLLHookStruct)Marshal. PtrToStructure(lParam, typeof(MouseLLHookStruct));
//detect button clicked
MouseButtons button = MouseButtons.None;
short mouseDelta = 0;
2 在安装全局钩子的时候,我们就要做替换了,将WH_MOUSE和WH_KEYBORAD分别换成WH_MOUSE_LL和WH_KEYBORAD_LL:
//SetWindowsHookEX 用于安装钩子
[DllImport(\"user32.dll\",CharSetCharSet=CharSet.Auto, CallingConventionCallingConvention=CallingConvention.StdCall,SetLastError=true)] private static extern int SetWindowsHookEx( intidHook, HookProclpfn, IntPtrhMod, intdwThreadId);
//UnHookWindowsHookEX 用于卸载钩子
[DllImport(\"user32.dll\",CharSetCharSet=CharSet.Auto, CallingConventionCallingConvention=CallingConvention.StdCall,SetLastError=true)] private static extern int UnhookWindowsHookEx(intidHook);
//CallNextHookEX 用于将hook信息传递到链表中下一个hook处理过程
[DllImport(\"user32.dll\",CharSetCharSet=CharSet.Auto, CallingConventionCallingConvention=CallingConvention.StdCall)] private static extern int CallNextHookEx( intidHook, intnCode, intwParam, IntPtrlParam);
//installhook 其中第一个参数WH_MOUSE_LL原来是WH_MOUSE
hMouseHook=SetWindowsHookEx(WH_MOUSE_LL,MouseHookProcedure,Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]),0);
//installhook 其中第一个参数WH_KEYBOARD_LL原来是WH_KEYBORAD
hKeyboardHook=SetWindowsHookEx(WH_KEYBOARD_LL,KeyboardHookProcedure,Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]), 0);
//下面是关于鼠标和键盘的两个Callback函数:
private int MouseHookProc(int nCode, int wParam, IntPtr lParam)
{ // if ok and someone listens to our events
if ((nCode >= 0) && (OnMouseActivity != null))
{
//Marshall the data from callback.
MouseLLHookStruct mouseHookStruct = (MouseLLHookStruct)Marshal. PtrToStructure(lParam, typeof(MouseLLHookStruct));
//detect button clicked
MouseButtons button = MouseButtons.None;
short mouseDelta = 0;
资源评论
mytopnumberone
- 粉丝: 0
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功