H
H
Homer_Simpson2015-09-24 22:08:12
C++ / C#
Homer_Simpson, 2015-09-24 22:08:12

Why can't I read c++ process memory?

HANDLE hProcess= OpenProcess(PROCESS_ALL_ACCESS, false, dwPID);

  if (hProcess)
  {
    SYSTEM_INFO si;
    GetSystemInfo(&si);

    auto minAplAdr = si.lpMinimumApplicationAddress;
    long num = (INT32)minAplAdr;
    MEMORY_BASIC_INFORMATION info;

    BYTE* Buf = new BYTE[61440];
    ReadProcessMemory(hProcess, 0, Buf, (unsigned long)20, (unsigned long*)20);
    std::cout << Buf;

  }
  CloseHandle(hProcess);

I get Access violation writing location 0x00000014.
Why is there a problem with recording?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2015-09-24
@Homer_Simpson

BOOL WINAPI ReadProcessMemory(
  _In_  HANDLE  hProcess,
  _In_  LPCVOID lpBaseAddress,
  _Out_ LPVOID  lpBuffer,
  _In_  SIZE_T  nSize,
  _Out_ SIZE_T  *lpNumberOfBytesRead
);

*lpNumberOfBytesRead - pointer to a variable that will store the number of bytes read. You indicated that this number should be written to address 0x14, causing an exception.
It will be correct like this:
SIZE_T bytesRead;
ReadProcessMemory(hProcess, 0, Buf, (unsigned long)20, &bytesRead);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question