From 45c5c880c7be81b186a033253075c951553f9e30 Mon Sep 17 00:00:00 2001 From: Toni Uhlig Date: Sat, 23 Dec 2023 14:38:40 +0100 Subject: Added basic CXX string obfuscation via constexpr. * obfuscate functions names retrieved via MmGetSystemRoutineAddress * add two new static libs: libcnative (C-only) and libcxxnative (CXX-only) Signed-off-by: Toni Uhlig --- CRT/obfuscate.hpp | 163 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 CRT/obfuscate.hpp (limited to 'CRT/obfuscate.hpp') diff --git a/CRT/obfuscate.hpp b/CRT/obfuscate.hpp new file mode 100644 index 0000000..5522aad --- /dev/null +++ b/CRT/obfuscate.hpp @@ -0,0 +1,163 @@ +#pragma once + +/*____________________________________________________________________________________________________________ + +Original Author: skadro +Github: https://github.com/skadro-official +License: See end of file + +skCrypter + Compile-time, Usermode + Kernelmode, safe and lightweight string crypter library for C++11+ + + *Not removing this part is appreciated* +____________________________________________________________________________________________________________*/ + +#ifdef _KERNEL_MODE + namespace std + { + // STRUCT TEMPLATE remove_reference + template + struct remove_reference { + using type = _Ty; + }; + + template + struct remove_reference<_Ty&> { + using type = _Ty; + }; + + template + struct remove_reference<_Ty&&> { + using type = _Ty; + }; + + template + using remove_reference_t = typename remove_reference<_Ty>::type; + + // STRUCT TEMPLATE remove_const + template + struct remove_const { // remove top-level const qualifier + using type = _Ty; + }; + + template + struct remove_const { + using type = _Ty; + }; + + template + using remove_const_t = typename remove_const<_Ty>::type; + } +#else + #include +#endif + +namespace skc +{ + template + using clean_type = typename std::remove_const_t>; + + template + class skCrypter + { + public: + __forceinline constexpr skCrypter(T* data) + { + crypt(data); + } + + __forceinline T* get() + { + return _storage; + } + + __forceinline int size() // (w)char count + { + return _size; + } + + __forceinline char key() + { + return _key1; + } + + __forceinline T* encrypt() + { + if (!isEncrypted()) + crypt(_storage); + + return _storage; + } + + __forceinline T* decrypt() + { + if (isEncrypted()) + crypt(_storage); + + return _storage; + } + + __forceinline bool isEncrypted() + { + return _storage[_size - 1] != 0; + } + + __forceinline void clear() // set full storage to 0 + { + for (int i = 0; i < _size; i++) + { + _storage[i] = 0; + } + } + + __forceinline operator T* () + { + decrypt(); + + return _storage; + } + + private: + __forceinline constexpr void crypt(T* data) + { + for (int i = 0; i < _size; i++) + { + _storage[i] = data[i] ^ (_key1 + i % (1 + _key2)); + } + } + + T _storage[_size]{}; + }; +} + +#define skCrypt(str) skCrypt_key(str, __TIME__[4], __TIME__[7]) +#define skCrypt_key(str, key1, key2) []() { \ + constexpr static auto crypted = skc::skCrypter \ + >((skc::clean_type*)str); \ + return crypted; }() + +/*________________________________________________________________________________ + +MIT License + +Copyright (c) 2020 skadro + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +________________________________________________________________________________*/ -- cgit v1.2.3