Skip to content

Instantly share code, notes, and snippets.

@CTCaer
Forked from SciresM/package1.py
Created January 22, 2018 13:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CTCaer/79389c6098df68335fb31833f781d5b8 to your computer and use it in GitHub Desktop.
Save CTCaer/79389c6098df68335fb31833f781d5b8 to your computer and use it in GitHub Desktop.
from struct import unpack as up, pack as pk
from binascii import unhexlify as uhx, hexlify as hx
from Crypto.Cipher import AES
from Crypto.Util import Counter
import sys
pk11key = uhx('') # Insert key here.
def string_to_ctr(ctr):
return Counter.new(128, initial_value=int(hx(ctr), 16))
def main(argc, argv):
if argc == 2:
out_fn = '%s.dec' % argv[1]
elif argc == 3:
out_fn = argv[2]
else:
print 'Usage: %s package1 out_fn' % argv[0]
sys.exit(1)
try:
with open(argv[1], 'rb') as f:
pk11 = f.read()
except IOError:
print 'Failed to read %s!' % argv[1]
sys.exit(1)
sz, padding, ctr = up('<I12s16s', pk11[0x3FE0:0x4000])
aes = AES.new(pk11key, AES.MODE_CTR, counter=string_to_ctr(ctr))
dec = aes.decrypt(pk11[0x4000:])
if not dec.startswith('PK11'):
print '%s is not a decryptable package1!' % argv[1]
sys.exit(1)
try:
with open(out_fn, 'wb') as f:
f.write(dec)
except IOError:
print 'Failed to write to %s' % out_fn
return 0
if __name__ == '__main__':
sys.exit(main(len(sys.argv), sys.argv))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment