nirai: add some encryption

This commit is contained in:
Master Jumblespeed 2015-08-16 22:32:55 -04:00
parent 41f5434069
commit 1c5e6503e4
2 changed files with 31 additions and 4 deletions

View file

@ -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))

View file

@ -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<unsigned char*>(code), size, key, iv, aes_decrypt);
std::string output(reinterpret_cast<char*>(aes_decrypt), decsize);
// Reverse
std::reverse(output.begin(), output.end());
return PyString_FromStringAndSize(output.data(), size);
return PyString_FromStringAndSize(output.data(), decsize);
}