Question

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.

Was it helpful?

Solution

You need to map the class name (e.g. "foo.Bar") to a resource path name (e.g. "/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.

OTHER TIPS

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.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top