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

Assembler - Fails to assemble IP relative instruction when a label was declared #121

Closed
Symbai opened this issue Aug 31, 2020 · 0 comments
Closed

Comments

@Symbai
Copy link
Contributor

Symbai commented Aug 31, 2020

The following code throws the exception IP relative memory operand is too far away and isn't currently supported. Try to allocate memory close to the original instruction (+/-2GB). This happens because, due to the previous declared label, the address of the instruction gets overridden and the RIP relative address is then wrong.

Example:

var c = new Assembler(64);
const ulong decodeIP = 0x1E520ED0025;

var codeReader = new ByteArrayCodeReader("F2 0F 11 05 D8 FF FF FF"); // movsd [7FFD2E570000],xmm0
var decoder = Decoder.Create(64, codeReader);
decoder.IP = decodeIP;
decoder.Decode(out var instr);
var w = new StreamCodeWriter(new MemoryStream());

c.cmp(rax,1);
c.jne(c.@F);
c.ret();
c.AnonymousLabel();
c.AddInstruction(instr); // movsd [7FFD2E570000],xmm0 => but after added it becomes => movsd [0FFFFFFFFFFFFFFE1],xmm0
c.ret();

c.Assemble(w, (ulong)decodeIP, BlockEncoderOptions.ReturnNewInstructionOffsets); // <--- throws

FYI: Occurs on anonymous and non anonymous label. If the label points to another instruction no exception is thrown.

Works:

c.AnonymousLabel();
c.nop();
c.AddInstruction(instr);

Fails:

c.AnonymousLabel();
c.AddInstruction(instr);
@Symbai Symbai changed the title Assembler - Fails to assemble IP relative instruction when an anonymous label was declared Assembler - Fails to assemble IP relative instruction when a label was declared Aug 31, 2020
@0xd4d 0xd4d closed this as completed in c5c04d2 Dec 28, 2020
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

1 participant