2013-05-10 81 views
1

我想知道是否有可能在汇编指令执行后立即读取另一个进程的eax寄存器。阅读eax寄存器

在我的情况,我有以下的汇编代码:

mov byte ptr ss:[EBP-4] 
call dword ptr ds:[<&[email protected]@Z>] 
add esp, 4 

的想法是让EAX值刚过“呼叫DWORD PTR DS:< & [email protected]@Z >]“指令已执行。 事实上,我必须在我的C++代码中检索由另一个进程中创建的对象的实例返回的内存地址。

不知道,如果我已经足够清楚。请原谅我不好的英语。

+0

它使用调试器是可能的。 – Lol4t0 2013-05-10 21:15:10

+1

您可以在该位置放置一个硬件断点。 – Matthew 2013-05-10 21:16:44

+1

更好的方法是修改其他进程,以便更干净地钩住它。例如,您可能有一个注册的调用,该调用在调用将值传递给调出的函数后进行。这种低级别的骇客往往非常脆弱。 – 2013-05-10 22:01:22

回答

2

您可以使用硬件断点调试进程。

实施例使用WINAPI:

DWORD address = 0x12345678; // address of the instruction after the call 

DebugActiveProcess(pid); // PID of target process 

CONTEXT ctx = {0}; 
ctx.ContextFlags = CONTEXT_DEBUG_REGISTERS | CONTEXT_INTEGER; 
ctx.Dr0 = address; 
ctx.Dr7 = 0x00000001; 
SetThreadContext(hThread, &ctx); // hThread with enough permissions 

DEBUG_EVENT dbgEvent; 
while (true) 
{ 
    if (WaitForDebugEvent(&dbgEvent, INFINITE) == 0) 
     break; 

    if (dbgEvent.dwDebugEventCode == EXCEPTION_DEBUG_EVENT && 
     dbgEvent.u.Exception.ExceptionRecord.ExceptionCode == EXCEPTION_SINGLE_STEP) 
    { 
     if (dbgEvent.u.Exception.ExceptionRecord.ExceptionAddress == (LPVOID)address) 
     { 
      GetThreadContext(hThread, &ctx); 
      DWORD eax = ctx.Eax; // eax get 
     } 
    } 

    ContinueDebugEvent(dbgEvent.dwProcessId, dbgEvent.dwThreadId, DBG_CONTINUE); 
} 
+0

我的调试对象进程在达到断点后继续阻塞。然后,似乎指令流程永远不会继续,我的调试器不断获取带有EXCEPTION_SINGLE_STEP的dbgEvent。我不知道我错过了什么。 – alkpone 2013-05-13 00:08:23

+0

有没有人知道如何继续执行,直到它再次到达断点? – alkpone 2013-05-14 17:37:35

+0

@alkpone是否设法做你想做的事? – victor 2015-10-20 09:11:50