Is it possible to serialize a java class object to a class file?
I am trying to reverse engineer a java class that is loaded by custom class loader.
I tried to store the binary content, and later tried to decompile, but开发者_高级运维 decompiler complained it as not a typical java class, I understood that class is loaded dynamically.
Now at runtime I have class object. Is it possible to serialize to a class file which follows the same convention as sun java class.
Added : alternatively, is there any decompiler API available which can work on java class object?
The easiest way (imo) to get around the case is directly hacking java.lang.ClassLoader
and replacing it to track any loaded class look for protected final Class<?> defineClass(String name, byte[] b, int off, int len, ProtectionDomain protectionDomain)
and replace it w/ your own version and a hook. When you compile your own version of java.lang.ClassLoader, just use java - -Xbootclasspath/p
Alternatively installing some instrumentation can yield similar effects.
Happy hacking!
Ehhhh. Why does the decompiler complain, exactly? Some code simply cannot be decompiled. For example, if the byte code pushes, but then doesn't pop, there's just no Java equivalent for that.
Try and inspect the byte code. A quick peek with javap might be quite revealing already.
精彩评论