diff options
author | BobTheBob <32057864+BobTheBob9@users.noreply.github.com> | 2021-07-08 15:33:31 +0100 |
---|---|---|
committer | BobTheBob <32057864+BobTheBob9@users.noreply.github.com> | 2021-07-08 15:33:31 +0100 |
commit | 4c4d605d10109e02708984755405bbe0947ef5c4 (patch) | |
tree | 1d5ffe7909b24b6c79fd444b420741e85f6c2b57 /NorthstarDedicatedTest/sigscanning.cpp | |
parent | 8dfb8e866119f653802609b24165b0458149c4cc (diff) | |
download | NorthstarLauncher-4c4d605d10109e02708984755405bbe0947ef5c4.tar.gz NorthstarLauncher-4c4d605d10109e02708984755405bbe0947ef5c4.zip |
initial commit
Diffstat (limited to 'NorthstarDedicatedTest/sigscanning.cpp')
-rw-r--r-- | NorthstarDedicatedTest/sigscanning.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/NorthstarDedicatedTest/sigscanning.cpp b/NorthstarDedicatedTest/sigscanning.cpp new file mode 100644 index 00000000..c75c80f0 --- /dev/null +++ b/NorthstarDedicatedTest/sigscanning.cpp @@ -0,0 +1,39 @@ +#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 GetDLLLength(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 dllAddress = GetModuleHandleA(dllName.c_str()); + char* dllEnd = (char*)(dllAddress + GetDLLLength(dllAddress)); + + size_t sigLength = strlen(mask); + + for (char* i = (char*)dllAddress; i < dllEnd - sigLength; 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 (void*)i; + } + + return nullptr; +} |