Skip to content

relativeToAbsolute #3424

Answered by danielkrupinski
Slavic asked this question in Q&A
Discussion options

You must be logged in to vote

In your example bytes:

  • FF 25 is the opcode of a relative jump with 4-byte offset
  • CAFC3200 - is the offset

Absolute address is calculated by adding the offset to the address of the next instruction after rel jmp (which is the address of the offset + 4).

You can also remove the + 2 and then (pointer being std::uintptr_t):

  • offset is *(int*)(pointer + 2)
  • address of the next instruction is pointer + 6

relativeToAbsolute requires input address to point to the offset, not to the opcode, because it also has to support call instruction with relative offset whose opcode (E8) is a single byte.

Bonus:
The offset in relative jump is a signed integer so you can jump backwards. I've seen some source…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Slavic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants