def analyze_file(item): global pool_sem os.setpgrp() filename = item[0] db = item[1] use_symbol = item[2] depth = item[3] instruction_converter = item[4] analyzer = RadareFunctionAnalyzer(filename, use_symbol, depth) p = ThreadPool(1) res = p.apply_async(analyzer.analyze) try: result = res.get(120) except multiprocessing.TimeoutError: print("Aborting due to timeout:" + str(filename)) print( 'Try to modify the timeout value in DatabaseFactory instruction result = res.get(TIMEOUT)' ) os.killpg(0, signal.SIGKILL) except Exception: print("Aborting due to error:" + str(filename)) os.killpg(0, signal.SIGKILL) for func in result: DatabaseFactory.insert_in_db(db, pool_sem, result[func], filename, func, instruction_converter) analyzer.close() return 0
def embedd_function(self, filename, address): analyzer = RadareFunctionAnalyzer(filename, use_symbol=False, depth=0) functions = analyzer.analyze() instructions_list = None for function in functions: if functions[function]['address'] == address: instructions_list = functions[function]['filtered_instructions'] break if instructions_list is None: print("Function not found") return None converted_instructions = self.converter.convert_to_ids(instructions_list) instructions, length = self.normalizer.normalize_functions([converted_instructions]) embedding = self.embedder.embedd(instructions, length) return embedding
def analyze_file(item): global pool_sem os.setpgrp() filename = item[0] db = item[1] use_symbol = item[2] depth = item[3] instruction_converter = item[4] analyzer = RadareFunctionAnalyzer(filename, use_symbol, depth) p = ThreadPool(1) res = p.apply_async(analyzer.analyze) try: result = res.get(120) except multiprocessing.TimeoutError: print("Aborting due to timeout:" + str(filename)) print( 'Try to modify the timeout value in DatabaseFactory instruction result = res.get(TIMEOUT)' ) os.killpg(0, signal.SIGKILL) except Exception: print("Aborting due to error:" + str(filename)) os.killpg(0, signal.SIGKILL) # use the shortest function name (ex. __glibc_malloc, __malloc, malloc) dups = [] for f1 in result: for f2 in result: if f1 != f2 and result[f1]['address'] == result[f2][ 'address'] and len(f1) > len(f2): dups.append(f1) dups = set(dups) for func in result: if len(result[func]['filtered_instructions']) < 16 or func in dups: continue DatabaseFactory.insert_in_db(db, pool_sem, result[func], filename, func, instruction_converter) analyzer.close() return 0