Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The . img files are sector - ordered raw 2 5 6 byte block images of a DEC RX 0 2 formatted floppy. 2 5

The .img files are sector-ordered raw 256 byte block images of a DEC RX02
formatted floppy. 256 bytes x 26 sectors x 77 tracks.
The disk was probably from a VAX running VMS.
CHM has no tools to decode these images to the file-level.
PLEASE WRITE A PYTHON SCRIPT TO HELP DECODE THESE .IMG FILES TO THE FILE LEVEL. BELOW IS A SCRIPT I MADE. PLEASE LET ME KNOW HOW I CAN FIX OR CHANGE IT:
import struct
import os
class ODS1Parser:
def __init__(self, image_path):
self.image_path = image_path
self.block_size =256 # Block size in bytes for RX02
def read_block(self, file, block_number):
file.seek(block_number * self.block_size)
return file.read(self.block_size)
def find_files(self, file, extension, start_block=37):
block_number = start_block
file_blocks ={}
while True:
block = self.read_block(file, block_number)
if not block:
break
if extension.encode() in block:
# Extract the filename and block number
start = block.find(extension.encode())-9
filename = block[start:start+12].decode('latin1').strip().replace('\x00','')
if filename.endswith(extension):
file_blocks[filename]= block_number
block_number +=1
return file_blocks
def parse_sector(self, block):
# Parsing sector assuming the data starts at byte 33 and ends at byte 289
data = block[33:289]
return data
def read_file(self, file, start_block):
content = b""
block_number = start_block
while True:
block = self.read_block(file, block_number)
if not block:
break
data = self.parse_sector(block)
if b'\x00'*256== data:
break
content += data
block_number +=1
return content
def format_content(self, content):
# This function attempts to format the content as LISP code
try:
return content.decode('latin1').replace('\xef\xbf\xbd','')
except Exception as e:
return str(e)
def parse_filesystem(self):
with open(self.image_path, 'rb') as file:
lsp_files = self.find_files(file,'.LSP',37)
lsp_contents ={}
for filename, start_block in lsp_files.items():
content = self.read_file(file, start_block)
formatted_content = self.format_content(content)
lsp_contents[filename]= formatted_content
return lsp_contents
def save_files(self, lsp_contents, output_dir):
os.makedirs(output_dir, exist_ok=True)
for filename, content in lsp_contents.items():
output_file_path = os.path.join(output_dir, filename)
with open(output_file_path, 'w') as f:
f.write(content)
print("Extracted: {}".format(filename))
# Example usage
parser = ODS1Parser('102719811_MYCIN/mycyn1.img')
lsp_contents = parser.parse_filesystem()
# Save the LSP files and their contents to the output directory
output_dir = 'extracted_lsp_files'
parser.save_files(lsp_contents, output_dir)
print(f"Extracted files are saved in the '{output_dir}' directory.")

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases And Python Programming MySQL MongoDB OOP And Tkinter

Authors: R. PANNEERSELVAM

1st Edition

9357011331, 978-9357011334

Students also viewed these Databases questions