飘云阁

 找回密码
 加入我们

QQ登录

只需一步,快速开始

查看: 3653|回复: 1

简单的硬件断点使用

[复制链接]
  • TA的每日心情
    慵懒
    2019-3-12 17:25
  • 签到天数: 3 天

    [LV.2]偶尔看看I

    发表于 2010-10-24 08:53:41 | 显示全部楼层 |阅读模式
    1. /*---------------------------------------------------------------------
    2. // DataBP.cpp : Demonstrate setting data access breakpoint manually.
    3. Software Debugging by Raymond Zhang, All rights reserved.
    4. ---------------------------------------------------------------------*/

    5. #include "stdafx.h"
    6. #include <windows.h>
    7. #include <stdlib.h>

    8. int main(int argc, char* argv[])
    9. {
    10.         CONTEXT cxt;
    11.         HANDLE hThread=GetCurrentThread();
    12.         DWORD dwTestVar=0;

    13.         if(!IsDebuggerPresent())
    14.         {
    15.                 printf("This sample can only run within a debugger.\n");
    16.                 return E_FAIL;
    17.         }
    18.         cxt.ContextFlags=CONTEXT_DEBUG_REGISTERS|CONTEXT_FULL;
    19.         if(!GetThreadContext(hThread,&cxt))
    20.         {
    21.                 printf("Failed to get thread context.\n");
    22.                 return E_FAIL;
    23.         }
    24.         cxt.Dr0=(DWORD) &dwTestVar;
    25.         cxt.Dr7=0xF0001;//4 bytes length read& write breakponits
    26.         if(!SetThreadContext(hThread,&cxt))
    27.         {
    28.                 printf("Failed to set thread context.\n");
    29.                 return E_FAIL;
    30.         }

    31.         dwTestVar=1;
    32.         GetThreadContext(hThread,&cxt);
    33.         printf("Break into debuger with DR6=%X.\n",cxt.Dr6);
    34.         printf("Break into debuger with DR0=%X.\n",cxt.Dr0);
    35.         return S_OK;
    36. }

    复制代码
    PYG19周年生日快乐!
  • TA的每日心情
    慵懒
    2019-3-12 17:25
  • 签到天数: 3 天

    [LV.2]偶尔看看I

     楼主| 发表于 2010-10-24 08:54:57 | 显示全部楼层
    1. typedef struct DECLSPEC_ALIGN(16) _CONTEXT {

    2.     //
    3.     // Register parameter home addresses.
    4.     //

    5.     DWORD64 P1Home;
    6.     DWORD64 P2Home;
    7.     DWORD64 P3Home;
    8.     DWORD64 P4Home;
    9.     DWORD64 P5Home;
    10.     DWORD64 P6Home;

    11.     //
    12.     // Control flags.
    13.     //

    14.     DWORD ContextFlags;
    15.     DWORD MxCsr;

    16.     //
    17.     // Segment Registers and processor flags.
    18.     //

    19.     WORD   SegCs;
    20.     WORD   SegDs;
    21.     WORD   SegEs;
    22.     WORD   SegFs;
    23.     WORD   SegGs;
    24.     WORD   SegSs;
    25.     DWORD EFlags;

    26.     //
    27.     // Debug registers
    28.     //

    29.     DWORD64 Dr0;
    30.     DWORD64 Dr1;
    31.     DWORD64 Dr2;
    32.     DWORD64 Dr3;
    33.     DWORD64 Dr6;
    34.     DWORD64 Dr7;

    35.     //
    36.     // Integer registers.
    37.     //

    38.     DWORD64 Rax;
    39.     DWORD64 Rcx;
    40.     DWORD64 Rdx;
    41.     DWORD64 Rbx;
    42.     DWORD64 Rsp;
    43.     DWORD64 Rbp;
    44.     DWORD64 Rsi;
    45.     DWORD64 Rdi;
    46.     DWORD64 R8;
    47.     DWORD64 R9;
    48.     DWORD64 R10;
    49.     DWORD64 R11;
    50.     DWORD64 R12;
    51.     DWORD64 R13;
    52.     DWORD64 R14;
    53.     DWORD64 R15;

    54.     //
    55.     // Program counter.
    56.     //

    57.     DWORD64 Rip;

    58.     //
    59.     // MMX/floating point state.
    60.     //

    61.     M128 Xmm0;
    62.     M128 Xmm1;
    63.     M128 Xmm2;
    64.     M128 Xmm3;
    65.     M128 Xmm4;
    66.     M128 Xmm5;
    67.     M128 Xmm6;
    68.     M128 Xmm7;
    69.     M128 Xmm8;
    70.     M128 Xmm9;
    71.     M128 Xmm10;
    72.     M128 Xmm11;
    73.     M128 Xmm12;
    74.     M128 Xmm13;
    75.     M128 Xmm14;
    76.     M128 Xmm15;

    77.     //
    78.     // Legacy floating point state.
    79.     //

    80.     LEGACY_SAVE_AREA FltSave;
    81.     DWORD Fill;

    82.     //
    83.     // Special debug control registers.
    84.     //

    85.     DWORD64 DebugControl;
    86.     DWORD64 LastBranchToRip;
    87.     DWORD64 LastBranchFromRip;
    88.     DWORD64 LastExceptionToRip;
    89.     DWORD64 LastExceptionFromRip;
    90.     DWORD64 Fill1;
    91. } CONTEXT, *PCONTEXT;
    复制代码
    PYG19周年生日快乐!
    您需要登录后才可以回帖 登录 | 加入我们

    本版积分规则

    快速回复 返回顶部 返回列表