-
Notifications
You must be signed in to change notification settings - Fork 10
/
veh_shell.hpp
64 lines (49 loc) · 1.27 KB
/
veh_shell.hpp
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
#pragma once
#define VEH_DATA_SIG32 0x77777777
#define VEH_DATA_SIG64 0x1488133714881337
#ifdef _WIN64
#define VEH_DATA_SIG VEH_DATA_SIG64
#else
#define VEH_DATA_SIG VEH_DATA_SIG32
#endif
// i use this fucking crutch because a compiler does some shit with volatile pointer to VEH_SHELL_DATA in the VEHShell function
__forceinline bool FindAndReplacePointers(BYTE* start, size_t len, UINT_PTR signature, UINT_PTR value)
{
if (!start || !len)
{
return false;
}
BYTE* _start = start;
bool found = false;
for (; start < (_start + len) - sizeof(UINT_PTR);)
{
found = true;
DWORD i = 0;
for (; start[i] == ((BYTE*)&signature)[(sizeof(UINT_PTR) - 1) - i] && i < sizeof(UINT_PTR); ++i);
if (i < sizeof(UINT_PTR) / 2)
{
found = false;
}
if (found)
{
DWORD offset = (*(DWORD*)(start - (sizeof(UINT_PTR) - i))) - signature;
*(DWORD*)(start - (sizeof(UINT_PTR) - i)) = value + offset;
start += i;
}
else
{
++start;
}
}
return true;
}
struct VEH_SHELL_DATA
{
DWORD os_version = 0;
BYTE* image_base = 0;
DWORD image_size = 0;
f_LdrProtectMrdata _LdrProtectMrdata;
f_LdrpInvertedFunctionTable _LdrpInvertedFunctionTable;
};
LONG CODE_SEG(".veh$1") CALLBACK VEHShell(EXCEPTION_POINTERS* EP);
LONG CODE_SEG(".veh$2") CALLBACK VEHShell_End();