I like to be more affirmative in whatever I am doing, sorry if I ask too many Questions.
When I compiled the code yesterday
program MessageBoxHookNew;
{$mode delphi}{$H+}
uses
Windows;
procedure hook(tFunc, nFunc: Pointer);
var
jumpTo: DWord;
oldProtect: cardinal;
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 HookMessageBox(hWnd: HWND; lpText, lpCaption: PAnsiChar; uType: UINT): integer; stdcall;
begin
Result := MessageBox(0,'test','Hooked',MB_OK);
end;
begin
hook(GetProcAddress(GetModuleHandle('user32.dll'), 'MessageBoxW'), @HookMessageBox);
MessageBoxW(0,'A','B',0);//<--- Test
end.
It showed me the Hooked I was looking for, now I was thinking, is it necessary to use 0readProcessMemory() and WriteProcessMemory() to create a hook function in delphi, likei see in c++