Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions ssr200/convert_fat.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,10 @@ def _overwrite_field(entry: bytes) -> bytearray:
print("Skip due to invalid cluster chain:", e)
continue

# Remove the odd numbers
filtered = cluster_chain[0:-1:2]

for c2 in filtered:
for c2 in cluster_chain[:-1]:
cluster_start = cluster_to_offset(bpb, c2)
cluster_end = cluster_to_offset(bpb, c2+1)

for off in range(cluster_start, cluster_end, 0x20):
ret[off + 0 : off + 0x20] = _overwrite_field(ret[off + 0 : off + 0x20])
return ret
Expand Down Expand Up @@ -249,7 +247,10 @@ def get_cluster_chain(fat: bytes, first_cluster: int) -> list:
cur_entry = first_cluster
while True:
if cur_entry == 0:
raise ValueError("The cluster chain contains a zero.")
raise ValueError("The cluster chain contains a free cluster (0x0000).")

if cur_entry == 0xFFF7:
raise ValueError("The cluster chain contains a bad cluster (0xFFF7).")

if cur_entry < 0xFFF8 and cur_entry*2 + 2 > len(fat):
raise ValueError("Cluster chain outside the FAT range.")
Expand Down Expand Up @@ -375,4 +376,4 @@ def main():
convert_fat_image(in_file, out_file, enable_normalize)

if __name__ == "__main__":
main()
main()
Loading