1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
struct MemInfo {
PVOID baseAddr;
SIZE_T regionSize;
};
void scan_memory_func2(std::mutex& g_queue,
std::queue<MemInfo>& mem_queue,
std::mutex& g_found,
std::vector<const uint8_t*>& addresses_found,
const std::atomic<bool>& searching,
const std::vector<uint8_t>& byte_check,
HANDLE proc) {
bool queue_empty = false;
MemInfo info{};
while (searching || !queue_empty) {
{
std::lock_guard<std::mutex> guard(g_queue);
if (mem_queue.empty()) {
queue_empty = true;
continue;
}
else {
info = mem_queue.front();
mem_queue.pop();
queue_empty = false;
}
}
std::vector<uint8_t> mem_chunk{};
size_t read;
mem_chunk.reserve(info.regionSize);
if (ReadProcessMemory(proc, info.baseAddr, mem_chunk.data(), info.regionSize, &read)) {
auto start = mem_chunk.data(), end = start + read, pos = start;
while ((pos = std::search(pos, end, byte_check.begin(), byte_check.end())) != end) {
{
std::lock_guard<std::mutex> guard(g_found);
addresses_found.push_back(static_cast<const uint8_t*>(info.baseAddr)
+ (pos - start));
}
pos += byte_check.size();
}
}
}
}
| |