def __decrypt_string(self, s, key, level, encrypt): if (encrypt >= level): return xxtea.decrypt(s, key) else: return s
def test_urandom(self): for i in range(2048): key = os.urandom(16) data = os.urandom(i) enc = xxtea.encrypt(data, key) dec = xxtea.decrypt(enc, key) self.assertEqual(data, dec) data = b'\0' * i enc = xxtea.encrypt(data, key) dec = xxtea.decrypt(enc, key) self.assertEqual(data, dec)
def test_zero_bytes(self): for i in range(2048): data = b'\0' * i key = os.urandom(16) enc = xxtea.encrypt(data, key) dec = xxtea.decrypt(enc, key) self.assertEqual(data, dec) key = b'\0' * 16 enc = xxtea.encrypt(data, key) dec = xxtea.decrypt(enc, key) self.assertEqual(data, dec)
def test(info: str, key: str): print('\nKey: {}\nCipher: {}'.format(key, info)) cipher = auth_base64.decode(info) plain = xxtea.decrypt(cipher, key.encode()) print('Plain text: {}'.format(json.loads(plain))) cipher2 = xxtea.encrypt(plain, key.encode()) print('encrypt(decrypt(Cipher)) == Cipher: {}'.format(cipher == cipher2))
def test_encrypt_nopadding_zero(self): key = os.urandom(16) for i in (8, 12, 16, 20): data = b'\0' * i enc = xxtea.encrypt(data, key, padding=False) dec = xxtea.decrypt(enc, key, padding=False) self.assertEqual(data, dec)
def main(path, key, force=False): result = [] targets = find_targets(path) for target in targets: out = target[:-1] if os.path.exists(out) and force: click.secho( "file is existed, please use `-f` to overwrite it: {}".format( out), fg="yellow") result.append(out) continue content = open(target, "rb").read() if key: content = xxtea.decrypt(content, key) if content[:2] == b'\037\213': try: mock_fp = BytesIO(content) gz = GzipFile(fileobj=mock_fp) content = gz.read() except Exception as e: import traceback click.secho("ungz fault {} in {}".format( e, traceback.format_tb(sys.exc_info()[2])[-1]), fg="red") with open(out, 'wb') as _: _.write(content) click.secho("decrypt successful: {}".format(out), fg="green") result.append(out) return result
def decrypt(filePath, key): """ 核心为XXtea 附zip/gzip压缩 :param filePath: 文件目录 :param key: xxteaKey :return: None """ if len(key) < 16: key += "".join("\0" * (16 - len(key))) # key填充 data = read_jsc_file(path=filePath) dec_data = xxtea.decrypt(data=data, key=key, padding=False) if dec_data[:2] == b"PK": fio = BytesIO(dec_data) fzip = zipfile.ZipFile(file=fio) dec_data = fzip.read(fzip.namelist()[0]).decode("utf-8") elif dec_data[:2] == b"\x1f\x8b": dec_data = bytes(zlib.decompress(dec_data, 16 + zlib.MAX_WBITS)).decode("utf-8") else: try: dec_data = bytes(dec_data).decode("utf-8") except UnicodeDecodeError: ColorPrinter.print_blue_text( " This file looks like have some unknown byte, try save as unknown files" ) return dec_data
def main(): global myStr, it #print('debut') #print('Attente de message') encryptedData = bytes(readUARTMessage()) #print('decryptage du message : '+encryptedData.decode('utf-8')) decrypted = xxtea.decrypt(encryptedData, key) #print('message decrypte : '+decrypted) finalRet = parseX(str(decrypted)) #print('enleve les x : '+finalRet) if (len(finalRet) != 0): print('ajout dans le buffer de ' + str(finalRet)) myStr += str(finalRet) for sep in str(finalRet): if sep == ';': it += 1 print('nb données dans buffer :' + str(it)) if it >= 50: myStr = myStr.replace("\'", "") myStr = myStr.replace("b", "") print('envoie dans la queue de P2 : ' + str(myStr)) bufferPost.put(myStr) bufferIoT.put(myStr) myStr = "" it = 0
def decrypt(buffer, bsig, bkey): if bsig: sig_len = len(bsig) if buffer[0: sig_len] != bsig: return buffer buffer = buffer[sig_len:] return xxtea.decrypt(buffer, bkey, padding=False)
def decrypt(filePath, key, sign): """The main process to decryption.""" data = read_luac_file(path=filePath) # 1.xxtea decrypt dec_data = xxtea.decrypt(data=data[len(sign):], key=key[:16], padding=False,rounds=0) # 2.determine file type dec_data = bytes(dec_data) return dec_data
def test_urandom(self): for i in range(2048): key = os.urandom(16) data = os.urandom(i) enc = xxtea.encrypt(data, key) dec = xxtea.decrypt(enc, key) self.assertEqual(data, dec)
def jiemi(content): # xxtex解密 xxt = xxtea.decrypt(content,'abcxyz1234567890') mw = str(xxt[-40:], 'utf-8') js = json.loads(xxt[:-40]) dic = dictPaixu(js) if mw == hxz(dic): return js else: False
def unlock_wallet(): with open(os.path.join(os.path.join(os.getcwd(), 'test.tau')), 'rb') as f: encrypted_wallet = f.read() password = getpass('Enter the password to unlock the wallet: ') signing_key = xxtea.decrypt(encrypted_wallet, password) UNLOCKED_WALLET = signing_key print(UNLOCKED_WALLET)
def decryptFile(fname, key): uKey = bytes(key, encoding='utf-8') with open(fname, 'r+b') as input: ciphertext = input.read() plaintext = xxtea.decrypt(ciphertext, uKey) input.seek(0) input.write(plaintext) input.truncate() input.close()
def decrypt(data, password, check_header=False): """Return decrypted data""" key = get_key(password) data = xxtea.decrypt(data, key) if check_header: return check_head(data) return data
def decrypt(key, data): """ @note: 加密 @param key: getTime() @param data: data @return: bytes """ try: return xxtea.decrypt(data, key[:16])[len(key):] except: return b""
def __decrypt(self, s, level, encryptmode): #return (xxtea.decrypt(s, self.__key) # if ((self.__key != None) and (encryptmode >= level)) # else s #) if ((self.__key != None) and (encryptmode >= level)) : result = xxtea.decrypt(s, self.__key) else : result = s return result
def __decrypt(self, s, level, encryptmode): #return (xxtea.decrypt(s, self.__key) # if ((self.__key != None) and (encryptmode >= level)) # else s #) if ((self.__key != None) and (encryptmode >= level)): result = xxtea.decrypt(s, self.__key) else: result = s return result
def test_xxtea1(self): if sys.version_info < (3, 0): text = "Hello World! 你好,中国!" key = "1234567890" else: text = "Hello World! 你好,中国!".encode("utf-8") key = "1234567890".encode("utf-8") encrypt_data = xxtea.encrypt(text, key) decrypt_data = xxtea.decrypt(encrypt_data, key) self.assertEqual(text, decrypt_data)
def decrypt(filePath, key, sign): """The main process to decryption.""" data = readJscFile(path=filePath) # 1.xxtea decrypt if len(key) < 16: key += "\0" * (16 - len(key)) # padding \0 dec_data = xxtea.decrypt(data=data[len(sign):], key=key[:16], padding=False, rounds=0) # 2.determine file type dec_data = bytes(dec_data) return dec_data
def decrypt(data): """ :param data: str or bytes """ try: data = data.encode() if isinstance(data, str) else data key = data[:16] offset = 16 + 3 + int(data[16:19].decode(), 16) return xxtea.decrypt(data[offset:], key) except: traceback.print_exc() return b''
def decrypt(filePath, key): data = read_jsc_file(path=filePath) dec_data = xxtea.decrypt(data=data, key=key, padding=False) if dec_data[:2] == b"PK": fio = BytesIO(dec_data) fzip = zipfile.ZipFile(file=fio) dec_data = fzip.read(fzip.namelist()[0]).decode("utf-8") elif dec_data[:2] == b"\x1f\x8b": dec_data = bytes(zlib.decompress(dec_data, 16 + zlib.MAX_WBITS)).decode("utf-8") else: dec_data = bytes(dec_data).decode("utf-8") return dec_data
def decrypt(file, output_file): print('************** xxtea decrypt =====>>>>> ' + file + ' **************') read_handle = open(file, 'rb') xxtea_content = read_handle.read() read_handle.close() xxtea_content = xxtea_content[len(ENCRYPT_SIGN):] content = xxtea.decrypt(xxtea_content, ENCRYPT_KEY) write_handle = open(output_file, 'wb') write_handle.write(content) write_handle.close()
def decrypt(data, key): if len(data) <= 3: return data # data length is not a multiple of 4, or less than 8. padding = len(data) / 4 * 4 to_data = data[0:padding] # print 'data' + str(len(data)) # print 'to_data:' + str(len(to_data)) plain = '' plain = xxtea.decrypt(to_data, key, False) if padding < len(data): plain = plain + data[padding::] return plain
def parse_command(self, command): if "CMD0" in command: print "sleep command (CMD0) from %s" % self.url elif "INJECTFILE" in command: print "config command (INJECTFILE) from %s" % self.url match = re.search( ">CV [0-9]+\r\n>DI\r\nINJECTFILE (?P<config_size>[0-9]+)\r\n", command) if not match: print "unhandled INJECTFILE command: %s" % command[0:64] return enc = command[match.end():match.end() + int(match.groupdict()["config_size"])] config = None try: comp = xxtea.decrypt(enc, self.xxtea_key, False) config = zlib.decompress(comp[10:], -15) except: print "bad decrypt or decompress" return if config: print "written to INJECTFILE (%d bytes)" % len(config) fp = open("INJECTFILE", "wb") fp.write(config) fp.close() elif "EXEUPDATE" in command: print "update command (EXEUPDATE) from %s" % self.url match = re.search( ">CV CMP\r\n>UD [0-9]+\r\n\*EXEUPDATE (?P<file_size>[0-9]+)\r\n", command) if not match: print "unhandled EXEUPDATE command: %s" % command[0:64] return update = command[match.end():match.end() + int(match.groupdict()["file_size"])] if update: print "written to EXEUPDATE (%d bytes)" % len(update) fp = open("EXEUPDATE", "wb") fp.write(update) fp.close() else: print "unknown command from %s: %s" % (self.url, command[0:64])
def load_module(cls, name): if name in sys.modules: return sys.modules[name] mod = ModuleType(name) mod.__loader__ = cls mod.__name__ = name mod.__file__ = name + ".irony" try: exec(xxtea.decrypt(open(mod.__file__, "rb").read(), KEY), mod.__dict__) except Exception as e: print(e) return None sys.modules[name] = mod return mod
def xxtea_test_memory(): s = 'xxtea is good' # key = os.urandom(16) key = b'1234567891234567' print('key:', key) enc = xxtea.encrypt(s, key) print(enc) dec = xxtea.decrypt(enc, key) print(dec) if s == dec.decode(): print(True)
def decrypt(is_zip, input_key, input_jsc_path): print 'begin decrypt.' prefix = 'decryptOutput' jsc_path = input_jsc_path if jsc_path == '': jsc_path = raw_input('please input your .jsc path:') if os.path.exists(jsc_path) is False: print "error: your .jsb file is not exist." return False enc_file_content = read_file_content(jsc_path) key = input_key if key == '': key = raw_input('please input your encrypt key:') if key == '': print "error: your key is empty." return False dec = xxtea.decrypt(enc_file_content, key) des_file_name = prefix + '/dec.js' if os.path.exists(des_file_name) is True: os.remove(des_file_name) if os.path.exists(prefix) is True: os.system('rm -r ' + prefix) os.mkdir(prefix) write_content_to_file(des_file_name, dec) decrypt_file_name = prefix + '/decrypt.js' if is_zip is True: print 'begin unzip.' isUnzipSuc = unzip_file(des_file_name, prefix) os.remove(des_file_name) if isUnzipSuc is False: return False else: os.rename(prefix + '/encrypt.js', decrypt_file_name) else: os.rename(des_file_name, decrypt_file_name) print "success. please check 'decryptOutput' directory." print '> note: if your decrypt.js is 0b,', print 'please confirm your zip option and your decrypt key is right.' return True
def decrypt(file_path, out_path, key, sign): print("===>decrypt %s to %s" % (file_path, out_path)) fp = open(file_path, "rb") encrypt_bytes = fp.read() fp.close() sign_len = len(sign) if encrypt_bytes[:sign_len] == sign: decrypt_bytes = xxtea.decrypt(encrypt_bytes[sign_len:], key) out_dir = os.path.dirname(out_path) if not os.path.exists(out_dir): os.makedirs(out_dir) fp = open(out_path, "wb") fp.write(decrypt_bytes) fp.close()
def DecodeLua(data): dataLen = len(data); signLen = len(CODE_SIGN); keyLen = len(CODE_KEY); print('dataLen = %d' % (dataLen) ) print('keyLen = %d' % (keyLen) ) if dataLen > signLen: checkSign = data[0:signLen] print('checkSign = %s', checkSign) if checkSign == CODE_SIGN: print('DecodeLua3333333333') data = data[signLen:dataLen] data = xxtea.decrypt(data, CODE_KEY); return data
def main(args): _xsign = "XXTEA" _key = "g5kgGYr3peprprGU" filein = args.file #4000117.dat' fileout = filein + ".lua" with open(filein, 'rb') as raw: with open(fileout, 'wb') as output: rawdata = raw.read() #print(rawdata) data = _remove_header(rawdata, _xsign) #print('\n', data) plain = xxtea.decrypt(data, _key) #print(plain) output.write(plain)
def decodeFile(story_path): with open(story_path,'rb') as f: text = f.read() original = xxtea.decrypt(text,key,False) original = original.decode('utf8') lines = original.splitlines() #去掉末尾的脏字符 lines[-1] = '}' x= ''.join(lines) table = json.loads(x) df = pd.DataFrame(table) df = df.T #df.to_csv(os.path.join(fpath,story_path+'.csv')) return df
def parse_command(self, command): if "CMD0" in command: print "sleep command (CMD0) from %s" % self.url elif "INJECTFILE" in command: print "config command (INJECTFILE) from %s" % self.url match = re.search(">CV [0-9]+\r\n>DI\r\nINJECTFILE (?P<config_size>[0-9]+)\r\n", command) if not match: print "unhandled INJECTFILE command: %s" % command[0:64] return enc = command[match.end():match.end()+int(match.groupdict()["config_size"])] config = None try: comp = xxtea.decrypt(enc, self.xxtea_key, False) config = zlib.decompress(comp[10:], -15) except: print "bad decrypt or decompress" return if config: print "written to INJECTFILE (%d bytes)" % len(config) fp = open("INJECTFILE", "wb") fp.write(config) fp.close() elif "EXEUPDATE" in command: print "update command (EXEUPDATE) from %s" % self.url match = re.search(">CV CMP\r\n>UD [0-9]+\r\n\*EXEUPDATE (?P<file_size>[0-9]+)\r\n", command) if not match: print "unhandled EXEUPDATE command: %s" % command[0:64] return update = command[match.end():match.end()+int(match.groupdict()["file_size"])] if update: print "written to EXEUPDATE (%d bytes)" % len(update) fp = open("EXEUPDATE", "wb") fp.write(update) fp.close() else: print "unknown command from %s: %s" % (self.url, command[0:64])
def decrypt_session_key(session_key): """ 解码session_key :param session_key: session key :return: (timestamp, numbers)/成功,None/失败 """ try: key = "key" cipher = session_key plain = decrypt(base64.b64decode(cipher), key) if not plain: return None timestamp = plain[0:10] numbers = plain[10:] return int(timestamp), numbers except Exception as e: g_log.error("<%s> %s", e.__class__, e) return None
def decrypt(path, source_dir, dest_dir, key): print(path) source_path = os.path.join(source_dir, path) dest_path = os.path.join(dest_dir, path) dest_folder = os.path.dirname(dest_path) os.makedirs(dest_folder, exist_ok=True) path, ext = os.path.splitext(dest_path) with open(source_path, 'rb') as f: enc = f.read() dec = xxtea.decrypt(enc, key, padding=False) # literally only 2 types of file in this game if dec.startswith(b'\x89PNG\r\n\x1a\n'): ext = '.png' else: ext = '.txt' with open(path + ext, 'wb') as f: f.write(dec)
file_old = open("C:\mlp_save.dat", "rb") file_new = open("C:\mlp_save_new.dat", "wb") gluid = "1ee4688454e7a830e44491c86a1140fc137b6c204d60742c5cdb0bb1e8eb0465453aaa43" gluid_new = "3c7675febad2a6448446f083cb4a837f7d52d3fdabf16a38afeed478865b17db128669a6" gluid_hex = gluid.decode("hex") gluid_hex_new = gluid_new.decode("hex") try: data = file_old.read() finally: file_old.close() data_size = len(data) uncomp_size = data[0:WORD_SIZE] comp_size = data[WORD_SIZE : 2 * WORD_SIZE] encry_size = data[2 * WORD_SIZE : 3 * WORD_SIZE] encry_data = data[3 * WORD_SIZE : data_size - WORD_SIZE] reserved = data[data_size - WORD_SIZE : len(data)] decry_data = xxtea.decrypt(encry_data, gluid_hex, False) new_encry_data = xxtea.encrypt(decry_data, gluid_hex_new, False) try: file_new.write(uncomp_size) file_new.write(comp_size) file_new.write(encry_size) file_new.write(new_encry_data) file_new.write(reserved) finally: file_new.close()
import struct, xxtea, zlib, binascii file_old = open("C:\mlp_save.dat", "rb") gluid = "3c7675febad2a6448446f083cb4a837f7d52d3fdabf16a38afeed478865b17db128669a6" gluid_hex = gluid.decode("hex") WORD_SIZE = 4 INNER_KEY = "302a75507acbd72f89504e4712901cf0" try: data = file_old.read() finally: file_old.close() data_size = len(data) uncomp_size = struct.unpack('i', data[0:WORD_SIZE]) comp_size = struct.unpack('i', data[WORD_SIZE:2 * WORD_SIZE]) encry_size = struct.unpack('i', data[2 * WORD_SIZE:3 * WORD_SIZE]) encry_data = data[3 * WORD_SIZE:data_size - WORD_SIZE] reserved = struct.unpack('i', data[data_size - WORD_SIZE:len(data)]) decry_data = xxtea.decrypt(encry_data, gluid_hex, False) uncomp_data = zlib.decompress(decry_data) xml_data = xxtea.decrypt(uncomp_data, binascii.unhexlify(INNER_KEY), False) file_xml = open("C:\mlp.xml", "w") try: file_xml.write(xml_data) finally: file_xml.close()
def decode(cls, metadata): return xxtea.decrypt( b64decode(metadata), cls.AMAZON_KEY, False).split('#')[1]
def _de(str=''): global xxtea_key return xxtea.decrypt(base64.b64decode(str),xxtea_key)
def decode(content, key): dec = xxtea.decrypt(content, key) return dec
def f3(): for i in range(1024): key = os.urandom(16) data = os.urandom(i * 8) xxtea.decrypt(data, key=key, padding=False)
def f1(): for i in range(1024): key = os.urandom(16) data = os.urandom(i * 8) xxtea.decrypt(data, key=key)
def test_decrypt(self): data = xxtea.decrypt(self.enc, self.key) self.assertEqual(data, self.data)