@@ -31,6 +31,22 @@ class Directory(NestedBuffer):
3131 ENTRY_SIZE = DirectoryEntry .ENTRY_SIZE
3232 FILE_CLASS = File
3333
34+ ZEN_GENERATION_IDS = {'Zen 1' : [b'\x00 \x09 \xBC ' , b'\x00 \x0A \xBC ' ],
35+ 'Zen 2' : [b'\x05 \x0B \xBC ' , b'\x01 \x0A \xBC ' ],
36+ 'Zen 3' : [b'\x01 \x0C \xBC ' , b'\x00 \x0C \xBC ' ],
37+ 'Zen 4' : [b'\x04 \x0D \xBC ' , b'\x0B \x0D \xBC ' ],
38+ 'Zen 4/5' : [b'\x03 \x0D \xBC ' ]
39+ }
40+
41+ @classmethod
42+ def get_possible_zen_generation (cls , zen_generation_id ):
43+ zen_generation = 'unknown'
44+ for possible_zen_generation in cls .ZEN_GENERATION_IDS :
45+ if zen_generation_id in cls .ZEN_GENERATION_IDS [possible_zen_generation ]:
46+ zen_generation = possible_zen_generation
47+
48+ return zen_generation
49+
3450 class ParseError (Exception ):
3551 pass
3652
@@ -43,6 +59,7 @@ def create_directories_if_not_exist(cls, offset, fet, zen_generation=None) -> Li
4359 # Recursively return or create and return found directories
4460
4561 if offset in fet .psptool .directories_by_offset :
62+ fet .psptool .directories_by_offset [offset ].update_zen_generation (fet , zen_generation )
4663 return [fet .psptool .directories_by_offset [offset ]]
4764 else :
4865 # 1. Create the immediate directory in front of us
@@ -69,6 +86,14 @@ def create_directories_if_not_exist(cls, offset, fet, zen_generation=None) -> Li
6986 for tertiary_directory_offset in directory .tertiary_directory_offsets :
7087 directory_body = fet .rom .get_bytes (tertiary_directory_offset , 32 )
7188 actual_tertiary_offset = int .from_bytes (directory_body [16 :20 ], 'little' )
89+ zen_generation_id = directory_body [21 :24 ]
90+ zen_generation = cls .get_possible_zen_generation (zen_generation_id )
91+ if zen_generation == 'unknown' :
92+ fet .psptool .ph .print_warning (f"Unknown { zen_generation_id = } " )
93+
94+ zen_generation_id = hex (int .from_bytes (directory_body [20 :24 ], 'little' ))
95+ zen_generation += f' (PSP ID { zen_generation_id } )'
96+
7297 # Resolve one more indirection
7398 tertiary_directories = cls .create_directories_if_not_exist (actual_tertiary_offset , fet , zen_generation )
7499 created_directories += tertiary_directories
@@ -198,6 +223,14 @@ def update_entry_fields(self, file: File, type_, size, offset):
198223 # 3. Update checksum
199224 self .update_checksum ()
200225
226+ def update_zen_generation (self , fet , zen_generation ):
227+ if zen_generation is not None :
228+ if zen_generation not in self .zen_generation :
229+ self .zen_generation += '\n ' + zen_generation
230+ for offset in self .secondary_directory_offsets :
231+ dir = fet .psptool .directories_by_offset [offset ]
232+ dir .update_zen_generation (fet , zen_generation )
233+
201234
202235class BiosDirectory (Directory ):
203236 DIRECTORY_MAGICS = [b'$BHD' , b'$BL2' ]
0 commit comments