""" relevant strings "Bad key length (should be 16) " "Bad block length (should be 8) " "Decryption failure" "Called Uint2Str with negative int " "Cannot convert string of more than 4 bytes" "ERROR: securemsg.seal failed - ctx is undefined. securemsg must unseal something before sealing." "bad scope_hex.length " "Message too short for headers: " "scope doesn't match: " "message too short for payload: " "message too short for signature: " "Message failed integrity checks during unseal" "clntcap_success" "clntcap_frame" "TSURLCK_test=test_cookie_support" "TSURLCK_test" """ import os import sys import re import binascii re1ex="Z\((?P\w+)(?P(,\s*(\d*)\s*)+)\)" re2ex="S\((?P-?\d+),\s*(?P\w+)\)" re3ex="S\((?P0x[0-9A-Fa-f]+),\s*(?P\w+)\)" re4ex="parseInt\((?P\d+)((\s\+\s\[\])*),\s(?P\d*)\)" re5ex="z\((?P\d+)\)\s\?\s(?P[\d\s:]+)" def b36_encode(i): if i < 0: return "-" + b36_encode(-i) if i < 36: return "0123456789abcdefghijklmnopqrstuvwxyz"[i] return b36_encode(i // 36) + b36_encode(i % 36) def is_int(Val): try: int(Val) return True except: return False def decode1(varname=None,data=None,pre=None,default=None): rawline=data.replace("\n","").replace(" ","") if not is_int(varname): varassign="{} = (\d+)".format(varname) key=int(find_last(varassign,pre)) else: key=int(varname) vals=[int(v) for v in rawline.split(",")[1:]] res=bytearray([((v-key)&0xff) for v in vals]) try: return "\"{}\"".format(res.decode('utf-8')) except: return default def decode2(varname=None,val=None,pre=None,default=None): if not is_int(varname): varassign="{} = (\d+)".format(varname) key=int(find_last(varassign,pre)) else: key=int(varname) return "\"{}\"".format(b36_encode(int(val)+key)) def decode3(varname=None,val=None,pre=None,default=None): val=int(val.split("0x")[-1],16) return decode2(varname,val,pre,default) def decode4(val=None,base=None,pre=None,default=None): return "{}".format(int(val,int(base))) def decode5(varname=None,data=None,pre=None,default=None): data=data.replace("\n","").replace(" ","") vals=data.split(":") if (567>int(varname)): return vals[0] return vals[1] fixups=[ (re1ex,decode1), (re2ex,decode2), (re3ex,decode3), (re4ex,decode4), (re5ex,decode5), ] def find_last(regex,data): try: res=re.findall(regex,data) if type(res)==type([]): res=res[-1] return res except Exception as e: print("find_last {} - {} {}".format(e,regex,data)) return None with open(sys.argv[1],"r") as infile: data=infile.read() for r in fixups: while True: try: res=re.search(r[0],data ,re.MULTILINE) if not res: break pre=data[:res.start()] post=data[res.end():] data=pre+"{}".format(r[1](**res.groupdict(),pre=pre) )+post except Exception as e: print("Failed {}\nwith {}".format(e,res.groupdict())) print("line {}".format(res.group(0))) print("pre {}".format(pre[-60:])) sys.exit(-1) print(data)