It is possible to do it in Java16+ without JNI #13
Replies: 2 comments
-
Yes, @Roberto-Gentili has already implemented this (using offset 12) in his jvm-driver package, as one of many different clever tricks he has come up with for different JVMs. |
Beta Was this translation helpful? Give feedback.
-
The default driver of the JVM Driver library is fully Java based and works for all jdk version and different operating system except Android. If you use the native driver it will use the Narcissus engine instead. Take also a look at the new Reflection library where the use of the JVM Driver is optional. |
Beta Was this translation helpful? Give feedback.
-
It is possible to do it in Java16+ without JNI but the solution is vendor-specific.
Basically the only thing that has to be broken is access to field "override" in AccessibleObject. Looks like after achieving it we can do anything. To get access to the field we just need to know its offset. But we cannot get the corresponded Field object.
However, the offset is a constant that may depends on for platform and JVM vendor. But I already know that for x64_86 (Windows & Linux), Amazon Corretto and IBM Semeru OpenJ9 the value is always 12. Thus we don't need JNI for these platforms. Yes, I know that potentially it can be changed but in some situation it is acceptable if you test your application with any new JDK before deployment.
I really tried to put example code here but the editor/formatter on github is weird...
Beta Was this translation helpful? Give feedback.
All reactions