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. ATL / WTL / STL
  4. ::ReadProcessMemory fails with ERROR_PARTIAL_COPY

::ReadProcessMemory fails with ERROR_PARTIAL_COPY

Scheduled Pinned Locked Moved ATL / WTL / STL
helpquestion
3 Posts 2 Posters 2 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.
  • G Offline
    G Offline
    Green Fuze
    wrote on last edited by
    #1

    Hey everybody. I wrote (according to articles I found on the net) the following code, in order to get the command line of another process (it is not the "full code", just until it fails.

    HANDLE hproc = ::OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
    if(!hproc)
    {
    printf("OpenProcess() failed: 0x%x", ::GetLastError());
    return _T("");
    }

    _NtQueryInformationProcess NtQueryInformationProcess = (_NtQueryInformationProcess)GetProcAddress(GetModuleHandleA("ntdll.dll"), "NtQueryInformationProcess");
    PROCESS_BASIC_INFORMATION pbi;
    DWORD size_written;
    NTSTATUS nt = NtQueryInformationProcess(hproc, ProcessBasicInformation, (void*)&pbi, sizeof(PROCESS_BASIC_INFORMATION), &size_written); // get pbi
    if(nt)
    {
    printf("NtQueryInformationProcess() failed: 0x%x", nt);
    return _T("");
    }

    PEB* peb = pbi.PebBaseAddress;
    ULONG session_id = peb->SessionId;
    SIZE_T read_size;
    RTL_USER_PROCESS_PARAMETERS* proc_params = NULL;
    DWORD old_protection;
    if(!::VirtualProtectEx(hproc, peb->ProcessParameters, sizeof(RTL_USER_PROCESS_PARAMETERS*), PAGE_EXECUTE_READWRITE, &old_protection))
    {
    printf("VirtualProtectEx() failed: 0x%x", ::GetLastError());
    return _T("");
    }

    // ************ FAILS HERE !!!! ***************
    if(!::ReadProcessMemory(hproc, peb->ProcessParameters, (RTL_USER_PROCESS_PARAMETERS*)proc_params, sizeof(RTL_USER_PROCESS_PARAMETERS*), &read_size))
    {
    printf("ReadProcessMemory() failed: 0x%x", ::GetLastError());
    return _T("");
    }

    if(!::VirtualProtectEx(hproc, peb->ProcessParameters, sizeof(RTL_USER_PROCESS_PARAMETERS*), old_protection, NULL))
    {
    printf("VirtualProtectEx() failed: 0x%x", ::GetLastError());
    return _T("");
    }

    The output is that ReadProcessMemory() fails with ERROR_PARTIAL_COPY. The code works in XP for processes in the same session. Currently I am trying to make it work in windows 7, for a process in the same session. ANY IDEAS any one ???? :confused: Thanks!

    _ 1 Reply Last reply
    0
    • G Green Fuze

      Hey everybody. I wrote (according to articles I found on the net) the following code, in order to get the command line of another process (it is not the "full code", just until it fails.

      HANDLE hproc = ::OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
      if(!hproc)
      {
      printf("OpenProcess() failed: 0x%x", ::GetLastError());
      return _T("");
      }

      _NtQueryInformationProcess NtQueryInformationProcess = (_NtQueryInformationProcess)GetProcAddress(GetModuleHandleA("ntdll.dll"), "NtQueryInformationProcess");
      PROCESS_BASIC_INFORMATION pbi;
      DWORD size_written;
      NTSTATUS nt = NtQueryInformationProcess(hproc, ProcessBasicInformation, (void*)&pbi, sizeof(PROCESS_BASIC_INFORMATION), &size_written); // get pbi
      if(nt)
      {
      printf("NtQueryInformationProcess() failed: 0x%x", nt);
      return _T("");
      }

      PEB* peb = pbi.PebBaseAddress;
      ULONG session_id = peb->SessionId;
      SIZE_T read_size;
      RTL_USER_PROCESS_PARAMETERS* proc_params = NULL;
      DWORD old_protection;
      if(!::VirtualProtectEx(hproc, peb->ProcessParameters, sizeof(RTL_USER_PROCESS_PARAMETERS*), PAGE_EXECUTE_READWRITE, &old_protection))
      {
      printf("VirtualProtectEx() failed: 0x%x", ::GetLastError());
      return _T("");
      }

      // ************ FAILS HERE !!!! ***************
      if(!::ReadProcessMemory(hproc, peb->ProcessParameters, (RTL_USER_PROCESS_PARAMETERS*)proc_params, sizeof(RTL_USER_PROCESS_PARAMETERS*), &read_size))
      {
      printf("ReadProcessMemory() failed: 0x%x", ::GetLastError());
      return _T("");
      }

      if(!::VirtualProtectEx(hproc, peb->ProcessParameters, sizeof(RTL_USER_PROCESS_PARAMETERS*), old_protection, NULL))
      {
      printf("VirtualProtectEx() failed: 0x%x", ::GetLastError());
      return _T("");
      }

      The output is that ReadProcessMemory() fails with ERROR_PARTIAL_COPY. The code works in XP for processes in the same session. Currently I am trying to make it work in windows 7, for a process in the same session. ANY IDEAS any one ???? :confused: Thanks!

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      Are you running the application with elevated privileges (Run as administrator)?

      «_Superman_»
      I love work. It gives me something to do between weekends.

      Microsoft MVP (Visual C++)

      Polymorphism in C

      G 1 Reply Last reply
      0
      • _ _Superman_

        Are you running the application with elevated privileges (Run as administrator)?

        «_Superman_»
        I love work. It gives me something to do between weekends.

        Microsoft MVP (Visual C++)

        Polymorphism in C

        G Offline
        G Offline
        Green Fuze
        wrote on last edited by
        #3

        Yes. :-)

        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