写了一个截获指定窗口所发送数据的Dll,现有些问题想向大家请教(40分)

  • 主题发起人 主题发起人 ChJK
  • 开始时间 开始时间
C

ChJK

Unregistered / Unconfirmed
GUEST, unregistred user!
写了一个截获指定窗口所发送数据的Dll,现有些问题想向大家请教,其实也是从网上抄下来的,代码如下:
library GetSendData;

uses
// madshi components
madCodeHook,

// windows units
Windows, Winsock, SysUtils, Messages,Classes;

{$I defs.inc}

const
WM_SENDDATA = WM_USER + 200;

var
sendNextHook : function(s: TSocket; Buf : Pointer; Len, Flags: Integer): Integer; stdcall;

DataStr: string;
HookHandle: HHOOK=0;//THandle;
Hooked: Boolean=false;

procedure SendMsg(msg : String);
var
SendData_Atom: integer; //全局原子表ID
FWinHandle:HWND;//主程序窗口句柄
begin
if msg<>'' then
begin
FWinHandle:= FindWindow('TForm_Main', nil);
SendData_Atom := GlobalAddAtom(pchar(msg)); //将字符串添加到全局原子表
PostMessage(FWinHandle, WM_SENDDATA, SendData_Atom, 0);
DataStr := '';
end;
end;



{----------
Procedure: sendHookProc
Author: Blad3
Date: 16-Sep-2004
Arguments: s: TSocket; var Buf; Len, Flags: Integer
Result: Integer
----------}
function sendHookProc(s: TSocket; Buf : Pointer; Len, Flags: Integer): Integer; stdcall;
var
dataLen: integer;
temp_str: string;
begin
// send message to user interface
if Len > 0 then
begin
temp_str := copy(Pchar(buf), 1, len);
SendMsg(temp_str);
end;

//call the real winsock function
Result := sendNextHook(s, Buf, Len, Flags);
end;

procedure UnHook;stdcall;
begin
UnhookAPI(@sendNextHook);
end;

procedure SetHookAPI;
begin
CollectHooks;

hookapi('ws2_32.dll', 'send', @sendHookProc, @sendNextHook);

FlushHooks;
end;

{----------}
{过程名:HookProc
{过程功能:HOOK过程
{过程参数:nCode, wParam, lParam消息的相
{ 关参数
{----------}
function HookProc(nCode, wParam, lParam: LongWORD):LRESULT;stdcall;//export;
begin
Result := 0;
if not Hooked then
begin
SetHookAPI;
Hooked := True;
end;
if HookHandle > 0 then
result:=CallNextHookEx(HookHandle,nCode,wparam,lparam)
else
result:=CallNextHookEx(0,nCode,wparam,lparam);
end;

{----------}
{函数名:InstallHook
{函数功能:在指定窗口上安装HOOK
{函数参数:sWindow:要安装HOOK的窗口
{返回值:成功返回TRUE,失败返回FALSE
{----------}
function InstallHook(HookWindow: LongWORD):Boolean;stdcall;
var
ThreadID: LongWORD;
begin
Result := False;
if HookWindow > 0 then begin
ThreadID := GetWindowThreadProcessId(HookWindow, nil);
//给指定窗口挂上钩子
HookHandle := SetWindowsHookEx(WH_GETMESSAGE, @HookProc, Hinstance,ThreadID);
if HookHandle > 0 then
Result := True //是否成功HOOK
else
exit;
end;
end;

{----------}
{过程名:DLL入口函数
{过程功能:进行DLL初始化,释放等
{过程参数:DLL状态
{----------}
procedure HOOKIPDLLHandler(Reason: Integer);
begin
case Reason of
DLL_PROCESS_ATTACH:
begin
end;
DLL_PROCESS_DETACH:
begin
UnHook;
end;
end;//end case
end;

exports
InstallHook,UnHook;

begin
DLLProc := @HOOKIPDLLHandler;
HOOKIPDLLHandler(DLL_PROCESS_ATTACH);
end.

我想请大家看看这个单元文件有什么问题还没有考虑清楚或考虑到,想问大家如果给多个窗口挂上它,会影响截获数据吗?因为是给线程挂钩子,会不会截获不到像IE那样的多窗口多线程序的数据?谢谢大家了!
 
大富翁里的高手们不知道跑到哪里去了,是不是都成了大富翁了,不管兄弟们了!
 
后退
顶部