Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Function GetAllSLVItems(ByVal lstviewhwnd As IntPtr) As String()
- Dim saReturn() As String = Nothing
- Dim result As Integer
- Dim myItem As LV_ITEMA
- Dim pHandle As IntPtr
- Dim pStrBufferMemory As Integer
- Dim pMyItemMemory As Integer
- Dim strBuffer() As Byte
- Dim index As Integer
- Dim tmpString As String
- Dim ProcessID As Integer
- Dim UserCount As Integer
- UserCount = SendMessage(lstviewhwnd, LVM_GETITEMCOUNT, 0, 0)
- For i As Integer = 0 To UserCount - 1
- 'ensure tmpString = Nothing
- tmpString = Nothing
- '**********************
- 'init the string buffer
- '**********************
- ReDim strBuffer(StringBufferLength)
- '***********************************************************
- 'open a handle to the process and allocate the string buffer
- '***********************************************************
- Call GetWindowThreadProcessId(lstviewhwnd, ProcessID)
- pHandle = OpenProcess(PROCESS_VM_OPERATION Or PROCESS_VM_READ Or PROCESS_VM_WRITE, False, ProcessID)
- pStrBufferMemory = VirtualAllocEx(pHandle, 0, StringBufferLength, MEM_COMMIT, PAGE_READWRITE)
- '************************************************************************************
- 'initialize the local LV_ITEM structure
- 'The myItem.iSubItem member is set to the index of the column that is being retrieved
- '************************************************************************************
- myItem.mask = LVIF_TEXT
- myItem.iSubItem = 0
- myItem.pszText = pStrBufferMemory
- myItem.cchTextMax = StringBufferLength
- '**********************************************************
- 'write the structure into the remote process's memory space
- '**********************************************************
- pMyItemMemory = VirtualAllocEx(pHandle, 0, Len(myItem), MEM_COMMIT, PAGE_READWRITE)
- result = WriteProcessMemory(pHandle, pMyItemMemory, myItem, Len(myItem), 0)
- '*************************************************************
- '*************************************************************
- 'send the get the item message and write back the memory space
- '*************************************************************
- result = SendMessage(lstviewhwnd, LVM_GETITEMTEXT, i, pMyItemMemory)
- result = ReadProcessMemory(pHandle, pStrBufferMemory, strBuffer(0), StringBufferLength, 0)
- result = ReadProcessMemory(pHandle, pMyItemMemory, myItem, Len(myItem), 0)
- If result > 0 Then
- '**************************************************
- 'turn the byte array into a string to return
- '**************************************************
- For index = LBound(strBuffer) To UBound(strBuffer)
- If Chr(strBuffer(index)) = vbNullChar Then Exit For
- tmpString = tmpString & Chr(strBuffer(index))
- Next index
- tmpString = Trim(tmpString)
- '**************************************************
- ' add returned string to string array for return
- '**************************************************
- If saReturn Is Nothing Then
- ReDim saReturn(0)
- Else
- ReDim Preserve saReturn(saReturn.Length)
- End If
- saReturn(saReturn.Length - 1) = tmpString
- End If
- '**************************************************
- 'deallocate the memory and close the process handle
- '**************************************************
- result = VirtualFreeEx(pHandle, pStrBufferMemory, 0, MEM_RELEASE)
- result = VirtualFreeEx(pHandle, pMyItemMemory, 0, MEM_RELEASE)
- result = CloseHandle(pHandle)
- Next
- Return saReturn
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement