使用ReadProcessMemory记录指向的指令

时间:2014-02-25 16:51:17

标签: debugging winapi instructions

我试图用ReadProcessMemory记录指向指令,实际上我使用EIP寄存器来获取下一个指令地址。接下来,我使用distorm lib来显示助记符。但ReadProcessMemory什么都不读。

void display_instruction(Debuggee* debuggee)
{
    CONTEXT lcContext;
    lcContext.ContextFlags = CONTEXT_ALL;
    GetThreadContext(debuggee->debugEvent->u.CreateProcessInfo.hThread, &lcContext);

    BYTE cInstruction = 0;
    DWORD dwReadBytes;
    ReadProcessMemory(debuggee->debugEvent->u.CreateProcessInfo.hProcess, (void*)&lcContext.Eip, &cInstruction, 1, &dwReadBytes);
    decode((void*)cInstruction); //Distorm Mnemonic 
    printf("Instruction  : 0x%03.3X , %d\n",cInstruction,dwReadBytes);
}

}

我需要你的帮助!^^

1 个答案:

答案 0 :(得分:0)

这可能是:

ReadProcessMemory(debuggee->debugEvent->u.CreateProcessInfo.hProcess,
                 (void*) &lcContext.Eip, // <
                 &cInstruction,
                 1,
                 &dwReadBytes);

应该是:

ReadProcessMemory(debuggee->debugEvent->u.CreateProcessInfo.hProcess,
                 (void*) lcContext.Eip, // <
                 &cInstruction,
                 1,
                 &dwReadBytes);

因为ReadProcessMemory需要目标进程的虚拟内存中的地址。

加上你可以检查返回值和失败的原因。