How to extract .class files from nested Jar?

本小妞迷上赌 提交于 2019-12-04 12:28:28

You need to create a second JarInputStream to process the inner entries. This does what you want:

FileInputStream fin = new FileInputStream("OuterJar.jar");
JarInputStream jin = new JarInputStream(fin);
ZipEntry ze = null;
while ((ze = jin.getNextEntry()) != null) {
    if (ze.getName().endsWith(".jar")) {
        JarInputStream jin2 = new JarInputStream(jin);
        ZipEntry ze2 = null;
        while ((ze2 = jin2.getNextEntry()) != null) {
            // this is bit of a hack to avoid stream closing,
            // since you can't get one for the inner entry
            // because you have no JarFile to get it from 
            FilterInputStream in = new FilterInputStream(jin2) {
                public void close() throws IOException {
                    // ignore the close
                }
            };

            // now you can process the input stream as needed
            JavaClass clazz = new ClassParser(in, "").parse();
        }
    }
}

Extract the InnerJar.jar first, then extract the class files from it.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!