Für 32-bit sähe das ungefähr so aus (
Unit als erstes ins Project einbinden)
Delphi-Quellcode:
unit AllocateHWndPatch;
interface
implementation
uses
Classes,
SysUtils,
Windows;
function PatchedAllocateHWnd(AMethod: TWndMethod): HWND;
begin
{...}
end;
procedure RedirectFunction(OrgProc, NewProc: Pointer);
type
TJmpOp =
packed record
Jmp: Byte;
Offset: Integer;
end;
var
JmpOp: TJmpOp;
n:
{$IF COMPILERVERSION < 23}Cardinal
{$ELSE}NativeUInt
{$IFEND};
begin
JmpOp.Jmp := $E9;
JmpOp.Offset := PByte(NewProc) - (PByte(OrgProc) + SizeOf(TJmpOp));
if not WriteProcessMemory(GetCurrentProcess, OrgProc, @JmpOp, SizeOf(TJmpOp), n)
then
RaiseLastOSError;
end;
initialization
RedirectFunction(@Classes.AllocateHWnd, @PatchedAllocateHWnd);
end.