# extract_cdpsts.py import numpy as np import sys from pathlib import Path # --- Configuration based on our analysis --- # The marker for "legacy" blocks, which include CDPSTS LEGACY_BLOCK_MARKER = 0x5A5A5A5A # The ID for the CDPSTS block name (from BLOCK_TYPE_MAP) CDPSTS_BLOCK_ID = 1397769283 # Offsets within the legacy block header LEGACY_NAME_OFFSET_WORDS = 17 LEGACY_SIZE_OFFSET_WORDS = 5 def extract_first_cdpsts_block(input_file: Path, output_file: Path): """ Finds the first CDPSTS block in the input file and writes it to the output file. """ if not input_file.is_file(): print(f"Error: Input file not found at '{input_file}'") return print(f"Loading data from '{input_file}'...") try: data_vector = np.fromfile(str(input_file), dtype=" start_index] if not next_block_starts.any(): print( "Found last CDPSTS block in file, cannot determine exact size." ) # Fallback to size from header, assuming it's the full block size # This is likely incorrect, but better than nothing. end_index = start_index + block_size_words else: end_index = next_block_starts[0] print(f"Extracting block from word {start_index} to {end_index}.") block_data = data_vector[start_index:end_index] print(f"Writing {block_data.size * 4} bytes to '{output_file}'...") with open(output_file, "wb") as f: f.write(block_data.tobytes()) print("Extraction complete.") return # Stop after the first one except IndexError: # This can happen if a marker is found too close to the end of the file continue print("No CDPSTS blocks were found in the file.") if __name__ == "__main__": if len(sys.argv) != 2: print("Usage: python extract_cdpsts.py ") sys.exit(1) input_path = Path(sys.argv[1]) output_path = Path("cdpsts_block_sample.out") extract_first_cdpsts_block(input_path, output_path)