|
|
|
@ -6,6 +6,7 @@ |
|
|
|
|
|
|
|
|
|
from ether import asm |
|
|
|
|
import sys |
|
|
|
|
import codecs |
|
|
|
|
import argparse |
|
|
|
|
import util |
|
|
|
|
|
|
|
|
@ -21,7 +22,7 @@ parser.add_argument('-d', '--disassemble', action='store_true', help='disassemb |
|
|
|
|
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('-t', '--transaction_hash', help='id of contract creation transaction') |
|
|
|
|
parser.add_argument('-o', '--outfile', help='file to write disassembly output to (e.g. "test.easm")') |
|
|
|
|
parser.add_argument('-o', '--outfile') |
|
|
|
|
parser.add_argument('--rpchost', nargs=1, help='RPC host') |
|
|
|
|
parser.add_argument('--rpcport', nargs=1, help='RPC port') |
|
|
|
|
|
|
|
|
@ -31,19 +32,19 @@ args = parser.parse_args() |
|
|
|
|
if (args.disassemble): |
|
|
|
|
|
|
|
|
|
if (args.code): |
|
|
|
|
disassembly = asm.disassemble(args.code[0]) |
|
|
|
|
encoded_bytecode = args.code[0] |
|
|
|
|
elif (args.transaction_hash): |
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
bytecode = util.bytecode_from_blockchain(args.transaction_hash) |
|
|
|
|
encoded_bytecode = util.bytecode_from_blockchain(args.transaction_hash) |
|
|
|
|
except Exception as e: |
|
|
|
|
exitWithError("Exception loading bytecode via RPC: " + str(e.message)) |
|
|
|
|
|
|
|
|
|
disassembly = asm.disassemble(bytecode) |
|
|
|
|
|
|
|
|
|
else: |
|
|
|
|
exitWithError("Disassembler: Pass either the -c or -t flag to specify the input bytecode") |
|
|
|
|
|
|
|
|
|
disassembly = asm.disassemble(util.safe_decode(encoded_bytecode)) |
|
|
|
|
|
|
|
|
|
easm_text = asm.disassembly_to_easm(disassembly) |
|
|
|
|
|
|
|
|
|
if (args.outfile): |
|
|
|
@ -57,7 +58,12 @@ elif (args.assemble): |
|
|
|
|
|
|
|
|
|
disassembly = asm.easm_to_disassembly(easm) |
|
|
|
|
|
|
|
|
|
print("0x" + asm.assemble(disassembly)) |
|
|
|
|
assembly = asm.assemble(disassembly) |
|
|
|
|
|
|
|
|
|
if (args.outfile): |
|
|
|
|
util.string_to_file(args.outfile, assembly) |
|
|
|
|
else: |
|
|
|
|
print("0x" + codecs.encode(assembly, "hex_codec")) |
|
|
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
|
|