Search in sources :

Example 6 with ClassNode

use of jdk.internal.org.objectweb.asm.tree.ClassNode in project OSJR by zeruth.

the class JarInjector method run.

public void run() {
    classnodes = new CanvasInjector(classnodes).run();
    try {
        injectedJar = new File("./export/gamepack_injected.jar");
        JarOutputStream jos = new JarOutputStream(new FileOutputStream(injectedJar));
        for (ClassNode cn : classnodes.values()) {
            ClassWriter cw = new ClassWriter(1);
            cn.accept(cw);
            JarEntry entry = new JarEntry(cn.name + ".class");
            jos.putNextEntry(entry);
            jos.write(cw.toByteArray());
            jos.closeEntry();
        }
        jos.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ClassNode(jdk.internal.org.objectweb.asm.tree.ClassNode) FileOutputStream(java.io.FileOutputStream) CanvasInjector(os.rs.paint.CanvasInjector) JarOutputStream(java.util.jar.JarOutputStream) JarEntry(java.util.jar.JarEntry) File(java.io.File) ClassWriter(jdk.internal.org.objectweb.asm.ClassWriter)

Example 7 with ClassNode

use of jdk.internal.org.objectweb.asm.tree.ClassNode in project OSJR by zeruth.

the class JarLoader method loadJar.

private void loadJar() {
    try {
        if (Settings.DOWNLOAD_GAMEPACK) {
            long start = System.currentTimeMillis();
            ReadableByteChannel rbc = Channels.newChannel(new URL(gamepackUrl).openStream());
            FileOutputStream fos = new FileOutputStream("gamepack.jar");
            fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
            System.out.println("Gamepack download took " + (System.currentTimeMillis() - start) + "ms");
        } else {
        }
        JarFile jar = new JarFile(new File("./export/gamepack.jar"));
        Enumeration<JarEntry> en = jar.entries();
        while (en.hasMoreElements()) {
            JarEntry entry = en.nextElement();
            if (entry.getName().endsWith(".class")) {
                ClassReader cr = new ClassReader(jar.getInputStream(entry));
                ClassNode cn = new ClassNode();
                cr.accept(cn, ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
                classnodes.put(cn.name, cn);
            }
        }
        jar.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ReadableByteChannel(java.nio.channels.ReadableByteChannel) ClassNode(jdk.internal.org.objectweb.asm.tree.ClassNode) FileOutputStream(java.io.FileOutputStream) ClassReader(jdk.internal.org.objectweb.asm.ClassReader) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry) JarFile(java.util.jar.JarFile) File(java.io.File) URL(java.net.URL)

Aggregations

ClassNode (jdk.internal.org.objectweb.asm.tree.ClassNode)7 ClassReader (jdk.internal.org.objectweb.asm.ClassReader)3 MethodNode (jdk.internal.org.objectweb.asm.tree.MethodNode)3 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 ArrayList (java.util.ArrayList)2 JarEntry (java.util.jar.JarEntry)2 ClassWriter (jdk.internal.org.objectweb.asm.ClassWriter)2 Type (jdk.internal.org.objectweb.asm.Type)2 Analyzer (jdk.internal.org.objectweb.asm.tree.analysis.Analyzer)2 BasicValue (jdk.internal.org.objectweb.asm.tree.analysis.BasicValue)2 SimpleVerifier (jdk.internal.org.objectweb.asm.tree.analysis.SimpleVerifier)2 URL (java.net.URL)1 ReadableByteChannel (java.nio.channels.ReadableByteChannel)1 JarFile (java.util.jar.JarFile)1 JarOutputStream (java.util.jar.JarOutputStream)1 InsnList (jdk.internal.org.objectweb.asm.tree.InsnList)1 CanvasInjector (os.rs.paint.CanvasInjector)1