Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int ScanMemoryInt(HANDLE pHandle, int searchValue)
- {
- int total = 0;
- // Get the page size information.
- SYSTEM_INFO sSysInfo = {};
- GetSystemInfo(&sSysInfo);
- // Variable to store the memory information for that page or pages.
- MEMORY_BASIC_INFORMATION memInfo;
- void * currentScanAddress = 0;
- char* buffer;
- while (true)
- {
- SIZE_T readBytes = VirtualQueryEx(pHandle, currentScanAddress, &memInfo, sizeof(memInfo));
- if (!readBytes)
- {
- std::cout << "Total: " << total << " Addresses" << std::endl;
- return total;
- }
- // Only look at committed memory
- if (memInfo.State == MEM_COMMIT && memInfo.Protect != PAGE_NOACCESS)
- {
- // Allocate a buffer to read the memory contents
- std::vector<int> buffer(memInfo.RegionSize / sizeof(int));
- // Read the memory contents into the buffer
- SIZE_T bytesRead;
- if (ReadProcessMemory(pHandle, memInfo.BaseAddress, buffer.data(), memInfo.RegionSize, &bytesRead))
- {
- //std::cout << "Successfully read " << bytesRead << " bytes from memory." << std::endl;
- // Process mem contents and print addresses and integer values
- for (SIZE_T i = 0; i < bytesRead / sizeof(int); ++i)
- {
- void* address = reinterpret_cast<char*>(memInfo.BaseAddress) + (i * sizeof(int));
- int value = buffer[i];
- if (value == (int)searchValue)
- {
- // Do things with the address here, the address variable stores the memory address.
- // As for me I store it in a list.
- currentValuesInt[address] = value;
- total++;
- }
- }
- }
- }
- currentScanAddress = (char *)memInfo.BaseAddress + memInfo.RegionSize;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment