Example usage for org.objectweb.asm Opcodes ACC_PUBLIC

List of usage examples for org.objectweb.asm Opcodes ACC_PUBLIC

Introduction

In this page you can find the example usage for org.objectweb.asm Opcodes ACC_PUBLIC.

Prototype

int ACC_PUBLIC

To view the source code for org.objectweb.asm Opcodes ACC_PUBLIC.

Click Source Link

Usage

From source file:appeng.transformer.asm.ASMTweaker.java

License:Open Source License

@Nullable
@Override/*from   w  w  w  .j  a  v a  2s  .co  m*/
public byte[] transform(String name, String transformedName, byte[] basicClass) {
    if (basicClass == null) {
        return null;
    }

    try {
        if (transformedName != null && this.privateToPublicMethods.containsKey(transformedName)) {
            ClassNode classNode = new ClassNode();
            ClassReader classReader = new ClassReader(basicClass);
            classReader.accept(classNode, 0);

            for (PublicLine set : this.privateToPublicMethods.get(transformedName)) {
                this.makePublic(classNode, set);
            }

            // CALL VIRTUAL!
            if (transformedName.equals("net.minecraft.client.gui.inventory.GuiContainer")) {
                for (MethodNode mn : classNode.methods) {
                    if (mn.name.equals("func_146977_a") || (mn.name.equals("a") && mn.desc.equals("(Lzk;)V"))) {
                        MethodNode newNode = new MethodNode(Opcodes.ACC_PUBLIC, "func_146977_a_original",
                                mn.desc, mn.signature, EXCEPTIONS);
                        newNode.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
                        newNode.instructions.add(new VarInsnNode(Opcodes.ALOAD, 1));
                        newNode.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, classNode.name,
                                mn.name, mn.desc, false));
                        newNode.instructions.add(new InsnNode(Opcodes.RETURN));
                        this.log(newNode.name + newNode.desc + " - New Method");
                        classNode.methods.add(newNode);
                        break;
                    }
                }

                for (MethodNode mn : classNode.methods) {
                    if (mn.name.equals("func_73863_a") || mn.name.equals("drawScreen")
                            || (mn.name.equals("a") && mn.desc.equals("(IIF)V"))) {
                        Iterator<AbstractInsnNode> i = mn.instructions.iterator();
                        while (i.hasNext()) {
                            AbstractInsnNode in = i.next();
                            if (in.getOpcode() == Opcodes.INVOKESPECIAL) {
                                MethodInsnNode n = (MethodInsnNode) in;
                                if (n.name.equals("func_146977_a")
                                        || (n.name.equals("a") && n.desc.equals("(Lzk;)V"))) {
                                    this.log(n.name + n.desc + " - Invoke Virtual");
                                    mn.instructions.insertBefore(n, new MethodInsnNode(Opcodes.INVOKEVIRTUAL,
                                            n.owner, n.name, n.desc, false));
                                    mn.instructions.remove(in);
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
            classNode.accept(writer);
            return writer.toByteArray();
        }
    } catch (Throwable ignored) {
    }

    return basicClass;
}

From source file:appeng.transformer.asm.ASMTweaker.java

License:Open Source License

private void makePublic(ClassNode classNode, PublicLine set) {
    for (MethodNode mn : classNode.methods) {
        if (mn.name.equals(set.name) && mn.desc.equals(set.desc)) {
            mn.access = (mn.access & (~(Opcodes.ACC_FINAL | Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED)))
                    | Opcodes.ACC_PUBLIC;
            this.log(mn.name + mn.desc + " - Transformed");
        }//  ww  w  .  j av a 2s  .  co  m
    }
}

From source file:asm.FindCallers.java

License:Apache License

@Override
public MethodVisitor visitMethod(int arg0, String arg1, String arg2, String arg3, String[] arg4) {
    if ((arg0 & Opcodes.ACC_BRIDGE) == Opcodes.ACC_BRIDGE
            && (arg0 & Opcodes.ACC_SYNTHETIC) == Opcodes.ACC_SYNTHETIC) {
        return null;
    }/*from  w  ww . j  av a  2  s . com*/

    this.currentMethod = new Annotated(className, baseClass, arg1, arg2,
            (arg0 & Opcodes.ACC_PUBLIC) == Opcodes.ACC_PUBLIC);
    return super.visitMethod(arg0, arg1, arg2, arg3, arg4);
}

From source file:ataspectj.UnweavableTest.java

License:Open Source License

ISome getJit() {
    ClassWriter cw = new ClassWriter(true, true);
    cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC, "ataspectj/ISomeGen", null, "java/lang/Object",
            new String[] { "ataspectj/UnweavableTest$ISome" });
    AnnotationVisitor av = cw.visitAnnotation("Lataspectj/UnweavableTest$ASome;", true);
    av.visitEnd();//  w w w .  j a v a 2  s  . co  m

    MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, new String[0]);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
    mv.visitInsn(Opcodes.RETURN);
    mv.visitMaxs(0, 0);
    mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "giveOne", "()I", null, new String[0]);
    mv.visitInsn(Opcodes.ICONST_2);
    mv.visitInsn(Opcodes.IRETURN);
    mv.visitMaxs(0, 0);
    cw.visitEnd();

    try {
        ClassLoader loader = this.getClass().getClassLoader();
        Method def = ClassLoader.class.getDeclaredMethod("defineClass",
                new Class[] { String.class, byte[].class, int.class, int.class });
        def.setAccessible(true);
        Class gen = (Class) def.invoke(loader, "ataspectj.ISomeGen", cw.toByteArray(), 0,
                cw.toByteArray().length);
        return (ISome) gen.newInstance();
    } catch (Throwable t) {
        fail(t.toString());
        return null;
    }
}

From source file:ataspectj.UnweavableTest.java

License:Open Source License

Serializable getJitNoMatch() {
    ClassWriter cw = new ClassWriter(true, true);
    cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC, "ataspectj/unmatched/Gen", null, "java/lang/Object",
            new String[] { "java/io/Serializable" });

    MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, new String[0]);
    mv.visitVarInsn(Opcodes.ALOAD, 0);// w ww. ja v  a2 s.  co  m
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
    mv.visitInsn(Opcodes.RETURN);
    mv.visitMaxs(0, 0);
    cw.visitEnd();

    try {
        ClassLoader loader = this.getClass().getClassLoader();
        Method def = ClassLoader.class.getDeclaredMethod("defineClass",
                new Class[] { String.class, byte[].class, int.class, int.class });
        def.setAccessible(true);
        Class gen = (Class) def.invoke(loader, "ataspectj.unmatched.Gen", cw.toByteArray(), 0,
                cw.toByteArray().length);
        return (Serializable) gen.newInstance();
    } catch (Throwable t) {
        fail(t.toString());
        return null;
    }
}

