Reputation: 43
I am working with this awesome little piece of code, and I need some help figuring it out.
Basically it has a big byte array, which is used to load a new class:
Class class = class1.loadClass(name, byteArray);
class.getMethod("run", new Class[0]).invoke(null, new Object[0]);
This is loadClass:
public Class<?> loadClass(String paramString, byte[] paramArrayOfByte) throws ClassNotFoundException
return defineClass(paramString, paramArrayOfByte, 0, paramArrayOfByte.length);
And then it calls the 'run' in this class. Now, besides this being an awesome way to hide your classes, how do I get a look into this class? I have the actual class in 'class', but I don't get further than the attributes and their values and the function names. I want to know what 'run' actually does. Is there any way to somehow print the content of this method or whatever? Or maybe I can transform the byte array containing the class in something readable?
Thanks!
Upvotes: 3
Views: 91
Reputation: 15090
What if you write this byteArray
in a .class
file and open it with a Java Decompiler tool (like jd-gui) ?
Upvotes: 2
Reputation: 6675
You are asking how to read a class file into something meaninful.So basically you are asking for it to be decompiled like JD-Decompiler .Also,the .class files are loaded in the memory by the classloader. I would suggest you take a dump of the .class file and write it in the file using ByteArrayOutputStream and ObjectOutputStream .Then decompile it using any decompiler software.
Please note that this process does not guarantee any accuracy of the source file decompiled..
Upvotes: 2