Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code_asm: expose rip/eip regs #212

Open
wtfsck opened this issue Oct 24, 2021 · 4 comments
Open

code_asm: expose rip/eip regs #212

wtfsck opened this issue Oct 24, 2021 · 4 comments

Comments

@wtfsck
Copy link
Member

wtfsck commented Oct 24, 2021

It's possible to use rip-relative addressing if you reference a label. It should be possible to do the same thing if you want to use any address (assuming it's close enough to the generated code).

#209

@ancorehraq
Copy link

I just ran into this in my Rust project. Would it be difficult for a newcomer to implement? It looks like AsmMemoryOperand::displ and Instruction::mem_displ are overloaded to contain a displacement or a label ID and I'd have to separate them somehow.

@wtfsck
Copy link
Member Author

wtfsck commented Jan 7, 2023

It could be easy, I don't remember all the details. You can try this:

  • Manually add rip to the generated code (registers.rs, no need to touch the C# generator yet)
  • try to assemble: lea rax,[rip+0x123456789AB] assuming 0x123456789AB is within 2GB of your generated code.

@ancorehraq
Copy link

That doesn't work by itself, the displacement is interpreted as an instruction index if it's a valid index, and used as a literal displacement without adjustment otherwise:

displ -1
0000000010000000 488D05F8FFFFEF lea rax,[0FFFFFFFFFFFFFFFFh]
displ 0
0000000010000000 488D05F9FFFFFF lea rax,[10000000h]
displ 1
0000000010000000 488D05FAFFFFEF lea rax,[1]
displ 2
0000000010000000 488D05FBFFFFEF lea rax,[2]

@wtfsck
Copy link
Member Author

wtfsck commented Jan 7, 2023

Try updating to_memory_operand() in mem.rs and set displ_size to 8 if base is RIP, will that work?

If that doesn't work, I'd compare the Instructions that was created by the assembler and compare it against another instruction created by the decoder that also has an RIP relative operand.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants