-
-
[求助]关于MFC DLL使用hook注入其他进程,这段代码是在MFC DLL中的,用启动程序调用之后,目标进程会自动退出,是什么原因呢
-
发表于:
2021-7-1 00:04
4910
-
[求助]关于MFC DLL使用hook注入其他进程,这段代码是在MFC DLL中的,用启动程序调用之后,目标进程会自动退出,是什么原因呢
//线程回调
DWORD WINAPI MyFun(LPVOID lpParam)
{
pMainDLLWnd = new CMainDLLWnd;
pMainDLLWnd->DoModal(); //显示窗口
delete pMainDLLWnd;
return 0;
}
// CnotepadhookApp 初始化
BOOL CnotepadhookApp::InitInstance()
{
CWinApp::InitInstance();
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | / / 创建钩子
handled = FALSE;
notepadhandle = FindWindow(L "Notepad" , NULL);
if (notepadhandle = = NULL)
{
printf( "未查找到窗口.\n" );
return TRUE;
}
hooker = SetWindowsHookEx(WH_GETMESSAGE, HookProc, (HINSTANCE)AfxGetResourceHandle(), GetWindowThreadProcessId(notepadhandle, NULL));
if (hooker) {
printf( "Hook Successfully.\nHookID:%d\n" , hooker);
}
else {
printf( "Hook Failed.\nError:%d\n" , GetLastError());
return TRUE;
}
PostMessage(notepadhandle, WM_DESTROY, 0 , 0 );
return TRUE;
|
}
//钩子函数
extern "C" __declspec(dllexport) LRESULT CALLBACK HookProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode < 0)
return CallNextHookEx(hooker, nCode, wParam, lParam);
tagMSG msg;
msg = (tagMSG)lParam;
if (nCode == HC_ACTION && (msg->message == WM_DESTROY))
{
if (handled == FALSE)
{
handled = TRUE;
::CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)MyFun, NULL, NULL, NULL);
//MessageBoxW(NULL, L"This is a messagebox from notepad.exe", L"hook", MB_OK);
1 2 3 4 5 6 7 8 9 10 | }
UnhookWindowsHookEx(hooker);
if (msg - >message = = WM_DESTROY)
{
msg - >message = WM_NULL;
}
return CallNextHookEx(hooker, nCode, wParam, (LPARAM)msg);
}
return CallNextHookEx(hooker, nCode, wParam, lParam);
|
## # }
[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)