Skip to content

Instantly share code, notes, and snippets.

@SomeKitten
Created May 19, 2023 02:12
Show Gist options
  • Select an option

  • Save SomeKitten/71c0abd0f0025ab293678f7cf89b2577 to your computer and use it in GitHub Desktop.

Select an option

Save SomeKitten/71c0abd0f0025ab293678f7cf89b2577 to your computer and use it in GitHub Desktop.
Extract files from FMapDat.dat found in Mario & Luigi: Dream Team. EXTREMELY FINECKY/HACKY AND UNFINISHED!!!
import os
# EDIT THESE TWO PATHS AS NEEDED
fmap_path = "./FMapDat.dat"
extract_dir = "./extract"
# EDIT THESE TWO PATHS AS NEEDED
os.makedirs(extract_dir, exist_ok=True)
fmap_file = open(fmap_path, "rb")
file_size = fmap_file.seek(0, 2)
fmap_file.seek(0)
origin = 0x0
index = 0x0
while True:
if origin > file_size: break
fmap_file.seek(origin)
while fmap_file.read(1) != b"\x68":
origin += 1
fmap_file.seek(origin)
fmap_file.seek(origin + 0x60)
offset = int.from_bytes(fmap_file.read(4), "little")
size = int.from_bytes(fmap_file.read(4), "little")
if size == 0:
print("End of file")
print(hex(origin))
print(hex(offset))
print(hex(size))
break
print(f"Offset: {offset:08X}")
print(f"Size: {size:08X}")
file_offset = origin + offset
f = open(extract_dir + "/" + str(f"{index:04d}_{file_offset:08X}") + ".bin", "wb")
fmap_file.seek(file_offset)
f.write(fmap_file.read(size))
f.close()
origin = fmap_file.tell()
print(f"Origin: {origin:08X}")
index += 1
fmap_file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment