Skip to content

Expose Relative Instruction API #443

Closed
@stevemk14ebr

Description

@stevemk14ebr

Feature Request:
Many modern disassemblers expose somewhere in their api a way to determine if a current instruction is relative to EIP/RIP in some manner. The capstone api only exposes the Opcode Types of MEM,IMM,REG, and FP. When writing code relocation utilities such as hooking libraries this is a significant drawback as it is currently impossible to determine if an instruction is relative or not and then modify that displacement if necessary.

This could be resolved by exposing two new features to the api:

  1. A flag of some sort defining if the currently instruction is RIP/EIP Relative
  2. An integer value describing the offset in bytes from the beggining of the instruction to the Displacement.

Ex (x64):

jmp [rip+0xDEADBEEF]
"\xFF\x25\xEF\xBE\xAD\xDE"

Proposed API:

cs_insn* CurIns = (cs_insn*)&Instructions[i];
if(CurIns->Flag & X86_INS_REL)
{   
    Displacement=CurIns->Relative.Displacement; //would be 0xdeadbeef in this example
    OffsetToDisp=CurIns->Relative.Offset; //would be 2 in this example
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions