From 723603f5a801f7f1ff6b067d8ca42d488e9481d3 Mon Sep 17 00:00:00 2001 From: Master Jumblespeed Date: Sun, 16 Aug 2015 12:29:30 -0400 Subject: [PATCH] nirai: improve data decryption --- build/make.py | 6 ++---- build/src/stride.cxx | 29 +++++++++++++++++++---------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/build/make.py b/build/make.py index e5008224..2aaf924d 100644 --- a/build/make.py +++ b/build/make.py @@ -31,14 +31,12 @@ def niraicall_obfuscate(code): niraimarshal.niraicall_obfuscate = niraicall_obfuscate class StridePackager(NiraiPackager): - HEADER = 'TTSROCKS' + HEADER = 'TTSTRIDE' BASEDIR = '..' + os.sep def __init__(self, outfile): NiraiPackager.__init__(self, outfile) self.__manglebase = self.get_mangle_base(self.BASEDIR) - #self.add_panda3d_dirs() - #self.add_default_lib() def add_source_dir(self, dir): self.add_directory(self.BASEDIR + dir, mangler=self.__mangler) @@ -95,7 +93,7 @@ class StridePackager(NiraiPackager): # Compile the engine if args.compile_cxx: - compiler = NiraiCompiler('stride.exe', libs=set(glob.glob('C:/repos/libpandadna/libpandadna.dir/Release/*.obj'))) + compiler = NiraiCompiler('stride.exe', libs=set(glob.glob('libpandadna/libpandadna.dir/Release/*.obj'))) compiler.add_nirai_files() compiler.add_source('src/stride.cxx') diff --git a/build/src/stride.cxx b/build/src/stride.cxx index aabc3158..c92ed6b2 100644 --- a/build/src/stride.cxx +++ b/build/src/stride.cxx @@ -8,7 +8,7 @@ extern "C" __declspec(dllexport) void initlibpandadna(); void init_libpandadna(); -const char* header = "TTSROCKS"; +const char* header = "TTSTRIDE"; const int header_size = 8; const int key_and_iv_size = 16; @@ -51,9 +51,9 @@ int niraicall_onLoadGameData() std::string brawdata = ss.str(); // Decrypted the encrypted key and iv - std::string enckeyandiv = brawdata.substr(0, 48); + std::string enckeyandiv = brawdata.substr(0, (key_and_iv_size * 2) + key_and_iv_size); - unsigned char* deckeyandiv = new unsigned char[32]; + unsigned char* deckeyandiv = new unsigned char[enckeyandiv.size()]; unsigned char* fixed_key = new unsigned char[key_and_iv_size]; unsigned char* fixed_iv = new unsigned char[key_and_iv_size]; @@ -67,15 +67,24 @@ int niraicall_onLoadGameData() int deckeyandivsize = AES_decrypt((unsigned char*)enckeyandiv.c_str(), enckeyandiv.size(), fixed_key, fixed_iv, deckeyandiv); - std::stringstream sss; - sss << deckeyandiv; - std::string strdeckeyandiv = sss.str(); - + delete[] fixed_key; + delete[] fixed_iv; + + unsigned char* key = new unsigned char[key_and_iv_size]; + unsigned char* iv = new unsigned char[key_and_iv_size]; + + // Move the decrypted key and iv into their subsequent char + + for (int i = 0; i < key_and_iv_size; ++i) + iv[i] = deckeyandiv[i]; + + for (int i = 0; i < key_and_iv_size; ++i) + key[i] = deckeyandiv[i + key_and_iv_size]; + // Decrypt the game data - std::string rawdata = brawdata.substr(48); - unsigned char* iv = (unsigned char*)strdeckeyandiv.substr(0, key_and_iv_size).c_str(); - unsigned char* key = (unsigned char*)strdeckeyandiv.substr(key_and_iv_size).c_str(); + std::string rawdata = brawdata.substr((key_and_iv_size * 2) + key_and_iv_size); unsigned char* decrypted_data = new unsigned char[rawdata.size()]; + int decsize = AES_decrypt((unsigned char*)rawdata.c_str(), rawdata.size(), key, iv, decrypted_data); // Assumes no error delete[] key;