【发布时间】:2018-09-30 11:16:19
【问题描述】:
我打开了一个进程:
HANDLE CreateDebuggedProcess(LPCSTR lpApplicationName)
{
STARTUPINFO startupInfo;
PROCESS_INFORMATION processInformation;
ZeroMemory(&startupInfo, sizeof(startupInfo));
startupInfo.cb = sizeof(startupInfo);
ZeroMemory(&processInformation, sizeof(processInformation));
if (!CreateProcessA(
lpApplicationName,
NULL,
NULL,
NULL,
FALSE,
DEBUG_PROCESS,
NULL,
NULL,
&startupInfo,
&processInformation
))
{
return INVALID_HANDLE_VALUE;
}
return processInformation.hProcess;
}
我正在等待第一个 BreakPoint 事件,然后我正在尝试打印内存撕裂指向的内容。我被 Get 搞砸了
void * getRip(DWORD threadId)
{
BOOL status = FALSE;
CONTEXT context = { 0 };
context.ContextFlags = CONTEXT_ALL;
HANDLE threadHandle = OpenThread(THREAD_GET_CONTEXT, FALSE, threadId);
if (NULL != threadHandle)
{
if(!GetThreadContext(threadHandle, &context))
{
status = FALSE;
return 0;
}
return (void *)context.Rip;
}
return 0;
}
并且返回的值似乎是正确的。然后我尝试调用 ReadProcessMemory,但我收到错误 299:ReadProcessMemory: invalid argument (Only part of a ReadProcessMemory or WriteProcessMemory request was completed.)。
BOOL queryMemory(HANDLE processHandle, void * address)
{
MEMORY_BASIC_INFORMATION memoryInformation = { 0 };
if (0 == VirtualQueryEx(processHandle, address, &memoryInformation, sizeof(memoryInformation)))
{
printf("failed :( Lasr error: %x\n", GetLastError());
return FALSE;
}
printf("AllocProtect: %x, state: %x, type: %x\n", memoryInformation.Protect
, memoryInformation.State
, memoryInformation.Type);
return TRUE;
}
返回AllocProtect: 1, state: 10000, type: 0。这意味着我没有访问权限,但这很奇怪,因为我应该可以访问所有内容,因为我已经创建了流程。
我做错了什么?
【问题讨论】:
-
您尝试读取未分配的内存 (
state == MEM_FREE) - 您必须在这里遇到错误。您没有关闭CreateDebuggedProcess和getRip中的线程句柄。你不需要在getRip中打开线程。你没有显示你如何称呼ReadProcessMemory -
你也不需要零初始化
PROCESS_INFORMATION和MEMORY_BASIC_INFORMATION