Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import argparse
- def split_dat_file(input_file):
- try:
- # Open the .DAT file in binary mode
- with open(input_file, 'rb') as file:
- data = file.read()
- # Define headers and initialize variables
- headers = [b'VAGp', b'XVAG']
- positions = []
- # Search for all occurrences of headers
- for header in headers:
- start = 0
- while (index := data.find(header, start)) != -1:
- positions.append((index, header))
- start = index + 1
- # Sort the positions by order of appearance
- positions.sort()
- # Extract files based on headers
- for i in range(len(positions)):
- start_index, header = positions[i]
- end_index = positions[i + 1][0] if i + 1 < len(positions) else len(data)
- # Extract file data
- file_data = data[start_index:end_index]
- extension = '.VAG' if header == b'VAGp' else '.XVAG'
- # Create output file name
- output_file = f'{os.path.splitext(input_file)[0]}_{i + 1}{extension}'
- # Write the extracted data to a new file
- with open(output_file, 'wb') as out_file:
- out_file.write(file_data)
- print(f"Created file: {output_file}")
- except Exception as e:
- print(f"Error: {e}")
- if __name__ == "__main__":
- parser = argparse.ArgumentParser(description="Split a .DAT file into multiple .VAG and .XVAG files.")
- parser.add_argument("input_file", help="Path to the input .DAT file")
- args = parser.parse_args()
- split_dat_file(args.input_file)
Add Comment
Please, Sign In to add comment