Results 1 to 4 of 4

Thread: API: ReadProcessMemory [Resolved]

Threaded View

  1. #1

    Thread Starter
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622

    API: ReadProcessMemory [Resolved]

    I HATE USING API's in .NET....


    Anyway....

    VB Code:
    1. Private Const PROCESS_VM_READ = (&H10)
    2.  
    3.     <DllImport("kernel32", EntryPoint:="OpenProcess")> _
    4.     Public Shared Function OpenProcess(ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Integer, ByVal dwProcessId As Integer) As Integer
    5.  
    6.     End Function

    This Seems to be working correctly....

    VB Code:
    1. <DllImport("kernel32", EntryPoint:="CloseHandle")> _
    2.     Public Shared Function CloseHandle(ByVal hObject As Integer) As Integer
    3.  
    4.     End Function


    VB Code:
    1. <DllImport("kernel32", EntryPoint:="ReadProcessMemory")> _
    2.     Public Shared Function ReadProcessMemory(ByVal hProcess As Integer, _
    3.         ByVal lpBaseAddress As Integer, _
    4.         ByRef lpBuffer As Object, _
    5.         ByVal nSize As Integer, _
    6.         ByRef lpNumberOfBytesWritten As Integer) As Integer
    7.  
    8.     End Function

    This seems to be giving me the problem....
    if it Fails the return value is 0

    VB Code:
    1. Private Function ReadStringPointer(ByVal intProcessId As Integer, ByVal intPointer As Integer) As String
    2.         'Read Pointer
    3.  
    4.         Dim ProcessHandle As Integer = OpenProcess(PROCESS_VM_READ, 0, intProcessId)
    5.  
    6.         If ProcessHandle = 0 Then
    7.             MsgBox("Invaild ProcessHandle")
    8.             Exit Function
    9.         End If
    10.  
    11.         Dim Buffer As String = New String(Chr(0), 260)
    12.  
    13.         Dim intRet As Integer = Winamp.ReadProcessMemory(ProcessHandle, intPointer, Buffer, 260, vbNull)
    14.  
    15.         Winamp.CloseHandle(ProcessHandle)
    16.  
    17.         MsgBox("Process Handle: " & ProcessHandle & vbCrLf & _
    18.             "Return Value: " & intRet)
    19.  
    20.         Return Buffer
    21.  
    22.     End Function


    This is driving me up the wall. After I grab the Proccess Id and the Pointer I call ReadStringPointer and my app just exits.... it doesnt throw exceptions, just exits. I dont even get to see the form (calling from Form_load)

    Orginally, I used IntPtr's for the Handles but it didnt work so i tried just integers.
    Last edited by <ABX; Aug 1st, 2004 at 08:26 PM.
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width