Java Code Examples for org.objectweb.asm.MethodVisitor#visitVarInsn()

The following examples show how to use org.objectweb.asm.MethodVisitor#visitVarInsn() . 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: InterfaceDesugaring.java    From bazel with Apache License 2.0 6 votes vote down vote up
private void generateStub(MethodVisitor stubMethod, String calledMethodName, String desc) {
  int slot = 0;
  Type neededType = Type.getMethodType(desc);
  for (Type arg : neededType.getArgumentTypes()) {
    stubMethod.visitVarInsn(arg.getOpcode(Opcodes.ILOAD), slot);
    slot += arg.getSize();
  }
  stubMethod.visitMethodInsn(
      Opcodes.INVOKESTATIC,
      getCompanionClassName(internalName),
      calledMethodName,
      desc,
      /*isInterface=*/ false);
  stubMethod.visitInsn(neededType.getReturnType().getOpcode(Opcodes.IRETURN));
  stubMethod.visitMaxs(slot, slot);
  stubMethod.visitEnd();
}
 
Example 2
Source File: WriterHelper.java    From sumk with Apache License 2.0 6 votes vote down vote up
public static int storeToLocalVariable(MethodVisitor mv, Class<?> c, int frameIndex) {
	if (c == Integer.TYPE || c == Boolean.TYPE || c == Byte.TYPE || c == Character.TYPE || c == Short.TYPE) {
		mv.visitVarInsn(ISTORE, frameIndex);
		return SINGLE;
	}
	if (c == Float.TYPE) {
		mv.visitVarInsn(FSTORE, frameIndex);
		return SINGLE;
	}
	if (c == Double.TYPE) {
		mv.visitVarInsn(DSTORE, frameIndex);
		return WIDTH;
	}
	if (c == Long.TYPE) {
		mv.visitVarInsn(LSTORE, frameIndex);
		return WIDTH;
	}

	mv.visitVarInsn(ASTORE, frameIndex);
	return SINGLE;

}
 
Example 3
Source File: StatementWriter.java    From groovy with Apache License 2.0 6 votes vote down vote up
private void writeCaseStatement(final CaseStatement statement, final int switchVariableIndex, final Label thisLabel, final Label nextLabel) {
    controller.getAcg().onLineNumber(statement, "visitCaseStatement");
    MethodVisitor mv = controller.getMethodVisitor();
    OperandStack operandStack = controller.getOperandStack();

    mv.visitVarInsn(ALOAD, switchVariableIndex);

    statement.getExpression().visit(controller.getAcg());
    operandStack.box();
    controller.getBinaryExpressionHelper().getIsCaseMethod().call(mv);
    operandStack.replace(ClassHelper.boolean_TYPE);

    Label l0 = controller.getOperandStack().jump(IFEQ);

    mv.visitLabel(thisLabel);

    statement.getCode().visit(controller.getAcg());

    // now if we don't finish with a break we need to jump past the next comparison
    if (nextLabel != null) {
        mv.visitJumpInsn(GOTO, nextLabel);
    }

    mv.visitLabel(l0);
}
 
Example 4
Source File: BytecodeCreatorImpl.java    From gizmo with Apache License 2.0 6 votes vote down vote up
static void storeResultHandle(MethodVisitor methodVisitor, ResultHandle handle) {
    if (handle.getResultType() == ResultHandle.ResultType.UNUSED) {
        if (handle.getType().equals("J") || handle.getType().equals("D")) {
            methodVisitor.visitInsn(Opcodes.POP2);
        } else {
            methodVisitor.visitInsn(Opcodes.POP);
        }
    } else if (handle.getResultType() == ResultHandle.ResultType.LOCAL_VARIABLE) {
        if (handle.getType().equals("S") || handle.getType().equals("Z") || handle.getType().equals("I") || handle.getType().equals("B") || handle.getType().equals("C")) {
            methodVisitor.visitVarInsn(Opcodes.ISTORE, handle.getNo());
        } else if (handle.getType().equals("J")) {
            methodVisitor.visitVarInsn(Opcodes.LSTORE, handle.getNo());
        } else if (handle.getType().equals("F")) {
            methodVisitor.visitVarInsn(Opcodes.FSTORE, handle.getNo());
        } else if (handle.getType().equals("D")) {
            methodVisitor.visitVarInsn(Opcodes.DSTORE, handle.getNo());
        } else {
            methodVisitor.visitVarInsn(Opcodes.ASTORE, handle.getNo());
        }
    }
}
 
Example 5
Source File: Beans.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@Override
public ClassVisitor apply(String className, ClassVisitor classVisitor) {
    return new ClassVisitor(Gizmo.ASM_API_VERSION, classVisitor) {

        @Override
        public void visit(int version, int access, String name, String signature,
                String superName,
                String[] interfaces) {
            super.visit(version, access, name, signature, superName, interfaces);
            MethodVisitor mv = visitMethod(Modifier.PUBLIC, Methods.INIT, "()V", null,
                    null);
            mv.visitCode();
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitMethodInsn(Opcodes.INVOKESPECIAL, superClassName, Methods.INIT, "()V",
                    false);
            // NOTE: it seems that we do not need to handle final fields?
            mv.visitInsn(Opcodes.RETURN);
            mv.visitMaxs(1, 1);
            mv.visitEnd();
            LOGGER.debugf("Added a no-args constructor to bean class: ", className);
        }
    };
}
 
Example 6
Source File: InnerClassCompletionVisitor.java    From groovy with Apache License 2.0 5 votes vote down vote up
private void getThis(MethodVisitor mv, String classInternalName, String outerClassDescriptor, String innerClassInternalName) {
    mv.visitVarInsn(ALOAD, 0);
    if (thisField != null && CLOSURE_TYPE.equals(thisField.getType())) {
        mv.visitFieldInsn(GETFIELD, classInternalName, "this$0", CLOSURE_DESCRIPTOR);
        mv.visitMethodInsn(INVOKEVIRTUAL, CLOSURE_INTERNAL_NAME, "getThisObject", "()Ljava/lang/Object;", false);
        mv.visitTypeInsn(CHECKCAST, innerClassInternalName);
    } else {
        mv.visitFieldInsn(GETFIELD, classInternalName, "this$0", outerClassDescriptor);
    }
}
 
Example 7
Source File: RobustAsmUtils.java    From Robust with Apache License 2.0 5 votes vote down vote up
private static void createFloatObj(MethodVisitor mv, int argsPostion) {
    mv.visitTypeInsn(Opcodes.NEW, "java/lang/Float");
    mv.visitInsn(Opcodes.DUP);
    mv.visitVarInsn(Opcodes.FLOAD, argsPostion);
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Float", "<init>", "(F)V");
    mv.visitInsn(Opcodes.AASTORE);
}
 
Example 8
Source File: BasicTests.java    From Despector with MIT License 5 votes vote down vote up
@Test
public void testLocals() {
    TestMethodBuilder builder = new TestMethodBuilder("main", "()V");
    MethodVisitor mv = builder.getGenerator();
    Label start = new Label();
    mv.visitLabel(start);
    Label end = new Label();
    mv.visitLdcInsn("Hello");
    mv.visitVarInsn(ASTORE, 0);
    Label start2 = new Label();
    mv.visitLabel(start2);
    mv.visitInsn(ICONST_2);
    mv.visitVarInsn(ISTORE, 1);
    mv.visitIincInsn(1, 5);
    mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", true);
    mv.visitLabel(end);
    mv.visitInsn(RETURN);
    mv.visitLocalVariable("s", "Ljava/lang/String;", null, start, end, 0);
    mv.visitLocalVariable("a", "I", null, start2, end, 1);

    String insn = KotlinTestHelper.getMethodAsString(builder.finish(), "main");
    String good = "fun main() {\n"
            + "    val s: String = \"Hello\"\n"
            + "    var a: Int = 2\n"
            + "    a += 5\n"
            + "    println(s)\n"
            + "}";
    Assert.assertEquals(good, insn);
}
 
Example 9
Source File: EqualsMethod.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Size apply(MethodVisitor methodVisitor, Context implementationContext) {
    methodVisitor.visitVarInsn(Opcodes.ASTORE, instrumentedMethod.getStackSize());
    methodVisitor.visitVarInsn(Opcodes.ASTORE, instrumentedMethod.getStackSize() + 1);
    methodVisitor.visitVarInsn(Opcodes.ALOAD, instrumentedMethod.getStackSize() + 1);
    methodVisitor.visitVarInsn(Opcodes.ALOAD, instrumentedMethod.getStackSize());
    methodVisitor.visitJumpInsn(Opcodes.IFNULL, secondValueNull);
    methodVisitor.visitJumpInsn(Opcodes.IFNULL, firstValueNull);
    methodVisitor.visitVarInsn(Opcodes.ALOAD, instrumentedMethod.getStackSize() + 1);
    methodVisitor.visitVarInsn(Opcodes.ALOAD, instrumentedMethod.getStackSize());
    return new Size(0, 0);
}
 
