diff options
author | BobTheBob9 <for.oliver.kirkham@gmail.com> | 2022-07-07 21:31:41 +0100 |
---|---|---|
committer | BobTheBob9 <for.oliver.kirkham@gmail.com> | 2022-07-07 21:31:41 +0100 |
commit | 2ae34b67e36b8ba05132d481876eb4ed7a826283 (patch) | |
tree | 63f44c8e2dcdc959d7a5317a3a7b36efedbd7d38 /NorthstarDLL/sigscanning.cpp | |
parent | 3406de7aaaf52cbef20b1549f2d7da0255d30f51 (diff) | |
download | NorthstarLauncher-2ae34b67e36b8ba05132d481876eb4ed7a826283.tar.gz NorthstarLauncher-2ae34b67e36b8ba05132d481876eb4ed7a826283.zip |
almost fully replaced hooking lib
Diffstat (limited to 'NorthstarDLL/sigscanning.cpp')
-rw-r--r-- | NorthstarDLL/sigscanning.cpp | 82 |
1 files changed, 41 insertions, 41 deletions
diff --git a/NorthstarDLL/sigscanning.cpp b/NorthstarDLL/sigscanning.cpp index 761f9f08..159d0f66 100644 --- a/NorthstarDLL/sigscanning.cpp +++ b/NorthstarDLL/sigscanning.cpp @@ -1,41 +1,41 @@ -#include "pch.h" -#include "sigscanning.h" -#include <map> - -// note: sigscanning is only really intended to be used for resolving stuff like shared function definitions -// we mostly use raw function addresses for stuff - -size_t GetModuleLength(HMODULE moduleHandle) -{ - // based on sigscn code from ttf2sdk, which is in turn based on CSigScan from https://wiki.alliedmods.net/Signature_Scanning - MEMORY_BASIC_INFORMATION mem; - VirtualQuery(moduleHandle, &mem, sizeof(mem)); - - IMAGE_DOS_HEADER* dos = (IMAGE_DOS_HEADER*)mem.AllocationBase; - IMAGE_NT_HEADERS* pe = (IMAGE_NT_HEADERS*)((unsigned char*)dos + dos->e_lfanew); - - return pe->OptionalHeader.SizeOfImage; -} - -void* FindSignature(std::string dllName, const char* sig, const char* mask) -{ - HMODULE module = GetModuleHandleA(dllName.c_str()); - - unsigned char* dllAddress = (unsigned char*)module; - unsigned char* dllEnd = dllAddress + GetModuleLength(module); - - size_t sigLength = strlen(mask); - - for (auto i = dllAddress; i < dllEnd - sigLength + 1; i++) - { - int j = 0; - for (; j < sigLength; j++) - if (mask[j] != '?' && sig[j] != i[j]) - break; - - if (j == sigLength) // loop finished of its own accord - return i; - } - - return nullptr; -} +#include "pch.h"
+#include "sigscanning.h"
+#include <map>
+
+// note: sigscanning is only really intended to be used for resolving stuff like shared function definitions
+// we mostly use raw function addresses for stuff
+
+size_t GetModuleLength(HMODULE moduleHandle)
+{
+ // based on sigscn code from ttf2sdk, which is in turn based on CSigScan from https://wiki.alliedmods.net/Signature_Scanning
+ MEMORY_BASIC_INFORMATION mem;
+ VirtualQuery(moduleHandle, &mem, sizeof(mem));
+
+ IMAGE_DOS_HEADER* dos = (IMAGE_DOS_HEADER*)mem.AllocationBase;
+ IMAGE_NT_HEADERS* pe = (IMAGE_NT_HEADERS*)((unsigned char*)dos + dos->e_lfanew);
+
+ return pe->OptionalHeader.SizeOfImage;
+}
+
+void* FindSignature(std::string dllName, const char* sig, const char* mask)
+{
+ HMODULE module = GetModuleHandleA(dllName.c_str());
+
+ unsigned char* dllAddress = (unsigned char*)module;
+ unsigned char* dllEnd = dllAddress + GetModuleLength(module);
+
+ size_t sigLength = strlen(mask);
+
+ for (auto i = dllAddress; i < dllEnd - sigLength + 1; i++)
+ {
+ int j = 0;
+ for (; j < sigLength; j++)
+ if (mask[j] != '?' && sig[j] != i[j])
+ break;
+
+ if (j == sigLength) // loop finished of its own accord
+ return i;
+ }
+
+ return nullptr;
+}
|