Hi, I have a C++ Jarload project, it works smoothly, but we can't change the classcount in the getloadedclasses hook in the update to the server I am doing right now
Our current code is as follows
But here's how we do it
im how to fix this (I don't know about JVM Bytecode Manipulation)
Our current code is as follows
C++:
jvmtiError detourGetLoadedClasses(jvmtiEnv* enva, jint* class_count_ptr, jclass** classes_ptr) {
return orginalJvmtiGetLoadedClasses(enva, class_count_ptr, classes_ptr);
}
C++:
typedef jvmtiError(__stdcall* p_hook)(jvmtiEnv* env, jint* class_count_ptr, jclass** classes_ptr);
p_hook original_GetLoadedClasses = nullptr;
jint originalClassCount = 0;
jclass* originalClassArray = nullptr;
bool firstCall = false;
bool jarLoadingInProgress = false;
bool jarLoadingCompleted = false;
jvmtiError GetLoadedClasses(jvmtiEnv* env, jint* class_count_ptr, jclass** classes_ptr) {
if (!firstCall) {
firstCall = true;
jarLoadingInProgress = true;
auto result = original_GetLoadedClasses(env, class_count_ptr, classes_ptr);
originalClassCount = *class_count_ptr;
originalClassArray = *classes_ptr;
return result;
}
else {
auto result = original_GetLoadedClasses(env, class_count_ptr, classes_ptr);
*class_count_ptr = originalClassCount;
return result;
}
}