Example 10
Source File: GenZipWithEntries.java    From bazel with Apache License 2.0 5 votes vote down vote up
public static byte[] dump(String name) {
  ClassWriter cw = new ClassWriter(0);
  cw.visit(52, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, name, null, "java/lang/Object", null);
  {
    MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
    mv.visitCode();
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
    mv.visitInsn(Opcodes.RETURN);
    mv.visitMaxs(1, 1);
    mv.visitEnd();
  }
  cw.visitEnd();
  return cw.toByteArray();
}
 
Example 11
Source File: WhileTests.java    From Despector with MIT License 5 votes vote down vote up
@Test
public void testWhileContinue() {
    TestMethodBuilder builder = new TestMethodBuilder("test_mth", "(IZ)V");
    MethodVisitor mv = builder.getGenerator();
    Label start = new Label();
    mv.visitLabel(start);
    Label end = new Label();
    Label l1 = new Label();
    Label l2 = new Label();
    mv.visitLabel(l1);
    mv.visitVarInsn(ILOAD, 0);
    mv.visitInsn(ICONST_5);
    mv.visitJumpInsn(IF_ICMPGE, end);
    mv.visitMethodInsn(INVOKESTATIC, THIS_TYPE.getInternalName(), "body", "()V", false);
    mv.visitVarInsn(ILOAD, 1);
    mv.visitJumpInsn(IFEQ, l2);
    mv.visitJumpInsn(GOTO, l1);
    mv.visitLabel(l2);
    mv.visitJumpInsn(GOTO, l1);
    mv.visitLabel(end);
    mv.visitInsn(RETURN);
    mv.visitLocalVariable("i", "I", null, start, end, 0);
    mv.visitLocalVariable("a", "Z", null, start, end, 1);

    String insn = TestHelper.getAsString(builder.finish(), "test_mth");
    String good = "while (i < 5) {\n"
            + "    org.spongepowered.test.decompile.WhileTests.body();\n"
            + "    if (a) {\n"
            + "        continue;\n"
            + "    }\n"
            + "}";
    Assert.assertEquals(good, insn);
}
 
Example 12
Source File: IfTests.java    From Despector with MIT License 5 votes vote down vote up
@Test
public void testNestedInstanceOfOptimized() {
    TestMethodBuilder builder = new TestMethodBuilder("test_mth", "(ZLjava/lang/Object;)V");
    MethodVisitor mv = builder.getGenerator();
    Label start = new Label();
    mv.visitLabel(start);
    Label end = new Label();
    mv.visitVarInsn(ILOAD, 0);
    mv.visitJumpInsn(IFEQ, end);
    mv.visitMethodInsn(INVOKESTATIC, THIS_TYPE.getInternalName(), "body", "()V", false);
    mv.visitVarInsn(ILOAD, 1);
    mv.visitTypeInsn(INSTANCEOF, THIS_TYPE.getInternalName());
    mv.visitJumpInsn(IFEQ, end);
    mv.visitMethodInsn(INVOKESTATIC, THIS_TYPE.getInternalName(), "body", "()V", false);
    mv.visitLabel(end);
    mv.visitInsn(RETURN);
    mv.visitLocalVariable("a", "Z", null, start, end, 0);
    mv.visitLocalVariable("b", "Ljava/lang/Object;", null, start, end, 1);

    String insn = TestHelper.getAsString(builder.finish(), "test_mth");
    String good = "if (a) {\n"
            + "    org.spongepowered.test.decompile.IfTests.body();\n"
            + "    if (b instanceof org.spongepowered.test.decompile.IfTests) {\n"
            + "        org.spongepowered.test.decompile.IfTests.body();\n"
            + "    }\n"
            + "}";
    Assert.assertEquals(good, insn);
}
 
