Some refactoring

pull/2/head
Bernhard Mueller 7 years ago
parent 6be089c9b7
commit 48948c4f7f
  1. 4
      code.easm
  2. 4
      e.asm
  3. 11
      ether/asm.py
  4. 1
      lol
  5. 18
      mythril.py

@ -0,0 +1,4 @@
PUSH2 0x4050
PUSH4 0x60708090
POP
POP

@ -0,0 +1,4 @@
PUSH1 0x60
PUSH1 0x40
POP
POP

@ -1,7 +1,6 @@
from ethereum import opcodes
import codecs
import re
import binascii
regex_PUSH = re.compile('^PUSH(\d*)$')
@ -108,9 +107,7 @@ def resolve_functions(disassembly):
return functions
def disassemble(encoded_bytecode):
bytecode = safe_decode(encoded_bytecode)
def disassemble(bytecode):
disassembly = []
i = 0
@ -145,7 +142,7 @@ def disassemble(encoded_bytecode):
def assemble(disassembly):
bytecode = ""
bytecode = b""
for instruction in disassembly:
@ -154,10 +151,10 @@ def assemble(disassembly):
except RuntimeError:
opcode = 0xbb
bytecode += binascii.hexlify(chr(opcode))
bytecode += chr(opcode)
if 'argument' in instruction:
bytecode += instruction['argument']
bytecode += codecs.decode(instruction['argument'], 'hex_codec')
return bytecode

1
lol

@ -0,0 +1 @@
```@PP

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

Loading…
Cancel
Save