Re: How to patch overload function/method?



Chau Chee Yang wrote:

May I know what are the best PatchMethod available that can be used
with packaged app and non-packaged app?

You can obtain the real address with this GetActualAddr method.

type
PWin9xDebugThunk = ^TWin9xDebugThunk;
TWin9xDebugThunk = packed record
PUSH: Byte;
Addr: Pointer;
JMP: Byte;
Offset: Integer;
end;

PAbsoluteIndirectJmp = ^TAbsoluteIndirectJmp;
TAbsoluteIndirectJmp = packed record
OpCode: Word; //$FF25(Jmp, FF /4)
Addr: ^Pointer;
end;

function GetActualAddr(Proc: Pointer): Pointer;

function IsWin9xDebugThunk(AAddr: Pointer): Boolean;
begin
Result := (AAddr <> nil) and
(PWin9xDebugThunk(AAddr).PUSH = $68) and
(PWin9xDebugThunk(AAddr).JMP = $E9);
end;

begin
if Proc <> nil then
begin
if (Win32Platform <> VER_PLATFORM_WIN32_NT) and
IsWin9xDebugThunk(Proc) then
Proc := PWin9xDebugThunk(Proc).Addr;
if (PAbsoluteIndirectJmp(Proc).OpCode = $25FF) then
Result := PAbsoluteIndirectJmp(Proc).Addr^
else
Result := Proc;
end
else
Result := nil;
end;


--
Regards,

Andreas Hausladen
.



Relevant Pages

  • Re: How to patch overload function/method?
    ... TAbsoluteIndirectJmp = packed record ... function GetActualAddr(Proc: Pointer): Pointer; ... Proc:= PWin9xDebugThunk.Addr; ...
    (borland.public.delphi.language.basm)
  • Major Breakthrough II in programming for Delphi.
    ... Pointer to pointer. ... Version: TprotocolVersion; ... TheaderVersion1Record = packed record ... // do this for debugging code only... ...
    (alt.comp.lang.borland-delphi)
  • Re: Global Namespace Variables
    ... miguel sofer wrote: ... :accessed several times in the proc body. ... might be a shared data pointer that various procs ...
    (comp.lang.tcl)
  • Re: Convert C-Builder program to Delphi?
    ... >> Now I am stumped again with a 'new' dynamic allocation ... Would that mean declaring the packed record type then ... declaring a pointer to that record, ...
    (comp.lang.pascal.delphi.misc)
  • Re: Convert C-Builder program to Delphi?
    ... >> Now I am stumped again with a 'new' dynamic allocation ... Would that mean declaring the packed record type then ... declaring a pointer to that record, ...
    (comp.lang.cpp)