diff --git a/mythril/disassembler/disassembly.py b/mythril/disassembler/disassembly.py index 9f8aff89..2f7aec4c 100644 --- a/mythril/disassembler/disassembly.py +++ b/mythril/disassembler/disassembly.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 diff --git a/mythril/ether/ethcontract.py b/mythril/ether/ethcontract.py index 7c012f25..8e19c746 100644 --- a/mythril/ether/ethcontract.py +++ b/mythril/ether/ethcontract.py @@ -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