-
-
Save gavz/7f0eefb143522612ce83777ea38d5b53 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # this IDAPython code can be used to disassembly an instruction | |
| instruction = ida_ua.insn_t() | |
| idaapi.decode_insn(instruction, address) | |
| disassembly = f"{hex(instruction.ea)} {instruction.get_canon_mnem()} " | |
| for i, op in enumerate(instruction.ops): | |
| if op.type == ida_ua.o_void: | |
| continue | |
| if i > 0: | |
| disassembly += ", " | |
| if op.type == ida_ua.o_reg: | |
| reg_name = ida_idp.get_reg_name(op.reg, ida_ua.get_dtype_size(op.dtype)) | |
| disassembly += f"{reg_name}" | |
| elif op.type == ida_ua.o_phrase: | |
| scale = (op.specflag2 >> 6) & 3 | |
| index = (op.specflag2 >> 3) & 7 | |
| base = op.specflag2 & 7 | |
| reg_name = ida_idp.get_reg_name(base, ida_ua.get_dtype_size(op.dtype)) | |
| reg_idx = ida_idp.get_reg_name(index, ida_ua.get_dtype_size(op.dtype)) | |
| disassembly += f"[{reg_name} + {reg_idx}*{1 << scale}]" | |
| elif op.type == ida_ua.o_displ: | |
| scale = (op.specflag2 >> 6) & 3 | |
| index = (op.specflag2 >> 3) & 7 | |
| base = op.specflag2 & 7 | |
| reg_name = ida_idp.get_reg_name(base, ida_ua.get_dtype_size(op.dtype)) | |
| reg_idx = ida_idp.get_reg_name(index, ida_ua.get_dtype_size(op.dtype)) | |
| disassembly += f"[{reg_name} + {reg_idx}*{1 << scale} + {op.addr:x}]" | |
| elif op.type == ida_ua.o_imm: | |
| disassembly += f"{hex(op.value)}" | |
| print(disassembly) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment