c++ - Breakpoint handling in another process -


following advices given in read eax register , wrote simple debugger using winapi. objective read eax register each time after assembly instruction executed in thread. working , managed put hardware breakpoint in process.

the problem arise when breakpoint reach inside debuggee thread, can read eax register intended, still couldn't find way resume thread's execution.

my code :

 int _tmain(int argc, _tchar* argv[])  {  // finding window hwnd window = findwindow(0, _t("test")); if( window == 0 ) {     printf("process not found!\n");     return 0; }  dword_ptr pid = 0; getwindowthreadprocessid(window, &pid);   // handle //handle _handle = openprocess(process_all_access, false, pid);  dword_ptr eax = 0; dword_ptr address = 0xc31e1b; // address of instruction after call hardware breakpoint  debugactiveprocess(pid); // pid of target process  // avoid killing app on exit debugsetprocesskillonexit(false);  // thread id of main thread in process dword_ptr dwthreadid = getprocessthreadid(pid);  // gain access thread handle hthread = openthread(thread_all_access, false, dwthreadid);  setdebugprivilege(true);  //ctx.dr6=0;           //clear debug status register (only bits 0-3 of dr6 cleared processor)  context ctx = {0}; ctx.contextflags = context_debug_registers | context_integer; ctx.dr0 = address; ctx.dr7 = 0x00000001;   // hthread enough permissions setthreadcontext(hthread, &ctx);   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) // exception_breakpoint     {         if (dbgevent.u.exception.exceptionrecord.exceptionaddress == (lpvoid)address)         {             getthreadcontext(hthread, &ctx);             eax = ctx.eax; // eax             std::cout<<eax<<"\n";             // resume execution             ctx.eip = address + 0x3;             setthreadcontext(hthread, &ctx);         }      }      continuedebugevent(dbgevent.dwprocessid, dbgevent.dwthreadid, dbg_continue); } return 0; } 

thanks !!

continuedebugevent(dwprocessid, dwthreadid, dwcontinuestatus)


this should job! don't need change eip. if want more information read writing debugger's main loop


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -