星之旅人 异或求助

解密逻辑在cocos2d::Image::decodePngData

def bytes_to_int(b: bytes) -> int:
    val = 0
    for byte in b:
        val = byte + 256 * val
    return val

def decrypt():
    with open("button_9.png", "rb") as f:
        encrypted_data = bytearray(f.read())

    file_size = len(encrypted_data)
    key_material = encrypted_data[file_size-8:]
    len_bytes = key_material[0:4]
    key_seed_bytes = key_material[4:8]
    
    decrypted_len = bytes_to_int(len_bytes)
    key_seed = bytes_to_int(key_seed_bytes)

    key_val = key_seed - 2048
    xor_key = bytearray(4)
    xor_key[0] = (key_val >> 24) & 0xFF
    xor_key[1] = (key_val >> 16) & 0xFF
    xor_key[2] = (key_val >> 8) & 0xFF
    xor_key[3] = key_seed & 0xFF

    for i in range(decrypted_len):
        encrypted_data[i] ^= xor_key[i % 4]

    with open("output.png", "wb") as f_out:
        f_out.write(encrypted_data[:file_size - 8])
    
if __name__ == '__main__':
    decrypt()
1 个赞