unit mess;<br><br>interface<br><br>uses<br> Windows,Messages,SysUtils,Classes,HookAPI;<br><br> procedure API_Hookup;<br> procedure Un_API_Hook;<br><br>var<br> FuncMessageboxA, FuncMessageboxW: PImportCode;<br><br>implementation<br><br>type<br> TMessageA = function(hwn: hwnd; lptext: pchar; lpcapion: pchar; utype: cardinal): integer; stdcall;<br> TMessageW = function(hwn: hwnd; lptext: pwidechar; lpcapion: pwidechar; utype: cardinal): integer; stdcall;<br><br> TCreateFile = function(lpFileName: PChar; dwDesiredAccess, dwShareMode: DWORD;<br> lpSecurityAttributes: PSecurityAttributes; dwCreationDisposition, dwFlagsAndAttributes: DWORD;<br> hTemplateFile: THandle): THandle; stdcall;<br> TCreateFileA = function(lpFileName: PAnsiChar; dwDesiredAccess, dwShareMode: DWORD;<br> lpSecurityAttributes: PSecurityAttributes; dwCreationDisposition, dwFlagsAndAttributes: DWORD;<br> hTemplateFile: THandle): THandle; stdcall;<br> TCreateFileW = function(lpFileName: PWideChar; dwDesiredAccess, dwShareMode: DWORD;<br> lpSecurityAttributes: PSecurityAttributes; dwCreationDisposition, dwFlagsAndAttributes: DWORD;<br> hTemplateFile: THandle): THandle; stdcall;<br><br>var<br> OldMessageBoxA: TMessageA;<br> OldMessageBoxW: TMessageW;<br><br> OldCreateFile: TCreateFile;<br> OldCreateFileA: TCreateFileA;<br> OldCreateFileW: TCreateFileW;<br><br>function MyBoxA(hwn:hwnd;lptext
char;lpcapion
char;utype:cardinal): integer; stdcall;<br>begin<br> result := OldMessageBoxA(hwn, 'Succes Hook A !', lpcapion, utype);<br>end;<br><br>function MyBoxw(hwn:hwnd;lptext
widechar;lpcapion
widechar;utype:cardinal): integer; stdcall;<br>begin<br> result := OldMessageBoxW(hwn, '成功挂上W!', lpcapion, utype);<br>end;<br><br>function MyCreateFile(lpFileName: PChar; dwDesiredAccess, dwShareMode: DWORD;<br> lpSecurityAttributes: PSecurityAttributes; dwCreationDisposition, dwFlagsAndAttributes: DWORD;<br> hTemplateFile: THandle): THandle; stdcall;<br>var<br> F:TextFile;<br>begin<br> oldCreateFile('c:/chenyi.txt',dwDesiredAccess, dwShareMode,lpSecurityAttributes,dwCreationDisposition,dwFlagsAndAttributes,hTemplateFile);<br>AssignFile(F,'c:/record.txt');<br>//writeln(f,'dads');<br>CloseFile(F);<br> result:=oldCreateFile(lpFileName,dwDesiredAccess, dwShareMode,lpSecurityAttributes,dwCreationDisposition,dwFlagsAndAttributes,hTemplateFile);<br>end;<br><br>function MyCreateFileA(lpFileName: PAnsiChar; dwDesiredAccess, dwShareMode: DWORD;<br> lpSecurityAttributes: PSecurityAttributes; dwCreationDisposition, dwFlagsAndAttributes: DWORD;<br> hTemplateFile: THandle): THandle; stdcall;<br>var<br> F:TextFile;<br>begin<br>oldCreateFile('c:/chenyi.txt',dwDesiredAccess, dwShareMode,lpSecurityAttributes,dwCreationDisposition,dwFlagsAndAttributes,hTemplateFile);<br>AssignFile(F,'c:/chenyi.txt');<br>Writeln(f,lpFileName);<br> result:=oldCreateFileA(lpFileName,dwDesiredAccess, dwShareMode,lpSecurityAttributes,dwCreationDisposition,dwFlagsAndAttributes,hTemplateFile);<br>end;<br><br>function MyCreateFileW(lpFileName: PWideChar; dwDesiredAccess, dwShareMode: DWORD;<br> lpSecurityAttributes: PSecurityAttributes; dwCreationDisposition, dwFlagsAndAttributes: DWORD;<br> hTemplateFile: THandle): THandle; stdcall;<br>begin<br>oldCreateFile('c:/chenyi.txt',dwDesiredAccess, dwShareMode,lpSecurityAttributes,dwCreationDisposition,dwFlagsAndAttributes,hTemplateFile);<br> result:=oldCreateFilew(lpFileName,dwDesiredAccess, dwShareMode,lpSecurityAttributes,dwCreationDisposition,dwFlagsAndAttributes,hTemplateFile);<br>end;<br><br><br>procedure API_Hookup;<br>begin<br> if @OldMessageBoxA = nil then<br> @OldMessageBoxA := TrueFunctionAddress(@messageboxA);<br> if @OldMessageBoxW = nil then<br> @OldMessageBoxW := TrueFunctionAddress(@messageboxW);<br><br> PermuteFunction(@OldMessageBoxA, @MyBoxA);<br> PermuteFunction(@OldMessageBoxW, @MyBoxW);<br><br> if @OldCreateFile = nil then<br> @OldCreateFile := TrueFunctionAddress(@CreateFile);<br> if @OldCreateFileA = nil then<br> @OldCreateFileA := TrueFunctionAddress(@CreateFileA);<br> if @OldCreateFileW = nil then<br> @OldCreateFileW := TrueFunctionAddress(@CreateFileW);<br><br> PermuteFunction(@OldCreateFile, @MyCreateFile);<br> PermuteFunction(@OldCreateFileA, @MyCreateFileA);<br> PermuteFunction(@OldCreateFileW, @MyCreateFileW);<br><br>end;<br><br>procedure Un_API_hook;<br>begin<br> If @OldMessageBoxA <> nil then begin<br> PermuteFunction(@MyBoxA, @OldMessageboxA);<br> PermuteFunction(@MyBoxW, @OldMessageboxW);<br> end;<br><br> if @OldCreateFile <> nil then<br> PermuteFunction(@MyCreateFile, @OldCreateFile);<br> if @OldCreateFileA <> nil then<br> PermuteFunction(@MyCreateFileA, @OldCreateFileA);<br> if @OldCreateFileW <> nil then<br> PermuteFunction(@MyCreateFileW, @OldCreateFileW);<br>end;<br><br>initialization<br> FuncMessageboxA := @MessageboxA;<br> FuncMessageboxW := @MessageboxW;<br><br>finalization<br> Un_API_hook;<br><br>end.