It's possible to save class from URLClassLoader to normal file.class? and then decompile it?
I trying save it just as object using
Class<?> clazz = classLoader.loadClass("foo.Bar");
FileOutputStream sf = new FileOutputStream(f);
ObjectOutputStream s = new ObjectOutputStream(sf);
s.writeObject(clazz);
s.close();
Bu that don't work.
So... how to decompile it? I need get something like result of jd-gui, but using class from URLClassLoader.
You need to map the class name (eg "foo.Bar"
) to a resource path name (eg "/foo/Bar.class"
) and then use classLoader.getResourceAsStream
to open a stream to read the bytecode file.
In theory, this can then be fed to a decompiler ... assuming that you have a decompiler that can read from an InputStream
.
What you are doing at the moment fails because a Class
object cannot be serialized.
Do a simple HTTP download, rather than URLClassLoader, to get the class into a file. Then decompile that.
(Writing an object to an ObjectOutputStream only saves the data in an instance of the object, and even that works only if the object has implemented Serializable. Not what you're looking for here.)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.