Configure hardware debug register for access, write and fetch breakpoints.
if apply to vmcs is true then should be called at vmx-root mode keep in mind that it applies only on one core Also, the caller must be sure that Load Debug Controls and Save Debug Controls on VM-entry and VM-exit controls on the VMCS of the target core, vmcalls VMCALL_SET_VM_ENTRY_LOAD_DEBUG_CONTROLS and VMCALL_SET_VM_EXIT_SAVE_DEBUG_CONTROLS are designed for this purpose should be called on vmx-root mode if the ApplyToVmcs is TRUE
38{
39 DR7 Dr7 = {0};
40
41
42
43
44 if (DebugRegNum >= 4)
45 {
47 }
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66 Dr7.Reserved1 = 1;
67
68
69
70
71
72 Dr7.LocalExactBreakpoint = 1;
73 Dr7.GlobalExactBreakpoint = 1;
74
75
76
77
78 if (DebugRegNum == 0)
79 {
80 __writedr(0, TargetAddress);
81
82 Dr7.GlobalBreakpoint0 = 1;
83
84
85
86
87
88
89
90
91
92
93
94 switch (ActionType)
95 {
97 Dr7.ReadWrite0 = 0b00;
98 break;
100 Dr7.ReadWrite0 = 0b01;
101 break;
103 Dr7.ReadWrite0 = 0b10;
104 LogError(
"Err, I/O access breakpoint by debug regs are not supported");
106 break;
108 Dr7.ReadWrite0 = 0b11;
109 break;
110
111 default:
112
113
114
115 LogError(
"Err, unknown parameter as debug reg action type");
117 break;
118 }
119 }
120 else if (DebugRegNum == 1)
121 {
122 __writedr(1, TargetAddress);
123 Dr7.GlobalBreakpoint1 = 1;
124
125
126
127
128
129
130
131
132
133
134
135 switch (ActionType)
136 {
138 Dr7.ReadWrite1 = 0b00;
139 break;
141 Dr7.ReadWrite1 = 0b01;
142 break;
144 Dr7.ReadWrite1 = 0b10;
145 LogError(
"Err, I/O access breakpoint by debug regs are not supported");
147 break;
149 Dr7.ReadWrite1 = 0b11;
150 break;
151
152 default:
153
154
155
156 LogError(
"Err, unknown parameter as debug reg action type");
158 break;
159 }
160 }
161 else if (DebugRegNum == 2)
162 {
163 __writedr(2, TargetAddress);
164 Dr7.GlobalBreakpoint2 = 1;
165
166
167
168
169
170
171
172
173
174
175
176 switch (ActionType)
177 {
179 Dr7.ReadWrite2 = 0b00;
180 break;
182 Dr7.ReadWrite2 = 0b01;
183 break;
185 Dr7.ReadWrite2 = 0b10;
186 LogError(
"Err, I/O access breakpoint by debug regs are not supported");
188 break;
190 Dr7.ReadWrite2 = 0b11;
191 break;
192
193 default:
194
195
196
197 LogError(
"Err, unknown parameter as debug reg action type");
199 break;
200 }
201 }
202 else if (DebugRegNum == 3)
203 {
204 __writedr(3, TargetAddress);
205 Dr7.GlobalBreakpoint3 = 1;
206
207
208
209
210
211
212
213
214
215
216
217 switch (ActionType)
218 {
220 Dr7.ReadWrite3 = 0b00;
221 break;
223 Dr7.ReadWrite3 = 0b01;
224 break;
226 Dr7.ReadWrite3 = 0b10;
227 LogError(
"Err, I/O access breakpoint by debug regs are not supported");
229 break;
231 Dr7.ReadWrite3 = 0b11;
232 break;
233
234 default:
235
236
237
238 LogError(
"Err, unknown parameter as debug reg action type");
240 break;
241 }
242 }
243
244
245
246
247
248
249 if (ApplyToVmcs)
250 {
251 __vmx_vmwrite(VMCS_GUEST_DR7, Dr7.AsUInt);
252 }
253 else
254 {
255 __writedr(7, Dr7.AsUInt);
256 }
257
259}
#define TRUE
Definition BasicTypes.h:55
#define FALSE
Definition BasicTypes.h:54
@ BREAK_ON_READ_AND_WRITE_BUT_NOT_FETCH
Definition DataTypes.h:73
@ BREAK_ON_IO_READ_OR_WRITE_NOT_SUPPORTED
Definition DataTypes.h:72
@ BREAK_ON_WRITE_ONLY
Definition DataTypes.h:71
@ BREAK_ON_INSTRUCTION_FETCH
Definition DataTypes.h:70
#define LogError(format,...)
Log in the case of error.
Definition HyperDbgHyperLogIntrinsics.h:113