-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
161 lines (123 loc) · 4.11 KB
/
main.cpp
File metadata and controls
161 lines (123 loc) · 4.11 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#define _CRT_SECURE_NO_DEPRECATE
#include "main.h"
#include "hooks.h"
#include <cstdio>
#include <algorithm>
#include <string>
#include <iostream>
#include <filesystem>
#include <direct.h>
JavaVM* jvm;
JNIEnv* jenv;
jvmtiEnv* jvmti;
JNIUtil* JUtil = nullptr;
jclass nativeBridgeClass = nullptr;
jmethodID nativeBridgeTransformClassMethod = nullptr;
void Main::createConsole() {
AllocConsole();
SetConsoleTitle("unicrack client rale? (i miss nikko)");
FILE* file;
freopen_s(&file, "CONOUT$", "w", stdout);
}
bool Main::envshit() {
if (JNI_GetCreatedJavaVMs(&jvm, 1, nullptr) != JNI_OK) {
LOG("failed to get created java vms");
return false;
}
if (jvm->AttachCurrentThread(reinterpret_cast<void**>(&jenv), nullptr) != JNI_OK) {
LOG("failed to attach to the current thread");
return false;
}
LOG("found jvm and attached to the current threadfr");
// fix this bruh
JUtil = new JNIUtil(jenv);
if (!JUtil) {
LOG("failed to init JNIUtil");
return false;
}
LOG("initialised JNIUtil and env");
return true;
}
NTSTATUS Main::HookJniFunctions() {
return Hooks::Init(jenv, jvmti);
}
bool Main::jvmtishit() {
if (jvm->GetEnv(reinterpret_cast<void**>(&jvmti), JVMTI_VERSION_1_2) != JNI_OK) {
LOG("failed to get jvmti");
return false;
}
jvmtiCapabilities capabilities = { 0 };
// get all capabilities (default struct is filled with 1s
//jvmtiCapabilities capabilities;
capabilities.can_generate_all_class_hook_events = 1;
capabilities.can_retransform_classes = 1;
// cant use these (probably OnLoad only)
//capabilities.can_generate_field_modification_events = 1;
//capabilities.can_generate_method_entry_events = 1;
if (jvmti->AddCapabilities(&capabilities) != JVMTI_ERROR_NONE) {
LOG("failed to add jvmti capabilities");
return false;
}
if (Hooks::HookJVMTI(jvmti) != JVMTI_ERROR_NONE) return false;
//jvmtiEvent events = JVMTI_EVENT_CLASS_FILE_LOAD_HOOK | JVMTI_EVENT_METHOD_ENTRY;
//jvmtiEvent[] events = { JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, JVMTI_EVENT_METHOD_ENTRY };
if (jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, nullptr) != JVMTI_ERROR_NONE) {
LOG("failed to enable jvmti event notifications");
return false;
}
if (jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_CLASS_PREPARE, nullptr) != JVMTI_ERROR_NONE) {
LOG("failed to enable jvmti event notifications 1");
return false;
}
/*if (jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_FIELD_MODIFICATION, nullptr) != JVMTI_ERROR_NONE) {
LOG("failed to enable jvmti event notifications 1");
return false;
}
if (jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_METHOD_ENTRY, nullptr) != JVMTI_ERROR_NONE) {
LOG("failed to enable jvmti event notifications 2");
return false;
}*/
LOG("jvmti success");
return true;
}
void Main::exit(HMODULE hModule) {
LOG("exiting");
if (jvmti) {
jvmti->SetEventNotificationMode(JVMTI_DISABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, nullptr);
}
if (jvm) {
jvm->DetachCurrentThread();
}
Sleep(500);
CreateThread(nullptr, 0, [](LPVOID mod) -> DWORD {
Sleep(500);
FreeLibraryAndExitThread((HMODULE)mod, 0);
return 0;
}, hModule, 0, nullptr);
}
char logFilePath[MAX_PATH];
char tmpPath[MAX_PATH];
void Main::main(HMODULE hModule) {
DWORD tempPathLength = GetTempPathA(MAX_PATH, logFilePath);
if (tempPathLength == 0 || tempPathLength > MAX_PATH) {
return;
}
GetTempPathA(MAX_PATH, tmpPath);
strcat_s(logFilePath, MAX_PATH, "log.txt");
FILE* logFile;
fopen_s(&logFile, logFilePath, "w");
if (logFile) fclose(logFile);
createConsole();
if (!envshit() || !jvmtishit()) {
exit(hModule);
return;
}
if (!_SUCCESS(HookJniFunctions())) {
LOG("failed to hook jni func ptrs");
return;
}
LOG("all init success");
while (!GetAsyncKeyState(VK_F7)) {
}
exit(hModule);
}