diff --git a/.gitignore b/.gitignore index 1302f6cb..b9a86fc3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .DS_Store .python-version +__pycache__ *.pyc *.easm *.asm diff --git a/mythril.py b/mythril.py index ec702bb9..851000b6 100755 --- a/mythril.py +++ b/mythril.py @@ -19,12 +19,12 @@ def exitWithError(message): parser = argparse.ArgumentParser(description='Ethereum VM bytecode assembler/ disassembler') parser.add_argument('-d', '--disassemble', action='store_true', help='disassemble, use with -c or -t') -parser.add_argument('-a', '--assemble', nargs=1, help='produce bytecode from easm input file', metavar='INPUT FILE') -parser.add_argument('-c', '--code', nargs=1, help='bytecode string ("6060604052...")', metavar='BYTECODE') +parser.add_argument('-a', '--assemble', help='produce bytecode from easm input file', metavar='INPUT FILE') +parser.add_argument('-c', '--code', help='bytecode string ("6060604052...")', metavar='BYTECODE') parser.add_argument('-t', '--transaction_hash', help='id of contract creation transaction') parser.add_argument('-o', '--outfile') -parser.add_argument('--rpchost', nargs=1, default='127.0.0.1', help='RPC host') -parser.add_argument('--rpcport', nargs=1, default=8545, help='RPC port') +parser.add_argument('--rpchost', default='127.0.0.1', help='RPC host') +parser.add_argument('--rpcport', type=int, default=[8545], help='RPC port') args = parser.parse_args() @@ -32,13 +32,16 @@ args = parser.parse_args() if (args.disassemble): if (args.code): - encoded_bytecode = args.code[0] + encoded_bytecode = args.code elif (args.transaction_hash): try: - encoded_bytecode = util.bytecode_from_blockchain(args.transaction_hash, args.rpchost[0], args.rpcport[0]) + + encoded_bytecode = util.bytecode_from_blockchain(args.transaction_hash, args.rpchost, args.rpcport) + + print(encoded_bytecode) except Exception as e: - exitWithError("Exception loading bytecode via RPC: " + str(e.message)) + exitWithError("Exception loading bytecode via RPC" + str(e.message)) else: exitWithError("Disassembler: Pass either the -c or -t flag to specify the input bytecode") @@ -54,7 +57,7 @@ if (args.disassemble): elif (args.assemble): - easm = util.file_to_string(args.assemble[0]) + easm = util.file_to_string(args.assemble) disassembly = asm.easm_to_disassembly(easm) diff --git a/test.easm b/test.easm deleted file mode 100644 index cfae8b47..00000000 --- a/test.easm +++ /dev/null @@ -1,60 +0,0 @@ -PUSH1 0x60 -PUSH1 0x40 -MSTORE -CALLDATASIZE -ISZERO -PUSH1 0x0a -JUMPI -JUMPDEST -PUSH1 0x5a -PUSH1 0x00 -DUP1 -SLOAD -PUSH1 0xff -AND -ISZERO -ISZERO -EQ -DUP1 -PUSH1 0x20 -JUMPI -POP -CALLVALUE -PUSH1 0x00 -EQ -JUMPDEST -DUP1 -PUSH1 0x52 -JUMPI -POP -PUSH1 0x01 -SLOAD -PUSH20 0xffffffffffffffffffffffffffffffffffffffff -AND -PUSH1 0x00 -CALLVALUE -PUSH1 0x60 -DUP3 -DUP2 -DUP2 -DUP2 -DUP6 -DUP9 -DUP4 -CALL -SWAP4 -POP -POP -POP -POP -ISZERO -JUMPDEST -ISZERO -PUSH1 0x5c -JUMPI -PUSH1 0x02 -JUMP -JUMPDEST -STOP -JUMPDEST -JUMP diff --git a/util.py b/util.py index 8d1fc679..4e63c199 100644 --- a/util.py +++ b/util.py @@ -13,7 +13,7 @@ def bytecode_from_blockchain(creation_tx_hash, rpc_host='127.0.0.1', rpc_port=85 creation_tx_hash = ID of transaction that created the contract. """ - eth = EthJsonRpcWithDebug(rpc_host, rpc_port) + eth = EthJsonRpcWithDebug(rpc_host, 8545) trace = eth.traceTransaction(creation_tx_hash)