Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows Development
  4. ReadProcessMemory fails in Windows 10 64 bit

ReadProcessMemory fails in Windows 10 64 bit

Scheduled Pinned Locked Moved Windows Development
helpdebuggingworkspacecsharpvisual-studio
12 Posts 3 Posters 51 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Lost User

    Your ReadProcessMemory call is missing the destination parameter to read into; see https://msdn.microsoft.com/en-gb/library/windows/desktop/ms680553(v=vs.85).aspx[^].

    1 Offline
    1 Offline
    11917640 Member
    wrote on last edited by
    #3

    Thanks, the post fixed. Real program contains the buffer parameter, of course.

    L 1 Reply Last reply
    0
    • 1 11917640 Member

      Thanks, the post fixed. Real program contains the buffer parameter, of course.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #4

      Member 11917640 wrote:

      Real program contains ...

      Then use copy and paste, so we can see exactly what your code is doing.

      1 1 Reply Last reply
      0
      • L Lost User

        Member 11917640 wrote:

        Real program contains ...

        Then use copy and paste, so we can see exactly what your code is doing.

        1 Offline
        1 Offline
        11917640 Member
        wrote on last edited by
        #5

        Thanks, this really helps.

        1 Reply Last reply
        0
        • 1 11917640 Member

          Consider the following two programs. One is the console application with this code:

          int main()
          {
          char *p = new char[100];
          return 0;
          }

          I run this program in Debug configuration and break on return 0 line. I the Watch window I see p variable value. The second program:

          HANDLE hProcess = OpenProcess( PROCESS_VM_READ, FALSE ,
          processId ); // ID of the process under debugger

          if ( hProcess == NULL ) return;
          char p[100];

          if (!ReadProcessMemory(hProcess,
          address, // value of p variable from the process under debugger
          p, 100,
          &NumberOfBytesRead))
          {
          // error handling
          }

          ReadProcessMemory is successful both in 32 and 64 bit (both program are compiled in Win32 or x64 configuration). Environment: Windows 7 64 bit, Visual Studio 2010. It also works in previous Windows versions. Now I try the same in Windows 10 64 bit. Both programs in 32 bit - OK. 64 bit: ReadProcessMemory returns FALSE with last error 299: Only part of a ReadProcessMemory request was completed. I tried: 1. To replace PROCESS_VM_READ with PROCESS_ALL_ACCESS 2. To run the second program as administrator 3. To use different Visual Studio versions (2010, 2015). Still doesn't help. ReadProcessMemory fails in Windows 10 for 64 bit processes. Edit: I tried to write this code from scratch, and it is working. So, the problem is somewhere in the original project, I don't know the solution yet, but API is working.

          Richard Andrew x64R Offline
          Richard Andrew x64R Offline
          Richard Andrew x64
          wrote on last edited by
          #6

          What data type is the address variable? What does the NumberOfBytesRead show after the call?

          The difficult we do right away... ...the impossible takes slightly longer.

          1 2 Replies Last reply
          0
          • Richard Andrew x64R Richard Andrew x64

            What data type is the address variable? What does the NumberOfBytesRead show after the call?

            The difficult we do right away... ...the impossible takes slightly longer.

            1 Offline
            1 Offline
            11917640 Member
            wrote on last edited by
            #7

            1. ULONG_PTR 2. 0

            1 Reply Last reply
            0
            • 1 11917640 Member

              Consider the following two programs. One is the console application with this code:

              int main()
              {
              char *p = new char[100];
              return 0;
              }

              I run this program in Debug configuration and break on return 0 line. I the Watch window I see p variable value. The second program:

              HANDLE hProcess = OpenProcess( PROCESS_VM_READ, FALSE ,
              processId ); // ID of the process under debugger

              if ( hProcess == NULL ) return;
              char p[100];

              if (!ReadProcessMemory(hProcess,
              address, // value of p variable from the process under debugger
              p, 100,
              &NumberOfBytesRead))
              {
              // error handling
              }

              ReadProcessMemory is successful both in 32 and 64 bit (both program are compiled in Win32 or x64 configuration). Environment: Windows 7 64 bit, Visual Studio 2010. It also works in previous Windows versions. Now I try the same in Windows 10 64 bit. Both programs in 32 bit - OK. 64 bit: ReadProcessMemory returns FALSE with last error 299: Only part of a ReadProcessMemory request was completed. I tried: 1. To replace PROCESS_VM_READ with PROCESS_ALL_ACCESS 2. To run the second program as administrator 3. To use different Visual Studio versions (2010, 2015). Still doesn't help. ReadProcessMemory fails in Windows 10 for 64 bit processes. Edit: I tried to write this code from scratch, and it is working. So, the problem is somewhere in the original project, I don't know the solution yet, but API is working.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #8

              address, // address of p variable from the process under debugger

              Should that not be the contents of p, i.e. whatever variable p is pointing to?

              1 1 Reply Last reply
              0
              • Richard Andrew x64R Richard Andrew x64

                What data type is the address variable? What does the NumberOfBytesRead show after the call?

                The difficult we do right away... ...the impossible takes slightly longer.

                1 Offline
                1 Offline
                11917640 Member
                wrote on last edited by
                #9

                Thank you for the help, this code is working when rewritten from scratch, so the problem is somewhere else in the original project.

                1 Reply Last reply
                0
                • L Lost User

                  address, // address of p variable from the process under debugger

                  Should that not be the contents of p, i.e. whatever variable p is pointing to?

                  1 Offline
                  1 Offline
                  11917640 Member
                  wrote on last edited by
                  #10

                  Thank you for the help, this code is working when rewritten from scratch, so the problem is somewhere else in the original project.

                  L 1 Reply Last reply
                  0
                  • 1 11917640 Member

                    Thank you for the help, this code is working when rewritten from scratch, so the problem is somewhere else in the original project.

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #11

                    So what is different?

                    1 1 Reply Last reply
                    0
                    • L Lost User

                      So what is different?

                      1 Offline
                      1 Offline
                      11917640 Member
                      wrote on last edited by
                      #12

                      I don't know yet, it is very old and messy code. Maybe I need to rewrite it from scratch and forget about this junk...

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups