Skip to content

Commit

Permalink
python: add a sample code to get back @stat_count when ks_asm() fails…
Browse files Browse the repository at this point in the history
…. see issue keystone-engine#228
  • Loading branch information
aquynh committed Jul 26, 2016
1 parent 961c2c8 commit 3aadf88
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions bindings/python/sample_asm_count.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env python

# By Nguyen Anh Quynh <[email protected]>, 2016
# Sample code for Keystone assembler engine.

# This shows how to get out of KsError the number of
# assembly instructions successfully compiled when error occur


from keystone import *

CODE = b"INC ecx; yyy; DEC edx" # input assembly with an invalid instruction

try:
# Initialize engine in X86-32bit mode
ks = Ks(KS_ARCH_X86, KS_MODE_32)
encoding, count = ks.asm(CODE)
print("%s = %s" %(CODE, encoding))
except KsError as e:
print("ERROR: %s" %e)
# get count via e.get_asm_count()
count = e.get_asm_count()
if count is not None:
# print out the number of instructions succesfully compiled
print("asmcount = %u" %e.get_asm_count())




0 comments on commit 3aadf88

Please sign in to comment.