From source file:blue.origami.asm.OAnno.java

License:Apache License

public void add(String spec) {
    String[] annos = spec.split(",");
    for (String s : annos) {
        s = s.toLowerCase();//w  w  w . j  a va  2  s .c o  m
        switch (s) {
        case "public":
            acc |= Opcodes.ACC_PUBLIC;
            acc &= ~Opcodes.ACC_PROTECTED;
            acc &= ~Opcodes.ACC_PRIVATE;
            break;
        case "protected":
            acc |= Opcodes.ACC_PROTECTED;
            acc &= ~Opcodes.ACC_PUBLIC;
            acc &= ~Opcodes.ACC_PRIVATE;
            break;
        case "private":
            acc |= Opcodes.ACC_PRIVATE;
            acc &= ~Opcodes.ACC_PUBLIC;
            acc &= ~Opcodes.ACC_PROTECTED;
            break;
        case "static":
            acc |= Opcodes.ACC_STATIC;
            break;
        case "abstract":
            acc |= Opcodes.ACC_ABSTRACT;
            break;
        case "interface":
            acc |= Opcodes.ACC_INTERFACE;
            break;
        case "final":
            acc |= Opcodes.ACC_FINAL;
            break;
        case "native":
            acc |= Opcodes.ACC_NATIVE;
            break;
        case "synchronized":
            acc |= Opcodes.ACC_SYNCHRONIZED;
            break;
        case "strictfp":
            acc |= Opcodes.ACC_STRICT;
            break;
        }
    }
}

