|
-
Jan 17th, 2009, 09:26 AM
#5
Thread Starter
Lively Member
Re: howto get text from listview with api?
 Originally Posted by minor28
Processes are running i virtual memory, i.e. all starts at address &H400000. You har requesting information from a remote process which will retrieve the data from a non existing listview structure. As I understand you have got the remote window handle already. This is how you do it.
1. Allocate memory in remote process
2. Fill your listview structre with values as you have done
3. Transfer the structure to allocated memory in remote process
4. Send the message but this time with address to allocated memory i remote process
5. Transfer the item text from allocated memory in remote process to allocated memory in your process
6. Free allocated memory
Now you can show messagebox with item text.
hey men help me
this is another,i find this but when get item only empty added to listbox?
why?
Code:
Option Explicit
Private Const LVIF_TEXT As Long = &H1
Private Const LVM_FIRST As Long = &H1000
Private Const LVM_GETITEM As Long = (LVM_FIRST + 5)
Private Const LVM_SETITEM As Long = (LVM_FIRST + 6)
Private Const LVM_GETITEMCOUNT As Long = (LVM_FIRST + 4)
Private Const MEM_COMMIT As Long = &H1000
Private Const PAGE_READWRITE As Long = &H4
Private Const STANDARD_RIGHTS_REQUIRED As Long = &HF0000
Private Const SYNCHRONIZE As Long = &H100000
Private Const PROCESS_ALL_ACCESS As Long = (STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &HFFF)
Private Const MEM_RELEASE As Long = &H8000
Private Type LVITEM
mask As Long
iItem As Long
iSubItem As Long
state As Long
stateMask As Long
pszText As Long 'Notice not string but long
cchTextMax As Long
iImage As Long
lParam As Long
iIndent As Long
End Type
Private Declare Function OpenProcess Lib "kernel32.dll" ( _
ByVal dwDesiredAccess As Long, _
ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long
Private Declare Function WriteProcessMemory Lib "kernel32.dll" ( _
ByVal hProcess As Long, _
ByRef lpBaseAddress As Any, _
ByRef lpBuffer As Any, _
ByVal nSize As Long, _
ByRef lpNumberOfBytesWritten As Long) As Long
Private Declare Function ReadProcessMemory Lib "kernel32.dll" ( _
ByVal hProcess As Long, _
ByRef lpBaseAddress As Any, _
ByRef lpBuffer As Any, _
ByVal nSize As Long, _
ByRef lpNumberOfBytesWritten As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32.dll" ( _
ByVal hwnd As Long, _
ByRef lpdwProcessId As Long) As Long
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
ByVal lpClassName As Long, _
ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" ( _
ByVal hwndParent As Long, _
ByVal hwndChildAfter As Long, _
ByVal lpszClass As String, _
ByVal lpszWindow As Long) As Long
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Private Declare Function VirtualAllocEx Lib "kernel32.dll" ( _
ByVal hProcess As Long, _
ByVal lpAddress As Long, _
ByVal dwSize As Long, _
ByVal flAllocationType As Long, _
ByVal flProtect As Long) As Long
Private Declare Function VirtualFreeEx Lib "kernel32.dll" ( _
ByVal hProcess As Long, _
ByVal lpAddress As Long, _
ByVal dwSize As Long, _
ByVal dwFreeType As Long) As Long
Private Declare Function CloseHandle Lib "kernel32.dll" ( _
ByVal hObject As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32.dll" ( _
ByVal hProcess As Long, _
ByVal uExitCode As Long) As Long
Dim hProcess As Long
Private Sub Command1_Click()
Dim hndl As Long
Dim hListView As Long
Dim lpdwProcessId As Long
Dim pMem As Long
Dim lvi As LVITEM
Dim lpNumberOfBytesWritten As Long
Dim i As Long
Dim cItems As Long
Dim txt As String
Dim pTxt As Long
'Get the handle of listview control
hndl = FindWindow(0, "WindowName")
hListView = FindWindowEx(hndl, 0, "SysListView32", 0)
'Retrieve a handle of the listview control process
GetWindowThreadProcessId hListView, lpdwProcessId
hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, lpdwProcessId)
'Allocate memory in listview process memory space for the LVITEM structure and listitem text
pMem = VirtualAllocEx(hProcess, 0, Len(lvi), MEM_COMMIT, PAGE_READWRITE)
pTxt = VirtualAllocEx(hProcess, 0, 256, MEM_COMMIT, PAGE_READWRITE)
'Retrieve number of listview items
cItems = SendMessage(hListView, LVM_GETITEMCOUNT, 0, 0)
'Fill a LVITEM structure with values
lvi.mask = LVIF_TEXT
lvi.cchTextMax = 256
lvi.pszText = pTxt 'This is a pointer to the address where item text will be hold
'Allocate space for a string
txt = Space(256)
For i = 0 To cItems - 1
'Add item index to structure
lvi.iItem = i
'Transfer the structure to allocated memory in listview memory space
WriteProcessMemory hProcess, ByVal pMem, lvi, Len(lvi), lpNumberOfBytesWritten
'Send message to get listview item [i]. Result hold in LVITEM strucktur at address pMem
SendMessage hListView, LVM_GETITEM, 0, ByVal pMem
'Transfer the item text from allocated memory at pTxt to txt space in this app process memory
ReadProcessMemory hProcess, ByVal pTxt, ByVal txt, 256, lpNumberOfBytesWritten
List1.AddItem txt
Next i
'Free allocated memory
VirtualFreeEx hProcess, pMem, Len(lvi), MEM_RELEASE
VirtualFreeEx hProcess, pTxt, 256, MEM_RELEASE
End Sub
Private Sub Form_Load()
Shell "fullpath to listview.exe"
End Sub
Private Sub Form_Terminate()
TerminateProcess hProcess, 0
CloseHandle hProcess
End Sub
Last edited by Y.P.Y; Jan 18th, 2009 at 02:05 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|