gpt4 book ai didi

delphi - GetWindowThreadProcessId() IAT Hook : How compare "dwProcessID" parameter?

转载 作者:行者123 更新时间:2023-12-01 17:55:46 26 4
gpt4 key购买 nike

我正在上钩GetWindowThreadProcessId()使用以下代码成功。

现在我想检查dwProcessID参数是否对应于确定进程的ID,并且在肯定情况下阻止执行原始函数:

Result := OldGetWindowThreadProcessId(hWnd, dwProcessID);

我尝试过这个,但没有成功:

if dwProcessID = 12345 then exit;

这是我的完整代码:

library MyLIB;

uses
Windows,
ImageHlp;

{$R *.res}

type
PGetWindowThreadProcessId = function(hWnd: THandle; dwProcessID: DWord)
: DWord; stdcall;

var
OldGetWindowThreadProcessId: PGetWindowThreadProcessId;

function HookGetWindowThreadProcessId(hWnd: THandle; dwProcessID: DWord)
: DWord; stdcall;

begin
try
// Check if is some process
except
MessageBox(0, 'Error', 'HookGetWindowThreadProcessId Error', 0);
end;
Result := OldGetWindowThreadProcessId(hWnd, dwProcessID);
end;

procedure PatchIAT(strMod: PAnsichar; Alt, Neu: Pointer);
var
pImportDir: pImage_Import_Descriptor;
size: CardinaL;
Base: CardinaL;
pThunk: PDWORD;
begin
Base := GetModuleHandle(nil);
pImportDir := ImageDirectoryEntryToData(Pointer(Base), True,
IMAGE_DIRECTORY_ENTRY_IMPORT, size);
while pImportDir^.Name <> 0 Do
begin
If (lstrcmpiA(PAnsichar(pImportDir^.Name + Base), strMod) = 0) then
begin
pThunk := PDWORD(Base + pImportDir^.FirstThunk);
While pThunk^ <> 0 Do
begin
if DWord(Alt) = pThunk^ Then
begin
pThunk^ := CardinaL(Neu);
end;
Inc(pThunk);
end;
end;
Inc(pImportDir);
end;
end;

procedure DllMain(reason: Integer);

begin
case reason of
DLL_PROCESS_ATTACH:
begin
OldGetWindowThreadProcessId := GetProcAddress(GetModuleHandle(user32),
'GetWindowThreadProcessId');

PatchIAT(user32, GetProcAddress(GetModuleHandle(user32),
'GetWindowThreadProcessId'), @HookGetWindowThreadProcessId);

end;
DLL_PROCESS_DETACH:
begin
end;
end;
end;

begin
DllProc := @DllMain;
DllProc(DLL_PROCESS_ATTACH);

end.

最佳答案

您的 PGetWindowThreadProcessId 类型和 HookGetWindowThreadProcessId() 函数都错误地声明了 dwProcessID 参数。它是一个输出参数,因此需要将其声明为 var dwProcessID: DWorddwProcessID: PDWord

然后您需要调用 OldGetWindowThreadProcessId() 来检索实际的 PID,然后才能将其与任何内容进行比较。因此,您的“在积极情况下阻止执行原始函数”的要求是不现实的,因为您需要执行原始函数才能确定要比较的dwProcessID值。

试试这个:

type
PGetWindowThreadProcessId = function(hWnd: THandle; var dwProcessID: DWord): DWord; stdcall;

...

function HookGetWindowThreadProcessId(hWnd: THandle; var dwProcessID: DWord): DWord; stdcall;
begin
Result := OldGetWindowThreadProcessId(hWnd, dwProcessID);
try
if dwProcessID = ... then
...
except
MessageBox(0, 'Error', 'HookGetWindowThreadProcessId Error', 0);
end;
end;

关于delphi - GetWindowThreadProcessId() IAT Hook : How compare "dwProcessID" parameter?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52787911/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com