Add basic pattern scanner.

Signed-off-by: aixxe <me@aixxe.net>
This commit is contained in:
aixxe 2016-12-20 20:14:58 +00:00
parent 8483f9b724
commit 5e10af4344
1 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1,29 @@
#pragma once
// Slightly modified version of P47R!CK & dom1n1k's pattern scanner.
inline bool Compare(const uint8_t* data, const uint8_t* pattern, const char* mask) {
for (; *mask; ++mask, ++data, ++pattern) {
if (*mask == 'x' && *data != *pattern) {
return false;
}
}
return *mask == 0;
}
static uintptr_t FindPattern(const char* library, const char* pattern_string, const char* mask) {
size_t address = 0, length = 0;
if (!Linker::GetLibraryInformation(library, &address, &length))
return 0;
const uint8_t* pattern = reinterpret_cast<const uint8_t*>(pattern_string);
for (size_t i = 0; i < length; i++) {
if (Compare(reinterpret_cast<uint8_t*>(address + i), pattern, mask)) {
return address + i;
}
}
return 0;
}