2y ago · Dec 15, 2023 6:30 PM
Here is a lightweight, modern C++ IDA-style pattern scanner that parses signatures with and wildcards at runtime into a fast vector mask:
Usage Example:
CODE
? CODE
?? CPP
#include <windows.h>
#include <vector>
#include <sstream>
uintptr_t PatternScan(uintptr_t moduleBase, size_t moduleSize, const char* signature) {
std::vector<int> patternBytes;
std::stringstream ss(signature);
std::string byteStr;
while (ss >> byteStr) {
if (byteStr == "?" || byteStr == "??") {
patternBytes.push_back(-1); // Wildcard
} else {
patternBytes.push_back(std::stoi(byteStr, nullptr, 16));
}
}
const uint8_t* scanBytes = reinterpret_cast<const uint8_t*>(moduleBase);
const size_t patternSize = patternBytes.size();
for (size_t i = 0; i < moduleSize - patternSize; ++i) {
bool found = true;
for (size_t j = 0; j < patternSize; ++j) {
if (patternBytes[j] != -1 && scanBytes[i + j] != static_cast<uint8_t>(patternBytes[j])) {
found = false;
break;
}
}
if (found) return moduleBase + i;
}
return 0;
}Usage Example:
CPP
uintptr_t fnAddr = PatternScan(base, size, "48 89 5C 24 ? 48 89 74 24 ? 57 48 83 EC 30");
SigScannerPro · Pattern scanning & Byte masking
The following users thanked SigScannerPro for this post: