diff --git a/myth b/myth index 67a679c1..455a3c95 100755 --- a/myth +++ b/myth @@ -4,10 +4,11 @@ http://www.github.com/b-mueller/mythril """ -from mythril.ether import evm,util +from mythril.ether import evm from mythril.disassembler.disassembly import Disassembly from mythril.disassembler.callgraph import generate_callgraph from mythril.ether.contractstorage import get_persistent_storage +from mythril.ether.ethcontract import ETHContract from mythril.rpc.client import EthJsonRpc from mythril.ipc.client import EthIpc from ethereum import utils @@ -40,7 +41,7 @@ commands.add_argument('-t', '--trace', action='store_true', help='trace, use wit commands.add_argument('-g', '--graph', help='generate a call graph', metavar='OUTPUT_FILE') commands.add_argument('-l', '--fire-lasers', action='store_true', help='detect vulnerabilities, use with -c or -a') commands.add_argument('-s', '--search', help='search the contract database') -commands.add_argument('--xrefs', help='get xrefs from contract in database', metavar='CONTRACT_HASH') +commands.add_argument('--xrefs', action='store_true', help='get xrefs from a contract, use with -c or -a') commands.add_argument('--hash', help='calculate function signature hash', metavar='SIGNATURE') commands.add_argument('--init-db', action='store_true', help='initialize the contract database') @@ -70,7 +71,7 @@ if (args.v): if (0 <= args.v < 3): logging.basicConfig(level=[logging.NOTSET, logging.INFO, logging.DEBUG][args.v]) -if (args.disassemble or args.graph or args.fire_lasers): +if (args.disassemble or args.graph or args.fire_lasers or args.xrefs): if (args.code): encoded_bytecode = args.code @@ -118,8 +119,15 @@ if (args.disassemble or args.graph or args.fire_lasers): with open(args.graph, "w") as f: f.write(html) except Exception as e: + print("Error saving graph: " + str(e)) + elif (args.xrefs): + + contract = ETHContract(encoded_bytecode) + + print("\n".join(contract.get_xrefs())) + elif (args.fire_lasers): @@ -154,7 +162,7 @@ elif (args.trace): else: print(str(i['pc']) + " " + i['op'] + ";\tSTACK: " + i['stack']) -elif args.search or args.xrefs or args.init_db: +elif args.search or args.init_db: contract_storage = get_persistent_storage(db_dir) @@ -165,19 +173,6 @@ elif args.search or args.xrefs or args.init_db: except SyntaxError: exitWithError("Syntax error in search expression.") - elif (args.xrefs): - - try: - contract_hash = util.safe_decode(args.xrefs) - except binascii.Error: - exitWithError("Invalid contract hash.") - - try: - contract = contract_storage.get_contract_by_hash(contract_hash) - print("\n".join(contract.get_xrefs())) - except KeyError: - exitWithError("Contract not found in the database.") - elif (args.init_db): if args.ipc: contract_storage.initialize(args.rpchost, args.rpcport, args.rpctls, args.sync_all, args.ipc) diff --git a/mythril/disassembler/callgraph.py b/mythril/disassembler/callgraph.py index 1ca5f357..b6e5cd04 100644 --- a/mythril/disassembler/callgraph.py +++ b/mythril/disassembler/callgraph.py @@ -7,11 +7,11 @@ graph_html = ''' diff --git a/mythril/rpc/client.py b/mythril/rpc/client.py index 1678f66a..f5bd4aa2 100644 --- a/mythril/rpc/client.py +++ b/mythril/rpc/client.py @@ -1,5 +1,4 @@ import json -import warnings import requests from requests.adapters import HTTPAdapter diff --git a/static/mythril.html b/static/mythril.html index e8d19145..4dfd1546 100644 --- a/static/mythril.html +++ b/static/mythril.html @@ -2,11 +2,11 @@