Skip to content

Instantly share code, notes, and snippets.

@bbbradsmith
Created September 29, 2023 03:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bbbradsmith/1aacbac0aa27dfe318010cb69a569060 to your computer and use it in GitHub Desktop.
Save bbbradsmith/1aacbac0aa27dfe318010cb69a569060 to your computer and use it in GitHub Desktop.
Unpacks PAK files from the game Abyss Boat by Leaf
# dumps PAK files from the game Abyss Boat by Leaf
import os
import struct
def printable(d):
s = ""
for c in d: s += chr(c) if (c >= 0x20 and c <= 126) else '.'
return s
def printhex(d,space=" "):
s = ""
for c in d: s += ("%02X" % c) + space
return s
def printinspect(d):
return printhex(d) + " [" + printable(d) + "]"
def pak_contents(filename,unpack=True):
print("PAK contents: " + filename)
pak = open(filename,"rb").read()
# first 4 bytes are fourCC 'L','A','C',0
print("FourCC: " + printinspect(pak[0:4]))
# next is a file count
filecount = struct.unpack("<L",pak[4:8])[0]
print("File Offset Size --- %d files" % filecount)
# next is a file directory, 36 bytes each
for i in range(filecount):
o = 8 + (36 * i)
en = pak[o:o+28] # filename (28 bytes)
(es,eo) = struct.unpack("<LL",pak[o+28:o+36]) # file size, file offset (4 bytes each)
while en[-1] == 0x01: en = en[0:-1] # strip terminal 01
while en[-1] == 0x00: en = en[0:-1] # strip trailing zeroes
# the encoding seems to be ASCII with an XOR inversion, guessed it by assuming D1 = '.' from what looked like file extensions
en = bytes((x ^ 0xFF) for x in en)
en = printable(en)
print("%03d: %8X %8X [%s]" % (i,eo,es,en))
if unpack:
unpack_dir = filename[:-4] + '_' + filename[-3:]
if not os.path.exists(unpack_dir):
os.makedirs(unpack_dir)
open(os.path.join(unpack_dir,en),"wb").write(pak[eo:eo+es])
print("End of PAK.")
for (root,dirs,files) in os.walk("."):
for f in files:
if f.lower().endswith(".pak"):
pak_contents(os.path.join(root,f))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment