Java Code Examples for org.objectweb.asm.tree.MethodNode#visitFieldInsn()
The following examples show how to use
org.objectweb.asm.tree.MethodNode#visitFieldInsn() .
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: MarkerTransformer.java From obfuscator with MIT License | 6 votes |
private MethodNode createMethod() { final MethodNode methodNode = new MethodNode(ACC_PUBLIC | ACC_STATIC, methodName, "()V", null, null); methodNode.visitCode(); final Label label0 = new Label(); methodNode.visitLabel(label0); methodNode.visitLineNumber(10, label0); methodNode.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;"); methodNode.visitLdcInsn(text); methodNode.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false); final Label label1 = new Label(); methodNode.visitLabel(label1); methodNode.visitLineNumber(11, label1); methodNode.visitInsn(RETURN); methodNode.visitMaxs(2, 0); methodNode.visitEnd(); return methodNode; }
Example 2
Source File: EngineExtender.java From 07kit with GNU General Public License v3.0 | 6 votes |
public MethodNode createGetter(GetterDefinition getter) { MethodNode method = new MethodNode(Opcodes.ACC_PUBLIC, getter.name, "()" + getter.signature, null, null); if (getter.member) { method.visitVarInsn(Opcodes.ALOAD, 0); method.visitFieldInsn(Opcodes.GETFIELD, getter.fieldClass, getter.fieldName, getter.actualSig); } else { method.visitFieldInsn(Opcodes.GETSTATIC, getter.fieldClass, getter.fieldName, getter.actualSig); } if (getter.multiplier != 0) { method.visitLdcInsn((int) getter.multiplier); method.visitInsn(Opcodes.IMUL); } method.visitInsn(Type.getType(getter.actualSig).getOpcode(Opcodes.IRETURN)); method.visitMaxs(1, 1); method.visitEnd(); return method; }
Example 3
Source File: EngineExtender.java From 07kit with GNU General Public License v3.0 | 6 votes |
public MethodNode createSetter(GetterDefinition getter) { MethodNode method = new MethodNode(Opcodes.ACC_PUBLIC, getter.name.replaceFirst("get", "set"), "(" + getter.signature + ")V", null, null); method.visitVarInsn(Opcodes.ALOAD, 0); method.visitVarInsn(Type.getType(getter.actualSig).getOpcode(Opcodes.ILOAD), 1); if (getter.actualSig.equals("I") && getter.multiplier != 0) { method.visitLdcInsn((int) modInverse(getter.multiplier)); method.visitInsn(Opcodes.IMUL); } if (getter.member) { method.visitFieldInsn(Opcodes.PUTFIELD, getter.fieldClass, getter.fieldName, getter.actualSig); } else { method.visitFieldInsn(Opcodes.PUTSTATIC, getter.fieldClass, getter.fieldName, getter.actualSig); } method.visitInsn(Opcodes.RETURN); method.visitMaxs(1, 1); method.visitEnd(); return method; }
Example 4
Source File: ConstructorThisInterpreterTest.java From AVM with MIT License | 5 votes |
private MethodNode buildTestConstructor() { MethodNode methodVisitor = new MethodNode(Opcodes.ACC_PUBLIC, "<init>", "(Lorg/aion/avm/core/persistence/ConstructorThisInterpreterTest;I)V", null, null); methodVisitor.visitCode(); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); methodVisitor.visitInsn(Opcodes.ICONST_5); methodVisitor.visitVarInsn(Opcodes.ILOAD, 2); Label label2 = new Label(); methodVisitor.visitJumpInsn(Opcodes.IF_ICMPNE, label2); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); Label label3 = new Label(); methodVisitor.visitJumpInsn(Opcodes.GOTO, label3); methodVisitor.visitLabel(label2); methodVisitor.visitFrame(Opcodes.F_FULL, 3, new Object[] {"org/aion/avm/core/persistence/ConstructorThisInterpreterTest", "org/aion/avm/core/persistence/ConstructorThisInterpreterTest", Opcodes.INTEGER}, 0, new Object[] {}); methodVisitor.visitVarInsn(Opcodes.ALOAD, 1); methodVisitor.visitLabel(label3); methodVisitor.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] {"org/aion/avm/core/persistence/ConstructorThisInterpreterTest"}); methodVisitor.visitVarInsn(Opcodes.ILOAD, 2); methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, "org/aion/avm/core/persistence/ConstructorThisInterpreterTest", "bar", "I"); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitInsn(Opcodes.ICONST_1); methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, "org/aion/avm/core/persistence/ConstructorThisInterpreterTest", "bar", "I"); methodVisitor.visitVarInsn(Opcodes.ALOAD, 1); methodVisitor.visitInsn(Opcodes.ICONST_2); methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, "org/aion/avm/core/persistence/ConstructorThisInterpreterTest", "bar", "I"); methodVisitor.visitInsn(Opcodes.RETURN); methodVisitor.visitMaxs(2, 3); methodVisitor.visitEnd(); return methodVisitor; }
Example 5
Source File: ConstructorThisInterpreterTest.java From AVM with MIT License | 5 votes |
private MethodNode buildSecondConstructor() { MethodNode methodVisitor = new MethodNode(Opcodes.ACC_PUBLIC, "<init>", "(Lorg/aion/avm/core/NonStaticInnerClassTarget$Inner;)V", null, null); methodVisitor.visitCode(); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitVarInsn(Opcodes.ALOAD, 1); methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, "org/aion/avm/core/NonStaticInnerClassTarget$Inner$Deeper", "this$1", "Lorg/aion/avm/core/NonStaticInnerClassTarget$Inner;"); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); methodVisitor.visitInsn(Opcodes.RETURN); methodVisitor.visitMaxs(2, 2); methodVisitor.visitEnd(); return methodVisitor; }
Example 6
Source File: StringPooler.java From radon with GNU General Public License v3.0 | 5 votes |
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 7
Source File: NbJShellAgent.java From netbeans with Apache License 2.0 | 5 votes |
/** * Transforms an existin <clinit> method. Adds bytecode before the return, if * exists. * @param className * @param target */ private void transformClassInit(String className, MethodNode target) { Type classType = Type.getObjectType(className); if (target.instructions.size() > 0) { if (target.instructions.getLast().getOpcode() == Opcodes.RETURN) { target.instructions.remove(target.instructions.getLast()); } } // ldc target.visitLdcInsn(classType); // invokevirtual --> classloader on stack target.visitMethodInsn( Opcodes.INVOKEVIRTUAL, JAVA_LANG_CLASS, CLASS_GET_CLASSLODER_METHOD, CLASS_GET_CLASSLOADER_DESC, false ); // putstatic target.visitFieldInsn( Opcodes.PUTSTATIC, AGENT_CLASS, AGENT_CLASSLOADER_FIELD, AGENT_CLASSLOADER_DESC ); target.visitInsn(Opcodes.RETURN); // ldc || classloader instance target.maxStack = Math.max(target.maxStack, 1); target.maxLocals = Math.max(target.maxLocals, 1); target.visitEnd(); }