Skip to content

Instantly share code, notes, and snippets.

@aquynh
Created August 12, 2015 07:31
Show Gist options
  • Save aquynh/295289cd96866a1e3bab to your computer and use it in GitHub Desktop.
Save aquynh/295289cd96866a1e3bab to your computer and use it in GitHub Desktop.
This sample shows how to use MASM syntax for Capstone X86
#!/usr/bin/env python
# Demo for MASM syntax of Capstone Python bindings
# By Nguyen Anh Quynnh
from __future__ import print_function
from capstone import *
X86_CODE32 = b"\xba\xcd\xab\x00\x00\x8d\x4c\x32\x08\x81\xc6\x34\x12\x00\x00"
md = Cs(CS_ARCH_X86, CS_MODE_32)
print(">> Intel syntax:")
for insn in md.disasm(X86_CODE32, 0x1000):
print("0x%x:\t%s\t%s" % (insn.address, insn.mnemonic, insn.op_str))
print()
# switch to MASM syntax
md.syntax = CS_OPT_SYNTAX_MASM
print(">> MASM syntax:")
for insn in md.disasm(X86_CODE32, 0x1000):
print("0x%x:\t%s\t%s" % (insn.address, insn.mnemonic, insn.op_str))
@Ou7law007
Copy link

Downgrading to 4.0.1 works for capstone.

Keystone also raises the same error for KS_OPT_SYNTAX_MASM. Not sure which version to downgrade to.

ks = Ks(KS_ARCH_X86, KS_MODE_32)
ks.syntax = KS_OPT_SYNTAX_MASM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment