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 from mythril.support.signatures import SignatureDb
import logging import logging
@ -7,7 +7,7 @@ class Disassembly(object):
def __init__(self, code): def __init__(self, code):
self.instruction_list = asm.disassemble(util.safe_decode(code)) self.instruction_list = asm.disassemble(util.safe_decode(code))
self.xrefs = [] self.func_hashes = []
self.func_to_addr = {} self.func_to_addr = {}
self.addr_to_func = {} self.addr_to_func = {}
self.bytecode = code self.bytecode = code
@ -24,6 +24,7 @@ class Disassembly(object):
for i in jmptable_indices: for i in jmptable_indices:
func_hash = self.instruction_list[i]['argument'] func_hash = self.instruction_list[i]['argument']
self.func_hashes.append(func_hash)
try: try:
# tries local cache, file and optional online lookup # 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 # 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 func_name = "_function_" + func_hash
try: try:
offset = self.instruction_list[i+2]['argument'] offset = self.instruction_list[i + 2]['argument']
jump_target = int(offset, 16) jump_target = int(offset, 16)
self.func_to_addr[func_name] = jump_target self.func_to_addr[func_name] = jump_target

@ -31,12 +31,12 @@ class ETHContract(persistent.Persistent):
def get_easm(self): def get_easm(self):
return Disassembly(self.code).get_easm() return self.disassembly.get_easm()
def matches_expression(self, expression): def matches_expression(self, expression):
easm_code = self.get_easm()
str_eval = '' str_eval = ''
easm_code = None
matches = re.findall(r'func#([a-zA-Z0-9\s_,(\\)\[\]]+)#', expression) 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) m = re.match(r'^code#([a-zA-Z0-9\s,\[\]]+)#', token)
if (m): if (m):
if easm_code is None:
easm_code = self.get_easm()
code = m.group(1).replace(",", "\\n") code = m.group(1).replace(",", "\\n")
str_eval += "\"" + code + "\" in easm_code" str_eval += "\"" + code + "\" in easm_code"
continue continue
@ -65,21 +68,8 @@ class ETHContract(persistent.Persistent):
m = re.match(r'^func#([a-fA-F0-9]+)#$', token) m = re.match(r'^func#([a-fA-F0-9]+)#$', token)
if (m): if (m):
str_eval += "\"" + m.group(1) + "\" in easm_code" str_eval += "\"" + m.group(1) + "\" in self.disassembly.func_hashes"
continue continue
return eval(str_eval.strip()) 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 binascii
import rlp import rlp
import hashlib
import logging import logging
from ethereum import utils from ethereum import utils
from ethereum.block import BlockHeader, Block 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.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 # Per https://github.com/ethereum/go-ethereum/blob/master/core/database_util.go
# prefixes and suffixes for keys in geth # 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 numSuffix = b'n' # headerPrefix + num (uint64 big endian) + numSuffix -> hash
blockHashPrefix = b'H' # blockHashPrefix + hash -> num (uint64 big endian) blockHashPrefix = b'H' # blockHashPrefix + hash -> num (uint64 big endian)
# known geth keys # known geth keys
headHeaderKey = b'LastBlock' # head (latest) header hash headHeaderKey = b'LastBlock' # head (latest) header hash
def _formatBlockNumber(number): def _formatBlockNumber(number):
''' '''
@ -24,12 +23,14 @@ def _formatBlockNumber(number):
''' '''
return utils.zpad(utils.int_to_big_endian(number), 8) return utils.zpad(utils.int_to_big_endian(number), 8)
def _encode_hex(v): def _encode_hex(v):
''' '''
encodes hash as hex encodes hash as hex
''' '''
return '0x' + utils.encode_hex(v) return '0x' + utils.encode_hex(v)
class EthLevelDB(object): class EthLevelDB(object):
''' '''
Go-Ethereum LevelDB client class Go-Ethereum LevelDB client class

Loading…
Cancel
Save