Skip to content

Instantly share code, notes, and snippets.

/PVD_Dumper.py Secret

Created Feb 19, 2017
Embed
What would you like to do?
"""
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