EDN Admin
Well-known member
I tried to write a hook dll file.
And then. Def file export function.
The following is my code:
<div style="color:black; background-color:white
<pre><span style="color:green // hookps.cpp : Custom DLLs exported function application.
<span style="color:green //
#include <windows.h>
#include <span style="color:#a31515 "stdafx.h"
#include <span style="color:#a31515 "hookps.h"
<span style="color:green //------------------------------------
#define WINAPI_stdcall
#define WM_PSD_ENVSTAMPRECT (WM_USER+5)
#define WM_USER 0x0400
<span style="color:green //----------------------------------------
<span style="color:green // Shared variable
# pragma data_seg (<span style="color:#a31515 ".shared")
HWND g_hWnd;
HHOOK hThisHook;
LPARAM lparamvalue;
<span style="color:green // save the hook handle
<span style="color:green //static UINT_PTR CALLBACK PaintHookProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
<span style="color:green //int GetWindowTextRemote(HWND hwnd,LPSTR lpString);
<span style="color:green //int ReleaseHook();
# pragma data_seg ()
# pragma comment (linker, <span style="color:#a31515 "/section:.shared,RWS")
<span style="color:green //--------------------------------------------------------------------------------
<span style="color:green //Export function
<span style="color:green //#define DllExport __declspec(dllexport)static UINT_PTR CALLBACK PaintHookProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) ;
<span style="color:green //#define DllExport2 __declspec( dllexport ) int GetWindowTextRemote(HWND hwnd,LPSTR lpString);
<span style="color:green //#define DllExport3 __declspec( dllexport ) int ReleaseHook();
<span style="color:green //---------------------------------------------------------
<span style="color:blue long (CALLBACK __stdcall PaintHookProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)) <span style="color:green // Message callback function
{
<span style="color:green //char value=0; //lParam is 16bit
<span style="color:blue switch (uMsg)
{
<span style="color:blue case WM_PSD_ENVSTAMPRECT:
<span style="color:green // uRet = PreDrawPage(WORD(wParam), WORD(wParam), (LPPAGESETUPDLG)lParam);
<span style="color:green //value= lParam;
lparamvalue=lParam;
<span style="color:blue break;
<span style="color:blue return TRUE;
<span style="color:blue default:
<span style="color:blue return FALSE;
};
<span style="color:blue return TRUE;
};
<span style="color:green //----------------------------------
HINSTANCE hDll;
<span style="color:green // Set the mount hook
<span style="color:blue long (__stdcall SetHook(HWND hwnd))
{
g_hWnd=hwnd;
hThisHook=SetWindowsHookEx(WH_CALLWNDPROC,(HOOKPROC) PaintHookProc,hDll,GetWindowThreadProcessId(hwnd,NULL) );
<span style="color:blue return 0;
};
<span style="color:green //
<span style="color:blue long ( __stdcall GetlParam(LPARAM lParam))
{
lParam=lparamvalue;
<span style="color:blue return TRUE;
};
<span style="color:blue int (__stdcall ReleaseHook()) <span style="color:green // <<<<<<Off the hook
{
<span style="color:blue if(hThisHook)
{
UnhookWindowsHookEx(hThisHook);
hThisHook = NULL;
}
<span style="color:blue return TRUE;
};
<span style="color:green //enum
<span style="color:green //{
<span style="color:green //HM_CALLWNDPROC = 0x0001,
<span style="color:green //};
[/code]
<br/>
.def File :
<div style="color:black; background-color:white
<pre>LIBRARY <span style="color:#a31515 "hookps"
EXPORTS
SetHook
ReleaseHook
GetlParam
PaintHookProc
----------------
[/code]
<br/>
I exported the four functions. But it is strange.
I use dependncy walker to check function.
I create a good hook dll that no export function.
I made reference to other peoples dll.
Dlls capacity is about the size of at least 300KB. But my dll only 28KB.
This is another doubt.
I will upload my file to skydriver for your reference:
<a title="123 https://skydrive.live.com/redir.aspx?cid=105b2868cb2df559&resid=105B2868CB2DF559!190
<br/>
View the full article
And then. Def file export function.
The following is my code:
<div style="color:black; background-color:white
<pre><span style="color:green // hookps.cpp : Custom DLLs exported function application.
<span style="color:green //
#include <windows.h>
#include <span style="color:#a31515 "stdafx.h"
#include <span style="color:#a31515 "hookps.h"
<span style="color:green //------------------------------------
#define WINAPI_stdcall
#define WM_PSD_ENVSTAMPRECT (WM_USER+5)
#define WM_USER 0x0400
<span style="color:green //----------------------------------------
<span style="color:green // Shared variable
# pragma data_seg (<span style="color:#a31515 ".shared")
HWND g_hWnd;
HHOOK hThisHook;
LPARAM lparamvalue;
<span style="color:green // save the hook handle
<span style="color:green //static UINT_PTR CALLBACK PaintHookProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
<span style="color:green //int GetWindowTextRemote(HWND hwnd,LPSTR lpString);
<span style="color:green //int ReleaseHook();
# pragma data_seg ()
# pragma comment (linker, <span style="color:#a31515 "/section:.shared,RWS")
<span style="color:green //--------------------------------------------------------------------------------
<span style="color:green //Export function
<span style="color:green //#define DllExport __declspec(dllexport)static UINT_PTR CALLBACK PaintHookProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) ;
<span style="color:green //#define DllExport2 __declspec( dllexport ) int GetWindowTextRemote(HWND hwnd,LPSTR lpString);
<span style="color:green //#define DllExport3 __declspec( dllexport ) int ReleaseHook();
<span style="color:green //---------------------------------------------------------
<span style="color:blue long (CALLBACK __stdcall PaintHookProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)) <span style="color:green // Message callback function
{
<span style="color:green //char value=0; //lParam is 16bit
<span style="color:blue switch (uMsg)
{
<span style="color:blue case WM_PSD_ENVSTAMPRECT:
<span style="color:green // uRet = PreDrawPage(WORD(wParam), WORD(wParam), (LPPAGESETUPDLG)lParam);
<span style="color:green //value= lParam;
lparamvalue=lParam;
<span style="color:blue break;
<span style="color:blue return TRUE;
<span style="color:blue default:
<span style="color:blue return FALSE;
};
<span style="color:blue return TRUE;
};
<span style="color:green //----------------------------------
HINSTANCE hDll;
<span style="color:green // Set the mount hook
<span style="color:blue long (__stdcall SetHook(HWND hwnd))
{
g_hWnd=hwnd;
hThisHook=SetWindowsHookEx(WH_CALLWNDPROC,(HOOKPROC) PaintHookProc,hDll,GetWindowThreadProcessId(hwnd,NULL) );
<span style="color:blue return 0;
};
<span style="color:green //
<span style="color:blue long ( __stdcall GetlParam(LPARAM lParam))
{
lParam=lparamvalue;
<span style="color:blue return TRUE;
};
<span style="color:blue int (__stdcall ReleaseHook()) <span style="color:green // <<<<<<Off the hook
{
<span style="color:blue if(hThisHook)
{
UnhookWindowsHookEx(hThisHook);
hThisHook = NULL;
}
<span style="color:blue return TRUE;
};
<span style="color:green //enum
<span style="color:green //{
<span style="color:green //HM_CALLWNDPROC = 0x0001,
<span style="color:green //};
[/code]
<br/>
.def File :
<div style="color:black; background-color:white
<pre>LIBRARY <span style="color:#a31515 "hookps"
EXPORTS
SetHook
ReleaseHook
GetlParam
PaintHookProc
----------------
[/code]
<br/>
I exported the four functions. But it is strange.
I use dependncy walker to check function.
I create a good hook dll that no export function.
I made reference to other peoples dll.
Dlls capacity is about the size of at least 300KB. But my dll only 28KB.
This is another doubt.
I will upload my file to skydriver for your reference:
<a title="123 https://skydrive.live.com/redir.aspx?cid=105b2868cb2df559&resid=105B2868CB2DF559!190
<br/>
View the full article