Merge pull request #2 from b-mueller/optimize_search

Optimize search
pull/358/head
Bernhard Mueller 6 years ago committed by GitHub
commit c07ebde04c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      mythril/disassembler/disassembly.py
  2. 9
      mythril/ether/ethcontract.py

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

@ -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,7 +68,7 @@ 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

Loading…
Cancel
Save