forked from keystone-engine/keystone
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
python: add a sample code to get back @stat_count when ks_asm() fails…
…. see issue keystone-engine#228
- Loading branch information
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
|
||
|
||
|
||
|