简体   繁体   English

从URLClassLoader将类保存到文件? 并反编译?

[英]Save class to file from URLClassLoader? and decompile it?

It's possible to save class from URLClassLoader to normal file.class? 可以将类从URLClassLoader保存到普通的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. 我需要得到像jd-gui的结果,但是使用来自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. 您需要将类名(例如"foo.Bar" )映射到资源路径名(例如"/foo/Bar.class" ),然后使用classLoader.getResourceAsStream打开流以读取字节码文件。

In theory, this can then be fed to a decompiler ... assuming that you have a decompiler that can read from an InputStream . 理论上,这可以被提供给反编译器...假设您有一个可以从InputStream读取的反编译器。


What you are doing at the moment fails because a Class object cannot be serialized. 您当前正在执行的操作失败,因为无法序列化Class对象。

Do a simple HTTP download, rather than URLClassLoader, to get the class into a file. 执行简单的HTTP下载而不是URLClassLoader,以将类放入文件中。 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.) (将对象写入ObjectOutputStream只会将数据保存在对象的实例中,即使该对象已实现Serializable也是如此。不是您在这里寻找的。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM