Re: Getting from TJump to TMethod.Code...
- From: "Avatar Zondertau" <avatarzt@xxxxxxxxx (please reply to newsgroup)>
- Date: 29 Jun 2005 23:04:50 -0700
> Is it possible to somehow translate TJump record to TMethod.Code,
> TJump being the following:
>
> TJump = packed record
> OpCode: Byte;
> Distance: Pointer;
> end;
>
> In case the question makes no sense - I'm trying to patch a specific
> method of a specific class, but I want to be able to call the original
> method from inside the patched one. I know I could probably write an
> asm block with a jmp instruction but I'd like to avoid it, because the
> method in question receives multiple parameters and I don't want to
> mess with registers and stack manually if not absolutely necessary.
Below are the different forms the JMP instrcution can take:
EB cb JMP rel8 Jump short, relative, displacement relative to next
instruction
E9 cw JMP rel16 Jump near, relative, displacement relative to next
instruction
E9 cd JMP rel32 Jump near, relative, displacement relative to next
instruction
FF /4 JMP r/m16 Jump near, absolute indirect, address given in r/m16
FF /4 JMP r/m32 Jump near, absolute indirect, address given in r/m32
EA cd JMP ptr16:16 Jump far, absolute, address given in operand
EA cp JMP ptr16:32 Jump far, absolute, address given in operand
FF /5 JMP m16:16 Jump far, absolute indirect, address given in m16:16
FF /5 JMP m16:32 Jump far, absolute indirect, address given in m16:32
You'll probably want to ignore the indirect and far jumps, so you
should check the opcode byte for:
EB - 8 bit immediate
E9 - 32 bit immediate
66 E9 - 16 bit immediate
Now if you have a Method variable of type TMethod and the jump is
stored in Jump: TJump then you can use this code (untested):
type
TOffsetSplitter = packed record
A: Byte;
B: Word;
C: Byte;
end;
....
Method.Code := nil;
case Jump.OpCode of
$66:
if TOffsetSplitter(Jump.Offset).A = $E9 then
Method.Code := Pointer(LongWord(JumpLocation) + 4 +
TOffsetSplitter(Jump.Offset).B);
$E9:
Method.Code := Pointer(LongWord(JumpLocation) + 5 +
LongWord(Jump.Offset));
$E9:
Method.Code := Pointer(LongWord(JumpLocation) + 2 +
TOffsetSplitter(Jump.Offset).A);
end;
JumpLocation should be a pointer to the location that the jump is
actually used (that is, the memory address of the start of the Jump
record in actual code).
.
- Follow-Ups:
- Re: Getting from TJump to TMethod.Code...
- From: Aleksander Oven
- Re: Getting from TJump to TMethod.Code...
- References:
- Getting from TJump to TMethod.Code...
- From: Aleksander Oven
- Getting from TJump to TMethod.Code...
- Prev by Date: Re: Survey: Which Delphi do you use?
- Next by Date: Re: Survey: Which Delphi do you use?
- Previous by thread: Getting from TJump to TMethod.Code...
- Next by thread: Re: Getting from TJump to TMethod.Code...
- Index(es):
Relevant Pages
|