-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathjmp.cpp
More file actions
59 lines (44 loc) · 814 Bytes
/
jmp.cpp
File metadata and controls
59 lines (44 loc) · 814 Bytes
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
#include "jmp.h"
#define UNHOOK() memcpy(destination, org, 5)
#define REHOOK() memcpy(destination, mod, 5)
JMP::JMP(void* pointer, void* hook)
{
origin = 0;
destination = pointer;
jmp = 0 - ((DWORD)destination - (DWORD)hook) - 5;
mod[0] = 0xE9;
memcpy(org, destination, 5);
memcpy((void*)((DWORD)mod + 1), &jmp, 4);
VirtualProtect(destination, 5, PAGE_EXECUTE_READWRITE, &oldp);
REHOOK();
}
JMP::~JMP()
{
UNHOOK();
VirtualProtect(destination, 5, oldp, &oldp);
}
void* JMP::Call(int n, ...)
{
UNHOOK();
va_list v;
va_start(v, n);
v += n * 4 + 4;
for (int i = 0; i < n; i++)
{
void* a = *(void**)((v -= 4) - 4);
__asm push a
}
void* m = destination;
void* t = origin;
void* r;
if (t)
__asm mov ecx, t
__asm
{
call m
mov r, eax
}
va_end(v);
REHOOK();
return r;
}