Search in sources :

Example 1 with JarResource

use of org.topdank.byteengineer.commons.data.JarResource in project maple-ir by LLVM-but-worse.

the class MultiJarDownloader method download.

@Override
public void download() throws IOException {
    URL[] urls = new URL[jarInfos.length];
    for (int i = 0; i < jarInfos.length; i++) {
        urls[i] = new URL(jarInfos[i].formattedURL());
    }
    contents = new LocateableJarContents<C>(urls);
    for (JarInfo jarinfo : jarInfos) {
        JarURLConnection connection = (JarURLConnection) new URL(jarinfo.formattedURL()).openConnection();
        JarFile jarFile = connection.getJarFile();
        Enumeration<JarEntry> entries = jarFile.entries();
        while (entries.hasMoreElements()) {
            JarEntry entry = entries.nextElement();
            byte[] bytes = IOUtil.read(jarFile.getInputStream(entry));
            if (entry.getName().endsWith(".class")) {
                C cn = factory.create(bytes, entry.getName());
                contents.getClassContents().add(cn);
            } else {
                JarResource resource = new JarResource(entry.getName(), bytes);
                contents.getResourceContents().add(resource);
            }
        }
    }
}
Also used : JarInfo(org.topdank.byteengineer.commons.data.JarInfo) JarURLConnection(java.net.JarURLConnection) JarResource(org.topdank.byteengineer.commons.data.JarResource) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry) URL(java.net.URL)

Example 2 with JarResource

use of org.topdank.byteengineer.commons.data.JarResource in project maple-ir by LLVM-but-worse.

the class SingleJarDownloader method download.

@Override
public void download() throws IOException {
    URL url = null;
    JarURLConnection connection = (JarURLConnection) (url = new URL(jarInfo.formattedURL())).openConnection();
    JarFile jarFile = connection.getJarFile();
    Enumeration<JarEntry> entries = jarFile.entries();
    contents = new LocateableJarContents<>(url);
    Map<String, ClassNode> map = new HashMap<>();
    while (entries.hasMoreElements()) {
        JarEntry entry = entries.nextElement();
        byte[] bytes = read(jarFile.getInputStream(entry));
        if (entry.getName().endsWith(".class")) {
            C cn = factory.create(bytes, entry.getName());
            if (!map.containsKey(cn.name)) {
                contents.getClassContents().add(cn);
            } else {
                throw new IllegalStateException("duplicate: " + cn.name);
            }
        // if(cn.name.equals("org/xmlpull/v1/XmlPullParser")) {
        // System.out.println("SingleJarDownloader.download() " +entry.getName() + " " + bytes.length);
        // }
        } else {
            JarResource resource = new JarResource(entry.getName(), bytes);
            contents.getResourceContents().add(resource);
        }
    }
}
Also used : ClassNode(org.objectweb.asm.tree.ClassNode) HashMap(java.util.HashMap) JarURLConnection(java.net.JarURLConnection) JarResource(org.topdank.byteengineer.commons.data.JarResource) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry) URL(java.net.URL)

Example 3 with JarResource

use of org.topdank.byteengineer.commons.data.JarResource in project maple-ir by LLVM-but-worse.

the class CompleteJarDumper method dump.

/**
 * Dumps the jars contents.
 *
 * @param file File to dump it to.
 */
@Override
public void dump(File file) throws IOException {
    if (file.exists())
        file.delete();
    file.createNewFile();
    JarOutputStream jos = new JarOutputStream(new FileOutputStream(file));
    int classesDumped = 0;
    int resourcesDumped = 0;
    for (ClassNode cn : contents.getClassContents()) {
        classesDumped += dumpClass(jos, cn.name, cn);
    }
    for (JarResource res : contents.getResourceContents()) {
        resourcesDumped += dumpResource(jos, res.getName(), res.getData());
    }
    if (!Debug.debugging)
        System.out.println("Dumped " + classesDumped + " classes and " + resourcesDumped + " resources to " + file.getAbsolutePath());
    jos.close();
}
Also used : ClassNode(org.objectweb.asm.tree.ClassNode) JarResource(org.topdank.byteengineer.commons.data.JarResource) FileOutputStream(java.io.FileOutputStream) JarOutputStream(java.util.jar.JarOutputStream)

Example 4 with JarResource

use of org.topdank.byteengineer.commons.data.JarResource in project maple-ir by LLVM-but-worse.

the class CompleteResolvingJarDumper method dump.

/**
 * Dumps the jars contents.
 *
 * @param file File to dump it to.
 */
@Override
public void dump(File file) throws IOException {
    if (file.exists())
        file.delete();
    file.createNewFile();
    JarOutputStream jos = new JarOutputStream(new FileOutputStream(file));
    int classesDumped = 0;
    int resourcesDumped = 0;
    for (ClassNode cn : contents.getClassContents()) {
        classesDumped += dumpClass(jos, cn.name, cn);
    }
    for (JarResource res : contents.getResourceContents()) {
        resourcesDumped += dumpResource(jos, res.getName(), res.getData());
    }
    if (!Debug.debugging)
        System.out.println("Dumped " + classesDumped + " classes and " + resourcesDumped + " resources to " + file.getAbsolutePath());
    jos.close();
}
Also used : ClassNode(org.objectweb.asm.tree.ClassNode) JarResource(org.topdank.byteengineer.commons.data.JarResource) FileOutputStream(java.io.FileOutputStream) JarOutputStream(java.util.jar.JarOutputStream)

Aggregations

JarResource (org.topdank.byteengineer.commons.data.JarResource)4 ClassNode (org.objectweb.asm.tree.ClassNode)3 FileOutputStream (java.io.FileOutputStream)2 JarURLConnection (java.net.JarURLConnection)2 URL (java.net.URL)2 JarEntry (java.util.jar.JarEntry)2 JarFile (java.util.jar.JarFile)2 JarOutputStream (java.util.jar.JarOutputStream)2 HashMap (java.util.HashMap)1 JarInfo (org.topdank.byteengineer.commons.data.JarInfo)1