Trace now returns a string

pull/2/head
Bernhard Mueller 7 years ago
parent d1761aae51
commit 28efcf92b4
  1. 1
      .gitignore
  2. 6
      contractstorage.py
  3. 13
      ether/evm.py
  4. 11
      mythril

1
.gitignore vendored

@ -8,3 +8,4 @@ mythril.egg-info
build
dist
contracts.json
hunt*

@ -76,7 +76,7 @@ class ContractStorage:
return ret[0]['code']
def search(self, expression):
def search(self, expression, callback_func):
all_contracts = self.db.all()
@ -87,8 +87,6 @@ class ContractStorage:
sign_hash = utils.sha3(m)[:4].hex()
print(sign_hash)
expression = expression.replace(m, sign_hash)
for c in all_contracts:
@ -98,5 +96,5 @@ class ContractStorage:
contract = ETHContract(c['code'], instance['balance'])
if (contract.matches_expression(expression)):
print("Found contract:" + instance['address'])
callback_func(instance['address'])

@ -2,7 +2,7 @@ from ethereum import vm, messages, transactions
from ethereum.state import State
from ethereum.slogging import get_logger
from logging import StreamHandler
import sys
from io import StringIO
import codecs
from .util import safe_decode
@ -11,7 +11,8 @@ def trace(code, address = "", calldata = ""):
logHandlers = ['eth.vm.op', 'eth.vm.op.stack', 'eth.vm.op.memory', 'eth.vm.op.storage']
streamHandler = StreamHandler(sys.stdout)
output = StringIO()
streamHandler = StreamHandler(output)
for handler in logHandlers:
log_vm_op = get_logger(handler)
@ -29,3 +30,11 @@ def trace(code, address = "", calldata = ""):
message = vm.Message(addr_from, addr_to, 0, 21000, data, code_address=addr_to)
res, gas, dat = vm.vm_execute(ext, message, code)
streamHandler.flush()
# print(output.getvalue())
ret = output.getvalue()
return ret

@ -11,6 +11,9 @@ import argparse
from rpc.client import EthJsonRpc
def searchCallback(address):
print(address)
def exitWithError(message):
print(message)
sys.exit()
@ -86,15 +89,17 @@ elif (args.trace):
exitWithError("Disassembler: Provide the input bytecode via -c BYTECODE or --id ID")
if (args.data):
evm.trace(util.safe_decode(encoded_bytecode), args.address, args.data)
output = evm.trace(util.safe_decode(encoded_bytecode), args.address, args.data)
else:
evm.trace(util.safe_decode(encoded_bytecode), args.address)
output = evm.trace(util.safe_decode(encoded_bytecode), args.address)
print(output)
elif (args.search):
storage.search(args.search)
storage.search(args.search, searchCallback)
elif (args.init_db):
storage.initialize(args.rpchost, args.rpcport)

Loading…
Cancel
Save