Example 13
Source File: LineNumbersTest.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void generate(TraceClassVisitor cw) {
	MethodVisitor mv;

	cw.visit(V1_1, ACC_PUBLIC + ACC_SUPER, "soot/asm/backend/targets/LineNumbers",
			null, "java/lang/Object", null);
	cw.visitSource("LineNumbers.java", null);
	
	{
	mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
	mv.visitCode();
	Label l1 = new Label();
	mv.visitLabel(l1);
	mv.visitLineNumber(3, l1);
	mv.visitVarInsn(ALOAD, 0);
	Label l2 = new Label();
	mv.visitLabel(l2);
	mv.visitLineNumber(3, l2);
	mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
	Label l3 = new Label();
	mv.visitLabel(l3);
	mv.visitLineNumber(3, l3);
	mv.visitInsn(RETURN);
	mv.visitMaxs(0, 0);
	mv.visitEnd();
	}
	{
	mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "main", "([Ljava/lang/String;)V", null, null);
	mv.visitCode();
	Label l0 = new Label();
	mv.visitLabel(l0);
	mv.visitLineNumber(6, l0);
	mv.visitInsn(RETURN);
	mv.visitMaxs(0, 0);
	mv.visitEnd();
	}
	cw.visitEnd();

}
 
Example 14
Source File: TransientClassLoader.java    From attic-polygene-java with Apache License 2.0 4 votes vote down vote up
private static int loadParameter( MethodVisitor mv, Class<?> aClass, int idx )
{
    if( aClass.equals( Integer.TYPE ) )
    {
        mv.visitVarInsn( ILOAD, idx );
    }
    else if( aClass.equals( Long.TYPE ) )
    {
        mv.visitVarInsn( LLOAD, idx );
        idx++; // Extra jump
    }
    else if( aClass.equals( Short.TYPE ) )
    {
        mv.visitVarInsn( ILOAD, idx );
    }
    else if( aClass.equals( Byte.TYPE ) )
    {
        mv.visitVarInsn( ILOAD, idx );
    }
    else if( aClass.equals( Double.TYPE ) )
    {
        mv.visitVarInsn( DLOAD, idx );
        idx++; // Extra jump
    }
    else if( aClass.equals( Float.TYPE ) )
    {
        mv.visitVarInsn( FLOAD, idx );
    }
    else if( aClass.equals( Boolean.TYPE ) )
    {
        mv.visitVarInsn( ILOAD, idx );
    }
    else if( aClass.equals( Character.TYPE ) )
    {
        mv.visitVarInsn( ILOAD, idx );
    }
    else
    {
        mv.visitVarInsn( ALOAD, idx );
    }

    return idx;
}
 
Example 15
Source File: ApplicationFactory.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 4 votes vote down vote up
public static byte[] create(String name, String context) {

        ClassWriter cw = new ClassWriter(0);
        MethodVisitor mv;
        AnnotationVisitor av0;

        cw.visit(V1_7, ACC_PUBLIC + ACC_SUPER,
                name.replace('.', '/'),
                null,
                "javax/ws/rs/core/Application", null);

        int lastDot = name.lastIndexOf('.');
        String simpleName = name.substring(lastDot + 1);
        cw.visitSource(simpleName + ".java", null);

        {
            av0 = cw.visitAnnotation("Ljavax/ws/rs/ApplicationPath;", true);
            av0.visit("value", "/");
            av0.visitEnd();
        }
        {
            mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
            mv.visitCode();
            Label l0 = new Label();
            mv.visitLabel(l0);
            mv.visitLineNumber(10, l0);
            mv.visitVarInsn(ALOAD, 0);
            mv.visitMethodInsn(INVOKESPECIAL, "javax/ws/rs/core/Application", "<init>", "()V", false);
            mv.visitInsn(RETURN);
            Label l1 = new Label();
            mv.visitLabel(l1);
            mv.visitLocalVariable("this",
                    "L" + name.replace('.', '/') + ";",
                    null,
                    l0,
                    l1,
                    0);
            mv.visitMaxs(1, 1);
            mv.visitEnd();
        }
        cw.visitEnd();

        return cw.toByteArray();
    }
 
