Java Code Examples for org.objectweb.asm.tree.MethodNode#visitTypeInsn()

The following examples show how to use org.objectweb.asm.tree.MethodNode#visitTypeInsn() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StringPooler.java    From radon with GNU General Public License v3.0 5 votes vote down vote up
private MethodNode stringPool(String className, String methodName, String fieldName, ArrayList<String> strings) {
    MethodNode method = new MethodNode(ACC_PRIVATE | ACC_STATIC | ACC_SYNTHETIC | ACC_BRIDGE, methodName, "()V",
            null, null);

    method.visitCode();
    int numberOfStrings = strings.size();
    if (numberOfStrings <= 5)
        method.visitInsn(numberOfStrings + 3);
    else if (numberOfStrings <= 127)
        method.visitIntInsn(BIPUSH, strings.size());
    else if (numberOfStrings <= 32767)
        method.visitIntInsn(SIPUSH, strings.size());
    else
        method.visitLdcInsn(strings.size());


    method.visitTypeInsn(ANEWARRAY, "java/lang/String");

    for (int i = 0; i < strings.size(); i++) {
        method.visitInsn(DUP);

        if (i <= 5)
            method.visitInsn(i + 3);
        else if (i <= 127)
            method.visitIntInsn(BIPUSH, i);
        else if (i <= 32767)
            method.visitIntInsn(SIPUSH, i);
        else
            method.visitLdcInsn(i);

        method.visitLdcInsn(strings.get(i));
        method.visitInsn(AASTORE);
    }
    method.visitFieldInsn(PUTSTATIC, className, fieldName, "[Ljava/lang/String;");
    method.visitInsn(RETURN);
    method.visitMaxs(3, 0);
    method.visitEnd();

    return method;
}
 
Example 2
Source File: AntiDebugTransformer.java    From obfuscator with MIT License 4 votes vote down vote up
@NotNull
private MethodNode createMethod(@NotNull ClassNode classNode) {
    final MethodNode methodNode = new MethodNode(ACC_PRIVATE | ACC_STATIC, "checkDebug", "()V", null, null);
    methodNode.visitCode();

    final Label label0 = new Label();
    methodNode.visitLabel(label0);
    methodNode.visitLineNumber(11, label0);
    methodNode.visitMethodInsn(INVOKESTATIC, "java/lang/management/ManagementFactory", "getRuntimeMXBean", "()Ljava/lang/management/RuntimeMXBean;", false);
    methodNode.visitMethodInsn(INVOKEINTERFACE, "java/lang/management/RuntimeMXBean", "getInputArguments", "()Ljava/util/List;", true);
    methodNode.visitMethodInsn(INVOKEINTERFACE, "java/util/List", "iterator", "()Ljava/util/Iterator;", true);
    methodNode.visitVarInsn(ASTORE, 1);

    final Label label1 = new Label();
    methodNode.visitLabel(label1);
    methodNode.visitFrame(F_APPEND, 1, new Object[]{"java/util/Iterator"}, 0, null);
    methodNode.visitVarInsn(ALOAD, 1);
    methodNode.visitMethodInsn(INVOKEINTERFACE, "java/util/Iterator", "hasNext", "()Z", true);

    final Label label2 = new Label();
    methodNode.visitJumpInsn(IFEQ, label2);
    methodNode.visitVarInsn(ALOAD, 1);
    methodNode.visitMethodInsn(INVOKEINTERFACE, "java/util/Iterator", "next", "()Ljava/lang/Object;", true);
    methodNode.visitTypeInsn(CHECKCAST, "java/lang/String");
    methodNode.visitVarInsn(ASTORE, 2);

    final Label label3 = new Label();
    methodNode.visitLabel(label3);
    methodNode.visitLineNumber(12, label3);
    methodNode.visitVarInsn(ALOAD, 2);

    final String debugType = debugTypes[RandomUtil.nextInt(debugTypes.length)];
    methodNode.visitLdcInsn(debugType == null ? debugTypes[0] : debugType);
    methodNode.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "startsWith", "(Ljava/lang/String;)Z", false);

    final Label label4 = new Label();
    methodNode.visitJumpInsn(IFEQ, label4);

    final Label label5 = new Label();
    methodNode.visitLabel(label5);
    methodNode.visitLineNumber(13, label5);
    methodNode.visitIntInsn(SIPUSH, 666);
    methodNode.visitMethodInsn(INVOKESTATIC, "java/lang/System", "exit", "(I)V", false);
    methodNode.visitLabel(label4);
    methodNode.visitLineNumber(15, label4);
    methodNode.visitFrame(F_SAME, 0, null, 0, null);
    methodNode.visitJumpInsn(GOTO, label1);
    methodNode.visitLabel(label2);
    methodNode.visitLineNumber(16, label2);
    methodNode.visitFrame(F_CHOP, 1, null, 0, null);
    methodNode.visitInsn(RETURN);

    final Label label6 = new Label();
    methodNode.visitLabel(label6);
    methodNode.visitLocalVariable("string", "Ljava/lang/String;", null, label3, label4, 2);
    methodNode.visitLocalVariable("this", "L" + classNode.name + ";", null, label0, label6, 0);

    methodNode.visitMaxs(2, 3);
    methodNode.visitEnd();

    return methodNode;
}
 
Example 3
Source File: TransformerInvokerGenerator.java    From Diorite with MIT License 4 votes vote down vote up
public static void generateMethodInjection(ControllerClassData classData, ControllerMethodData methodData, MethodNode mv, boolean printMethods,
                                           int lineNumber)
{
    MethodDescription.InDefinedShape member = methodData.getMember();
    boolean isStatic = member.isStatic();

    if (printMethods)
    {
        lineNumber = printMethods(mv, classData.getType().getInternalName(), methodData.getBefore(), isStatic, lineNumber);
    }
    lineNumber = AsmUtils.printLineNumber(mv, lineNumber);

    if (! isStatic)
    {
        mv.visitVarInsn(ALOAD, 0);
    }

    for (InjectValueData<?, Generic> valueData : methodData.getInjectValues())
    {
        if (isStatic)
        {
            mv.visitInsn(ACONST_NULL);
        }
        else
        {
            mv.visitVarInsn(ALOAD, 0);
        }
        AsmUtils.storeInt(mv, classData.getIndex());
        AsmUtils.storeInt(mv, methodData.getIndex());
        AsmUtils.storeInt(mv, valueData.getIndex());
        mv.visitInsn(ICONST_0); // skip null checks in methods.
        lineNumber = AsmUtils.printLineNumber(mv, lineNumber);
        mv.visitMethodInsn(INVOKESTATIC, INJECTOR_CLASS, INJECTOR_METHOD, INJECTOR_METHOD_DESC, false);
        TypeDescription paramType = valueData.getType().asErasure();
        mv.visitTypeInsn(CHECKCAST, paramType.getInternalName()); // skip cast check?
    }

    lineNumber = AsmUtils.printLineNumber(mv, lineNumber);

    if (isStatic)
    {
        mv.visitMethodInsn(INVOKESTATIC, classData.getType().getInternalName(), member.getName(), member.getDescriptor(), false);
    }
    else
    {
        mv.visitMethodInsn(INVOKESPECIAL, classData.getType().getInternalName(), member.getName(), member.getDescriptor(), false);
    }

    if (printMethods)
    {
        printMethods(mv, classData.getType().getInternalName(), methodData.getAfter(), isStatic, lineNumber);
    }
}