Improve tracing output

pull/7/head
Bernhard Mueller 7 years ago
parent a16907666f
commit 41912739ee
  1. 12
      myth
  2. 48
      mythril/ether/evm.py

12
myth

@ -14,7 +14,7 @@ import binascii
import sys
import argparse
import os
import re
def searchCallback(code_hash, code, addresses, balances):
print("Matched contract with code hash " + code_hash )
@ -103,12 +103,16 @@ elif (args.trace):
exitWithError("Disassembler: Provide the input bytecode via -c BYTECODE or --id ID")
if (args.data):
output = evm.trace(encoded_bytecode, args.address, args.data)
trace = evm.trace(encoded_bytecode, args.address, args.data)
else:
output = evm.trace(encoded_bytecode, args.address)
trace = evm.trace(encoded_bytecode, args.address)
print(output)
for i in trace:
if (re.match(r'^PUSH.*', i['op'])):
print(str(i['pc']) + " " + i['op'] + " " + i['pushvalue'] + ";\tSTACK: " + i['stack'])
else:
print(str(i['pc']) + " " + i['op'] + ";\tSTACK: " + i['stack'])
elif (args.search):

@ -4,7 +4,8 @@ from ethereum.slogging import get_logger
from mythril.ether import util
from logging import StreamHandler
from io import StringIO
import codecs
import re
def trace(code, calldata = ""):
@ -19,7 +20,7 @@ def trace(code, calldata = ""):
log_vm_op.setLevel("TRACE")
log_vm_op.addHandler(streamHandler)
addr = codecs.decode('0123456789ABCDEF0123456789ABCDEF01234567', 'hex_codec')
addr = bytes.fromhex('0123456789ABCDEF0123456789ABCDEF01234567')
state = State()
@ -33,4 +34,45 @@ def trace(code, calldata = ""):
ret = output.getvalue()
return ret
lines = ret.split("\n")
trace = []
for line in lines:
m = re.search(r'pc=b\'(\d+)\'.*op=([A-Z0-9]+)', line)
if m:
pc = m.group(1)
op = m.group(2)
m = re.match(r'.*stack=(\[.*?\])', line)
if (m):
stackitems = re.findall(r'b\'(\d+)\'', m.group(1))
stack = "[";
if (len(stackitems)):
for i in range(0, len(stackitems) - 1):
stack += hex(int(stackitems[i])) + ", "
stack += hex(int(stackitems[-1]))
stack += "]"
else:
stack = "[]"
if (re.match(r'^PUSH.*', op)):
val = re.search(r'pushvalue=(\d+)', line).group(1)
pushvalue = hex(int(val))
trace.append({'pc': pc, 'op': op, 'stack': stack, 'pushvalue': pushvalue})
else:
trace.append({'pc': pc, 'op': op, 'stack': stack})
return trace

Loading…
Cancel
Save