This repository was archived by the owner on Aug 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathveh.h
More file actions
89 lines (78 loc) · 1.96 KB
/
Copy pathveh.h
File metadata and controls
89 lines (78 loc) · 1.96 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#pragma once
#include <Windows.h>
#include <vector>
#include "pointer.h"
typedef void func(PEXCEPTION_POINTERS debug_context);
struct VEHUnit {
bool exists = false;
pointer address;
void* callback;
byte oldByte;
bool post_call = false;
void enable()
{
*(byte*)address = 0xCC;
}
void disable()
{
*(byte*)address = oldByte;
}
};
struct VEHStruct {
std::vector<VEHUnit> list;
VEHUnit Find(pointer address) {
for (int i = 0; i < list.size(); i++) {
auto tpl = list[i];
if (tpl.address == address || (tpl.address > address - 0x16 && tpl.address < address)) {
return tpl;
}
}
VEHUnit pl;
return pl;
};
void Append(pointer address, void* callback, bool postcall = false) {
DWORD dwOld;
VirtualProtect((void*)address, 1, PAGE_EXECUTE_READWRITE, &dwOld);
VEHUnit h = {
true,
address,
callback,
*(byte*)address,
postcall
};
list.push_back(h);
h.enable();
}
};
VEHStruct VEH;
LONG WINAPI CorruptionHandler(PEXCEPTION_POINTERS ExceptionInfo) {
if (!ExceptionInfo || !ExceptionInfo->ExceptionRecord || !ExceptionInfo->ContextRecord)
{
return EXCEPTION_CONTINUE_SEARCH;
}
auto code = ExceptionInfo->ExceptionRecord->ExceptionCode;
if (code != EXCEPTION_BREAKPOINT && code != EXCEPTION_SINGLE_STEP)
{
return EXCEPTION_CONTINUE_SEARCH;
}
auto h = VEH.Find((pointer)ExceptionInfo->ContextRecord->Rip);
if (h.exists) {
if (code == EXCEPTION_BREAKPOINT) {
h.disable();
ExceptionInfo->ContextRecord->EFlags |= 0x100;
if (!h.post_call) ((func*)h.callback)(ExceptionInfo);
ExceptionInfo->ContextRecord->Rip = h.address;
return EXCEPTION_CONTINUE_EXECUTION;
}
else {
h.enable();
ExceptionInfo->ContextRecord->EFlags &= ~(0x100);
if (h.post_call) ((func*)h.callback)(ExceptionInfo);
return EXCEPTION_CONTINUE_EXECUTION;
}
}
else {
return EXCEPTION_CONTINUE_EXECUTION;
}
return EXCEPTION_CONTINUE_EXECUTION;
}