def __init__(self, code: str, enable_online_lookup: bool = False): self.bytecode = code self.instruction_list = asm.disassemble(util.safe_decode(code)) self.func_hashes = [] self.function_name_to_address = {} self.address_to_function_name = {} # open from default locations # control if you want to have online signature hash lookups signatures = SignatureDB(enable_online_lookup=enable_online_lookup) # Need to take from PUSH1 to PUSH4 because solc seems to remove excess 0s at the beginning for optimizing jump_table_indices = asm.find_op_code_sequence( [("PUSH1", "PUSH2", "PUSH3", "PUSH4"), ("EQ", )], self.instruction_list) for index in jump_table_indices: function_hash, jump_target, function_name = get_function_info( index, self.instruction_list, signatures) self.func_hashes.append(function_hash) if jump_target is not None and function_name is not None: self.function_name_to_address[function_name] = jump_target self.address_to_function_name[jump_target] = function_name
def __init__(self, code: str, enable_online_lookup: bool = False) -> None: """ :param code: :param enable_online_lookup: """ self.bytecode = code self.instruction_list = asm.disassemble(util.safe_decode(code)) self.func_hashes = [] # type: List[str] self.function_name_to_address = {} # type: Dict[str, int] self.address_to_function_name = {} # type: Dict[int, str] self.enable_online_lookup = enable_online_lookup self.assign_bytecode(bytecode=code)