Created
March 4, 2018 10:33
-
-
Save krzys-h/3ca6b39b616c9a8ad430b46843f18829 to your computer and use it in GitHub Desktop.
FunPack3D .wfa unpacker
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
import struct | |
import os | |
import sys | |
PACKAGE_HEADER = "<I" | |
FILE_HEADER = "<32sII" | |
print("FunPack 3D .WFA unpacker by krzys_h") | |
if len(sys.argv) != 2: | |
print("Usage: {} path_to_file.wfa".format(sys.argv[0])) | |
sys.exit(1) | |
file_path = sys.argv[1] | |
print("* Opening '{}'...".format(file_path)) | |
f = open(file_path, "rb") | |
print("* Parsing file list...") | |
file_count, = struct.unpack(PACKAGE_HEADER, f.read(struct.calcsize(PACKAGE_HEADER))) | |
print(" - The archive contains {} files".format(file_count)) | |
files = [] | |
for fileid in range(file_count): | |
filename, filestart, filesize = struct.unpack(FILE_HEADER, f.read(struct.calcsize(FILE_HEADER))) | |
filename = filename.split(b'\x00')[0].decode() | |
print(" - File '{}', size {}, starts at {}".format(filename, filesize, filestart)) | |
files.append((filename, filestart, filesize)) | |
datastart = f.tell() | |
print(" - Actual data starts at {}".format(datastart)) | |
target_dir = os.path.splitext(file_path)[0] | |
print("* Unpacking files into '{}'".format(target_dir)) | |
print(" - Create output directory") | |
os.mkdir(target_dir) | |
for filename, filestart, filesize in files: | |
print(" - {}".format(filename)) | |
f.seek(datastart + filestart) | |
outf = open(os.path.join(target_dir, filename), "wb") | |
outf.write(f.read(filesize)) | |
outf.close() | |
print("* Done") | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment