4 from __future__
import print_function
7 from xprint
import to_hex, to_x, to_x_32
10 X86_CODE64 = b
"\x55\x48\x8b\x05\xb8\x13\x00\x00\xe9\xea\xbe\xad\xde\xff\x25\x23\x01\x00\x00\xe8\xdf\xbe\xad\xde\x74\xff"
11 X86_CODE16 = b
"\x8d\x4c\x32\x08\x01\xd8\x81\xc6\x34\x12\x00\x00\x05\x23\x01\x00\x00\x36\x8b\x84\x91\x23\x01\x00\x00\x41\x8d\x84\x39\x89\x67\x00\x00\x8d\x87\x89\x67\x00\x00\xb4\xc6\x66\xe9\xb8\x00\x00\x00\x67\xff\xa0\x23\x01\x00\x00\x66\xe8\xcb\x00\x00\x00\x74\xfc"
12 X86_CODE32 = b
"\x8d\x4c\x32\x08\x01\xd8\x81\xc6\x34\x12\x00\x00\x05\x23\x01\x00\x00\x36\x8b\x84\x91\x23\x01\x00\x00\x41\x8d\x84\x39\x89\x67\x00\x00\x8d\x87\x89\x67\x00\x00\xb4\xc6\xe9\xea\xbe\xad\xde\xff\xa0\x23\x01\x00\x00\xe8\xdf\xbe\xad\xde\x74\xff"
15 (CS_ARCH_X86, CS_MODE_16, X86_CODE16,
"X86 16bit (Intel syntax)",
None),
16 (CS_ARCH_X86, CS_MODE_32, X86_CODE32,
"X86 32 (AT&T syntax)", CS_OPT_SYNTAX_ATT),
17 (CS_ARCH_X86, CS_MODE_32, X86_CODE32,
"X86 32 (Intel syntax)",
None),
18 (CS_ARCH_X86, CS_MODE_64, X86_CODE64,
"X86 64 (Intel syntax)",
None),
23 if eflag == X86_EFLAGS_UNDEFINED_OF:
25 elif eflag == X86_EFLAGS_UNDEFINED_SF:
27 elif eflag == X86_EFLAGS_UNDEFINED_ZF:
29 elif eflag == X86_EFLAGS_MODIFY_AF:
31 elif eflag == X86_EFLAGS_UNDEFINED_PF:
33 elif eflag == X86_EFLAGS_MODIFY_CF:
35 elif eflag == X86_EFLAGS_MODIFY_SF:
37 elif eflag == X86_EFLAGS_MODIFY_ZF:
39 elif eflag == X86_EFLAGS_UNDEFINED_AF:
41 elif eflag == X86_EFLAGS_MODIFY_PF:
43 elif eflag == X86_EFLAGS_UNDEFINED_CF:
45 elif eflag == X86_EFLAGS_MODIFY_OF:
47 elif eflag == X86_EFLAGS_RESET_OF:
49 elif eflag == X86_EFLAGS_RESET_CF:
51 elif eflag == X86_EFLAGS_RESET_DF:
53 elif eflag == X86_EFLAGS_RESET_IF:
55 elif eflag == X86_EFLAGS_TEST_OF:
57 elif eflag == X86_EFLAGS_TEST_SF:
59 elif eflag == X86_EFLAGS_TEST_ZF:
61 elif eflag == X86_EFLAGS_TEST_PF:
63 elif eflag == X86_EFLAGS_TEST_CF:
65 elif eflag == X86_EFLAGS_RESET_SF:
67 elif eflag == X86_EFLAGS_RESET_AF:
69 elif eflag == X86_EFLAGS_RESET_TF:
71 elif eflag == X86_EFLAGS_RESET_NT:
73 elif eflag == X86_EFLAGS_PRIOR_OF:
75 elif eflag == X86_EFLAGS_PRIOR_SF:
77 elif eflag == X86_EFLAGS_PRIOR_ZF:
79 elif eflag == X86_EFLAGS_PRIOR_AF:
81 elif eflag == X86_EFLAGS_PRIOR_PF:
83 elif eflag == X86_EFLAGS_PRIOR_CF:
85 elif eflag == X86_EFLAGS_PRIOR_TF:
87 elif eflag == X86_EFLAGS_PRIOR_IF:
89 elif eflag == X86_EFLAGS_PRIOR_DF:
91 elif eflag == X86_EFLAGS_TEST_NT:
93 elif eflag == X86_EFLAGS_TEST_DF:
95 elif eflag == X86_EFLAGS_RESET_PF:
97 elif eflag == X86_EFLAGS_PRIOR_NT:
99 elif eflag == X86_EFLAGS_MODIFY_TF:
101 elif eflag == X86_EFLAGS_MODIFY_IF:
103 elif eflag == X86_EFLAGS_MODIFY_DF:
105 elif eflag == X86_EFLAGS_MODIFY_NT:
107 elif eflag == X86_EFLAGS_MODIFY_RF:
109 elif eflag == X86_EFLAGS_SET_CF:
111 elif eflag == X86_EFLAGS_SET_DF:
113 elif eflag == X86_EFLAGS_SET_IF:
121 print(comment, end=
' '),
123 print(
"0x%02x " % c, end=
''),
127 print(
"0x%x:\t%s\t%s" % (insn.address, insn.mnemonic, insn.op_str))
140 print(
"\trex: 0x%x" % (insn.rex))
143 print(
"\taddr_size: %u" % (insn.addr_size))
146 print(
"\tmodrm: 0x%x" % (insn.modrm))
149 if insn.modrm_offset != 0:
150 print(
"\tmodrm_offset: 0x%x" % (insn.modrm_offset))
153 print(
"\tdisp: 0x%s" %
to_x_32(insn.disp))
156 if insn.disp_offset != 0:
157 print(
"\tdisp_offset: 0x%x" % (insn.disp_offset))
160 if insn.disp_size != 0:
161 print(
"\tdisp_size: 0x%x" % (insn.disp_size))
164 if (mode & CS_MODE_16 == 0):
166 print(
"\tsib: 0x%x" % (insn.sib))
168 if insn.sib_base != 0:
169 print(
"\t\tsib_base: %s" % (insn.reg_name(insn.sib_base)))
170 if insn.sib_index != 0:
171 print(
"\t\tsib_index: %s" % (insn.reg_name(insn.sib_index)))
172 if insn.sib_scale != 0:
173 print(
"\t\tsib_scale: %d" % (insn.sib_scale))
176 if insn.xop_cc != X86_XOP_CC_INVALID:
177 print(
"\txop_cc: %u" % (insn.xop_cc))
180 if insn.sse_cc != X86_SSE_CC_INVALID:
181 print(
"\tsse_cc: %u" % (insn.sse_cc))
184 if insn.avx_cc != X86_AVX_CC_INVALID:
185 print(
"\tavx_cc: %u" % (insn.avx_cc))
189 print(
"\tavx_sae: TRUE")
192 if insn.avx_rm != X86_AVX_RM_INVALID:
193 print(
"\tavx_rm: %u" % (insn.avx_rm))
195 count = insn.op_count(X86_OP_IMM)
197 print(
"\timm_count: %u" % count)
198 for i
in range(count):
199 op = insn.op_find(X86_OP_IMM, i + 1)
200 print(
"\t\timms[%u]: 0x%s" % (i + 1,
to_x(op.imm)))
201 if insn.imm_offset != 0:
202 print(
"\timm_offset: 0x%x" % (insn.imm_offset))
203 if insn.imm_size != 0:
204 print(
"\timm_size: 0x%x" % (insn.imm_size))
206 if len(insn.operands) > 0:
207 print(
"\top_count: %u" %
len(insn.operands))
209 for i
in insn.operands:
211 if i.type == X86_OP_REG:
212 print(
"\t\toperands[%u].type: REG = %s" % (c, insn.reg_name(i.reg)))
213 if i.type == X86_OP_IMM:
214 print(
"\t\toperands[%u].type: IMM = 0x%s" % (c,
to_x(i.imm)))
215 if i.type == X86_OP_MEM:
216 print(
"\t\toperands[%u].type: MEM" % c)
217 if i.mem.segment != 0:
218 print(
"\t\t\toperands[%u].mem.segment: REG = %s" % (c, insn.reg_name(i.mem.segment)))
220 print(
"\t\t\toperands[%u].mem.base: REG = %s" % (c, insn.reg_name(i.mem.base)))
222 print(
"\t\t\toperands[%u].mem.index: REG = %s" % (c, insn.reg_name(i.mem.index)))
224 print(
"\t\t\toperands[%u].mem.scale: %u" % (c, i.mem.scale))
226 print(
"\t\t\toperands[%u].mem.disp: 0x%s" % (c,
to_x(i.mem.disp)))
229 if i.avx_bcast != X86_AVX_BCAST_INVALID:
230 print(
"\t\toperands[%u].avx_bcast: %u" % (c, i.avx_bcast))
233 if i.avx_zero_opmask:
234 print(
"\t\toperands[%u].avx_zero_opmask: TRUE" % (c))
236 print(
"\t\toperands[%u].size: %u" % (c, i.size))
238 if i.access == CS_AC_READ:
239 print(
"\t\toperands[%u].access: READ\n" % (c))
240 elif i.access == CS_AC_WRITE:
241 print(
"\t\toperands[%u].access: WRITE\n" % (c))
242 elif i.access == CS_AC_READ | CS_AC_WRITE:
243 print(
"\t\toperands[%u].access: READ | WRITE\n" % (c))
245 (regs_read, regs_write) = insn.regs_access()
247 if len(regs_read) > 0:
248 print(
"\tRegisters read:", end=
"")
250 print(
" %s" %(insn.reg_name(r)), end=
"")
253 if len(regs_write) > 0:
254 print(
"\tRegisters modified:", end=
"")
256 print(
" %s" %(insn.reg_name(r)), end=
"")
261 for i
in range(0,46):
262 if insn.eflags & (1 << i):
264 print(
"\tEFLAGS: %s" % (
','.join(p
for p
in updated_flags)))
270 for (arch, mode, code, comment, syntax)
in all_tests:
272 print(
"Platform: %s" % comment)
273 print(
"Code: %s" %
to_hex(code))
280 if syntax
is not None:
283 for insn
in md.disasm(code, 0x1000):
286 print (
"0x%x:\n" % (insn.address + insn.size))
288 print(
"ERROR: %s" % e)
291 if __name__ ==
'__main__':
def print_insn_detail(mode, insn)
def get_eflag_name(eflag)
def to_hex(s, prefix_0x=True)