How to get instruction information from libopcodes?

前端 未结 3 1457
后悔当初
后悔当初 2020-12-09 19:42

I am writing a tool which uses libbfd and libopcodes in x86-32 and x86-64 Linux to perform disassembly. The problem is that whilst I am able to get

3条回答
  •  囚心锁ツ
    2020-12-09 19:48

    Libopcodes prints disassembled instructions into the stream which is intercepted by your custom_printf function. Your mistake is that you assume that custom_printf is called once each time a single instruction is disassembled, however, it is called more often, particularly, to print each mnemonic,operand, address or separator.

    So, resulting disassembly of your binary is

    xor %ebp, %ebp
    
    mov %rdx, %r9
    
    pop %rsi
    
    mov %rsp, %rdx
    
    and $0xfffffffffffffff0, %rsp
    
    push %rax
    
    push %rsp
    
    mov $0x401450,%r8
    
    ...
    

提交回复
热议问题