-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbreakpoint.cpp
More file actions
50 lines (40 loc) · 1.49 KB
/
breakpoint.cpp
File metadata and controls
50 lines (40 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "protection.hpp"
#include <windows.h>
#include <chrono>
#include <iostream>
namespace protection::breakpoint {
static bool handlerReady = false;
static long long elapsedMs = 0;
static LONG WINAPI exceptionHandler(PEXCEPTION_POINTERS info) {
if (!info || !info->ExceptionRecord || !info->ContextRecord)
return EXCEPTION_CONTINUE_SEARCH;
if (info->ExceptionRecord->ExceptionCode == EXCEPTION_BREAKPOINT) {
return EXCEPTION_CONTINUE_EXECUTION;
}
return EXCEPTION_CONTINUE_SEARCH;
}
void int3() {
if (!handlerReady) {
if (!AddVectoredExceptionHandler(1, exceptionHandler)) {
std::cout << "[breakpoint] failed to setup exception handler" << std::endl;
}
handlerReady = true;
}
auto start = std::chrono::high_resolution_clock::now();
__try {
RaiseException(EXCEPTION_BREAKPOINT, 0, 0, nullptr);
}
__except (EXCEPTION_CONTINUE_EXECUTION) {}
auto end = std::chrono::high_resolution_clock::now();
elapsedMs = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
}
void check() {
constexpr long long threshold = 30;
if (elapsedMs < threshold) {
std::cout << "[breakpoint] good, time: " << elapsedMs << " ms" << std::endl;
}
else {
std::cout << "[breakpoint] bad, time: " << elapsedMs << " ms" << std::endl;
}
}
}