-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexit.c
48 lines (42 loc) · 1.36 KB
/
exit.c
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
#include "exit.h"
#include <Windows.h>
#include <Psapi.h>
#include "scan.h"
bool started = false;
void setupHook(void) {
if (started) return;
started = true;
AllocConsole();
//freopen("CONOUT$", "w", stdout);
HMODULE jvmModule = GetModuleHandle(L"jvm.dll");
if (jvmModule == NULL) {
puts("jvm.dll module not found!");
return;
}
MODULEINFO moduleinfo;
HANDLE procHandle = GetCurrentProcess();
GetModuleInformation(procHandle, jvmModule, &moduleinfo, sizeof(moduleinfo));
CloseHandle(procHandle);
//use if necessary
//uintptr_t found = ps_find_idastyle("48 89 5C 24 08 48 89 74 24 10 57 48 83 EC 20 8B F9 8B 0D 11 4B 63 00 FF 15 E3 B3 45 00 48 8B D8 C7 80 70 02 00 00 05 00 00 00", (uintptr_t)moduleinfo.EntryPoint, moduleinfo.SizeOfImage);
void* found = GetProcAddress(jvmModule, "JVM_Halt");
if (found)
{
if (MH_Initialize() != MH_OK) {
puts("Something went wrong while initializing hooks");
return;
}
if (MH_CreateHook((void*)found, (void*)hookedExit, NULL) != MH_OK) {
puts("Hook failed!");
return;
}
if (MH_EnableHook((void*)found) != MH_OK) {
puts("Hook failed!");
}
puts("Hook has been initialized and enabled!");
}
}
void hookedExit(int status) {
//puts("¯\_(ツ)_/¯");
}