Created
November 17, 2018 18:07
-
-
Save LemonBoy/2903f324d9ed6d241ad93a01ffca8ebd to your computer and use it in GitHub Desktop.
Quick and dirty script to extract Quartus II .qar archives
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
# Quick and dirty script to extract Quartus II .qar archives | |
import os, sys, struct, zlib | |
buf = open(sys.argv[1], 'rb').read() | |
file_no = struct.unpack_from('<H', buf, 2)[0] | |
off = 4 | |
for _ in range(file_no): | |
(len, unk, filename_len) = struct.unpack_from('<IHH', buf, off) | |
content = buf[off + 8 + filename_len:off + 8 + filename_len + len] | |
if ord(buf[off + 8 + filename_len]) == 0x78 and \ | |
ord(buf[off + 8 + filename_len + 1]) == 0x9C: | |
content = zlib.decompress(content) | |
else: | |
print('Not Zlib') | |
assert(false) | |
fn = buf[off + 8: off + 8 + filename_len] | |
dest_fn = 'qar_content/' + fn | |
print('Extracting {}'.format((fn))) | |
try: | |
os.makedirs(os.path.dirname(dest_fn)) | |
except OSError: | |
pass | |
with open(dest_fn, 'w+b') as fp: | |
fp.write(content) | |
off += 8 + filename_len + len |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment