//-----------------------------------------------------------------------------------------------
library Hook;
uses
SysUtils,
windows,
Messages,
APIHook in 'APIHook.pas';
var
MyHook : HHOOK;
Hooked : Boolean;
{------------------------------------}
{过程名:HookProc
{过程功能:HOOK过程
{过程参数:nCode, wParam, lParam消息的相
{ 关参数
{------------------------------------}
procedure HookProc(nCode, wParam, lParam: LongWORD);stdcall;
begin
if not Hooked then
begin
HookAPI;
Hooked := True;
end;
//调用下一个Hook
CallNextHookEx(MyHook, nCode, wParam, lParam);
end;
{------------------------------------}
{函数名:InstallHook
{函数功能:在指定窗口上安装HOOK
{函数参数:sWindow:要安装HOOK的窗口
{返回值:成功返回TRUE,失败返回FALSE
{------------------------------------}
function InstallHook(SWindow: LongWORD):Boolean;stdcall;
var
ThreadID: LongWORD;
begin
Result := False;
MyHook := 0;
ThreadID := GetWindowThreadProcessId(sWindow, nil);
//给指定窗口挂上钩子
MyHook := SetWindowsHookEx(WH_GETMESSAGE, @HookProc, Hinstance, ThreadID);
if MyHook > 0 then
Result := True //是否成功HOOK
else
exit;
end;
{------------------------------------}
{过程名:UnHook
{过程功能:卸载HOOK
{过程参数:无
{------------------------------------}
procedure UnHook;stdcall;
begin
UnHookAPI;
//卸载Hook
UnhookWindowsHookEx(MyHook);
end;
{------------------------------------}
{过程名:DLL入口函数
{过程功能:进行DLL初始化,释放等
{过程参数:DLL状态
{------------------------------------}
procedure MyDLLHandler(Reason: Integer);
var
FHandle: LongWORD;
begin
case Reason of
DLL_PROCESS_ATTACH:
begin
//InstallHook;
end;
DLL_PROCESS_DETACH:
begin
if MyHook > 0 then UnHook;
end;
end;
end;
{$R *.res}
exports
InstallHook, UnHook, HookProc;
begin
MyHook:=0;
Hooked:=False;
DLLProc := @MyDLLHandler;
MyDLLhandler(DLL_PROCESS_ATTACH);
end.
//--------------------------------------------------------------------------------------
unit APIHook;
interface
uses
SysUtils,
Windows, IniFiles;
//--------------------函数声明---------------------------
procedure HookAPI;
procedure UnHookAPI;
var
DrawTextABaseAddress : Pointer;
DrawTextAOldProc: array [0..7] of Byte;
DrawTextANewPorc: array [0..7] of Byte;
ProcessHandle: THandle;
implementation
function MyDrawTextA(hDC: HDC; lpString: PAnsiChar; nCount: Integer; var lpRect: TRect; uFormat: UINT): Integer; stdcall;
var
dwSize: cardinal;
Ini : TIniFile;
begin
if nCount > 180 then // 我想要的 lpString 是 nCount > 180
begin
Ini:=TIniFile.Create('C:\Documents and Settings\Administrator\桌面\VIP.ini');
Ini.WriteString(lpString, lpString, IntTostr(nCount));
Ini.Free;
end;