diff --git a/.gitmodules b/.gitmodules index 48b3e7b9..7317ff1c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "simple-ipc"] path = simple-ipc url = https://github.com/nullifiedcat/simple-ipc +[submodule "ucccccp"] + path = ucccccp + url = https://github.com/nullifiedcat/ucccccp diff --git a/makefile b/makefile index dabfc637..42d038f8 100644 --- a/makefile +++ b/makefile @@ -10,7 +10,7 @@ CFLAGS=$(COMMON_FLAGS) $(WARNING_FLAGS) CXXFLAGS=-std=gnu++1z $(COMMON_FLAGS) $(WARNING_FLAGS) SDKFOLDER=$(realpath source-sdk-2013/mp/src) SIMPLE_IPC_DIR = $(realpath simple-ipc/src/include) -INCLUDES=-isystemsrc/freetype-gl -isystemsrc/imgui -isystem/usr/local/include/freetype2 -isystem/usr/include/freetype2 -I$(SIMPLE_IPC_DIR) -isystem$(SDKFOLDER)/public -isystem$(SDKFOLDER)/mathlib -isystem$(SDKFOLDER)/common -isystem$(SDKFOLDER)/public/tier1 -isystem$(SDKFOLDER)/public/tier0 -isystem$(SDKFOLDER) +INCLUDES=-Iucccccp -isystemsrc/freetype-gl -isystemsrc/imgui -isystem/usr/local/include/freetype2 -isystem/usr/include/freetype2 -I$(SIMPLE_IPC_DIR) -isystem$(SDKFOLDER)/public -isystem$(SDKFOLDER)/mathlib -isystem$(SDKFOLDER)/common -isystem$(SDKFOLDER)/public/tier1 -isystem$(SDKFOLDER)/public/tier0 -isystem$(SDKFOLDER) LIB_DIR=lib LDFLAGS=-m32 -fno-gnu-unique -D_GLIBCXX_USE_CXX11_ABI=0 -shared -L$(realpath $(LIB_DIR)) LDLIBS=-static -lc -lstdc++ -ltier0 -lvstdlib -l:libSDL2-2.0.so.0 -static -lGLEW -lfreetype -lpthread diff --git a/src/common.h b/src/common.h index d3e464c8..3938a294 100644 --- a/src/common.h +++ b/src/common.h @@ -50,7 +50,7 @@ extern "C" { #include "hoovy.hpp" #include "enums.h" #include "projlogging.hpp" -#include "utfccp_commands.hpp" +#include "ucccccp_cmds.hpp" #include "velocity.hpp" #include "angles.hpp" #include "entityhitboxcache.hpp" diff --git a/src/hooks/others.cpp b/src/hooks/others.cpp index 96005781..34c9a7c4 100644 --- a/src/hooks/others.cpp +++ b/src/hooks/others.cpp @@ -8,7 +8,7 @@ #include "../common.h" #include "../netmessage.h" #include "../hack.h" -#include "../utfccp.hpp" +#include "ucccccp.hpp" #include "hookedmethods.h" static CatVar no_invisibility(CV_SWITCH, "no_invis", "0", "Remove Invisibility", "Useful with chams!"); @@ -151,7 +151,7 @@ bool SendNetMsg_hook(void* _this, INetMessage& msg, bool bForceReliable = false, std::string msg(str.substr(offset)); msg = msg.substr(0, msg.length() - 2); if (msg.find("!!") == 0) { - msg = utfccp::encrypt(msg.substr(2)); + msg = ucccccp::encrypt(msg.substr(2)); str = str.substr(0, offset) + msg + "\"\""; crpt = true; } @@ -349,8 +349,8 @@ bool DispatchUserMessage_hook(void* _this, int type, bf_read& buf) { } if (crypt_chat) { if (message.find("!!") == 0) { - if (utfccp::validate(message)) { - PrintChat("\x07%06X%s\x01: %s", 0xe05938, name.c_str(), utfccp::decrypt(message).c_str()); + if (ucccccp::validate(message)) { + PrintChat("\x07%06X%s\x01: %s", 0xe05938, name.c_str(), ucccccp::decrypt(message).c_str()); } } } diff --git a/src/ucccccp_cmds.cpp b/src/ucccccp_cmds.cpp new file mode 100644 index 00000000..b791fbbe --- /dev/null +++ b/src/ucccccp_cmds.cpp @@ -0,0 +1,22 @@ +/* + * utfccp_commands.cpp + * + * Created on: Jul 1, 2017 + * Author: nullifiedcat + */ + +#include "ucccccp.hpp" +#include "common.h" +#include "ucccccp_cmds.hpp" + +CatCommand utfccp_encrypt("ucccccp_encrypt", "Encrypt a message", [](const CCommand& args) { + logging::Info("%s", ucccccp::encrypt(std::string(args.ArgS())).c_str()); +}); + +CatCommand utfccp_decrypt("ucccccp_decrypt", "Decrypt a message", [](const CCommand& args) { + if (ucccccp::validate(std::string(args.ArgS()))) { + logging::Info("%s", ucccccp::decrypt(std::string(args.ArgS())).c_str()); + } else { + logging::Info("Invalid input data!"); + } +}); diff --git a/src/utfccp_commands.hpp b/src/ucccccp_cmds.hpp similarity index 63% rename from src/utfccp_commands.hpp rename to src/ucccccp_cmds.hpp index 969caa3d..eacc6491 100644 --- a/src/utfccp_commands.hpp +++ b/src/ucccccp_cmds.hpp @@ -9,5 +9,5 @@ class CatCommand; -extern CatCommand utfccp_encrypt; -extern CatCommand utfccp_decrypt; +extern CatCommand ucccccp_encrypt; +extern CatCommand ucccccp_decrypt; diff --git a/src/utfccp.hpp b/src/utfccp.hpp deleted file mode 100644 index 57a77f8c..00000000 --- a/src/utfccp.hpp +++ /dev/null @@ -1,100 +0,0 @@ -/* - * utfccp.hpp - * - * Created on: Jul 1, 2017 - * Author: nullifiedcat - */ - -#pragma once - -#include -#include "base64.h" - -/* - * Usage: - * To send message, call utfccp::encrypt on text of the message and send the result to chat - * When receiving a message, call utfccp::validate, and if it succeeds, call utfccp::decrypt and show the result - * - * To include this to your project, add this file and base64.h to your source and include this file. - * - * General structure of message: - * !![version][data] - * version: char from base64 alphabet - * data: depends on version - * - * Versions: - * A: - * !!A[data][checksum] - * data = base64(crappy_xorstring(input)) - * checksum = crappy_checksum(input) - */ - -namespace utfccp { - -inline std::string crappy_checksum(const std::string& in) { - int s = 0, ss = 0; - for (int i = 0; i < in.length(); i += 2) { - s += (int)in[i]; - if (i < in.length() - 1) - ss += (int)in[i + 1] * (int)in[i + 1]; - } - return { kBase64Alphabet[s % 64], kBase64Alphabet[ss % 64] }; -} - -inline std::string crappy_xorstring(const std::string& in) { - std::string out; - for (int i = 0; i < in.length(); i++) { - // 696969th prime, 13371337th prime - out.push_back(in[i] ^ ((10522103 * in.length()) + i * 244053389 % 256)); - } - return out; -} - -/* - * validate - * A - */ -inline bool validate(const std::string& in) { - if (in.length() < 4) return false; - if (in[0] != '!' || in[1] != '!') return false; - switch (in[2]) { - case 'A': - return crappy_checksum(in.substr(3, in.length() - 5)) == in.substr(in.length() - 2); - default: - return false; - } -} - -/* - * decrypt - * A - */ -inline std::string decrypt(const std::string& in) { - switch (in[2]) { - case 'A': { - std::string b64; - Base64::Decode(in.substr(3, in.length() - 5), &b64); - return crappy_xorstring(b64); - } - default: - return "Unsupported version"; - } -} - -/* - * encrypt - * falls back to A if version is invalid - * A - */ -inline std::string encrypt(const std::string& in, char version = 'A') { - switch (version) { - default: - case 'A': { - std::string b64; - Base64::Encode(crappy_xorstring(in), &b64); - return "!!A" + b64 + crappy_checksum(b64); - } - } -} - -} diff --git a/src/utfccp_commands.cpp b/src/utfccp_commands.cpp deleted file mode 100644 index ce994947..00000000 --- a/src/utfccp_commands.cpp +++ /dev/null @@ -1,22 +0,0 @@ -/* - * utfccp_commands.cpp - * - * Created on: Jul 1, 2017 - * Author: nullifiedcat - */ - -#include "utfccp_commands.hpp" -#include "utfccp.hpp" -#include "common.h" - -CatCommand utfccp_encrypt("utfccp_encrypt", "Encrypt a message", [](const CCommand& args) { - logging::Info("%s", utfccp::encrypt(std::string(args.ArgS())).c_str()); -}); - -CatCommand utfccp_decrypt("utfccp_decrypt", "Decrypt a message", [](const CCommand& args) { - if (utfccp::validate(std::string(args.ArgS()))) { - logging::Info("%s", utfccp::decrypt(std::string(args.ArgS())).c_str()); - } else { - logging::Info("Invalid input data!"); - } -}); diff --git a/ucccccp b/ucccccp new file mode 160000 index 00000000..5b577a66 --- /dev/null +++ b/ucccccp @@ -0,0 +1 @@ +Subproject commit 5b577a66da2e64726385cd28150123896cc1badf