Skip to content

Instantly share code, notes, and snippets.

@aquynh
Created August 8, 2015 13:56
Show Gist options
  • Save aquynh/fa5c8aaa3cebbe2c8f3d to your computer and use it in GitHub Desktop.
Save aquynh/fa5c8aaa3cebbe2c8f3d to your computer and use it in GitHub Desktop.
# Test op_access feature of Capstone
from __future__ import print_function
from capstone import *
CODE = b"\x8d\x4c\x32\x08\x01\xd8"
md = Cs(CS_ARCH_X86, CS_MODE_32)
md.detail = True
for insn in md.disasm(CODE, 0x1000):
print("%s\t%s" % (insn.mnemonic, insn.op_str))
(regs_read, regs_write) = insn.regs_access()
if len(regs_read) > 0:
print("\tRegisters read:", end="")
for r in regs_read:
print(" %s" %(insn.reg_name(r)), end="")
print()
if len(regs_write) > 0:
print("\tRegisters modified:", end="")
for r in regs_write:
print(" %s" %(insn.reg_name(r)), end="")
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment