Windows掛鈎注入DLL

來源:互聯網
上載者:User

標籤:ati   pcm   source   har   ext   thread   register   ids   ssi   

注入DLL實現源碼:
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) {switch (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 = FALSE;// 從一個對話方塊模版資源建立一個無模式的對話方塊CreateDialog(g_hInstDll, MAKEINTRESOURCE(IDD_DIPS), NULL, DipDlg_Proc);PostThreadMessage(g_dwThreadId, WM_NULL, 0, 0);}return (CallNextHookEx(g_hHook, nCode, wp, lp));}// 設定鉤子函數DIPSLIB_API BOOL SetDipsHook(DWORD dThreadId){BOOL bRet = FALSE;if (dThreadId != 0){g_dwThreadId = dThreadId;g_hHook = 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;}
代理進程實現源碼:
HWND g_DestWindowWnd= NULL;// 此代碼模組中包含的函數的前向聲明: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;// 返回0就停止枚舉return 0;    }return TRUE;}int APIENTRY _tWinMain(HINSTANCE hInstance,                     HINSTANCE hPrevInstance,                     LPTSTR    lpCmdLine,                     int       nCmdShow){UNREFERENCED_PARAMETER(hPrevInstance);UNREFERENCED_PARAMETER(lpCmdLine); // TODO: 在此放置代碼。MSG msg;HACCEL hAccelTable;// 初始化全域字串LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);LoadString(hInstance, IDC_DIPS, szWindowClass, MAX_LOADSTRING);MyRegisterClass(hInstance);// 執行應用程式初始化:if (!InitInstance (hInstance, nCmdShow)){return FALSE;}hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_DIPS));HWND hPromanWnd = FindWindow("ProgMan", NULL);EnumChildWindows(hPromanWnd, ProcEnumChildWindows, NULL);DWORD nThreadId, nProcessId;nThreadId = GetWindowThreadProcessId(g_DestWindowWnd, &nProcessId);SetDipsHook(nThreadId);// 主訊息迴圈: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掛鈎注入DLL

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.