def get_binary_and_file_name(self, uid): tmp = self._get_file_name_and_path_from_db(uid) if tmp is None: return None, None else: binary = get_binary_from_file(tmp['file_path']) return (binary, tmp['file_name'])
def get_binary_and_file_name( self, uid: str) -> Tuple[Optional[bytes], Optional[str]]: file_name = self._get_file_name_from_db(uid) if file_name is None: return None, None binary = get_binary_from_file( self.fs_organizer.generate_path_from_uid(uid)) return binary, file_name
def _get_query(query, query_file): if query is not None: search_query = query elif query_file is not None: search_query = get_binary_from_file(query_file).decode('utf-8', 'ignore') else: raise RuntimeError('No query given. Please specify a query with -q or -Q option') logging.debug('Search query is: {}'.format(search_query)) return search_query
def test_extraction(self): input_file = Path(TEST_DATA_DIR, 'raw.bin') unpacked_files, meta_data = self.unpacker.extract_files_from_file(str(input_file), self.tmp_dir.name) self.assertEqual(meta_data['number_of_ff_padded_sections'], 3) self.assertEqual(meta_data['number_of_lzma_streams'], 1) self.assertEqual(len(unpacked_files), 4) self.assertIn('{}/0x2f'.format(self.tmp_dir.name), unpacked_files) self.assertIn('{}/0x8d_lzma_decompressed'.format(self.tmp_dir.name), unpacked_files) decompressed_data = get_binary_from_file('{}/0x8d_lzma_decompressed'.format(self.tmp_dir.name)) self.assertEqual(decompressed_data, b'compressed_stream_data')
def test_get_list_of_binwalk_signatures(): binwalk_output = get_binary_from_file(TEST_FILE).decode('utf-8') result = get_list_of_binwalk_signatures(binwalk_output) assert len(result) == 8 assert '0 0x0 ELF, 64-bit LSB executable, AMD x86-64, version 1 (SYSV)' in result
def parse_log_file(log_file_path): return get_binary_from_file(log_file_path).decode(encoding='utf_8', errors='replace')