According to Wikipedia, there are 3 class loaders.
The Boot Class-Loader which loads everything in RT.jar and /../jre/lib
Then the extensions class loader and the system class loader.
I'm only interested in the Boot class loader because I want to hook it and redefine a class in RT.jar without all the legality issues that come with -Xbootclasspath:/p
.
Docs: http://docs.oracle.com/cd/E13150_01/jrockit_jvm/jrockit/jrdocs/refman/optionX.html
Note: Applications that use this option to override a class in rt.jar should not be deployed. Doing so would contravene the Java 2 Runtime Environment binary code license.
And the license here: http://www.oracle.com/technetwork/java/javase/downloads/jre-6u21-license-159054.txt
states:
C. Java Technology Restrictions. You may not create, modify, or change the behavior of, or authorize your licensees to create, modify, or change the behavior of, classes, interfaces, or subpackages that are in any way identified as "java", "javax", "sun" or similar convention as specified by Oracle in any naming convention designation.
So I'm thinking that if I can hook the boot class loader from native code via C++, I can replace a class in by hooking the JVM_DefineClass
function from JVM.dll
without any legal trouble.
The function has the signature:
JNIEXPORT jclass JNICALL JVM_DefineClass(JNIEnv *env, const char *name, jobject _loader, const jbyte *buf, jsize len, jobject pd)
- 1: Does this function actually get call when a JVM is starting up?
- 2: Would I still be breaking the license if I hook it?
- 3: Am I hooking the right function or should I be doing something else(better method maybe?)?
JVM_DefineClass
fromJNI.dll
) to define a class. It also callsJava_lang_lang_DefineClassX
fromJava.dll
where X is a number from 0 to 2 inclusive. Replacing the bytes with your own allows you to redefine any class. Of course,Xbootclasspath
is easier though. – user11780 Feb 18 '15 at 17:00