From 8fc83cde538ef00007cd76c7f46348d27136766b Mon Sep 17 00:00:00 2001 From: slayercio Date: Tue, 18 Nov 2025 20:07:29 +0100 Subject: [PATCH] feat: added rage header --- src/detail/rage.hpp | 235 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 235 insertions(+) create mode 100644 src/detail/rage.hpp diff --git a/src/detail/rage.hpp b/src/detail/rage.hpp new file mode 100644 index 0000000..4e70f60 --- /dev/null +++ b/src/detail/rage.hpp @@ -0,0 +1,235 @@ +#pragma once +#include + +namespace fxn::rage +{ + namespace sysObfuscatedTypes + { + std::uint32_t obfuscatedRandom() + { + static std::uint32_t next = 0xCB536E6A; + next = next * 214013 + 2531011; + return next; + } + } + + template + class sysObfuscated + { + public: + sysObfuscated() + { + static_assert((sizeof(T) & 3) == 0, "Size of T must be a multiple of 4"); + Init(); + } + + sysObfuscated(const sysObfuscated& rhs) + { + Init(); + Set(rhs.Get()); + } + + public: + template + sysObfuscated(const sysObfuscated& rhs) + { + Init(); + Set(rhs.Get()); + } + + explicit sysObfuscated(const T& data) + { + Init(); + Set(data); + } + + ~sysObfuscated() {} + public: + T Get() const; + void Set(const T& data); + operator T() const { return Get(); } + + public: + template bool operator==(const sysObfuscated& rhs) const { return Get() == rhs.Get(); } + template bool operator!=(const sysObfuscated& rhs) const { return Get() != rhs.Get(); } + template bool operator<(const sysObfuscated& rhs) const { return Get() < rhs.Get(); } + template bool operator<=(const sysObfuscated& rhs) const { return Get() <= rhs.Get(); } + template bool operator>(const sysObfuscated& rhs) const { return Get() > rhs.Get(); } + template bool operator>=(const sysObfuscated& rhs) const { return Get() >= rhs.Get(); } + + public: + template sysObfuscated& operator=(const sysObfuscated& rhs) { Set(rhs.Get()); return *this; } + sysObfuscated& operator=(const T& data) { Set(data); return *this; } + + public: + template sysObfuscated& operator+=(const sysObfuscated& rhs) { Set(Get()+rhs.Get()); return *this; } + sysObfuscated& operator+=(const T& data) { Set(Get()+data); return *this; } + template sysObfuscated& operator-=(const sysObfuscated& rhs) { Set(Get()-rhs.Get()); return *this; } + sysObfuscated& operator-=(const T& data) { Set(Get()-data); return *this; } + template sysObfuscated& operator*=(const sysObfuscated& rhs) { Set(Get()*rhs.Get()); return *this; } + sysObfuscated& operator*=(const T& data) { Set(Get()*data); return *this; } + template sysObfuscated& operator/=(const sysObfuscated& rhs) { Set(Get()/rhs.Get()); return *this; } + sysObfuscated& operator/=(const T& data) { Set(Get()/data); return *this; } + + private: + void Init(); + + mutable std::uint32_t m_data[(TMutate ? sizeof(T)*2 : sizeof(T)) / sizeof(std::uint32_t)]; + mutable std::uint32_t m_xor; + mutable std::uint32_t m_mutate; + }; + + template __forceinline void sysObfuscated::Init() + { + m_xor = sysObfuscatedTypes::obfuscatedRandom(); + if(TMutate) + { + m_mutate = sysObfuscatedTypes::obfuscatedRandom(); + } + } + + template __forceinline T sysObfuscated::Get() const + { + std::uint32_t xorVal = m_xor ^ (std::uint32_t)(size_t)this; + std::uint32_t ret[sizeof(T)/sizeof(std::uint32_t)]; + std::uint32_t* src = const_cast(&m_data[0]); + std::uint32_t* dest = (std::uint32_t*)&ret; + for(size_t i=0; i> 16); + std::uint32_t entropyB = ((src[sizeof(T)/4] & m_mutate) << 16) | ((src[sizeof(T)/4] & m_mutate) >> 16); + *src = (*src & m_mutate) | entropyA; + src[sizeof(T)/4] = (src[sizeof(T)/4] & (~m_mutate)) | entropyB; + + *dest++ = a | b; + ++src; + } + else + { + *dest++ = *src++ ^ xorVal; + } + } + + // Call Set() to reset the xor and mutate keys on every call to Get() + if(TMutate) + { + const_cast*>(this)->Set(*(T*)&ret); + } + + return *(T*)&ret; + } + + template __forceinline void sysObfuscated::Set(const T& data) + { + // Reset xor and mutate keys + Init(); + + std::uint32_t xorVal = m_xor ^ (std::uint32_t)(size_t)this; + std::uint32_t* src = (std::uint32_t*)&data; + std::uint32_t* dest = &m_data[0]; + for(size_t i=0; i + class scrCommandHash + { + private: + static const int ToplevelSize = 256; + static const int PerBucket = 7; + + struct Bucket + { + sysObfuscated obf_Next; + _T Data[PerBucket]; + sysObfuscated obf_Count; + sysObfuscated obf_Hashes[PerBucket]; + std::uint64_t plainText_Hashes[PerBucket]; + }; + + public: + void RegistrationComplete(bool val) + { + m_bRegistrationComplete = val; + } + + void Init() + { + m_Occupancy = 0; + m_bRegistrationComplete = false; + for (int i=0; iobf_Next.Get(); + delete[] old; + } + m_Buckets[i] = NULL; + } + m_Occupancy = 0; + } + + void Insert(std::uint64_t hashcode,_T cmd) + { + Bucket * b = m_Buckets[hashcode & (ToplevelSize-1)]; + // If this chain is empty, or the first bucket is full, allocate and patch in a new bucket + if (!b || b->obf_Count.Get() == PerBucket) { + Bucket *nb = (Bucket*) new char[sizeof(Bucket)]; + nb->obf_Next.Set(m_Buckets[hashcode & (ToplevelSize-1)]); + nb->obf_Count.Set(0); + b = m_Buckets[hashcode & (ToplevelSize-1)] = nb; + } + b->obf_Hashes[b->obf_Count.Get()].Set(hashcode); + b->plainText_Hashes[b->obf_Count.Get()] = 0; //hashcode; + b->Data[b->obf_Count] = cmd; + b->obf_Count.Set(b->obf_Count.Get()+1); //inc count + } + + _T Lookup(std::uint64_t hashcode) + { + Bucket *b = m_Buckets[hashcode & (ToplevelSize-1)]; + while (b) { + for (std::uint32_t i=0; iobf_Count.Get(); i++) + if (b->obf_Hashes[i].Get() == hashcode) + return b->Data[i]; + b = b->obf_Next.Get(); + } + + return 0; + } + + private: + Bucket* m_Buckets[ToplevelSize]; + int m_Occupancy; + bool m_bRegistrationComplete; + }; +} \ No newline at end of file