문제

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

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top