Search in sources :

Example 76 with ClassNode

use of org.objectweb.asm.tree.ClassNode in project Galacticraft by micdoodle8.

the class MCPDeobfuscationTransformer method transform.

@Override
public byte[] transform(String name, String transformedName, byte[] bytes) {
    if (name.equals("net.minecraftforge.fml.common.Loader")) {
        bytes = injectCallback(bytes);
        activated = true;
    }
    if (!activated || bytes == null) {
        return bytes;
    }
    ClassNode cnode = ASMHelper.createClassNode(bytes, ClassReader.EXPAND_FRAMES);
    ClassWriter cw = new CC_ClassWriter(0, true);
    run.remap(cnode, cw);
    return cw.toByteArray();
}
Also used : ClassNode(org.objectweb.asm.tree.ClassNode) CC_ClassWriter(codechicken.lib.asm.CC_ClassWriter) ClassWriter(org.objectweb.asm.ClassWriter) CC_ClassWriter(codechicken.lib.asm.CC_ClassWriter)

Example 77 with ClassNode

use of org.objectweb.asm.tree.ClassNode in project openj9 by eclipse.

the class ClassFileCompare method compare.

private int compare(byte[] classFile1, byte[] classFile2) {
    ClassNode classNode1 = new ClassNode();
    ClassNode classNode2 = new ClassNode();
    /* Read in all data from byte arrays into ClassNodes 
		 * Specify SKIP_DEBUG mode to filter out information related to LineNumber and LocalVariable
		 */
    int debugMode = shouldCompareDebugInfo ? 0 : ClassReader.SKIP_DEBUG;
    new ClassReader(classFile1).accept(classNode1, debugMode);
    new ClassReader(classFile2).accept(classNode2, debugMode);
    /*
		 * Non-standard attributes and runtime invisible annotations are stripped by the JVM - don't compare them.
		 * Constant pools are reordered by the JVM - don't compare them.
		 * BootstrapMethods attribute is referenced by invokedynamic instructions 
		 * - BSM entries are compared in the case of INVOKE_DYNAMIC_INSN in the method "compareInstructions"
		 */
    compareMagic(classFile1, classFile2);
    compare(classNode1.version, classNode2.version, "Version numbers", false);
    /* ACC_SYNTHETIC is placed in access_flag of item as part of composition value */
    compareAccessFlag(classNode1.access, classNode2.access, "Class access flags", true);
    compare(classNode1.name, classNode2.name, "Class name");
    compare(classNode1.superName, classNode2.superName, "Superclass name");
    compare(classNode1.signature, classNode2.signature, "Generic signature");
    compare(classNode1.sourceFile, classNode2.sourceFile, "Source file name");
    compare(classNode1.sourceDebug, classNode2.sourceDebug, "Source debug extension");
    compare(classNode1.outerClass, classNode2.outerClass, "Outer class name");
    compare(classNode1.outerMethod, classNode2.outerMethod, "Enclosing method name");
    compare(classNode1.outerMethodDesc, classNode2.outerMethodDesc, "Enclosing method descriptor");
    compare(classNode1.interfaces, classNode2.interfaces, "Interfaces");
    compareInnerClasses(classNode1, classNode2);
    compareFields(classNode1, classNode2);
    compareAnnotations(classNode1.visibleAnnotations, classNode2.visibleAnnotations, "class " + classNode1.name);
    compareMethods(classNode1, classNode2);
    return diffCount;
}
Also used : InnerClassNode(org.objectweb.asm.tree.InnerClassNode) ClassNode(org.objectweb.asm.tree.ClassNode) ClassReader(org.objectweb.asm.ClassReader)

Example 78 with ClassNode

use of org.objectweb.asm.tree.ClassNode in project Galacticraft by micdoodle8.

the class ClassDiscoverer method checkAddClass.

private void checkAddClass(String resource) {
    try {
        String classname = resource.replace(".class", "").replace("\\", ".").replace("/", ".");
        byte[] bytes = Launch.classLoader.getClassBytes(classname);
        if (bytes == null) {
            return;
        }
        ClassNode cnode = ASMHelper.createClassNode(bytes);
        for (String superclass : superclasses) {
            if (!cnode.interfaces.contains(superclass) && !cnode.superName.equals(superclass)) {
                return;
            }
        }
        addClass(classname);
    } catch (IOException e) {
        CodeChickenCorePlugin.logger.error("Unable to load class: " + resource, e);
    }
}
Also used : ClassNode(org.objectweb.asm.tree.ClassNode) IOException(java.io.IOException)

Example 79 with ClassNode

use of org.objectweb.asm.tree.ClassNode in project phosphor by gmu-swe.

the class Instrumenter method analyzeClass.

public static void analyzeClass(InputStream is) {
    ClassReader cr;
    nTotal++;
    try {
        cr = new ClassReader(is);
        if (Configuration.WITH_SELECTIVE_INST) {
            try {
                ClassNode cn = new ClassNode();
                cr.accept(cn, ClassReader.SKIP_CODE);
                allClasses.put(cn.name, cn);
                cr.accept(new ClassHierarchyCreator(), ClassReader.EXPAND_FRAMES);
                cr.accept(new PartialInstrumentationInferencerCV(), ClassReader.EXPAND_FRAMES);
            } catch (ClassFormatError ex) {
                ex.printStackTrace();
            }
        }
        cr.accept(new ClassVisitor(Opcodes.ASM5) {

            @Override
            public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
                super.visit(version, access, name, signature, superName, interfaces);
                ClassNode cn = new ClassNode();
                cn.name = name;
                cn.superName = superName;
                cn.interfaces = new ArrayList<String>();
                Instrumenter.classes.put(name, cn);
            }
        }, ClassReader.SKIP_CODE);
        is.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : ClassNode(org.objectweb.asm.tree.ClassNode) ArrayList(java.util.ArrayList) ClassReader(org.objectweb.asm.ClassReader) TaintTrackingClassVisitor(edu.columbia.cs.psl.phosphor.instrumenter.TaintTrackingClassVisitor) ClassVisitor(org.objectweb.asm.ClassVisitor) IOException(java.io.IOException)

Example 80 with ClassNode

use of org.objectweb.asm.tree.ClassNode in project BuildCraft by BuildCraft.

the class EventBusProviderASM method generateGenerator.

private byte[] generateGenerator(Class<? extends IEventHandler<?>> handlerClass, Class<?> parClass, String clsName) {
    ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
    ClassNode node = new ClassNode();
    node.name = clsName.replace('.', '/');
    node.version = Opcodes.V1_6;
    node.access = Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL;
    node.interfaces = Lists.newArrayList(IEventHandlerProvider.class.getName().replace('.', '/'));
    node.superName = "java/lang/Object";
    // Method:
    // public ClassName() {
    // super();
    // }
    {
        MethodNode consturctorMethod = new MethodNode();
        consturctorMethod.access = Opcodes.ACC_PUBLIC;
        consturctorMethod.desc = "()V";
        consturctorMethod.name = "<init>";
        consturctorMethod.exceptions = Lists.newArrayList();
        consturctorMethod.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
        consturctorMethod.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false));
        consturctorMethod.instructions.add(new InsnNode(Opcodes.RETURN));
        node.methods.add(consturctorMethod);
    }
    // Method:
    // public IEventHandler createNewHandler(Object obj) {
    // return new ClassHandler(obj);
    // }
    {
        MethodNode generationMethod = new MethodNode();
        // public final void handle(Object)
        generationMethod.access = Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL;
        generationMethod.desc = "(Ljava/lang/Object;)Lbuildcraft/core/lib/event/IEventHandler;";
        generationMethod.name = "createNewHandler";
        generationMethod.exceptions = Lists.newArrayList();
        {
            generationMethod.instructions.add(new TypeInsnNode(Opcodes.NEW, Type.getInternalName(handlerClass)));
            generationMethod.instructions.add(new InsnNode(Opcodes.DUP));
            generationMethod.instructions.add(new VarInsnNode(Opcodes.ALOAD, 1));
            generationMethod.instructions.add(new TypeInsnNode(Opcodes.CHECKCAST, Type.getInternalName(parClass)));
            generationMethod.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, Type.getInternalName(handlerClass), "<init>", Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(parClass)), false));
            generationMethod.instructions.add(new InsnNode(Opcodes.ARETURN));
        }
        node.methods.add(generationMethod);
    }
    node.accept(writer);
    return writer.toByteArray();
}
Also used : ClassNode(org.objectweb.asm.tree.ClassNode) FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) TypeInsnNode(org.objectweb.asm.tree.TypeInsnNode) VarInsnNode(org.objectweb.asm.tree.VarInsnNode) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) MethodNode(org.objectweb.asm.tree.MethodNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) TypeInsnNode(org.objectweb.asm.tree.TypeInsnNode) VarInsnNode(org.objectweb.asm.tree.VarInsnNode) ClassWriter(org.objectweb.asm.ClassWriter)

Aggregations

ClassNode (org.objectweb.asm.tree.ClassNode)323 ClassReader (org.objectweb.asm.ClassReader)148 MethodNode (org.objectweb.asm.tree.MethodNode)120 ClassWriter (org.objectweb.asm.ClassWriter)70 IOException (java.io.IOException)44 AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)37 MethodInsnNode (org.objectweb.asm.tree.MethodInsnNode)34 InsnList (org.objectweb.asm.tree.InsnList)29 FieldNode (org.objectweb.asm.tree.FieldNode)28 ArrayList (java.util.ArrayList)27 Test (org.junit.Test)26 VarInsnNode (org.objectweb.asm.tree.VarInsnNode)26 Label (org.objectweb.asm.Label)21 InputStream (java.io.InputStream)20 FieldInsnNode (org.objectweb.asm.tree.FieldInsnNode)18 JumpInsnNode (org.objectweb.asm.tree.JumpInsnNode)18 InnerClassNode (org.objectweb.asm.tree.InnerClassNode)17 InsnNode (org.objectweb.asm.tree.InsnNode)17 Method (java.lang.reflect.Method)16 List (java.util.List)16