Example 16
Source File: FragmentClassLoader.java    From attic-polygene-java with Apache License 2.0 4 votes vote down vote up
private static int loadParameter( MethodVisitor mv, Class<?> aClass, int idx )
{
    if( aClass.equals( Integer.TYPE ) )
    {
        mv.visitVarInsn( ILOAD, idx );
    }
    else if( aClass.equals( Long.TYPE ) )
    {
        mv.visitVarInsn( LLOAD, idx );
        idx++; // Extra jump
    }
    else if( aClass.equals( Short.TYPE ) )
    {
        mv.visitVarInsn( ILOAD, idx );
    }
    else if( aClass.equals( Byte.TYPE ) )
    {
        mv.visitVarInsn( ILOAD, idx );
    }
    else if( aClass.equals( Double.TYPE ) )
    {
        mv.visitVarInsn( DLOAD, idx );
        idx++; // Extra jump
    }
    else if( aClass.equals( Float.TYPE ) )
    {
        mv.visitVarInsn( FLOAD, idx );
    }
    else if( aClass.equals( Boolean.TYPE ) )
    {
        mv.visitVarInsn( ILOAD, idx );
    }
    else if( aClass.equals( Character.TYPE ) )
    {
        mv.visitVarInsn( ILOAD, idx );
    }
    else
    {
        mv.visitVarInsn( ALOAD, idx );
    }

    return idx;
}
 
Example 17
Source File: AnnotatedFieldTest.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void generate(TraceClassVisitor cw) {

	FieldVisitor fv;
	MethodVisitor mv;
	AnnotationVisitor av0;

	cw.visit(V1_8, ACC_PUBLIC + ACC_SUPER, "soot/asm/backend/targets/AnnotatedField",
			null, "java/lang/Object", null);
	cw.visitSource("AnnotatedField.java", null);
	
	{
	fv = cw.visitField(0, "a", "Ljava/lang/String;", null, null);
	{
	av0 = fv.visitAnnotation("Lsoot/asm/backend/targets/MyTestAnnotation;", true);
	av0.visit("iVal", new Integer(124));
	av0.visit("fVal", new Float("5132.0"));
	av0.visit("lVal", new Long(5123L));
	av0.visit("dVal", new Double("745.0"));
	av0.visit("zVal", Boolean.TRUE);
	av0.visit("bVal", new Byte((byte)1));
	av0.visit("sVal", new Short((short)123));
	av0.visit("strVal", "435243");
	av0.visit("rVal", Type.getType("Lsoot/asm/backend/targets/AnnotatedClass;"));
	av0.visit("iAVal", new int[] {123,234,345,456});
	{
	AnnotationVisitor av1 = av0.visitArray("sAVal");
	av1.visit(null, "A");
	av1.visit(null, "B");
	av1.visit(null, "C");
	av1.visitEnd();
	}
	av0.visitEnd();
	}
	fv.visitEnd();
	}
	{
	mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
	mv.visitCode();
	mv.visitVarInsn(ALOAD, 0);
	mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
	mv.visitInsn(RETURN);
	mv.visitMaxs(0, 0);
	mv.visitEnd();
	}
	cw.visitEnd();


}
 
Example 18
Source File: DummyClassGenerator.java    From GriefDefender with MIT License 4 votes vote down vote up
private void generateMethods(ClassWriter cw, String internalName, List<Method> methods, Class<?> exceptionType) {
    for (Method method: methods) {
        MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, method.getName(), Type.getMethodDescriptor(method), null, null);
        mv.visitCode();

        String internalException = Type.getInternalName(exceptionType);

        mv.visitTypeInsn(NEW, internalException);
        mv.visitInsn(DUP);

        // Load first argument to String.format
        mv.visitLdcInsn("A method was invoked on a dummy class, due to the static field %s not being initialized "
                + "(most likely in a CatalogType-related class).\n"
                + "Method: " + method);

        // Create new array
        mv.visitLdcInsn(1);
        mv.visitTypeInsn(ANEWARRAY, "java/lang/String");

        // Store in local var 2
        mv.visitVarInsn(Opcodes.ASTORE, 2);

        // AASTORE part 1 - array reference
        mv.visitVarInsn(Opcodes.ALOAD, 2);

        // AASTORE part 2 - array index
        mv.visitLdcInsn(0);

        // AASTORE part 3 = the actual value
        // Load formatter argument (the field FIELD_NAME)
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, internalName, FIELD_NAME, Type.getDescriptor(String.class));

        // Store in array
        mv.visitInsn(AASTORE);

        // Load array reference
        mv.visitVarInsn(ALOAD, 2);

        // Call String.format
        mv.visitMethodInsn(INVOKESTATIC, Type.getInternalName(String.class), "format",
            "(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;", false);

        // Invoke throwable constructor
        mv.visitMethodInsn(INVOKESPECIAL, internalException, "<init>", "(Ljava/lang/String;)V", false);
        mv.visitInsn(ATHROW);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }
}
 
