-
-
Save anonymous/2a308eb7bddf9e6a2b7b880b829a9c92 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
PVD Dumper | |
Prints the Primary Volume Descriptor from a .bin file | |
""" | |
import string | |
# Take a BIN file and returns the contents of sector 16 | |
def get_sector16(filename): | |
with open(filename, 'rb') as f: | |
f.seek(0x8000, 0) # first 0x7FFF bytes are reserved space | |
sector = "" | |
beaidx = None | |
while f.tell() < 0xA000: | |
start = f.tell() | |
sector = f.read(2048) | |
if b"CD001" in sector: # Find CD001 in the sector | |
cdix = start + sector.index(b"CD001") - 1 # offset the sector to before ".CD001" | |
f.seek(cdix) | |
return f.read(2048) | |
if b"BEA01" in sector and beaidx is None: | |
beaidx = start + sector.index(b"BEA01") - 1 | |
if beaidx is not None: | |
f.seek(beaidx) | |
return f.read(2048) | |
return None | |
# Returns selected sector data in IsoBuster format | |
def format_sector(data, start, finish): | |
col_count = 1 | |
offset = start | |
output = [] | |
for b in data[start:finish]: | |
if col_count == 1: | |
row = "{:04X} : ".format(offset) | |
row_data = "" | |
row += "{:02X} ".format(b) | |
row_data += chr(b) if chr(b) in string.printable else "." | |
if col_count == 8: # extra gap in the center | |
row += " " | |
if col_count == 16: # end of the row | |
col_count = 0 # inc at end of loop | |
row += " " | |
row += row_data | |
output.append(row) | |
offset += 0x10 | |
col_count += 1 | |
if col_count > 1: # Append unfilled row | |
row = row.ljust(58, " ") | |
row += row_data | |
output.append(row) | |
return "\n".join(output) | |
def get_formatted_pvd(filename): | |
sector16 = get_sector16(filename) | |
if sector16 is None: | |
return None | |
return format_sector(sector16, 0x320, 0x320 + 6 * 16) | |
def main(): | |
import argparse | |
parser = argparse.ArgumentParser(description= | |
"Print Primary Volume Descriptor (PVD) from BIN file") | |
parser.add_argument("filename", help="filename for reading PVD data from") | |
args = parser.parse_args() | |
pvd = get_formatted_pvd(args.filename) | |
if pvd: | |
print(pvd) | |
else: | |
print("Error finding PVD") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment