Skip to content

Commit 2b3ed50

Browse files
committed
Improve PVD detection
Locate PVD properly if it's not the first entry in the volume descriptor table. An exception is thrown if PVD cannot be found. This should not happen for PSP ISOs though (that I know of...).
1 parent 6e8b3d4 commit 2b3ed50

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

redump_psp.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,16 @@
88
from sfo_info import get_sfo_info
99

1010

11-
def hexdump(data, print_offset):
11+
def hexdump(data, offset, size):
1212
dump = ""
13-
line_nb = len(data) // 0x10
13+
line_nb = size // 0x10
1414
for i in range(line_nb):
15-
line = f"{print_offset + i * 16:04x} : "
15+
line = f"{offset + i * 16:04x} : "
1616
for j in range(0x10):
17-
line += f"{data[i * 16 + j]:02X}"
17+
line += f"{data[offset + i * 16 + j]:02X}"
1818
line += " " if j == 0x7 else " "
19-
2019
line += " "
21-
r_line = data[i * 0x10: i * 0x10 + 0x10]
20+
r_line = data[offset + i * 0x10: offset + i * 0x10 + 0x10]
2221
line += "".join([chr(b) if 0x20 <= b <= 0x7F else "." for b in r_line])
2322
dump += line
2423
if i < line_nb - 1:
@@ -34,6 +33,7 @@ def read_in_chunks(file_object, chunk_size=1024):
3433
break
3534
yield data
3635

36+
filestream.seek(0)
3737
prev_crc32 = 0
3838
sha1 = hashlib.sha1()
3939
md5 = hashlib.md5()
@@ -47,15 +47,24 @@ def read_in_chunks(file_object, chunk_size=1024):
4747
md5.hexdigest().zfill(32))
4848

4949

50+
def get_pvd_dump(filestream):
51+
filestream.seek(0x8000)
52+
raw_sector = filestream.read(0x800)
53+
while raw_sector[0] != 0xFF:
54+
if raw_sector[6] == 0x1:
55+
return hexdump(raw_sector, 0x320, 0x60)
56+
raw_sector = filestream.read(0x800)
57+
raise Exception("Could not find PVD")
58+
59+
5060
def gen_psp_redump(iso, out):
5161
if not os.path.exists(iso):
5262
print(f"Unable to access {iso}")
5363
return
5464

5565
with open(iso, 'rb') as f:
5666
hashes = gen_hashes(f)
57-
f.seek(0x800 * 16 + 0x320) # Go to sector 16 + offset of PVD
58-
pvd_dump = hexdump(f.read(0x60), 0x320)
67+
pvd_dump = get_pvd_dump(f)
5968
size_b = os.stat(iso).st_size
6069
size_mb = round(size_b / (1024 * 1024))
6170
sfo_info = get_sfo_info(iso)

0 commit comments

Comments
 (0)