Pattern16 allocates memory which it eventually finds...
- Run a process that definitely does not have a test string in memory
- Check through a debugger or in any other way that this string is not in memory
- Inject the library and let it finish scanning
- Check again for the presence of this string in memory
Code to reproduce the problem
#include <Windows.h>
#include <iostream>
#include "pattern16/include/Pattern16.h"
void* ScanMemory(const char* string)
{
uintptr_t* address = nullptr;
MEMORY_BASIC_INFORMATION meminfo{};
while (VirtualQuery(address, &meminfo, sizeof(meminfo)))
{
address = reinterpret_cast<uintptr_t*>
(reinterpret_cast<SIZE_T>(meminfo.BaseAddress) + meminfo.RegionSize);
if (!(meminfo.State == MEM_COMMIT &&
meminfo.Type == MEM_PRIVATE &&
meminfo.Protect == PAGE_READWRITE))
continue;
void* ptr = Pattern16::scan(meminfo.BaseAddress, meminfo.RegionSize, string);
if (ptr)
return ptr;
}
return nullptr;
}
int main()
{
// Hello World
void* ptr = ScanMemory("48 65 6C 6C 6F 20 57 6F 72 6C 64");
if (ptr)
std::cout << ptr << std::endl;
else
std::cout << "String not found!" << std::endl;
system("pause");
return EXIT_SUCCESS;
}
Pattern16 allocates memory which it eventually finds...
Code to reproduce the problem