capstone/bindings/python/test_evm.py
Kevin Phoenix 8ce088bf58
Python2 leftovers v2 (#2395)
* Remove python2 leftovers
* Remove python2 references from BUILDING.txt
* Remove some leftover install3 references
* Update shebangs to python3
* Delete suite/test_corpus.py
2024-07-01 14:10:12 +08:00

48 lines
1.3 KiB
Python
Executable file

#!/usr/bin/env python3
# Capstone Python bindings, by Nguyen Anh Quynnh <aquynh@gmail.com>
from capstone import *
from xprint import to_hex
EVM_CODE = b"\x60\x61\x50"
all_tests = (
(CS_ARCH_EVM, 0, EVM_CODE, "EVM"),
)
def test_class():
address = 0x80001000
for (arch, mode, code, comment) in all_tests:
print("*" * 16)
print("Platform: %s" % comment)
print("Code: %s " % to_hex(code))
print("Disasm:")
try:
md = Cs(arch, mode)
md.detail = True
for i in md.disasm(code, address):
print("0x%x:\t%s\t%s" %(i.address, i.mnemonic, i.op_str))
if i.pop > 0:
print("\tPop: %u" %i.pop)
if i.push > 0:
print("\tPush: %u" %i.push)
if i.fee > 0:
print("\tGas fee: %u" %i.fee)
if len(i.groups) > 0:
print("\tGroups: ", end=''),
for m in i.groups:
print("%s " % i.group_name(m), end=''),
print()
print ("0x%x:\n" % (i.address + i.size))
except CsError as e:
print("ERROR: %s" % e.__str__())
if __name__ == '__main__':
test_class()