This commit is contained in:
2026-05-27 13:24:57 +08:00
commit 4bf9a42170
21 changed files with 901 additions and 0 deletions
+66
View File
@@ -0,0 +1,66 @@
#include "utils.h"
namespace utils
{
auto GetVersion() -> OSVERSIONINFOW
{
OSVERSIONINFOW osver{ 0 };
osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW);
RtlGetVersion(&osver);
return osver;
}
auto patternCheck(const char* data, const char* pattern, const char* mask) -> bool
{
size_t len = strlen(mask);
for (size_t i = 0; i < len; i++)
{
if (data[i] == pattern[i] || mask[i] == '?')
continue;
else
return false;
}
return true;
}
auto patternFind(unsigned long long addr, unsigned long size, const char* pattern, const char* mask) -> ULONG64
{
size -= (unsigned long)strlen(mask);
for (unsigned long i = 0; i < size; i++)
{
if (patternCheck((const char*)addr + i, pattern, mask))
return addr + i;
}
return 0;
}
auto FindSectionsCode(unsigned long long Base, const char* pattern, const char* mask, const char* name) -> ULONG64
{
auto image_dos = (PIMAGE_DOS_HEADER)Base;
auto ntheader = (PIMAGE_NT_HEADERS)(Base + image_dos->e_lfanew);
auto section = IMAGE_FIRST_SECTION(ntheader);
for (size_t i = 0; i < ntheader->FileHeader.NumberOfSections; i++)
{
PIMAGE_SECTION_HEADER p = &section[i];
if (strstr((const char*)p->Name, name))
{
unsigned long long result = patternFind(Base + p->VirtualAddress, p->Misc.VirtualSize, pattern, mask);
if (result) return result;
}
}
return 0;
}
}