Refactor & fix cmdline parsing

pull/2/head
Bernhard Mueller 7 years ago
parent ed7902cb5c
commit 95a8834f69
  1. 1
      .gitignore
  2. 19
      mythril.py
  3. 60
      test.easm
  4. 2
      util.py

1
.gitignore vendored

@ -1,5 +1,6 @@
.DS_Store .DS_Store
.python-version .python-version
__pycache__
*.pyc *.pyc
*.easm *.easm
*.asm *.asm

@ -19,12 +19,12 @@ def exitWithError(message):
parser = argparse.ArgumentParser(description='Ethereum VM bytecode assembler/ disassembler') 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('-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('-a', '--assemble', 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('-c', '--code', help='bytecode string ("6060604052...")', metavar='BYTECODE')
parser.add_argument('-t', '--transaction_hash', help='id of contract creation transaction') parser.add_argument('-t', '--transaction_hash', help='id of contract creation transaction')
parser.add_argument('-o', '--outfile') parser.add_argument('-o', '--outfile')
parser.add_argument('--rpchost', nargs=1, default='127.0.0.1', help='RPC host') parser.add_argument('--rpchost', default='127.0.0.1', help='RPC host')
parser.add_argument('--rpcport', nargs=1, default=8545, help='RPC port') parser.add_argument('--rpcport', type=int, default=[8545], help='RPC port')
args = parser.parse_args() args = parser.parse_args()
@ -32,13 +32,16 @@ args = parser.parse_args()
if (args.disassemble): if (args.disassemble):
if (args.code): if (args.code):
encoded_bytecode = args.code[0] encoded_bytecode = args.code
elif (args.transaction_hash): elif (args.transaction_hash):
try: 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: except Exception as e:
exitWithError("Exception loading bytecode via RPC: " + str(e.message)) exitWithError("Exception loading bytecode via RPC" + str(e.message))
else: else:
exitWithError("Disassembler: Pass either the -c or -t flag to specify the input bytecode") exitWithError("Disassembler: Pass either the -c or -t flag to specify the input bytecode")
@ -54,7 +57,7 @@ if (args.disassemble):
elif (args.assemble): elif (args.assemble):
easm = util.file_to_string(args.assemble[0]) easm = util.file_to_string(args.assemble)
disassembly = asm.easm_to_disassembly(easm) disassembly = asm.easm_to_disassembly(easm)

@ -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

@ -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. 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) trace = eth.traceTransaction(creation_tx_hash)

Loading…
Cancel
Save