Example 19
Source File: StubGenerator.java    From AVM with MIT License 4 votes vote down vote up
private static void populateExceptionConstructors(ClassVisitor out, String superName) {
    MethodVisitor methodVisitor = null;
    // Generate the () constructor.
    {
        String noArgDescriptor = "()V";
        methodVisitor = out.visitMethod(Opcodes.ACC_PUBLIC, INIT_NAME, noArgDescriptor, null, null);
        methodVisitor.visitCode();
        methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
        methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, superName, INIT_NAME, noArgDescriptor, false);
        methodVisitor.visitInsn(Opcodes.RETURN);
        methodVisitor.visitMaxs(1, 1);
        methodVisitor.visitEnd();
    }
    
    // Generate the (String) constructor.
    {
        String oneStringDescriptor = "(L" + PackageConstants.kShadowSlashPrefix + "java/lang/String;)V";
        methodVisitor = out.visitMethod(Opcodes.ACC_PUBLIC, INIT_NAME, oneStringDescriptor, null, null);
        methodVisitor.visitCode();
        methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
        methodVisitor.visitVarInsn(Opcodes.ALOAD, 1);
        methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, superName, INIT_NAME, oneStringDescriptor, false);
        methodVisitor.visitInsn(Opcodes.RETURN);
        methodVisitor.visitMaxs(2, 2);
        methodVisitor.visitEnd();
    }
    
    // Generate the (String, Throwable) constructor.
    {
        String stringThrowableDescriptor = "(L" + PackageConstants.kShadowSlashPrefix + "java/lang/String;L" + PackageConstants.kShadowSlashPrefix + "java/lang/Throwable;)V";
        methodVisitor = out.visitMethod(Opcodes.ACC_PUBLIC, INIT_NAME, stringThrowableDescriptor, null, null);
        methodVisitor.visitCode();
        methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
        methodVisitor.visitVarInsn(Opcodes.ALOAD, 1);
        methodVisitor.visitVarInsn(Opcodes.ALOAD, 2);
        methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, superName, INIT_NAME, stringThrowableDescriptor, false);
        methodVisitor.visitInsn(Opcodes.RETURN);
        methodVisitor.visitMaxs(3, 3);
        methodVisitor.visitEnd();
    }
    
    // Generate the (Throwable) constructor.
    {
        String oneThrowableDescriptor = "(L" + PackageConstants.kShadowSlashPrefix + "java/lang/Throwable;)V";
        methodVisitor = out.visitMethod(Opcodes.ACC_PUBLIC, INIT_NAME, oneThrowableDescriptor, null, null);
        methodVisitor.visitCode();
        methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
        methodVisitor.visitVarInsn(Opcodes.ALOAD, 1);
        methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, superName, INIT_NAME, oneThrowableDescriptor, false);
        methodVisitor.visitInsn(Opcodes.RETURN);
        methodVisitor.visitMaxs(2, 2);
        methodVisitor.visitEnd();
    }
    
    // Generate the deserialization constructor:  "(Ljava/lang/Void;I)V".
    {
        String deserializationDescriptor = "(Ljava/lang/Void;I)V";
        methodVisitor = out.visitMethod(Opcodes.ACC_PUBLIC, INIT_NAME, deserializationDescriptor, null, null);
        methodVisitor.visitCode();
        methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
        methodVisitor.visitVarInsn(Opcodes.ALOAD, 1);
        methodVisitor.visitVarInsn(Opcodes.ILOAD, 2);
        methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, superName, INIT_NAME, deserializationDescriptor, false);
        methodVisitor.visitInsn(Opcodes.RETURN);
        methodVisitor.visitMaxs(3, 3);
        methodVisitor.visitEnd();
    }
}
 
Example 20
Source File: LLoad.java    From OSRS-Deobfuscator with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void accept(MethodVisitor visitor)
{
	visitor.visitVarInsn(this.getType().getCode(), this.getVariableIndex());
}