-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdllmain.cpp
More file actions
133 lines (101 loc) · 2.33 KB
/
Copy pathdllmain.cpp
File metadata and controls
133 lines (101 loc) · 2.33 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include <Windows.h>
#include <iostream>
#include <jvmti.h>
#include <jni.h>
#include <string>
#include <winuser.h>
#include <jvmti.h>
#include "dllmain.h"
#include "functions.h"
using namespace std;
static boolean DEBUG = false;
HMODULE dll;
static JavaVM *jvm;
static JNIEnv *env;
static jvmtiEnv *jvmti;
void inject()
{
if (DEBUG)
{
AllocConsole();
SetConsoleCtrlHandler(NULL, true);
FILE *fIn;
FILE *fOut;
freopen_s(&fIn, "conin$", "r", stdin);
freopen_s(&fOut, "conout$", "w", stdout);
freopen_s(&fOut, "conout$", "w", stderr);
}
printf("Injection Successful!\n");
jsize count;
if (JNI_GetCreatedJavaVMs(&jvm, 1, &count) != JNI_OK || count == 0)
{
printf("Failed to get the JVM\n");
return;
}
jint res = jvm->GetEnv((void **)&env, JNI_VERSION_1_6);
if (res == JNI_EDETACHED)
res = jvm->AttachCurrentThread((void **)&env, nullptr);
if (res != JNI_OK)
{
printf("Failed to attach to thread\n");
return;
}
jint res2 = jvm->GetEnv((void **)&jvmti, JVMTI_VERSION_1_2);
if (res2 == JNI_EDETACHED)
res2 = jvm->AttachCurrentThread((void **)&jvmti, nullptr);
if (res2 != JNI_OK)
{
printf("Failed to attach to thread\n");
return;
}
jvmtiCapabilities caps = {};
caps.can_tag_objects = 1;
if (jvmti->AddCapabilities(&caps) != JVMTI_ERROR_NONE)
{
printf("Failed to add capabilities\n");
return;
}
printf("Attached to JVM.\n");
bool essential = using_essential();
get_launchwrapper();
auto mc = get_minecraft();
auto player = get_player(mc);
send_chat(player, "§8<> §7EssentialPatcher - by Debuggings §8<>");
send_chat(player, "§aInjected successfully!");
printf("Using Essential? %s\n", essential ? "Yes" : "No");
if (essential)
{
send_chat(player, "§aUsing Essential, overriding classloader.");
override_normal_with_essential();
}
else
{
send_chat(player, "§cNot using Essential, aborting...");
}
send_chat(player, "Done. Exiting...");
printf("Done. Exiting...\n");
}
void thread()
{
inject();
FreeLibraryAndExitThread(dll, 0);
}
BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
dll = hinstDLL;
if (fdwReason == DLL_PROCESS_ATTACH)
CreateThread(nullptr, 0, (LPTHREAD_START_ROUTINE)thread, nullptr, 0, nullptr);
return TRUE;
}
JavaVM *get_jvm()
{
return jvm;
}
JNIEnv *get_env()
{
return env;
}
jvmtiEnv *get_jvmti()
{
return jvmti;
}