Skip to content

Instantly share code, notes, and snippets.

@LemonBoy
Created November 17, 2018 18:07
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save LemonBoy/2903f324d9ed6d241ad93a01ffca8ebd to your computer and use it in GitHub Desktop.
Save LemonBoy/2903f324d9ed6d241ad93a01ffca8ebd to your computer and use it in GitHub Desktop.
Quick and dirty script to extract Quartus II .qar archives
# 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