一点猥琐代码


 
    
// Register app for pen windows (if possible) bPenWin = FALSE; if ((hPenWin = GetSystemMetrics (SM_PENWINDOWS)) != NULL) { if ((RegisterPenApp = (LPREGISTERPENAPP) GetProcAddress (hPenWin, " RegisterPenApp " )) != NULL) { ( * RegisterPenApp)(RPA_DEFAULT, TRUE); bPenWin = TRUE; } }

SetWinEventHook这个函数可以用来注入DLL..

具体如何注入看MSDN吧..还有其他很多猥琐的用法```具体如何猥琐大家自己想吧。

我刚开始用这个函数的时候始终能安装成功,但是就是无法捕获到信息..

最后到国外...再查阅MSDN发现有这么一句话..

The client thread that calls SetWinEventHook must have a message loop in order to receive events.

翻译一下就是:调用了SetWinEventHook h函数的线程需要一个消息循环来接受事件。

之前一直写个MAIN就完了..杯具啊!!

代码如下:

#include

#include

#include

#include

#include "resource.h"

 

#pragma comment(lib, "Oleacc.lib")

 

// Global variable.

HWINEVENTHOOK g_hook;

// Callback function that handles events.

//

void _stdcall HandleWinEvent(HWINEVENTHOOK hook, DWORD event, HWND hwnd, 

LONG idObject, LONG idChild, 

DWORD dwEventThread, DWORD dwmsEventTime)

{

IAccessible* pAcc = NULL;

VARIANT varChild;

HRESULT hr = AccessibleObjectFromEvent(hwnd, idObject, idChild, &pAcc, &varChild);  

if ((hr == S_OK) && (pAcc != NULL))

{

BSTR bstrName;

pAcc->lpVtbl->get_accName(pAcc, varChild, &bstrName);

if (event == EVENT_SYSTEM_MENUSTART) 

{

printf("Begin: ");

}

else if (event == EVENT_SYSTEM_MENUEND)

{

printf("End:   ");

}

printf("%S\n", bstrName);

SysFreeString(bstrName);

pAcc->lpVtbl->Release(pAcc);

}

}

 

// Initializes COM and sets up the event hook.

//

void InitializeMSAA()

{

CoInitialize(NULL);

g_hook = SetWinEventHook(

EVENT_MIN, EVENT_MAX,  // Range of events (4 to 5).

NULL,                                          // Handle to DLL.

HandleWinEvent,                                // The callback.

0, 0,              // Process and thread IDs of interest (0 = all)

WINEVENT_OUTOFCONTEXT); // Flags.

}

 

// Unhooks the event and shuts down COM.

//

void ShutdownMSAA()

{

UnhookWinEvent(g_hook);

CoUninitialize();

}

 

INT_PTR CALLBACK DialogProc(

__in  HWND hwndDlg,

__in  UINT uMsg,

__in  WPARAM wParam,

__in  LPARAM lParam

)

{

switch(uMsg)

{

case WM_CLOSE:

EndDialog(hwndDlg, 0);

break;

default:

return FALSE;

}

return TRUE;

 

}

 

int main(int _argc, char **_argv, char **_evn)

{

HINSTANCE hInstance;

hInstance = GetModuleHandle(NULL);

InitializeMSAA();

DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL,

DialogProc, 0);

ShutdownMSAA();

return 0;

}


你可能感兴趣的:(计算机安全)