File: test_evm.py

package info (click to toggle)
capstone 5.0.7-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid
  • size: 58,212 kB
  • sloc: ansic: 96,103; cpp: 67,489; cs: 29,510; python: 25,829; pascal: 24,412; java: 15,582; ml: 14,473; makefile: 1,274; sh: 479; ruby: 386
file content (50 lines) | stat: -rwxr-xr-x 1,299 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python

# Capstone Python bindings, by Nguyen Anh Quynnh <aquynh@gmail.com>

from __future__ import print_function
from capstone import *
import sys

from xprint import to_hex

_python3 = sys.version_info.major == 3


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("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()

        except CsError as e:
            print("ERROR: %s" % e.__str__())


if __name__ == '__main__':
    test_class()