make this more advanced and add logging to the console and a way to ensure it dont exit…
- User
make this more advanced and add logging to the console and a way to ensure it dont exit to i press i enter and a way to selct what process to attech to dont use pid #include <windows.h> #include <tlhelp32.h> #include #include #include
struct MemoryRegion { uintptr_t start; uintptr_t end; };
std::vector getMemoryRegions(HANDLE hProcess) { std::vector regions; MEMORY_BASIC_INFORMATION mbi; uintptr_t address = 0;
while (VirtualQueryEx(hProcess, (LPCVOID)address, &mbi, sizeof(mbi)) == sizeof(mbi)) { if (mbi.State == MEM_COMMIT && (mbi.Protect & PAGE_READWRITE)) { regions.push_back({ (uintptr_t)mbi.BaseAddress, (uintptr_t)mbi.BaseAddress + mbi.RegionSize }); } address += mbi.RegionSize; } return regions;}
std::vector<uintptr_t> scanMemory(HANDLE hProcess, const std::vector& regions) { std::vector<uintptr_t> pointers; for (const auto& region : regions) { uintptr_t address = region.start; while (address < region.end) { uintptr_t potential_pointer; SIZE_T bytesRead; if (ReadProcessMemory(hProcess, (LPCVOID)address, &potential_pointer, sizeof(potential_pointer), &bytesRead) && bytesRead == sizeof(potential_pointer)) { // Optionally, validate the pointer here pointers.push_back(potential_pointer); } address += sizeof(potential_pointer); } } return pointers; }
int main(int argc, char* argv[]) { if (argc != 2) { std::cerr << "Usage: " << argv[0] << " " << std::endl; return 1; }
DWORD pid = std::stoi(argv[1]); HANDLE hProcess = OpenProcess(PROCESS_VM_READ | PROCESS_QUERY_INFORMATION, FALSE, pid); if (!hProcess) { std::cerr << "Failed to open process: " << GetLastError() << std::endl; return 1; } auto regions = getMemoryRegions(hProcess); auto pointers = scanMemory(hProcess, regions); CloseHandle(hProcess); std::cout << "Found " << pointers.size() << " potential pointers in process memory." << std::endl; for (auto ptr : pointers) { std::cout << std::hex << ptr << std::endl; } return 0;}
- Assistant
- User
'std::vector<uintptr_t,std::allocator<uintptr_t>> scanMemory(HANDLE,const std::vector<MemoryRegion,std::allocator> &)': cannot convert argument 2 from 'std::vector<MemoryRegion,std::allocator> (__cdecl *)(HANDLE)' to 'const std::vector<MemoryRegion,std::allocator> &' no operator "==" matches these operands '#' not expected here no operator "==" matches these operands The intermediate directory (x64\Release) contains files shared from another project (Dxgi.vcxproj, Project4.vcxproj). This can lead to incorrect clean and rebuild behavior. binary '==': no operator found which takes a left-hand operand of type 'const std::string' (or there is no acceptable conversion) preprocessor command must start as first nonwhite space 'MemoryRegion': 'struct' type redefinition function 'void logMessage(const std::string &)' already has a body function 'std::vector<MemoryRegion,std::allocator> getMemoryRegions(HANDLE)' already has a body 'std::vector<MemoryRegion,std::allocator>::push_back': no overloaded function could convert all the argument types function 'std::vector<uintptr_t,std::allocator<uintptr_t>> scanMemory(HANDLE,const std::vector<MemoryRegion,std::allocator> &)' already has a body use of undefined type 'MemoryRegion' use of undefined type 'MemoryRegion' 'logMessage': error in function definition or declaration; function not called function 'DWORD getProcessIDByName(const std::string &)' already has a body binary '==': no operator found which takes a left-hand operand of type 'const std::string' (or there is no acceptable conversion) function 'void chooseProcess(void)' already has a body function 'int main(void)' already has a body 'getProcessIDByName': error in function definition or declaration; function not called 'logMessage': error in function definition or declaration; function not called 'logMessage': error in function definition or declaration; function not called 'logMessage': error in function definition or declaration; function not called
- Assistant