1 #include <ail/string.hpp>
2 #include "debug_registers.hpp"
5 namespace debug_register_data_type
13 namespace debug_register_data_size
21 debug_register_data::debug_register_data()
25 debug_register_data::debug_register_data(unsigned address
):
27 type(debug_register_data_type::execute
),
28 size(debug_register_data_size::one
)
32 debug_register_data::debug_register_data(unsigned address
, uchar type
, uchar size
):
39 void set_debug_registers(CONTEXT
& thread_context
, unsigned address
)
41 debug_register_vector entries
;
42 entries
.push_back(debug_register_data(address
, debug_register_data_type::execute
, debug_register_data_size::one
));
43 set_debug_registers(thread_context
, entries
);
46 void set_debug_registers(CONTEXT
& thread_context
, debug_register_vector
& entries
)
48 DWORD
* dr_addresses
[] =
56 thread_context
.Dr6
= 0;
57 thread_context
.Dr7
= 0;
59 thread_context
.ContextFlags
= CONTEXT_FULL
| CONTEXT_DEBUG_REGISTERS
;
61 for(std::size_t i
= 0; i
< 4 && i
< entries
.size(); i
++)
63 debug_register_data
& data
= entries
[i
];
64 *(dr_addresses
[i
]) = data
.address
;
65 uchar high_group
= (data
.size
<< 2) | data
.type
;
66 thread_context
.Dr7
|= (high_group
<< (4 * i
+ 16)) | (1 << (2 * i
));
69 for(std::size_t i
= entries
.size(); i
< 4; i
++)
70 *(dr_addresses
[i
]) = 0;
73 void print_debug_registers(CONTEXT
& thread_context
)
75 write_line("DR0: " + ail::hex_string_32(thread_context
.Dr0
));
76 write_line("DR1: " + ail::hex_string_32(thread_context
.Dr1
));
77 write_line("DR2: " + ail::hex_string_32(thread_context
.Dr2
));
78 write_line("DR3: " + ail::hex_string_32(thread_context
.Dr3
));
79 write_line("DR7: " + ail::hex_string_32(thread_context
.Dr7
));