Fremdprogramm (SysListView32) auslesen

  • VB.NET

    Fremdprogramm (SysListView32) auslesen

    Ich versuche gerade auf ein SysListView32 (Fremdprogramm) zuzugreifen.
    Ich habe nach langem Suchen folgendes gefunden und verstehe nicht wirklich viel.
    mycsharp.de/wbb2/thread.php?postid=3760476

    VB.NET-Quellcode

    1. Public Shared Function GetListItemText(ByVal hWnd As IntPtr, ByVal index As Integer, ByVal Optional column As Integer = 0) As String
    2. Dim bufferSize As Integer = 256
    3. Dim processId As UInteger = GetProcessId(hWnd)
    4. Dim hProcess As IntPtr = Win32API_Methods.OpenProcess(8 Or 16 Or 32, True, CInt(processId))
    5. Dim remoteBuffer As IntPtr = Win32API_Methods.VirtualAllocEx(hProcess, IntPtr.Zero, CUInt(bufferSize), &H1000, 4)
    6. Dim localBuffer As IntPtr = Marshal.AllocHGlobal(bufferSize)
    7. Dim lvi As Win32API_Structs.LVITEM = New Win32API_Structs.LVITEM()
    8. lvi.mask = 1
    9. lvi.cchTextMax = bufferSize - Marshal.SizeOf(lvi)
    10. lvi.iItem = index
    11. lvi.iSubItem = column
    12. lvi.pszText = IntPtr.Add(remoteBuffer, Marshal.SizeOf(lvi))
    13. Dim ptrLvi As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(lvi))
    14. Marshal.StructureToPtr(lvi, ptrLvi, False)
    15. Win32API_Methods.WriteProcessMemory(hProcess, remoteBuffer, ptrLvi, Marshal.SizeOf(lvi), IntPtr.Zero)
    16. Win32API_Methods.SendMessage(hWnd, &H1000 + 75, IntPtr.Zero, remoteBuffer)
    17. Win32API_Methods.ReadProcessMemory(hProcess, remoteBuffer, localBuffer, bufferSize, IntPtr.Zero)
    18. lvi.pszText = localBuffer + Marshal.SizeOf(lvi)
    19. Marshal.FreeHGlobal(localBuffer)
    20. Win32API_Methods.VirtualFreeEx(hProcess, remoteBuffer, 0, &H8000)
    21. Win32API_Methods.CloseHandle(hProcess)
    22. Return Marshal.PtrToStringAuto(lvi.pszText)
    23. End Function


    Gibt es irgendwo eine Sammlung der Deklarationen von Win32API_Methods?

    edit.
    Habe die Deklaration mal zusammengesucht :thumbsup:

    VB.NET-Quellcode

    1. Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Integer, ByVal dwProcessId As Integer) As Integer
    2. Declare Function VirtualAllocEx Lib "kernel32.dll" (ByVal hProcess As Int32, ByVal lpAddress As Int32, ByVal dwSize As Int32, ByVal flAllocationType As Int32, ByVal flProtect As Int32) As Int32
    3. Public Declare Function WriteProcessMemory Lib "kernel32" Alias "WriteProcessMemory" (ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Integer, ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As Integer
    4. Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
    5. Public Declare Function ReadProcessMemory Lib "kernel32" Alias "ReadProcessMemory" (ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Integer, ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As Integer
    6. Declare Function VirtualFreeEx Lib "kernel32.dll" (ByVal hProcess As Integer, lpAddress As Object, ByRef dwSize As Integer, ByVal dwFreeType As Integer) As Integer
    7. Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Integer) As Integer
    8. Friend Structure LVITEM
    9. Public mask As Integer
    10. Public iItem As Integer
    11. Public iSubItem As Integer
    12. Public state As Integer
    13. Public stateMask As Integer
    14. Public pszText As IntPtr
    15. Public cchTextMax As Integer
    16. Public iImage As Integer
    17. Public lParam As IntPtr
    18. Public iIndent As Integer
    19. Public iGroupId As Integer
    20. Public cColumns As Integer
    21. Public puColumns As IntPtr
    22. End Structure


    Wie ich die Funktion jetzt aber anwenden muss, fehlt mir noch :)
    In Arbeit...

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „vico255“ ()