From source file:blue.origami.asm.OAnno.java

License:Apache License

public final boolean isPublic() {
    return ((acc & Opcodes.ACC_PUBLIC) == Opcodes.ACC_PUBLIC);
}

From source file:blusunrize.immersiveengineering.common.util.compat.jei.arcfurnace.ArcFurnaceRecipeWrapper.java

private static Class<? extends ArcFurnaceRecipeWrapper> createSubWrapper(String subtype) throws Exception {
    String entitySuperClassName = Type.getInternalName(ArcFurnaceRecipeWrapper.class);
    String entityProxySubClassName = ArcFurnaceRecipeWrapper.class.getSimpleName().concat(subtype);
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    cw.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, entityProxySubClassName, null,
            entitySuperClassName, null);
    cw.visitSource(entityProxySubClassName.concat(".java"), null);
    //create constructor
    String methodDescriptor = "(L" + Type.getInternalName(ArcFurnaceRecipe.class) + ";)V";
    MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", methodDescriptor, null, null);
    mv.visitCode();//from   w w  w  .j  av  a  2s .c  o m
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitVarInsn(Opcodes.ALOAD, 1);
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, entitySuperClassName, "<init>", methodDescriptor, false);
    mv.visitInsn(Opcodes.RETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
    cw.visitEnd();
    return (Class<? extends ArcFurnaceRecipeWrapper>) new ProxyClassLoader(
            Thread.currentThread().getContextClassLoader(), cw.toByteArray())
                    .loadClass(entityProxySubClassName.replaceAll("/", "."));
}

From source file:bndtools.diff.JarDiff.java

License:Open Source License

