Procedure TForm1.GetItemsSysListView(SysListHWND: Hwnd; Listbox: TListBox);
Var
iCount,i : integer;
lvItem : LV_ITEM;
plvRemoteItem : ^LV_ITEM;
pszItemText : PChar;
pszRemoteItemText : PChar;
nReadWritten : DWORD;
ProcessHND : THandle;
PID : DWORD;
stResult :
string;
const
ITEM_BUFFER : Integer = $4000;
begin
if SysListHWND = 0
then RaiseLastWin32Error;
GetWindowThreadProcessId(SysListHWND, @PID);
ProcessHND:= OpenProcess(PROCESS_VM_OPERATION
or PROCESS_VM_READ
or PROCESS_VM_WRITE
or PROCESS_QUERY_INFORMATION,false, PID);
try
pszItemText := AllocMem(ITEM_BUFFER);
FillMemory(addr(lvItem), sizeof(LV_ITEM), 0);
plvRemoteItem := VirtualAllocEx(ProcessHND,
nil, sizeof(LV_ITEM), MEM_COMMIT, PAGE_READWRITE);
pszRemoteItemText := VirtualAllocEx(ProcessHND,
nil, ITEM_BUFFER, MEM_COMMIT, PAGE_READWRITE);
iCount:= sendmessage(SysListHWND,LVM_GETITEMCOUNT,0,0);
dec(iCount);
lvItem.cchTextMax := ITEM_BUFFER;
lvItem.iSubItem := 2;
lvItem.pszText := pszRemoteItemText;
stResult:= '
';
for i:= 0
to iCount
do
begin
if (
not WriteProcessMemory(ProcessHND, plvRemoteItem, addr(lvItem), sizeof(LV_ITEM), nReadWritten))
then
showmessage(inttostr(getLastError));
SendMessage(SysListHWND, LVM_GETITEMTEXT, WPARAM(i), LPARAM(plvRemoteItem));
if (
not ReadProcessMemory(ProcessHND, pszRemoteItemText, pszItemText, ITEM_BUFFER, nReadWritten))
then
showmessage(inttostr(getLastError));
stResult:= stResult + strpas(pszItemText);
ListBox.Items.Append(pszItemText);
end;
finally
FreeMem(pszItemText);
VirtualFreeEx(ProcessHND, pszRemoteItemText, 0, MEM_RELEASE);
VirtualFreeEx(ProcessHND, plvRemoteItem, 0, MEM_RELEASE);
end;
end;