解码自定义加密文件

Decoding custom encrypted file

我目前正在处理旧游戏的保存文件。 我的问题是该文件是使用自定义算法加密的。 我只有一个模糊的描述:

"The file is encrypted by adding 39393939 and then rotating each DWord right 5 bits."

我试图在每个 4 字节块上使用此 java 代码来逆转进度 ()

private static byte[] decryptDWord(byte[] in) {
    //in is 4 bytes

    IntBuffer buf=ByteBuffer.wrap(in).asIntBuffer();
    int dword=buf.get();
    dword=Integer.rotateLeft(dword, 5);
    dword -=0x39393939;
    byte[] out = ByteBuffer.allocate(4).putInt(dword).array();

    return out;
}

但是应用在 0x70, 0x4E, 0x33, 0x43 上应该给我 0x73, 0x63, 0x30, 0x2E 并且应用在 0x74, 0x60, 0x33, 0x03 上应该给我 0x73, 0x63, 0x34, 0x20

尽管 word 大小取决于机器,但在此上下文中 DWORD 很可能是 4 个字节长,因此在 java 中它对应于 int。 此外,您必须考虑到原始架构在位和字节方面可能都是 LSB or MSB,因此您自己将单独的字节打包成 'int' 可能会改变位的顺序:总共 4 种不同的组合。那么你首先需要向左循环5位,然后减去39393939。'decryption'之后你可能需要恢复原来的byte/bit顺序。