-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextractor.py
More file actions
36 lines (27 loc) · 1.22 KB
/
Copy pathextractor.py
File metadata and controls
36 lines (27 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import configparser
# Create a ConfigParser object
config = configparser.ConfigParser()
# Read the configuration file
config.read('config.ini')
# Get the ROM path from the config
rom_path = config['ROM']['path']
# Loop through each FILE section
for FILE_section in config.sections():
if FILE_section.startswith('FILE'):
# Calculate the size to read based on start and end offsets
start_offset = int(config[FILE_section]['start_offset'], 16)
end_offset = int(config[FILE_section]['end_offset'], 16)
size = end_offset - start_offset + 1
# Open the ROM file in binary read mode
with open(rom_path, "rb") as f:
# Seek to the starting offset
f.seek(start_offset)
# Read the data from the starting offset to the ending offset
data = f.read(size)
# Write the data to the output file
output_file = config[FILE_section]['output_file']
with open(output_file, "wb") as out_file:
out_file.write(data)
print(f"Data extracted and saved to {output_file}")
# Inform the user that all FILEs have been extracted
print("All FILE data extracted successfully.")