- UID
 - 66114
 
 注册时间2010-4-1
阅读权限30
最后登录1970-1-1
龙战于野 
  
 
 
 
TA的每日心情  | 慵懒 2019-3-12 17:25 | 
|---|
 
  签到天数: 3 天 [LV.2]偶尔看看I  
 | 
 
- /*---------------------------------------------------------------------
 
 - // DataBP.cpp : Demonstrate setting data access breakpoint manually.
 
 - Software Debugging by Raymond Zhang, All rights reserved. 
 
 - ---------------------------------------------------------------------*/
 
  
- #include "stdafx.h"
 
 - #include <windows.h>
 
 - #include <stdlib.h>
 
  
- int main(int argc, char* argv[])
 
 - {
 
 -         CONTEXT cxt;
 
 -         HANDLE hThread=GetCurrentThread();
 
 -         DWORD dwTestVar=0;
 
  
-         if(!IsDebuggerPresent())
 
 -         {
 
 -                 printf("This sample can only run within a debugger.\n");
 
 -                 return E_FAIL;
 
 -         }
 
 -         cxt.ContextFlags=CONTEXT_DEBUG_REGISTERS|CONTEXT_FULL;
 
 -         if(!GetThreadContext(hThread,&cxt))
 
 -         {
 
 -                 printf("Failed to get thread context.\n");
 
 -                 return E_FAIL;
 
 -         }
 
 -         cxt.Dr0=(DWORD) &dwTestVar;
 
 -         cxt.Dr7=0xF0001;//4 bytes length read& write breakponits
 
 -         if(!SetThreadContext(hThread,&cxt))
 
 -         {
 
 -                 printf("Failed to set thread context.\n");
 
 -                 return E_FAIL;
 
 -         }
 
  
-         dwTestVar=1;
 
 -         GetThreadContext(hThread,&cxt);
 
 -         printf("Break into debuger with DR6=%X.\n",cxt.Dr6);
 
 -         printf("Break into debuger with DR0=%X.\n",cxt.Dr0);
 
 -         return S_OK;
 
 - }
 
  
  复制代码 |   
 
 
 
 |