Skip to content

Instantly share code, notes, and snippets.

@HarukaMa
Created September 21, 2021 17:43
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 HarukaMa/0772fc47311f6bbcb79ce3f84a7134d7 to your computer and use it in GitHub Desktop.
Save HarukaMa/0772fc47311f6bbcb79ce3f84a7134d7 to your computer and use it in GitHub Desktop.
geekbench plar
import bz2
import io
import os
from hashlib import sha1
from utils import read_uint32
plar = open("geekbench.plar", "rb")
dest = "./plar"
assert plar.read(4) == b"PRLA"
file_table_offset = read_uint32(plar.read(4))
file_table_size = read_uint32(plar.read(4))
plar.seek(file_table_offset, io.SEEK_SET)
while plar.tell() != file_table_offset + file_table_size:
filename_length = read_uint32(plar.read(4))
file_start_offset = read_uint32(plar.read(4))
uncompressed_file_size = read_uint32(plar.read(4))
compressed_file_size = read_uint32(plar.read(4))
file_sha1 = plar.read(20)
filename = plar.read(filename_length).decode()
next_ptr = plar.tell()
plar.seek(file_start_offset, io.SEEK_SET)
compressed_data = plar.read(compressed_file_size)
assert file_sha1 == sha1(compressed_data).digest()
if uncompressed_file_size != compressed_file_size:
uncompressed_data = bz2.decompress(compressed_data)
assert len(uncompressed_data) == uncompressed_file_size
else:
uncompressed_data = compressed_data
target_filename = f"{dest}/{filename}"
mkdir_target = "/".join(target_filename.split("/")[:-1])
os.makedirs(mkdir_target, exist_ok=True)
open(target_filename, "wb").write(uncompressed_data)
plar.seek(next_ptr, io.SEEK_SET)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment