Good morning everyone,
I have been battling with a simple MessageBox() hook in lazarus Delphi, code compiles without problems, but it doesn't show if its hooked or not, so I decided to paste source here, pls I do need help of some sort.
My source code
program MessageBoxHookNew;
{$mode delphi}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes , Windows
{ you can add units after this };
var
data: String;
procedure hook(tFunc,nFunc:Pointer);
var
jumpTo:DWord;
oldProtect:Cardinal;
var
MainMessageBox : Function(hWnd:HWND; lpText,lpCaption:PAnsiChar; uType:UINT):Integer; stdcall;
HookMessageBox: Function (hWnd:HWND; lpText,lpCaption:PAnsiChar; uType:UINT):Integer; stdcall;
begin
jumpTo:=DWord(nFunc)-DWord(tFunc)-5;
VirtualProtect(tFunc,5,PAGE_EXECUTE_READWRITE,@oldProtect);
pbyte(tFunc)^:=$e9;
pdword(DWord(tFunc)+1)^:=jumpTo;
end;
function MainMessageBox(hWnd:HWND; lpText,lpCaption:PAnsiChar; uType:UINT):Integer;assembler;stdcall;
asm
push ebp
push esp
push ebx
push esi
push edi
end;
function HookMessageBox(hWnd:HWND; lpText,lpCaption:PAnsiChar; uType:UINT):Integer; stdcall;
begin
//MessageBox(0,'test','Hooked',MB_OK);
Result:= MainMessageBox(hWnd,lpText,lpCaption,uType);
end;
begin
data:=Pointer(DWord(GetProcAddress(GetModuleHandle('user32.dll'),MessageBoxW))+5);
hook(GetProcAddress(GetModuleHandle('user32.dll'),'MessageBoxW'),@HookMessageBox);
end.
Pls I need Help, and some form of explanation