import os def find_hex_string_and_save_multiple_ascii(file_path, hex_string, size_to_extract=1024 * 1024, output_path='output_files/'): try: with open(file_path, 'rb') as f: search_bytes = bytes.fromhex(hex_string) content = f.read() offset = 0 match_count = 0 while True: offset = content.find(search_bytes, offset) if offset == -1: break offset += len(search_bytes) end_offset = offset + size_to_extract end_offset = min(end_offset, len(content)) extracted_data = content[offset:end_offset] ascii_data = extracted_data.decode('ascii', errors='ignore') output_file = f"{output_path}output_{match_count}.txt" with open(output_file, 'w') as out_f: out_f.write(ascii_data) print(f"Extracted data has been saved to {output_file}") offset = end_offset match_count += 1 except IOError as e: print(f"Unable to open file: {e}") if __name__ == '__main__': file_path = 'F:\Virtual Machines\Win10\Windows 10 x64-da1a05fb.vmem' hex_string = '6D6573736167655F656C656D5F6172726179' output_path = 'F:/1/' find_hex_string_and_save_multiple_ascii(file_path, hex_string, output_path=output_path)