private static Set<ClassInfo> getClassesFromPackage(PackageInfo pi, Jar jar, String packageName,
        String version) {// w w  w. jav  a  2s.c  o m
    packageName = packageName.replace('.', '/');
    Map<String, Map<String, Resource>> dirs = jar.getDirectories();
    if (dirs == null) {
        return Collections.emptySet();
    }
    Map<String, Resource> res = dirs.get(packageName);
    if (res == null) {
        return Collections.emptySet();
    }
    Set<ClassInfo> ret = new TreeSet<ClassInfo>();

    for (Map.Entry<String, Resource> me : res.entrySet()) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        if (me.getKey().endsWith(".class")) {
            InputStream is = null;
            try {
                is = me.getValue().openInputStream();
                byte[] bytes = new byte[8092];
                int bytesRead = 0;
                while ((bytesRead = is.read(bytes, 0, 8092)) != -1) {
                    baos.write(bytes, 0, bytesRead);
                }

                byte[] classBytes = baos.toByteArray();
                MessageDigest md = MessageDigest.getInstance("SHA1");
                md.update(classBytes);
                byte[] digest = md.digest();
                ClassReader cr = new ClassReader(classBytes);
                ClassInfo ca = new ClassInfo(pi, digest);
                cr.accept(ca, 0);

                for (int i = 0; i < ca.methods.size(); i++) {
                    MethodNode mn = (MethodNode) ca.methods.get(i);
                    // Ignore anything but public and protected methods
                    if ((mn.access & Opcodes.ACC_PUBLIC) == Opcodes.ACC_PUBLIC
                            || (mn.access & Opcodes.ACC_PROTECTED) == Opcodes.ACC_PROTECTED) {
                        MethodInfo mi = new MethodInfo(mn, ca);
                        ca.addPublicMethod(mi);
                    }
                }
                for (int i = 0; i < ca.fields.size(); i++) {
                    FieldNode mn = (FieldNode) ca.fields.get(i);
                    // Ignore anything but public fields
                    if ((mn.access & Opcodes.ACC_PUBLIC) == Opcodes.ACC_PUBLIC
                            || (mn.access & Opcodes.ACC_PROTECTED) == Opcodes.ACC_PROTECTED) {
                        FieldInfo mi = new FieldInfo(mn, ca);
                        ca.addPublicField(mi);
                    }
                }
                ret.add(ca);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }
    return ret;
}

From source file:br.usp.each.saeg.badua.test.validation.MaxTest.java

License:Open Source License

@Override
@Before// w  w  w . ja va  2 s .c  om
public void setUp() throws Exception {
    super.setUp();

    final int classVersion = Opcodes.V1_6;
    final int classAccessor = Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER;
    final String className = "Max";
    final String superName = "java/lang/Object";

    final int methodAccessor = Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC;
    final String methodName = "max";
    final String methodDesc = "([II)I";

    final ClassWriter cw = new ClassWriter(0);
    final MethodVisitor mw;

    cw.visit(classVersion, classAccessor, className, null, superName, null);
    mw = cw.visitMethod(methodAccessor, methodName, methodDesc, null, null);
    mw.visitCode();
    // block 0 (definitions {0, 1, 2, 3})
    mw.visitInsn(Opcodes.ICONST_0);
    mw.visitVarInsn(Opcodes.ISTORE, 2);
    mw.visitVarInsn(Opcodes.ALOAD, 0);
    mw.visitVarInsn(Opcodes.ILOAD, 2);
    mw.visitIincInsn(2, 1);
    mw.visitInsn(Opcodes.IALOAD);
    mw.visitVarInsn(Opcodes.ISTORE, 3);
    // block 1 (p-uses {1, 2})
    final Label backLoop = new Label();
    mw.visitLabel(backLoop);
    mw.visitVarInsn(Opcodes.ILOAD, 2);
    mw.visitVarInsn(Opcodes.ILOAD, 1);
    final Label breakLoop = new Label();
    mw.visitJumpInsn(Opcodes.IF_ICMPGE, breakLoop);
    // block 3 (p-uses {0, 2, 3})
    mw.visitVarInsn(Opcodes.ALOAD, 0);
    mw.visitVarInsn(Opcodes.ILOAD, 2);
    mw.visitInsn(Opcodes.IALOAD);
    mw.visitVarInsn(Opcodes.ILOAD, 3);
    final Label jump = new Label();
    mw.visitJumpInsn(Opcodes.IF_ICMPLE, jump);
    // block 5 (definitions {3}, uses {0, 2})
    mw.visitVarInsn(Opcodes.ALOAD, 0);
    mw.visitVarInsn(Opcodes.ILOAD, 2);
    mw.visitInsn(Opcodes.IALOAD);
    mw.visitVarInsn(Opcodes.ISTORE, 3);
    // block 4 (definitions {2}, uses {2})
    mw.visitLabel(jump);
    mw.visitIincInsn(2, 1);
    mw.visitJumpInsn(Opcodes.GOTO, backLoop);
    // block 2 ( uses {3})
    mw.visitLabel(breakLoop);
    mw.visitVarInsn(Opcodes.ILOAD, 3);
    mw.visitInsn(Opcodes.IRETURN);
    mw.visitMaxs(2, 4);
    mw.visitEnd();
    cw.visitEnd();

    final byte[] bytes = cw.toByteArray();
    klass = addClass(className, bytes);
    method = klass.getMethod(methodName, int[].class, int.class);
    classId = CRC64.checksum(bytes);

    RT.init(new RuntimeData());
}