99
1010
1111def hexdump (data , offset , size ):
12+ """Return hexdump string of given data in isobuster format."""
13+ def ascii_print (c ):
14+ return chr (c ) if 32 <= c <= 127 else "."
15+
1216 dump = ""
13- line_nb = size // 0x10
14- for i in range (line_nb ):
15- line = f"{ offset + i * 16 :04x} : "
16- for j in range (0x10 ):
17- line += f"{ data [offset + i * 16 + j ]:02X} "
18- line += " " if j == 0x7 else " "
19- line += " "
20- r_line = data [offset + i * 0x10 : offset + i * 0x10 + 0x10 ]
21- line += "" .join ([chr (b ) if 0x20 <= b <= 0x7F else "." for b in r_line ])
22- dump += line
23- if i < line_nb - 1 :
24- dump += "\n "
17+ for i in range (size // 0x10 ):
18+ line_offset = offset + i * 0x10
19+ line_data = data [line_offset : line_offset + 0x10 ]
20+
21+ line_format = "{:04X} :" + " {:02X}" * 8 + " " + " {:02X}" * 8
22+ dump += line_format .format (line_offset , * line_data )
23+ dump += " " + "" .join ([ascii_print (b ) for b in line_data ]) + "\n "
2524 return dump
2625
2726
2827def gen_hashes (filestream ):
29- def read_in_chunks (file_object , chunk_size = 1024 ):
28+ def read_in_chunks (file_object , chunk_size ):
3029 while True :
3130 data = file_object .read (chunk_size )
3231 if not data :
@@ -47,14 +46,16 @@ def read_in_chunks(file_object, chunk_size=1024):
4746 return (format (prev_crc32 & 0xFFFFFFFF , 'x' ).zfill (8 ),
4847 sha1 .hexdigest ().zfill (40 ),
4948 md5 .hexdigest ().zfill (32 ),
50- sha256 .hexdigest ())
49+ sha256 .hexdigest (). zfill ( 64 ) )
5150
5251
5352def get_pvd_dump (filestream ):
53+ # Locate PVD sector, starting from sector 0x10
54+ # See: https://wiki.osdev.org/ISO_9660#Volume_Descriptors
5455 filestream .seek (0x8000 )
5556 raw_sector = filestream .read (0x800 )
5657 while raw_sector [0 ] != 0xFF :
57- if raw_sector [6 ] == 0x1 :
58+ if raw_sector [0 ] == 0x01 :
5859 return hexdump (raw_sector , 0x320 , 0x60 )
5960 raw_sector = filestream .read (0x800 )
6061 raise Exception ("Could not find PVD" )
@@ -75,7 +76,7 @@ def gen_psp_redump(iso, out):
7576 dump = TEMPLATE .format (
7677 size_mb = size_mb , size_b = size_b ,
7778 md5 = hashes [2 ], sha1 = hashes [1 ], crc32 = hashes [0 ], sha256 = hashes [3 ],
78- pvd_hexdump = pvd_dump , sfo_info = sfo_info )
79+ pvd_hexdump = pvd_dump . strip ( ' \n ' ) , sfo_info = sfo_info )
7980 if out :
8081 with open (out , 'w' , encoding = 'utf8' ) as f :
8182 f .write (dump )
0 commit comments