def test_fail_safe_read_file_string_list(self): test_file_path = os.path.join(self.get_directory_of_current_file(), "data", "multiline_test.txt") lines = get_string_list_from_file(test_file_path) self.assertEqual( lines, ['first line', 'second line', 'th\ufffdrd line', '', 'first line'], "lines not correct")
def get_software_names(yara_file_path): scanned_software = [] for line in get_string_list_from_file(yara_file_path): line = line.strip() parts_of_line = line.split('=') if parts_of_line[0].strip() == 'software_name': software_name = parts_of_line[1].strip() software_name = software_name.replace('"', '') scanned_software.append(software_name) return scanned_software
def test_blacklist_generation(): tmp_dir = TemporaryDirectory() blacklist_file = os.path.join(tmp_dir.name, 'test.bl') output, return_code = execute_shell_command_get_return_code( '{} -o {} {}'.format(MAINSCRIPT, blacklist_file, TEST_DATA_DIR), timeout=60) assert return_code == 0 assert os.path.exists(blacklist_file) assert '6 files found' in output assert 'Blacklisting 5 unique files' in output blacklist_entries = get_string_list_from_file(blacklist_file) assert len(blacklist_entries) == 5 assert '2e3a5a43a8516b8cdac92161f890a68caa5ac5b820125378c586ac40fe45250f_287352' in blacklist_entries tmp_dir.cleanup()
def load_word_list(): word_list_file = os.path.join( get_parent_dir(get_dir_of_file(__file__)), 'internal/optimized_word_list.txt') return get_string_list_from_file(word_list_file)