This is not always true. CMP reg/mem32, imm32 is an example.
Locally, I fixed this by scanning the bytes of the original instruction for the original displacement value, making sure there's only one match, and then using that location as the index.
There's probably a cleaner way to do that (ideally you'd get the offset of the operand within the instruction from the disassembler). I can put up a PR if you'd like, but my code simply asserts that there's one matching location, which is probably not flexible enough to include in the library.
The code that handles RIP relative addressing assumes that the displacement is always the last 4 bytes of the instruction:
https://github.com/Hpmason/retour-rs/blob/3bf7863bc0ad4ba1d0657e6ee98d43145c16b658/src/arch/x86/trampoline/mod.rs#L166-L167
This is not always true.
CMP reg/mem32, imm32
is an example.Locally, I fixed this by scanning the bytes of the original instruction for the original displacement value, making sure there's only one match, and then using that location as the index.
There's probably a cleaner way to do that (ideally you'd get the offset of the operand within the instruction from the disassembler). I can put up a PR if you'd like, but my code simply asserts that there's one matching location, which is probably not flexible enough to include in the library.