Home > Software engineering >  Windows 7 across processes read SysListView32 is invalid, what reason be
Windows 7 across processes read SysListView32 is invalid, what reason be

Time:09-24


SysListView32 handle to have read, rows and columns are checked in, but read less than content, may be what causes?

I am Windows 7 64 - bit systems, the program is a 32-bit



//find the window handle
The HWND HWND;
The hWnd=: : FindWindow (NULL, _T (" Windows task manager "));
HWnd=: : FindWindowEx (hWnd, 0, # 32770, 0).
HListview=: : FindWindowEx (hWnd, 0, _T (" SysListView32 "), NULL);



//process interface window handle, obtained by SPY
//hListview=m_TradeCtrls. HStockList;

//listview column head handle
Headerhwnd=: : SendMessage (hListview LVM_GETHEADER, 0, 0);

//total number: the number of process
Rows=: : SendMessage (hListview LVM_GETITEMCOUNT, 0, 0);
//list the number of columns
Cols=: : SendMessage ((HWND) headerhwnd HDM_GETITEMCOUNT, 0, 0).
//cols=Header_GetItemCount (ListView_GetHeader (hListview));

ThreadID=GetWindowThreadProcessId (hListview, & amp; ProcessID);

//open and insert process
//hProcess=OpenProcess (PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE | PROCESS_QUERY_INFORMATION, FALSE, ProcessID);
HProcess=OpenProcess (PROCESS_ALL_ACCESS, FALSE, ProcessID);
//application code memory area
Pointer=(LVITEM *) VirtualAllocEx (hProcess, NULL, sizeof (LVITEM), MEM_COMMIT, PAGE_READWRITE);

for (int i=0; I & lt; Rows; I++)
{
For (int j=0; J & lt; Cols. J++)
{
LVITEM vItem;
VItem. Mask=LVIF_TEXT;//is given to illustrate the effectiveness of the pszText
VItem. IItem=I;//line number
VItem. ISubItem=j;//column number
VItem. CchTextMax=512;//the biggest text can store of 256 bytes
LPSTR pItem=NULL;
//the application memory space
PItem=(LPSTR) VirtualAllocEx (hProcess, NULL, 512, MEM_COMMIT, PAGE_READWRITE);
VItem. PszText=pItem;

BOOL b=WriteProcessMemory (hProcess, pointer, & amp; VItem, sizeof (LVITEM), NULL);
Int nRet=: : SendMessage (hListview LVM_GETITEM, (WPARAM), I (LPARAM) pointer);
//: : SendMessage (hListview LVM_GETITEMTEXTA, (WPARAM), I (LPARAM) pointer);
Char ItemBuf [512].
Memset (ItemBuf, 0512);
ReadProcessMemory (hProcess, PVOID pItem, ItemBuf, 512, NULL);
CString str;
STR. The Format (_T (" % s "), ItemBuf);
if (! STR. IsEmpty ())
AfxMessageBox (STR);

//release the memory space
VirtualFreeEx (hProcess, pItem, 0, MEM_RELEASE);
}
}
//release the memory space
VirtualFreeEx (hProcess, pointer, 0, MEM_RELEASE);//in the process of other release application for virtual memory space, MEM_RELEASE way very thoroughly, fully recycling
The CloseHandle (hProcess);//off to open the process object

CodePudding user response:

 
//
LPMYLVITEM CRemoteListCtrlDlg: : RemoteLVGetItem (int index, HWND hLvWnd)
{//
M_hHdWnd=ListView_GetHeader (m_hLvWnd);
Int nColumn=: : SendMessage (m_hHdWnd HDM_GETITEMCOUNT, 0, 0);
//Get hProcess
DWORD pid;
GetWindowThreadProcessId (m_hLvWnd, & amp; pid);
HANDLE hProcess=OpenProcess (PROCESS_ALL_ACCESS, FALSE, pid);
//
LPMYLVITEM pRemoteItem=(LPMYLVITEM) VirtualAllocEx (hProcess, NULL, nColumn * sizeof (MYLVITEM), MEM_COMMIT, PAGE_READWRITE);
if (! PRemoteItem)
{
: : MessageBox (NULL, "unable to allocate memory!" , "wrong!" , NULL);
The CloseHandle (hProcess);
return 0;
}
//local
LPMYLVITEM pLocalItem=new MYLVITEM [nColumn];
Memset (pLocalItem, 0, nColumn * sizeof (MYLVITEM));
for(int i=0; i{
PLocalItem [I]. OldItem. Mask=LVIF_TEXT | LVIF_STATE | LVIF_IMAGE;//
PLocalItem [I]. OldItem. IItem=index;//
PLocalItem [I]. OldItem. ISubItem=I;//
PLocalItem [I]. OldItem. CchTextMax=80;
PLocalItem [I]. OldItem. PszText=pRemoteItem [I] the text;//not pLocalItem [I]. Text
if(! WriteProcessMemory (hProcess, & amp; PRemoteItem [I], & amp; PLocalItem [I], sizeof (MYLVITEM), NULL))
{
: : MessageBox (NULL, "WriteProcessMemory!" , "wrong!" , NULL);
The CloseHandle (hProcess);
return 0;
}
ListView_GetItem (m_hLvWnd, & amp; PRemoteItem [I]);
//: : SendMessage (m_hLvWnd LVM_GETITEM, (WPARAM), I (LPARAM) & amp; PRemoteItem [I]);
if(! ReadProcessMemory (hProcess, & amp; PRemoteItem [I], & amp; PLocalItem [I], sizeof (MYLVITEM), NULL))
{
: : MessageBox (NULL, "ReadProcessMemory!" , "wrong!" , NULL);
The CloseHandle (hProcess);
return 0;
}
//!!!!!!
PLocalItem [I]. OldItem. PszText=pLocalItem [I] the text;
//
//afxDump & lt; //
//HIMAGELIST hRemoteImageLst=ListView_GetImageList (m_hLvWnd LVSIL_SMALL);
//HICON HICON=ImageList_ExtractIcon (0, hRemoteImageLst, pLocalItem [I] oldItem. IImage);
}
//release the memory
The CloseHandle (hProcess);
VirtualFreeEx (hProcess, pRemoteItem, 0, MEM_RELEASE);
Return pLocalItem;
}

In another, allocating memory,

CodePudding user response:

Windows task manager 64 - bit system model of this program is 64, if start a 32-bit task manager, yes, I've tried

CodePudding user response:

Each process has its own process space, cannot directly access other buffer. In the process of the most simple, can use WM_COPYDATA message, bring back the string,
  • Related