me and a friend of mine are working on a coding project and we ran into a little issue. We are essentially trying to modify Java Methods/Bytecode during runtime using C++. I am just curious if this is possible or how it is possible. We have already tried using JVMTI and JNI to accomplish this but it seems that you can only modify classes that are currently being loaded into the JVM. We are loading our code in as a DLL while the process is running so we can not do this. We also thought assembly might work by accomplishing this. A little demonstration of what we are trying to do can be seen below.
public boolean Method()
{
boolean value = true;
return value; //<- Value that we want to modify (in java)
}
jclass JVMUtilities::getClass(std::string clazzname) {
jstring name = Wrapper::getJVMHook().getJNI()->NewStringUTF(clazzname.c_str());
jobject classLoader = getclassloader();
jmethodID mid = Wrapper::getJVMHook().getJNI()->GetMethodID(Wrapper::getJVMHook().getJNI()->GetObjectClass(classLoader), "findClass", "(Ljava/lang/String;)Ljava/lang/Class;");
return (jclass)Wrapper::getJVMHook().getJNI()->CallObjectMethod(classLoader, mid, name);
//This is the function we use for geting the class information in c++ including location
}
Basically going by above, we want to change the return value to what we want during run time by manipulating the byte code.