Security analysis tool for EVM bytecode. Supports smart contracts built for Ethereum, Hedera, Quorum, Vechain, Roostock, Tron and other EVM-compatible blockchains.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
mythril/ethcontract.py

47 lines
1.1 KiB

from ether import asm, util
import re
class ETHContract:
def __init__(self, code = "", balance = 0):
self.disassembly = asm.disassemble(util.safe_decode(code))
self.easm_code = asm.disassembly_to_easm(self.disassembly)
self.balance = balance
def matches_expression(self, expression):
str_eval = ""
tokens = re.split("( and | or )", expression, re.IGNORECASE)
for token in tokens:
if token == " and " or token == " or ":
str_eval += token
continue
m = re.match(r'^code\[([a-zA-Z0-9\s,]+)\]$', token)
if (m):
code = m.group(1).replace(",", "\\n")
str_eval += "\"" + code + "\" in self.easm_code"
continue
m = re.match(r'^balance\s*[=><]+\s*\d+$', token)
if (m):
str_eval += "self." + m.group(0)
continue
m = re.match(r'^func\[([a-zA-Z0-9\s,()]+)\]$', token)
if (m):
str_eval += "\"" + m.group(1) + "\" in self.easm_code"
continue
return eval(str_eval)