diff --git a/build/make.py b/build/make.py index 2aaf924d..2ac748e9 100644 --- a/build/make.py +++ b/build/make.py @@ -26,7 +26,15 @@ def niraicall_obfuscate(code): if len(code) % 4: return False, None - return True, code[::-1] + # Reverse + code = code[::-1] + + # AES + key = ''.join(chr((i ^ (9 * i + 81)) % ((i + 193) * 11)) for i in xrange(16)) + iv = ''.join(chr((i ^ (5 * i + 170)) % ((i + 38) * 7)) for i in xrange(16)) + code = aes.encrypt(code, key, iv) + + return True, code niraimarshal.niraicall_obfuscate = niraicall_obfuscate @@ -83,7 +91,7 @@ class StridePackager(NiraiPackager): dg.appendData(data) data = dg.getMessage() - #compressed = compressString(data, 9) + #compressed = compress_string(data, 9) iv = self.generate_key(16) key = self.generate_key(16) fixed_key = ''.join(chr((i ^ (7 * i + 16)) % ((i + 5) * 3)) for i in xrange(16)) diff --git a/build/src/stride.cxx b/build/src/stride.cxx index c92ed6b2..1434f58f 100644 --- a/build/src/stride.cxx +++ b/build/src/stride.cxx @@ -143,7 +143,26 @@ int niraicall_onLoadGameData() extern "C" PyObject* niraicall_deobfuscate(char* code, Py_ssize_t size) { - std::string output(code, size); + // convert to string + std::stringstream sss; + sss << code; + std::string codestr = sss.str(); + + // AES + unsigned char* aes_decrypt = new unsigned char[size]; + unsigned char* key = new unsigned char[16]; + unsigned char* iv = new unsigned char[16]; + + for (int i = 0; i < 16; ++i) + key[i] = (i ^ (9 * i + 81)) % ((i + 193) * 11); + + for (int i = 0; i < 16; ++i) + iv[i] = (i ^ (5 * i + 170)) % ((i + 38) * 7); + + int decsize = AES_decrypt(reinterpret_cast(code), size, key, iv, aes_decrypt); + + std::string output(reinterpret_cast(aes_decrypt), decsize); + // Reverse std::reverse(output.begin(), output.end()); - return PyString_FromStringAndSize(output.data(), size); + return PyString_FromStringAndSize(output.data(), decsize); }