inject DLL to realize the source code:
HInstance G_hinstdll = NULL; Hhook G_hhook = Null;dword g_dwthreadid = 0; #ifdef _managed#pragma MANAGED (push, off) #endifBOOL apientry DllMain (hmodule hmodule, DWORD Ul_reason_for_call, lpvoid lpreserved) {switch (ul_reason_for_ Call) {Case dll_process_attach:g_hinstdll = (hinstance) hmodule;case dll_thread_attach:case dll_thread_detach:case DLL _process_detach:break;} return TRUE;} #ifdef _managed#pragma MANAGED (pop) #endifINT_PTR WINAPI Dipdlg_proc (HWND hwnd, UINT umsg, WPARAM WPARAM, LPARAM LPARAM) {s Witch (umsg) {case Wm_close:{destroywindow (hWnd);} Break;case Wm_app:if (LParam) {ShowWindow (hWnd, sw_show);} break;} return (FALSE);} LRESULT CALLBACK prochookmsg (int nCode, WPARAM WP, LPARAM lp) {static BOOL Bfirsttime = True;if (bfirsttime) {bfirsttime = F alse;//creates a modeless dialog box from a dialog template resource createdialog (G_hinstdll, Makeintresource (idd_dips), NULL, Dipdlg_proc); PostThreadMessage (G_dwthreadid, wm_null, 0, 0);} Return (CallNextHookEx (G_hhook, NCode, WP, LP));} //Set hook function dipslib_api bool Setdipshook (DWORD dthreadid) {bool BRet = false;if (Dthreadid! = 0) {G_dwthreadid = Dthreadid;g_hho OK = SetWindowsHookEx (Wh_getmessage, Prochookmsg, G_hinstdll, Dthreadid); if (NULL! = G_hhook) {BRet = PostThreadMessage ( Dthreadid, wm_null, NULL, NULL);}} Else{if (G_hhook! = null) {BRet = UnhookWindowsHookEx (g_hhook); g_hhook = NULL;}} return bRet;}
Agent process to implement the source code:
HWND g_destwindowwnd= null;//The forward declaration of functions contained in this code module: Atommyregisterclass (hinstance hinstance); Boolinitinstance (HINSTANCE, int.); LRESULT Callbackwndproc (hwnd, UINT, WPARAM, LPARAM); Int_ptr Callbackabout (hwnd, UINT, WPARAM, LPARAM); BOOL CALLBACK Procenumchildwindows (HWND hwnd, LPARAM LP) {CHAR Pbuff[max_path] = {0}; GetWindowText (HWnd, Pbuff, MAX_PATH); if (0 = = strcmp ("Folderview", Pbuff)) {G_destwindowwnd = hwnd;//returns 0 stops enumerating return 0; }return TRUE;} int Apientry _tWinMain (hinstance hinstance, hinstance hprevinstance, LPTSTR LpC mdline, int ncmdshow) {unreferenced_parameter (hprevinstance); Unreferenced_parameter (lpCmdLine); TODO: Place the code here. MSG msg; Haccel hacceltable;//Initialization of global string LOADSTRING (HInstance, Ids_app_title, SzTitle, max_loadstring); LoadString (HInstance, Idc_dips, Szwindowclass, max_loadstring); MyRegisterClass (HINSTANCE);//Execution of application initialization: if (! InitInstance (HINSTANCE, nCmdShow)) {return FALSE;} hacceltable = Loadaccelerators (hinstance, Makeintresource (idc_dips)); HWND Hpromanwnd = FindWindow ("ProgMan", NULL); Enumchildwindows (Hpromanwnd, Procenumchildwindows, NULL);D word nthreadid, Nprocessid;nthreadid = GetWindowThreadProcessId (G_destwindowwnd, &nprocessid); Setdipshook (Nthreadid);//main message loop: while (GetMessage (&msg, NULL, 0, 0)) {HWND hwnddips = FindWindow (NULL, TEXT ("Test Dips ")); SendMessage (Hwnddips, Wm_app, (WPARAM) G_destwindowwnd, TRUE); Sleep (2000); SendMessage (hwnddips, wm_close, 0, 0); Setdipshook (0); }return 0;}
Windows Hook injection DLLs