diff options
author | KittenPopo <Pokeberry123@gmail.com> | 2022-03-26 16:20:09 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-26 23:20:09 +0000 |
commit | 379cbc8bc251307777a14b901e5617e834398485 (patch) | |
tree | 4722db4a3c301462ca009f5bb2976508b652677e /NorthstarDedicatedTest/NSMem.h | |
parent | 2c74033440212308eb0fe0d8b3135ffc5cd0422e (diff) | |
download | NorthstarLauncher-379cbc8bc251307777a14b901e5617e834398485.tar.gz NorthstarLauncher-379cbc8bc251307777a14b901e5617e834398485.zip |
Major exploit fixes and some minor bug fixes/improvements (#117)v1.6.0-rc3
* Added main exploit fixes
* Fixed typo in sigscanning.cpp
* Fully implemented
* Added proper includes for new files
* Update README.md
* typo
* spare me my sanity (fixed ridiculous code)
* Added rest of KittenMemUtils
* Rename KittenMemUtils
* Removed all messy memory edits, implemented NSMem instead
* Update NorthstarDedicatedTest.vcxproj
* [1] Move everything from securitypatches to ExploitFixes
* [2] Move everything from securitypatches to ExploitFixes
* Fixed module offsets in stack trace
* Fixed UTF8 Parsing (Multiplayer Crash)
* Implemented UT8 fix
* Update NorthstarDedicatedTest.vcxproj
* Update hookutils.cpp
* Small fixes
* all my homies hate clang-format
* Temporarily restore README.md
* Added string hash macro
* Added convenient vtfunc macro
* Made lil ConCommand creation macro
* Fixed multiple NET_SetConVar exploits
* Quick fixerino
* Fix convar struct (and other things)
* Revive clang-format (but good, i think)
* Update .clang-format
* Reformatted code to meet .clang-format requirements
* Minor formatting fixes
* Fixed Northstar "crashing" when console is closed
* Update .clang-format
Diffstat (limited to 'NorthstarDedicatedTest/NSMem.h')
-rw-r--r-- | NorthstarDedicatedTest/NSMem.h | 95 |
1 files changed, 63 insertions, 32 deletions
diff --git a/NorthstarDedicatedTest/NSMem.h b/NorthstarDedicatedTest/NSMem.h index a6ddf033..a5bbd42f 100644 --- a/NorthstarDedicatedTest/NSMem.h +++ b/NorthstarDedicatedTest/NSMem.h @@ -4,8 +4,10 @@ // KittenPopo's memory stuff, made for northstar (because I really can't handle working with northstar's original memory stuff tbh) #pragma region Pattern Scanning -namespace NSMem { - inline void* PatternScan(void* module, const int* pattern, int patternSize, int offset) { +namespace NSMem +{ + inline void* PatternScan(void* module, const int* pattern, int patternSize, int offset) + { if (!module) return NULL; @@ -16,16 +18,20 @@ namespace NSMem { auto scanBytes = (BYTE*)module; - for (auto i = 0; i < sizeOfImage - patternSize; ++i) { + for (auto i = 0; i < sizeOfImage - patternSize; ++i) + { bool found = true; - for (auto j = 0; j < patternSize; ++j) { - if (scanBytes[i + j] != pattern[j] && pattern[j] != -1) { + for (auto j = 0; j < patternSize; ++j) + { + if (scanBytes[i + j] != pattern[j] && pattern[j] != -1) + { found = false; break; } } - if (found) { + if (found) + { uintptr_t addressInt = (uintptr_t)(&scanBytes[i]) + offset; return (uint8_t*)addressInt; } @@ -34,31 +40,42 @@ namespace NSMem { return nullptr; } - inline void* PatternScan(const char* moduleName, const char* pattern, int offset = 0) { + inline void* PatternScan(const char* moduleName, const char* pattern, int offset = 0) + { std::vector<int> patternNums; bool lastChar = 0; int size = strlen(pattern); - for (int i = 0; i < size; i++) { + for (int i = 0; i < size; i++) + { char c = pattern[i]; // If this is a space character, ignore it if (c == ' ' || c == '\t') continue; - if (c == '?') { + if (c == '?') + { // Add a wildcard (-1) patternNums.push_back(-1); - } else if (i < size - 1) { + } + else if (i < size - 1) + { BYTE result = 0; - for (int j = 0; j < 2; j++) { + for (int j = 0; j < 2; j++) + { int val = 0; char c = (pattern + i + j)[0]; - if (c >= 'a') { + if (c >= 'a') + { val = c - 'a' + 0xA; - } else if (c >= 'A') { + } + else if (c >= 'A') + { val = c - 'A' + 0xA; - } else { + } + else + { val = c - '0'; } @@ -72,24 +89,28 @@ namespace NSMem { return PatternScan(GetModuleHandleA(moduleName), &patternNums[0], patternNums.size(), offset); } - inline void BytePatch(uintptr_t address, const BYTE* vals, int size) { + inline void BytePatch(uintptr_t address, const BYTE* vals, int size) + { WriteProcessMemory(GetCurrentProcess(), (LPVOID)address, vals, size, NULL); } - inline void BytePatch(uintptr_t address, std::initializer_list<BYTE> vals) { + inline void BytePatch(uintptr_t address, std::initializer_list<BYTE> vals) + { std::vector<BYTE> bytes = vals; if (!bytes.empty()) BytePatch(address, &bytes[0], bytes.size()); } - inline void NOP(uintptr_t address, int size) { + inline void NOP(uintptr_t address, int size) + { BYTE* buf = (BYTE*)malloc(size); memset(buf, 0x90, size); BytePatch(address, buf, size); free(buf); } - inline bool IsMemoryReadable(void* ptr, size_t size) { + inline bool IsMemoryReadable(void* ptr, size_t size) + { BYTE* buffer = (BYTE*)malloc(size); size_t numWritten = 0; @@ -98,18 +119,21 @@ namespace NSMem { return numWritten == size; } -} +} // namespace NSMem #pragma region KHOOK -struct KHookPatternInfo { - const char* moduleName, *pattern; +struct KHookPatternInfo +{ + const char *moduleName, *pattern; int offset = 0; - KHookPatternInfo(const char* moduleName, const char* pattern, int offset = 0) - : moduleName(moduleName), pattern(pattern), offset(offset) {} + KHookPatternInfo(const char* moduleName, const char* pattern, int offset = 0) : moduleName(moduleName), pattern(pattern), offset(offset) + { + } }; -struct KHook { +struct KHook +{ KHookPatternInfo targetFunc; void* targetFuncAddr; void* hookFunc; @@ -117,13 +141,15 @@ struct KHook { static inline std::vector<KHook*> _allHooks; - KHook(KHookPatternInfo targetFunc, void* hookFunc, void** original) : targetFunc(targetFunc) { + KHook(KHookPatternInfo targetFunc, void* hookFunc, void** original) : targetFunc(targetFunc) + { this->hookFunc = hookFunc; this->original = original; _allHooks.push_back(this); } - bool Setup() { + bool Setup() + { targetFuncAddr = NSMem::PatternScan(targetFunc.moduleName, targetFunc.pattern, targetFunc.offset); if (!targetFuncAddr) return false; @@ -132,11 +158,16 @@ struct KHook { } // Returns true if succeeded - static bool InitAllHooks() { - for (KHook* hook : _allHooks) { - if (hook->Setup()) { + static bool InitAllHooks() + { + for (KHook* hook : _allHooks) + { + if (hook->Setup()) + { spdlog::info("KHook hooked at {}", hook->targetFuncAddr); - } else { + } + else + { return false; } } @@ -144,9 +175,9 @@ struct KHook { return MH_EnableHook(MH_ALL_HOOKS) == MH_OK; } }; -#define KHOOK(name, funcPatternInfo, returnType, convention, args) \ +#define KHOOK(name, funcPatternInfo, returnType, convention, args) \ returnType convention hk##name args; \ auto o##name = (returnType(convention*) args)0; \ - KHook k##name = KHook(KHookPatternInfo funcPatternInfo, &hk##name, (void**)&o##name); \ + KHook k##name = KHook(KHookPatternInfo funcPatternInfo, &hk##name, (void**)&o##name); \ returnType convention hk##name args #pragma endregion
\ No newline at end of file |