c++assemblyx86-64asmjit

AsmJit emit bytes or x64 absolute far jump


I want to emit absolute far jump using asmjit. Bytes of this jump:

FF 25 00 00 00 00 // jmp qword ptr [null offset]
00 00 00 00 00 00 00 00 // 8-byte jump target address

But I don't know how to emit jmp qword ptr [*] with 0 offset and raw address bytes after it.
Can someone help me?
Thanks in advance!

UPD: I know how to emit jmp qword ptr [*].

a.jmp(asmjit::x86::ptr(asmjit::x86::rip));

But how can I emit raw address bytes?


Solution

  • There are multiple options:

    a) Embed the address after jump, this answers the question:

    a.jmp(asmjit::x86::ptr(asmjit::x86::rip));
    a.embedUInt64(addressToEmbed);
    

    b) Do the same with Label:

    Label constPool = a.newLabel();
    a.jmp(x86::ptr(constPool));
    
    // later in the code.
    a.bind(constPool);
    a.embedUInt64(addressToEmbed);
    // possibly more addresses in the pool.
    embedUInt64(anotherAddress);
    

    c) Use absolute address in the jmp itself as AsmJit would add that address to AddressTable that will be emitted at the end of the instruction stream (it would basically do (b) by itself or use 32-bit relative displacement if that's possible).

    a.jmp(absoluteAddress);
    

    d) If you want the constant pool approach (b), but you want to emit the address immediately it's also possible to use multiple sections - multiple sections are like having multiple buffers that will be flattened at the end of assembling. I would point you to AsmJit test called asmjit_test_x86_sections.cpp in AsmJit's test directory.

    Additionally, Asmjit has a documentation available here: https://asmjit.com/doc/index.html - it's regularly updated and reflects master branch.