def funcs(request): """ Returns: a FunExtract object extracted from a file """ settings.import_config() f = open(dir_path + request.param[0], 'r') cfg = tac_cfg.TACGraph.from_bytecode(f.read()) dataflow.analyse_graph(cfg) fun_extractor = function.FunctionExtractor(cfg) fun_extractor.extract() return fun_extractor, request.param[1], request.param[2], request.param[3]
def vandal_cfg(**kwargs): # logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO) # logging.getLogger().setLevel(logging.INFO) # logging.info("asd") settings.import_config(settings._CONFIG_LOC_) cfg = tac_cfg.TACGraph.from_bytecode(kwargs['input']) settings.import_config(settings._CONFIG_LOC_) dataflow.analyse_graph(cfg) kwargs['res']['res'] = exporter.CFGStringExporter(cfg).export()
period: flush the result_queue to result_list every period seconds run_sig: terminate when the Event run_sig is cleared. result_queue: the queue in which results accumulate before being flushed result_list: the final list of results. """ while run_sig.is_set(): time.sleep(period) while not result_queue.empty(): item = result_queue.get() result_list.append(item) # Main Body args = parser.parse_args() settings.import_config(args.config_file) # Override config file with any provided settings. if args.config is not None: pairs = [pair.split("=") for pair in args.config.replace(" ", "").split(",")] for k, v in pairs: settings.set_from_string(k, v) settings.max_iterations = args.max_iter settings.bailout_seconds = args.bail_time # Force analytics to be turned on. settings.collect_analytics = True log_level = logging.WARNING if args.quiet else logging.INFO + 1 log = lambda msg: logging.log(logging.INFO + 1, msg) logging.basicConfig(format='%(message)s', level=log_level)
# Parse the arguments. args = parser.parse_args() # Set up logger, with appropriate log level depending on verbosity. log_level = logging.WARNING if args.prolix: log_level = logging.DEBUG elif args.verbose: log_level = logging.INFO logging.basicConfig(format='%(levelname)s: %(message)s', level=log_level) if args.prettify: from termcolor import colored # Initialise settings. settings.import_config(settings._CONFIG_LOC_) settings.strict = args.strict def format_pc(pc): pc = "0x{:02x}".format(pc) if args.prettify: pc = colored(pc, PC_COL) return pc def format_opcode(opcode): op = "{:<6}".format(opcode.name) if args.prettify: if opcode.halts(): op = colored(op, OP_HALT_COL)
else: for line in f: func_name = line.strip() func_match = func_re.fullmatch(func_name) sig_match = sig_re.fullmatch(func_name) # Handle either the unencoded string or the four-byte selector if func_match is not None: interface[func_name] = ensure_0x(encode_sig(func_name).hex()) elif sig_match is not None: interface[func_name] = ensure_0x(func_name) interfaces[interface_file] = interface print() # Perform a minimal decompile and extract functions. settings.import_config() settings.extract_functions = True settings.mark_functions = False settings.max_iterations = 0 settings.analytics = False settings.merge_unreachable = False settings.remove_unreachable = False for contract_file in listdir(CONTRACTS_DIR): with open(join(CONTRACTS_DIR, contract_file), 'r') as f: print("{}".format(contract_file), end="") cfg = tac_cfg.TACGraph.from_bytecode(f) dataflow.analyse_graph(cfg) sigs = [func.signature for func in cfg.function_extractor.public_functions] # Pad any short signatures with leading zeroes until eight nibbles long.