|
楼主 |
发表于 2017-10-15 18:21:45
|
显示全部楼层
这两天一直在参照键盘钩子做AARDIO的WH_CALLWNDPROC钩子类,经过版主解释了解到键盘鼠标钩子是特殊钩子,可以在EXE中写,这里也给所有和我一样不知道的小白提醒一下吧!
这是最终的WN_CALLWNDPROC钩子的DLL
- #include<Windows.h>
- #include <string>
- #include"resource.h"
- using namespace std;
- HMODULE GModule;
- HHOOK hhk;
- HWND WND;
- //DWORD TID;
- HHOOK StartHook();
- BOOL EndHook();
- LRESULT CALLBACK HookProc(int nCode, WPARAM wParam, LPARAM lParam);
- BOOL CALLBACK DlgProc(HWND, UINT, WPARAM, LPARAM);
- BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
- {
- switch (ul_reason_for_call)
- {
- case DLL_PROCESS_ATTACH:
- {
- GModule = hModule;
- //这里可以随便找个非C#程序用SPY++获取到这两个参数!
- WND=FindWindow(L"#32770",L"stud_PE");
- hhk = StartHook();
- if (NULL == hhk)
- {
- MessageBox(NULL, L"Set Hook Failed!", L"ERROR", MB_OK);
- return FALSE;
- }
- else
- {
- MessageBox(NULL, L"Set Hook Successed!", L"OK", MB_OK);
- }
- break;
- }
- case DLL_PROCESS_DETACH:
- {
- if (FALSE == EndHook())
- {
- MessageBox(NULL, L"End Hook Successed!", L"CLOSE", MB_OK);
- return FALSE;
- }
- break;
- }
- case DLL_THREAD_ATTACH:
- case DLL_THREAD_DETACH:
- break;
- }
- return TRUE;
- }
- HHOOK StartHook()
- {
- return SetWindowsHookEx(4, HookProc,GModule,GetWindowThreadProcessId(WND,NULL));
- }
- BOOL EndHook()
- {
- return UnhookWindowsHookEx(hhk);
- }
- LRESULT CALLBACK HookProc(int nCode, WPARAM wParam, LPARAM lParam)
- {
- if (nCode >= 0)
- {
- CWPSTRUCT* cwps = (CWPSTRUCT*)lParam;
- if (WM_COMMAND == cwps->message)
- {
- INT wmId = LOWORD(cwps->wParam);
- if (wmId==1099)//这里可以随便找个非C#程序用SPY++获取到控件ID
- {
- //DialogBoxParam(g_hModule, (LPCTSTR)IDD_DIALOG, NULL, DlgProc, NULL);
- MessageBox(NULL,TEXT("HELLOW"),TEXT("HOOK"),MB_OK);
- nCode=-1;
- }
- }
- }
- return CallNextHookEx(hhk, nCode, wParam, lParam);
- }
- //just for exporting a function
- __declspec(dllexport) void EmptyFunc()
- {
- //Do nothing
- }
复制代码
这是主程序代码,感兴趣的可以试一试
import win.ui;
import process;
import process.apiHook;
/*DSG{{*/
mainForm = win.form(text="aardio form";right=405;bottom=177)
mainForm.add(
button={cls="button";text="安装钩子";left=53;top=23;right=353;bottom=154;z=1}
)
/*}}*/
mainForm.button.oncommand = function(id,event){
//mainForm.msgbox( mainForm.button.text );
mainForm.button.disabled=true;
proc=process("C:\Users\Administrator\Desktop\StudPE\Stud_PE.exe");
var HK = raw.remoteApi(proc.handle,"void()","C:\Users\Administrator\Desktop\StudPE\HOOKMSG.dll","?EmptyFunc@@YAXXZ");
sleep(1000);
HK();
}
mainForm.show();
return win.loopMessage(); |
|