【再谈Hook API】

hzlan 2003-10-21 11:15:50
前几日得到一Hook API的例程,关于Hook TextOutA,DrawTextW等函数的。
但只能对自已的程序起作用而不能对所有系统程序有作用,不知何故?
请大家指点。
...全文
34 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
hzlan 2003-10-24
  • 打赏
  • 举报
回复
怎么没有收到你的源码啊?
: vagerent(哪天我打电话给她)
hzlan 2003-10-23
  • 打赏
  • 举报
回复
hzlan@cwtoys.com.cn
谢了
我会给分的.
xiangding 2003-10-22
  • 打赏
  • 举报
回复
boyxd@163.net
谢谢
Erice 2003-10-22
  • 打赏
  • 举报
回复
erice@borlandsoft.com
谢谢
vagerent 2003-10-22
  • 打赏
  • 举报
回复
我给你一份变速器源码,delphi的,用了ring0,留下email
hzlan 2003-10-22
  • 打赏
  • 举报
回复
我记得当时有一份“兄弟变速器”提供了C的源码的,哪位大虾能改成Delphi版本的?谢了!
ehom 2003-10-22
  • 打赏
  • 举报
回复
做个钩子DLL,在主函数中写下上面的代码即可,其它进程会主动加载这个DLL,也就达到了你的目的
pankun 2003-10-21
  • 打赏
  • 举报
回复
没细看,但你的API HOOK是改写的本身进程的IDT表(也就是改了调用API的入口地址)不是API的真实地址,当然只对本身有效.
hzlan 2003-10-21
  • 打赏
  • 举报
回复
具体代码如下:
unit HookAPI;

interface

uses
Windows, Classes;
function LocateFunctionAddress(Code: Pointer): Pointer;
function RepointFunction(OldFunc, NewFunc: Pointer): Integer;

type //定义一个入口结构
PImage_Import_Entry = ^Image_Import_Entry;
Image_Import_Entry = record
Characteristics: DWORD;
TimeDateStamp: DWORD;
MajorVersion: Word;
MinorVersion: Word;
Name: DWORD;
LookupTable: DWORD;
end;

type //定义一个跳转的结构
TImportCode = packed record
JumpInstruction: Word; //定义跳转指令jmp
AddressOfPointerToFunction: ^Pointer; //定义要跳转到的函数
end;
PImportCode = ^TImportCode;
implementation

function LocateFunctionAddress(Code: Pointer): Pointer;
var
func: PImportCode;
begin
Result := Code;
if Code = nil then exit;
try
func := code;
if (func.JumpInstruction = $25FF) then
begin
Result := func.AddressOfPointerToFunction^;
end;
except
Result := nil;
end;
end;

function RepointFunction(OldFunc, NewFunc: Pointer): Integer;
var
IsDone: TList;
function RepointAddrInModule(hModule: THandle; OldFunc, NewFunc: Pointer): Integer;
var
Dos: PImageDosHeader;
NT: PImageNTHeaders;
ImportDesc: PImage_Import_Entry;
RVA: DWORD;
Func: ^Pointer;
DLL: string;
f: Pointer;
written: DWORD;
begin
Result := 0;
Dos := Pointer(hModule);
if IsDone.IndexOf(Dos) >= 0 then exit;
IsDone.Add(Dos);

OldFunc := LocateFunctionAddress(OldFunc);

if IsBadReadPtr(Dos, SizeOf(TImageDosHeader)) then exit;
if Dos.e_magic <> IMAGE_DOS_SIGNATURE then exit;
NT := Pointer(Integer(Dos) + dos._lfanew);

RVA := NT^.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT]
.VirtualAddress;

if RVA = 0 then exit;
ImportDesc := pointer(integer(Dos) + RVA);
while (ImportDesc^.Name <> 0) do
begin
DLL := PChar(Integer(Dos) + ImportDesc^.Name);
RepointAddrInModule(GetModuleHandle(PChar(DLL)), OldFunc, NewFunc);
Func := Pointer(Integer(DOS) + ImportDesc.LookupTable);
while Func^ <> nil do
begin
f := LocateFunctionAddress(Func^);
if f = OldFunc then
begin
WriteProcessMemory(GetCurrentProcess, Func, @NewFunc, 4, written);
if Written > 0 then Inc(Result);
end;
Inc(Func);
end;
Inc(ImportDesc);
end;
end;

begin
IsDone := TList.Create;
try
Result := RepointAddrInModule(GetModuleHandle(nil), OldFunc, NewFunc);
finally
IsDone.Free;
end;
end;

end.

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