Going deep out of hooks (之)

zhaozj2021-02-16  48

How to get the content of the password window ------ Unveil the veil of HOOK

PAN Ying (Zero World)

Many programs now have the function of obtaining the content of the password window. Have you ever thought about how to do this? I have asked me like this. At that time, I couldn't answer, and now I have a certain understanding after I study the HOOK function of the window. Here are my mystery of the hook function.

First introduce the meaning of hook:

Hook refers to a function that pre-initiated before accepting information in the normal operation of the program, is used to check and modify information transmitted to the program. For example, after you click on the mouse on a window, the corresponding HOOK function is first received, and then it passes to the corresponding application.

How to define hook functions:

Setwindowshookex:

Used to load new HOOK functions, the list of parameters is under:

INT IDHOOK: Mount Hook Type, with WH_MOUSE, etc.

HookProc LPFN: Hook function addresses to be loaded.

Hinstance HMOD: The process where the function is located, if the function must be in the DLL for the global HOOK function.

DWORD DWTHREADID: Which process is loaded, if it is a global, it is 0.

Returns the corresponding HOOK identity.

HookProc:

Your custom HOOK function should have the parameters as follows:

INT NCODE: Incoming information type.

WPARAM WPARAM: Short integer parameters.

LPARAM LPARAM: Long integer parameters.

To call CallNextHookex in a function to pass the information to the next hook function.

CallNexthookex:

Used to pass the information to the next hook function, you need to pass the obtained HOOK identity and the corresponding parameters.

UnHookWindowsHookex:

Used to remove the loaded HOOK function from the HOOK chain list, should be passed to the obtained Hook ID.

Let's take a look at one example:

Example of the original code download: hooktest.zip This program passes under Window98 and Delphi5.

First, call LoadLibrary and getProcAddress to get the function address.

Hinstdll: = loading (LPCTSTR ('hooktest.dll');

@HKPRCSYSMSG: = GetProcaddress (Hinstdll, 'MouseProc');

Second, put the resulting function with SETWINDOWSHOKEX.

HHK: = SETWINDOWSHOKEX (wh_mouse, @ hkprcsmsmsg, hinstdll, 0);

Third, Windows will put the function into each process.

4. Whenever the mouse click, the custom hook function will pass the window title to the title of the program.

IF (ncode = hc_action) and (wparam = wm_lbuttondown)

THEN

Begin

MyMouse: = CPointer (LPARAM);

MyHandle2: = mymouse ^ .hwnd;

Getmem (MyString, getWindowTextLength); "MyHandle2) 1);

GetWindowText (MyHandle2, MyString, getWindowTextLength);

TemphLle: = myHandle2;

While (Temphandle <> 0) DO

Begin

MyHandle2: = Temph1;

Temphandle: = getParent (Temph1); END;

IF (MyHandle2 <> 0)

THEN

SetwindowText (MyHandle2, MyString);

Freemem (MyString);

end

This completes the function of obtaining the contents of the password window.

转载请注明原文地址:https://www.9cbs.com/read-23190.html

New Post(0)