Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import zipfile
import xxtea
import re
import os
# setXXTEAKeyAndSign
apk = zipfile.ZipFile("xxxx.apk", "r")
probe_file = []
for filename in apk.namelist():
if filename.endswith(".luac"):
print ('File:', filename)
if len(probe_file)==2:
sign = []
for i in range(len(probe_file[0])):
if probe_file[0][i]!=probe_file[1][i]:
sign= probe_file[0][:i]
print('Sign:', sign, len(sign))
key = []
pattern = re.compile("(\w+)\0")
for filename in apk.namelist():
if filename.endswith(""):
print ('File:', filename)
content =
pos = content.find(sign)
subcontent = content[pos-512:pos+512]
sign = sign.decode()
strlist = pattern.findall(subcontent.decode("ascii", "ignore"))
for index, found_str in enumerate(strlist):
if found_str==sign:
key = strlist[index-1].encode('ascii')
print('Key:', key)
for filename in apk.namelist():
if filename.endswith(".luac"):
content =
data = b''
data = xxtea.decrypt(content[len(sign):], key)
filename = os.path.splitext(filename)[0] + ".lua"
os.makedirs(os.path.dirname(filename), exist_ok=True)
with open(filename, 'wb') as decrypted_file:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment