Merge branch 'master' into version-option

pull/365/head
Bernhard Mueller 6 years ago
commit 3249cfff55
  1. 7
      mythril/disassembler/disassembly.py
  2. 22
      mythril/ether/ethcontract.py
  3. 11
      mythril/leveldb/client.py

@ -1,4 +1,4 @@
from mythril.ether import asm,util
from mythril.ether import asm, util
from mythril.support.signatures import SignatureDb
import logging
@ -7,7 +7,7 @@ class Disassembly(object):
def __init__(self, code):
self.instruction_list = asm.disassemble(util.safe_decode(code))
self.xrefs = []
self.func_hashes = []
self.func_to_addr = {}
self.addr_to_func = {}
self.bytecode = code
@ -24,6 +24,7 @@ class Disassembly(object):
for i in jmptable_indices:
func_hash = self.instruction_list[i]['argument']
self.func_hashes.append(func_hash)
try:
# tries local cache, file and optional online lookup
# may return more than one function signature. since we cannot probe for the correct one we'll use the first
@ -38,7 +39,7 @@ class Disassembly(object):
func_name = "_function_" + func_hash
try:
offset = self.instruction_list[i+2]['argument']
offset = self.instruction_list[i + 2]['argument']
jump_target = int(offset, 16)
self.func_to_addr[func_name] = jump_target

@ -31,12 +31,12 @@ class ETHContract(persistent.Persistent):
def get_easm(self):
return Disassembly(self.code).get_easm()
return self.disassembly.get_easm()
def matches_expression(self, expression):
easm_code = self.get_easm()
str_eval = ''
easm_code = None
matches = re.findall(r'func#([a-zA-Z0-9\s_,(\\)\[\]]+)#', expression)
@ -58,6 +58,9 @@ class ETHContract(persistent.Persistent):
m = re.match(r'^code#([a-zA-Z0-9\s,\[\]]+)#', token)
if (m):
if easm_code is None:
easm_code = self.get_easm()
code = m.group(1).replace(",", "\\n")
str_eval += "\"" + code + "\" in easm_code"
continue
@ -65,21 +68,8 @@ class ETHContract(persistent.Persistent):
m = re.match(r'^func#([a-fA-F0-9]+)#$', token)
if (m):
str_eval += "\"" + m.group(1) + "\" in easm_code"
str_eval += "\"" + m.group(1) + "\" in self.disassembly.func_hashes"
continue
return eval(str_eval.strip())
class InstanceList(persistent.Persistent):
def __init__(self):
self.addresses = []
self.balances = []
pass
def add(self, address, balance=0):
self.addresses.append(address)
self.balances.append(balance)
self._p_changed = True

@ -1,13 +1,11 @@
import plyvel
import binascii
import rlp
import hashlib
import logging
from ethereum import utils
from ethereum.block import BlockHeader, Block
from mythril.leveldb.state import State, Account
from mythril.leveldb.state import State
from mythril.leveldb.eth_db import ETH_DB
from mythril.ether.ethcontract import ETHContract, InstanceList
from mythril.ether.ethcontract import ETHContract
# Per https://github.com/ethereum/go-ethereum/blob/master/core/database_util.go
# prefixes and suffixes for keys in geth
@ -16,7 +14,8 @@ bodyPrefix = b'b' # bodyPrefix + num (uint64 big endian) + hash -> block b
numSuffix = b'n' # headerPrefix + num (uint64 big endian) + numSuffix -> hash
blockHashPrefix = b'H' # blockHashPrefix + hash -> num (uint64 big endian)
# known geth keys
headHeaderKey = b'LastBlock' # head (latest) header hash
headHeaderKey = b'LastBlock' # head (latest) header hash
def _formatBlockNumber(number):
'''
@ -24,12 +23,14 @@ def _formatBlockNumber(number):
'''
return utils.zpad(utils.int_to_big_endian(number), 8)
def _encode_hex(v):
'''
encodes hash as hex
'''
return '0x' + utils.encode_hex(v)
class EthLevelDB(object):
'''
Go-Ethereum LevelDB client class

Loading…
Cancel
Save