# -*- coding:utf-8 -*- from capstone import * from capstone.x86 import * cs = Cs(CS_ARCH_X86, CS_MODE_64) cs.detail = True code = '\x8B\x87\x76\x98\x00\x00\xeb\x0b\x5b\x31\xc0\x31\xc9\x31\xd2\xb0\x0b\xcd\x80\xe8\xf0\xff\xff\xff\x2f\x62\x69\x6e\x2f\x73\x68' for insn in cs.disasm(code, 0x1000): print"0x%x:\t%s\t%s" % (insn.address,insn.mnemonic,insn.op_str) c = 0 for i in insn.operands: c+=1 print"\toperands[%d]:"%c if i.type == X86_OP_REG: print"\t\tREG=%s"%(insn.reg_name(i.value.reg))#获取寄存器的名称 if i.type == X86_OP_IMM: print"\t\tIMM=0x%x"%(i.value.imm)#获取立即数 if i.type == X86_OP_MEM:#如[rax+0x10]或[rax+rbx] if i.mem.base != 0: print"\t\tREG=%s"%(insn.reg_name(i.mem.base))#获取寄存器名称,即rax if i.mem.index != 0: print"\t\tIMM=0x%x"%(i.mem.index)#获取第二个寄存器名称,即rbx if i.mem.disp != 0: print"\t\tIMM=0x%x"%(i.mem.disp)#获取偏移量,即0x10