Created
September 10, 2020 16:56
-
-
Save mzyy94/eadad9fc3fd66c91c15dfe874e955f8c to your computer and use it in GitHub Desktop.
Joying Allapp.pkg extractor
This file contains 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
#!/usr/bin/env python | |
# Copyright (C) 2020 Yuki MIZUNO | |
# SPDX-License-Identifier: GPL-3.0-only | |
from __future__ import print_function, unicode_literals | |
from argparse import ArgumentParser, FileType | |
from os import makedirs | |
from os.path import exists, join | |
from struct import unpack, calcsize | |
def unpack_input(fmt, f): | |
size = calcsize(fmt) | |
data = f.read(size) | |
return unpack(fmt, data) | |
def parse_args(): | |
parser = ArgumentParser() | |
parser.add_argument( | |
'-i', '--input', help='input file', type=FileType('rb'), required=True) | |
parser.add_argument( | |
'-o', '--output', help='output directory', default='./out') | |
return parser.parse_args() | |
def main(): | |
args = parse_args() | |
if not exists(args.output): | |
makedirs(args.output) | |
[count, start] = unpack_input("12xI48xI", args.input) | |
args.input.seek(start, 0) | |
for _ in range(count): | |
[entry_size, name_size] = unpack_input("4xI28xI", args.input) | |
name = args.input.read(name_size)[:-1].decode() | |
with open(join(args.output, name), 'wb') as f: | |
f.write(args.input.read(entry_size)) | |
padding = 4 - (args.input.tell() % 4) | |
args.input.seek(padding, 1) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment