Search code examples
pythonarmreverse-engineeringdisassemblyida

Disassmbling with IDA python for extract instruction


I am using IDA Python for extract the instructions of a binary. But unfortunately it does not print some instructions completely. For example, BCC, BCS, BEQ are printed as B. Is there any way to correct this problem? Here is my code!!!

for function_ea in idautils.Functions():
    for ins in idautils.FuncItems(function_ea):
        if idaapi.isCode(idaapi.getFlags(ins)):
            print idc.GetMnem(ins)

Solution

  • Try something like that (I checked this on my databases for ARM):

    import idautils
    
    for function_ea in idautils.Functions():
        for ins in idautils.FuncItems(function_ea):
            if idaapi.isCode(idaapi.getFlags(ins)):
                cmd = idc.GetDisasm(ins)
                mnem = cmd.split(' ')[0]
                print mnem
    

    From IDA manual:

    Get instruction mnemonics

    ea - linear address of instruction

    returns: 0 - no instruction at the specified location

    note: this function may not return exactly the same mnemonics as you see on the screen.

    So, if you want to see full mnemonic name you should use external dissasembler/plugin or parse disassembly line.