unit mess;
interface
uses
Windows,Messages,SysUtils,Classes,HookAPI;
procedure API_Hookup;
procedure Un_API_Hook;
implementation
type
TCreateFile = function(lpFileName: PChar; dwDesiredAccess, dwShareMode: DWORD;
lpSecurityAttributes: PSecurityAttributes; dwCreationDisposition, dwFlagsAndAttributes: DWORD;
hTemplateFile: THandle): THandle; stdcall;
TCreateFileA = function(lpFileName: PAnsiChar; dwDesiredAccess, dwShareMode: DWORD;
lpSecurityAttributes: PSecurityAttributes; dwCreationDisposition, dwFlagsAndAttributes: DWORD;
hTemplateFile: THandle): THandle; stdcall;
TCreateFileW = function(lpFileName: PWideChar; dwDesiredAccess, dwShareMode: DWORD;
lpSecurityAttributes: PSecurityAttributes; dwCreationDisposition, dwFlagsAndAttributes: DWORD;
hTemplateFile: THandle): THandle; stdcall;
var
OldCreateFile: TCreateFile;
OldCreateFileA: TCreateFileA;
OldCreateFileW: TCreateFileW;
function MyCreateFile(lpFileName: PChar; dwDesiredAccess, dwShareMode: DWORD;
lpSecurityAttributes: PSecurityAttributes; dwCreationDisposition, dwFlagsAndAttributes: DWORD;
hTemplateFile: THandle): THandle; stdcall;
var
F:TextFile;
begin
//在这里做处理
end;
function MyCreateFileA(lpFileName: PAnsiChar; dwDesiredAccess, dwShareMode: DWORD;
lpSecurityAttributes: PSecurityAttributes; dwCreationDisposition, dwFlagsAndAttributes: DWORD;
hTemplateFile: THandle): THandle; stdcall;
var
F:TextFile;
begin
//在这里做处理
end;
function MyCreateFileW(lpFileName: PWideChar; dwDesiredAccess, dwShareMode: DWORD;
lpSecurityAttributes: PSecurityAttributes; dwCreationDisposition, dwFlagsAndAttributes: DWORD;
hTemplateFile: THandle): THandle; stdcall;
begin
//在这里做处理
end;
procedure API_Hookup;
begin
if @OldCreateFile = nil then
@OldCreateFile := TrueFunctionAddress(@CreateFile);
if @OldCreateFileA = nil then
@OldCreateFileA := TrueFunctionAddress(@CreateFileA);
if @OldCreateFileW = nil then
@OldCreateFileW := TrueFunctionAddress(@CreateFileW);
PermuteFunction(@OldCreateFile, @MyCreateFile);
PermuteFunction(@OldCreateFileA, @MyCreateFileA);
PermuteFunction(@OldCreateFileW, @MyCreateFileW);
end;
procedure Un_API_hook;
begin
if @OldCreateFile <> nil then
PermuteFunction(@MyCreateFile, @OldCreateFile);
if @OldCreateFileA <> nil then
PermuteFunction(@MyCreateFileA, @OldCreateFileA);
if @OldCreateFileW <> nil then
PermuteFunction(@MyCreateFileW, @OldCreateFileW);
end;
initialization
finalization
Un_API_hook;
end.