Fix bug in GCM implementation when writing more than one output ISO
@@ -209,9 +209,9 @@ class GCM:
new_file = FileEntry()
new_file.name = basename
new_file.file_path = file_path
- new_file.file_data_offset = None
+ # file_data_offset is used for ordering the files in the new ISO, so we give it a huge value so new files are placed after vanilla files.
+ new_file.file_data_offset = (1<<32)
new_file.file_size = data_len(file_data)
- new_file.vanilla_file_data_offset = (1<<32) # Order new files to be written after vanilla files in the ISO
parent_dir = self.get_dir_file_entry(dirname)
parent_dir.children.append(new_file)
@@ -341,7 +341,7 @@ class GCM:
file_entry for file_entry in self.file_entries
if not file_entry.is_dir
]
- file_entries_by_data_order.sort(key=lambda fe: fe.vanilla_file_data_offset)
+ file_entries_by_data_order.sort(key=lambda fe: fe.file_data_offset)
for file_entry in file_entries_by_data_order:
current_file_start_offset = self.output_iso.tell()
@@ -367,15 +367,15 @@ class GCM:
offset_in_file += size_to_read
file_entry_offset = self.fst_offset + file_entry.file_index*0xC
- file_entry.file_data_offset = current_file_start_offset
write_u32(self.output_iso, file_entry_offset+4, current_file_start_offset)
if file_entry.file_path in self.changed_files:
file_size = data_len(self.changed_files[file_entry.file_path])
else:
file_size = file_entry.file_size
- file_entry.file_size = file_size
write_u32(self.output_iso, file_entry_offset+8, file_size)
+ # Note: The file_data_offset and file_size fields of the FileEntry must not be updated, they refer only to the offset and size of the file data in the input ISO, not this output ISO.
+
self.output_iso.seek(current_file_start_offset + file_size)
self.align_output_iso_to_nearest(4)
@@ -403,7 +403,6 @@ class FileEntry:
self.children = []
else:
self.file_data_offset = file_data_offset_or_parent_fst_index
- self.vanilla_file_data_offset = file_data_offset_or_parent_fst_index
self.file_size = file_size_or_next_fst_index
self.parent = None
