Advertisement
TLama

Untitled

Feb 1st, 2014
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Public Function GetAllSLVItems(ByVal lstviewhwnd As IntPtr) As String()
  2.     Dim saReturn() As String = Nothing
  3.     Dim result As Integer
  4.     Dim myItem As LV_ITEMA
  5.     Dim pHandle As IntPtr
  6.     Dim pStrBufferMemory As Integer
  7.     Dim pMyItemMemory As Integer
  8.     Dim strBuffer() As Byte
  9.     Dim index As Integer
  10.     Dim tmpString As String
  11.     Dim ProcessID As Integer
  12.     Dim UserCount As Integer
  13.     UserCount = SendMessage(lstviewhwnd, LVM_GETITEMCOUNT, 0, 0)
  14.     For i As Integer = 0 To UserCount - 1
  15.         'ensure tmpString = Nothing
  16.        tmpString = Nothing
  17.         '**********************
  18.        'init the string buffer
  19.        '**********************
  20.        ReDim strBuffer(StringBufferLength)
  21.         '***********************************************************
  22.        'open a handle to the process and allocate the string buffer
  23.        '***********************************************************
  24.        Call GetWindowThreadProcessId(lstviewhwnd, ProcessID)
  25.         pHandle = OpenProcess(PROCESS_VM_OPERATION Or PROCESS_VM_READ Or PROCESS_VM_WRITE, False, ProcessID)
  26.         pStrBufferMemory = VirtualAllocEx(pHandle, 0, StringBufferLength, MEM_COMMIT, PAGE_READWRITE)
  27.         '************************************************************************************
  28.        'initialize the local LV_ITEM structure
  29.        'The myItem.iSubItem member is set to the index of the column that is being retrieved
  30.        '************************************************************************************
  31.        myItem.mask = LVIF_TEXT
  32.         myItem.iSubItem = 0
  33.         myItem.pszText = pStrBufferMemory
  34.         myItem.cchTextMax = StringBufferLength
  35.         '**********************************************************
  36.        'write the structure into the remote process's memory space
  37.        '**********************************************************
  38.        pMyItemMemory = VirtualAllocEx(pHandle, 0, Len(myItem), MEM_COMMIT, PAGE_READWRITE)
  39.         result = WriteProcessMemory(pHandle, pMyItemMemory, myItem, Len(myItem), 0)
  40.         '*************************************************************
  41.        '*************************************************************
  42.        'send the get the item message and write back the memory space
  43.        '*************************************************************
  44.        result = SendMessage(lstviewhwnd, LVM_GETITEMTEXT, i, pMyItemMemory)
  45.         result = ReadProcessMemory(pHandle, pStrBufferMemory, strBuffer(0), StringBufferLength, 0)
  46.         result = ReadProcessMemory(pHandle, pMyItemMemory, myItem, Len(myItem), 0)
  47.         If result > 0 Then
  48.             '**************************************************
  49.            'turn the byte array into a string to return
  50.            '**************************************************
  51.            For index = LBound(strBuffer) To UBound(strBuffer)
  52.                 If Chr(strBuffer(index)) = vbNullChar Then Exit For
  53.                 tmpString = tmpString & Chr(strBuffer(index))
  54.             Next index
  55.             tmpString = Trim(tmpString)
  56.             '**************************************************
  57.            ' add returned string to string array for return
  58.            '**************************************************
  59.            If saReturn Is Nothing Then
  60.                 ReDim saReturn(0)
  61.             Else
  62.                 ReDim Preserve saReturn(saReturn.Length)
  63.             End If
  64.             saReturn(saReturn.Length - 1) = tmpString
  65.         End If
  66.  
  67.         '**************************************************
  68.        'deallocate the memory and close the process handle
  69.        '**************************************************
  70.        result = VirtualFreeEx(pHandle, pStrBufferMemory, 0, MEM_RELEASE)
  71.         result = VirtualFreeEx(pHandle, pMyItemMemory, 0, MEM_RELEASE)
  72.         result = CloseHandle(pHandle)
  73.     Next
  74.     Return saReturn
  75. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement