Created
December 8, 2021 04:37
-
-
Save loveemu/9b663463b375be862586a0d6424230c1 to your computer and use it in GitHub Desktop.
Unpacker for Alice in Cyberland "ALICE.PAC" (Playstation)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Unpacker for Alice in Cyberland "ALICE.PAC" (Playstation)""" | |
import argparse | |
import dataclasses | |
import struct | |
from typing import BinaryIO | |
# ALICE.PAC archive format: | |
# File info table | |
# (name, offset, length) | |
# (0, 0, 0) -- terminator | |
# File data | |
@dataclasses.dataclass | |
class FileRecord: | |
name: str | |
offset: int | |
length: int | |
parser = argparse.ArgumentParser(description=__doc__) | |
parser.add_argument('file', type=argparse.FileType('rb'), help='PAC file to be unpacked') | |
args = parser.parse_args() | |
pac_file: BinaryIO = args.file | |
files_info: list[FileRecord] = [] | |
while True: | |
name_bytes, offset, length = struct.unpack('<12sLL', pac_file.read(20)) | |
name = name_bytes.rstrip(b'\0').decode() | |
if not name: | |
break | |
files_info.append(FileRecord(name=name, offset=offset, length=length)) | |
# extract all files | |
for f in files_info: | |
pac_file.seek(f.offset) | |
data = pac_file.read(f.length) | |
with open(f.name, 'wb') as out_file: | |
out_file.write(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment