Skip to content

Instantly share code, notes, and snippets.

@developerfromjokela
Created September 22, 2026 21:40
Show Gist options
  • Select an option

  • Save developerfromjokela/de143f2a0b05cd34c2e210b6edd6c650 to your computer and use it in GitHub Desktop.

Select an option

Save developerfromjokela/de143f2a0b05cd34c2e210b6edd6c650 to your computer and use it in GitHub Desktop.
Clarion Maps structure + decompressor of CMP files
import json
import os
import sys
import zlib
from pathlib import Path
if len(sys.argv) < 2:
print("Usage: python decompressor.py <Directory of MAP Data> (<optional output directory, default: same dir with map data>)")
BASE_PATH = sys.argv[1] or ""
SAVE_DIR = os.path.join(BASE_PATH, "uncompressed")
if len(sys.argv) == 3:
SAVE_DIR = sys.argv[2]
COMPR_LIST = []
with open(os.path.join(BASE_PATH, "CMP.LST"), "rb") as f:
string = ""
data = f.read()
count = 0
while count < len(data):
byte = bytes([data[count]])
if byte == b'\x00':
COMPR_LIST.append(string.replace("\\SystemSD\\", "").replace("\\", "/"))
string = ""
else:
string += byte.decode("ascii")
count += 1
if len(COMPR_LIST) == 0:
COMPR_LIST = ["REFER001/"]
if len(COMPR_LIST) == 1:
dir = COMPR_LIST[0]
COMPR_LIST = []
for itm in os.listdir(os.path.join(BASE_PATH, dir)):
if itm.endswith(".ind") or itm.endswith(".cmp"):
name = itm.replace(".ind", "").replace(".cmp", "")
if name not in COMPR_LIST:
COMPR_LIST.append(dir+name)
Path(SAVE_DIR).mkdir(parents=True, exist_ok=True)
for itm in COMPR_LIST:
zlib_offsets = []
FILE_PATH = os.path.join(SAVE_DIR, itm)
with open(os.path.join(BASE_PATH, f"{itm}.ind"), "rb") as f:
index_data = f.read()
uncmp_size = int.from_bytes(index_data[:4], "little")
cmp_size = int.from_bytes(index_data[4:8], "little")
blocks_size = int.from_bytes(index_data[8:9], "little")
meta_data = index_data[9:0x10]
offset = 0x10
while offset < len(index_data):
zlib_offsets.append(int.from_bytes(index_data[offset:offset + 4], "little"))
offset += 4
print(itm, "UNCOMP SIZE", uncmp_size, "COMP SIZE", cmp_size, "BLOCKS", blocks_size, meta_data,)
Path(FILE_PATH).mkdir(parents=True, exist_ok=True)
with open(os.path.join(FILE_PATH, "info.json"), "w") as f:
json.dump({
"uncompressed_size": uncmp_size,
"compressed_size": cmp_size,
"blocks_count": blocks_size,
"meta_data": meta_data.hex(),
}, f)
with open(os.path.join(BASE_PATH, f"{itm}.cmp"), "rb") as f:
comp_data = f.read()
for idx, block in enumerate(zlib_offsets):
offset_dat = comp_data[block:]
print(" >> Decompressing block", idx, end="")
data = zlib.decompress(offset_dat)
with open(os.path.join(FILE_PATH, f"data.bin"), "ab") as f:
f.write(data)

Directory Structure File

TOP SECTION

0x28 items (top level dirs)

2F 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 01 00 0F 00 00 00 00 00 00 00 00 00 00 00 78 05 00 00

Top Level Dir Record (starts from offset 0)

  • 0x00 - 0x12: File name
  • 0x14: Item ID
  • 0x16: Type, 1 = top directory, 2 = subdir?
  • 0x18: Children count
  • 0x24 - 0x28: Little endian, offset to children items
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment