Created
January 23, 2016 15:42
-
-
Save thebabush/bdfc0a81bf59f95c43fd to your computer and use it in GitHub Desktop.
Get ZIP file from Chrome CRX extension format
This file contains hidden or 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
# Because I was on Windows, without dd :) | |
import os | |
import struct | |
import sys | |
if len(sys.argv) != 3: | |
print "Usage:", sys.argv[0], "<crx file> <zip file>" | |
exit(0) | |
crx = open(sys.argv[1], "rb") | |
if crx.read(4) == "Cr24": | |
print "CRX File" | |
else: | |
print "Not a CRX File!" | |
exit(0) | |
version, pk_length, sig_length = struct.unpack("<lll", crx.read(4 * 3)) | |
print "Version:", version | |
print "Public key length:", pk_length | |
print "Signature length:", sig_length | |
crx.seek(pk_length + sig_length, os.SEEK_CUR) | |
zip_offset = crx.tell() | |
print "Zip offset:", zip_offset, "({0})".format(hex(zip_offset)) | |
crx.seek(0, os.SEEK_END) | |
file_size = crx.tell() | |
zip_size = file_size - zip_offset | |
print "Zip size:", zip_size, "({0})".format(hex(zip_size)) | |
crx.seek(zip_offset, os.SEEK_SET) | |
open(sys.argv[2], "wb").write(crx.read(zip_size)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment