I allocate memory in someone else's process via VirtualAllocEx, write LVFINDINFOA to it, call ListView_FindItem, but it constantly returns -1

#include <Windows.h> #include <Commctrl.h> #include <iostream> #include <string> using namespace std; int main() { HWND h = 0; char* name = "chrome.exe"; size_t name_s = strlen(name) + 1; h = FindWindowA(NULL, "Диспетчер задач Windows"); DWORD PID = 0; GetWindowThreadProcessId(h, &PID); HANDLE mem = OpenProcess(PROCESS_ALL_ACCESS, false, PID); LPVOID strptr = VirtualAllocEx(mem, NULL, name_s, MEM_COMMIT, PAGE_READWRITE); cout << "write=" << WriteProcessMemory(mem, (LPVOID)strptr, name, name_s, NULL) << endl; LVFINDINFOA l; l.flags = LVFI_STRING; l.psz = (char*)strptr; LPVOID foptr = VirtualAllocEx(mem, NULL, sizeof(LVFINDINFOA), MEM_COMMIT, PAGE_READWRITE); cout << "write=" << WriteProcessMemory(mem, (LPVOID)foptr, &l, sizeof(LVFINDINFOA), NULL) << endl; h = FindWindowEx(h, 0, NULL, "Процессы"); h = FindWindowEx(h, 0, "SysListView32", NULL); int i = ListView_FindItem(h, -1, strptr); cout << "index=" << i << endl; cout << "err=" << GetLastError() << endl; } 
  • And try to allocate memory in your process, I have a suspicion that it cannot write like this to someone else ... - Vladimir Martyanov

0