From 7c0deddadb6983863f92a62a6d170a3d32161daa Mon Sep 17 00:00:00 2001 From: Bernhard Mueller Date: Mon, 12 Mar 2018 18:59:10 +0700 Subject: [PATCH] Add --solc-args option --- myth | 7 ++++--- mythril/ether/soliditycontract.py | 4 ++-- mythril/ether/util.py | 12 ++++++++++-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/myth b/myth index 5efa57e7..a4064dd6 100755 --- a/myth +++ b/myth @@ -81,6 +81,7 @@ utilities.add_argument('--solv', help='specify solidity compiler version. If not options = parser.add_argument_group('options') options.add_argument('--sync-all', action='store_true', help='Also sync contracts with zero balance') options.add_argument('--max-depth', type=int, default=12, help='Maximum recursion depth for symbolic execution') +options.add_argument('--solc-args', help='Extra arguments for solc') options.add_argument('--enable-physics', type=bool, default=False, help='enable graph physics simulation') options.add_argument('-v', type=int, help='log level (0-2)', metavar='LOG_LEVEL') @@ -95,6 +96,8 @@ rpc.add_argument('--infura-ropsten', action='store_true', help='Preset: Infura N # Get config values +args = parser.parse_args() + try: mythril_dir = os.environ['MYTHRIL_DIR'] except KeyError: @@ -130,8 +133,6 @@ else: # Parse cmdline args -args = parser.parse_args() - if not (args.search or args.init_db or args.hash or args.disassemble or args.graph or args.xrefs or args.fire_lasers or args.storage or args.truffle): parser.print_help() sys.exit() @@ -293,7 +294,7 @@ elif (len(args.solidity_file)): try: signatures.add_signatures_from_file(file, sigs) # Parse file for new function signatures - contract = SolidityContract(file, contract_name) + contract = SolidityContract(file, contract_name, solc_args=args.solc_args) logging.info("Analyzing contract %s:%s" % (file, contract.name)) diff --git a/mythril/ether/soliditycontract.py b/mythril/ether/soliditycontract.py index 568942ea..e9ffabf4 100644 --- a/mythril/ether/soliditycontract.py +++ b/mythril/ether/soliditycontract.py @@ -20,9 +20,9 @@ class SolidityFile: class SolidityContract(ETHContract): - def __init__(self, input_file, name=None): + def __init__(self, input_file, name=None, solc_args=None): - data = get_solc_json(input_file) + data = get_solc_json(input_file, solc_args=solc_args) self.solidity_files = [] diff --git a/mythril/ether/util.py b/mythril/ether/util.py index f79e51fe..be739949 100644 --- a/mythril/ether/util.py +++ b/mythril/ether/util.py @@ -16,10 +16,18 @@ def safe_decode(hex_encoded_string): return bytes.fromhex(hex_encoded_string) -def get_solc_json(file, solc_binary="solc"): +def get_solc_json(file, solc_binary="solc", solc_args=None): + + cmd = [solc_binary, "--combined-json", "bin,bin-runtime,srcmap-runtime", '--allow-paths', "."] + + if solc_args: + cmd.extend(solc_args.split(" ")) + + cmd.append(file) try: - p = Popen([solc_binary, "--combined-json", "bin,bin-runtime,srcmap-runtime", '--allow-paths', ".", file], stdout=PIPE, stderr=PIPE) + p = Popen(cmd, stdout=PIPE, stderr=PIPE) + stdout, stderr = p.communicate() ret = p.returncode