Announcement

Collapse
No announcement yet.

ReadProcessMemory

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • ReadProcessMemory

    Im using ReadProcessMemory() to read parts of the memory in both my process and one other process. I need to find out the SIZE of the memory being used by the other process before I use ReadProcessMemory, so that I know how big to set my buffer before I read it in, especially as according to MSDN "The entire area to be read must be accessible, or the operation fails"
    Does anybody have any ideas what API calls are needed to find out the size of the memory space area of a process? I've tried with VirtualQuery, VirtualQueryEx and GetWorkingSetSize, but to no avail


    ------------------
    -

  • #2
    Wayne,

    check the PSAPI. The Function you are looking for should be

    GetProcessMemoryInfo

    Regards,

    Torsten

    P.S.: Needs NT4.0 or higher

    ------------------

    Comment


    • #3
      Thankyou very much Torte! But that only solves half my problem as my program is intended for Win9x as well as WinNT/2K - do you, or does anyone, have any idea as to how to determine the process memory space size for Win9x processes? Is such info available from the ToolHelp APIs??? Ive done a lot of hunting around for this and Im getting nowhere, so any help is very very much appreciated


      ------------------
      -

      Comment


      • #4
        Wayne,

        you should keep the following in mind.
        <SDK>
        lpBaseAddress [in] Base address in the specified process to read.
        Before transferring any data, the system verifies that
        all data in the base address and memory of the specified
        size is accessible for read access.
        If this is the case, the function proceeds.
        Otherwise, the function fails
        </SDK>

        has the following meaning. Process(A) must
        have sufficient rights to read the memory from an process(B).
        If the memory to be read from process(B) is protected by
        process(B), than the process(A) will fail to read memory from
        process(b).
        Example:
        Process(A) has mem from addr 0 - 999
        Process(B) has mem from addr 1000 - 1999
        Process(B) has locked mem from addr 1500 - 1800
        Process(A) will read mem from Process(B) from 1200-1600 and
        will fail due Process(B) has protected mem in the range of
        Process(A) wants to read.

        BTW, the ToolHelp API seems to be right way on Win9x. It is interesting
        that the ToolHelp API works on both 9x and 2k. So you should
        use PSAPI first on 2k, then ToolHelp on 2k and compare the
        returned addresses and values. If you are satified, you can move
        your 2k ToolHelp code to 9x.

        Regards,

        Torsten

        ------------------

        Comment

        Working...
        X