List of usage examples for org.objectweb.asm Opcodes IFEQ
int IFEQ
To view the source code for org.objectweb.asm Opcodes IFEQ.
Click Source Link
From source file:bytecode.InstructionExporter.java
License:Apache License
/** * Output conditional branch instructions, choosing between integer and * reference comparisons, and also abbreviating comparisons with 0 or * <code>null</code>.//from w w w . j a v a 2 s .c o m * * @param instruction Comparison instruction. * @return . <code>null</code> */ @Override public Void visit(Condition instruction) { Label label = BlockExporter.getLabel(instruction.getDestination()); // Produce integer instructions if (instruction.getOperandA().getType().isIntBased()) { // Comparisons with zero if (instruction.getOperandB().equals(new Constant(new Integer(0)))) { switch (instruction.getOperator()) { case EQ: mv.visitJumpInsn(Opcodes.IFEQ, label); break; case NE: mv.visitJumpInsn(Opcodes.IFNE, label); break; case LT: mv.visitJumpInsn(Opcodes.IFLT, label); break; case GE: mv.visitJumpInsn(Opcodes.IFGE, label); break; case GT: mv.visitJumpInsn(Opcodes.IFGT, label); break; case LE: mv.visitJumpInsn(Opcodes.IFLE, label); break; } // Direct comparisons } else { switch (instruction.getOperator()) { case EQ: mv.visitJumpInsn(Opcodes.IF_ICMPEQ, label); break; case NE: mv.visitJumpInsn(Opcodes.IF_ICMPNE, label); break; case LT: mv.visitJumpInsn(Opcodes.IF_ICMPLT, label); break; case GE: mv.visitJumpInsn(Opcodes.IF_ICMPGE, label); break; case GT: mv.visitJumpInsn(Opcodes.IF_ICMPGT, label); break; case LE: mv.visitJumpInsn(Opcodes.IF_ICMPLE, label); break; } } // Produce reference instructions } else if (instruction.getOperandA().getType().getSort() == Type.Sort.REF) { // Comparisons with null if (instruction.getOperandB().equals(new Constant(null))) { switch (instruction.getOperator()) { case EQ: mv.visitJumpInsn(Opcodes.IFNULL, label); break; case NE: mv.visitJumpInsn(Opcodes.IFNONNULL, label); break; } // Direct comparisons } else { switch (instruction.getOperator()) { case EQ: mv.visitJumpInsn(Opcodes.IF_ACMPEQ, label); break; case NE: mv.visitJumpInsn(Opcodes.IF_ACMPNE, label); break; } } // Flag up others. } else { throw new RuntimeException("Attempt to export condition of unknown type."); } return null; }
From source file:bytecode.MethodImporter.java
License:Apache License
/** * Imports branch instructions, both conditional and unconditional. * * @param opcode Opcode./* ww w . ja va2 s . c o m*/ * @param label Destination of branch. */ @Override public void visitJumpInsn(final int opcode, final Label label) { BasicBlock section = getBasicBlock(label); switch (opcode) { // Unconditional Branch case Opcodes.GOTO: finishBlock(section); setCurrent(null); break; // Zero Test case Opcodes.IFEQ: createZeroCondition(Condition.Operator.EQ, section); break; case Opcodes.IFNE: createZeroCondition(Condition.Operator.NE, section); break; case Opcodes.IFLT: createZeroCondition(Condition.Operator.LT, section); break; case Opcodes.IFGE: createZeroCondition(Condition.Operator.GE, section); break; case Opcodes.IFGT: createZeroCondition(Condition.Operator.GT, section); break; case Opcodes.IFLE: createZeroCondition(Condition.Operator.LE, section); break; // Integer Comparison case Opcodes.IF_ICMPEQ: createCondition(Condition.Operator.EQ, section); break; case Opcodes.IF_ICMPNE: createCondition(Condition.Operator.NE, section); break; case Opcodes.IF_ICMPLT: createCondition(Condition.Operator.LT, section); break; case Opcodes.IF_ICMPGE: createCondition(Condition.Operator.GE, section); break; case Opcodes.IF_ICMPGT: createCondition(Condition.Operator.GT, section); break; case Opcodes.IF_ICMPLE: createCondition(Condition.Operator.LE, section); break; // Reference Comparisons case Opcodes.IF_ACMPEQ: createCondition(Condition.Operator.EQ, section); break; case Opcodes.IF_ACMPNE: createCondition(Condition.Operator.NE, section); break; case Opcodes.IFNULL: createNullCondition(Condition.Operator.EQ, section); break; case Opcodes.IFNONNULL: createNullCondition(Condition.Operator.NE, section); break; // TODO: JSR (paired with RET) case Opcodes.JSR: System.err.println("visitJumpInsn: JSR"); } }
From source file:Client.JClassPatcher.java
License:Open Source License
private void patchClient(ClassNode node) { Logger.Info("Patching client (" + node.name + ".class)"); Iterator<MethodNode> methodNodeList = node.methods.iterator(); while (methodNodeList.hasNext()) { MethodNode methodNode = methodNodeList.next(); // I (I)V is where most of the interface is processed if (methodNode.name.equals("I") && methodNode.desc.equals("(I)V")) { // Show combat menu Iterator<AbstractInsnNode> insnNodeList = methodNode.instructions.iterator(); while (insnNodeList.hasNext()) { AbstractInsnNode insnNode = insnNodeList.next(); if (insnNode.getOpcode() == Opcodes.BIPUSH) { IntInsnNode bipush = (IntInsnNode) insnNode; if (bipush.operand == -9) { AbstractInsnNode findNode = insnNode; while (findNode.getOpcode() != Opcodes.IF_ICMPEQ) findNode = findNode.getNext(); LabelNode label = ((JumpInsnNode) findNode).label; methodNode.instructions.insertBefore(insnNode, new FieldInsnNode(Opcodes.GETSTATIC, "Client/Settings", "COMBAT_MENU", "Z")); methodNode.instructions.insertBefore(insnNode, new JumpInsnNode(Opcodes.IFGT, label)); break; }// ww w. java 2 s .c om } } } else if (methodNode.name.equals("J") && methodNode.desc.equals("(I)V")) { Iterator<AbstractInsnNode> insnNodeList = methodNode.instructions.iterator(); while (insnNodeList.hasNext()) { AbstractInsnNode insnNode = insnNodeList.next(); // Chat command patch if (insnNode.getOpcode() == Opcodes.SIPUSH) { IntInsnNode call = (IntInsnNode) insnNode; if (call.operand == 627) { AbstractInsnNode jmpNode = insnNode; while (jmpNode.getOpcode() != Opcodes.IFEQ) jmpNode = jmpNode.getNext(); AbstractInsnNode insertNode = insnNode; while (insertNode.getOpcode() != Opcodes.INVOKEVIRTUAL) insertNode = insertNode.getPrevious(); JumpInsnNode jmp = (JumpInsnNode) jmpNode; methodNode.instructions.insert(insertNode, new VarInsnNode(Opcodes.ASTORE, 2)); methodNode.instructions.insert(insertNode, new MethodInsnNode(Opcodes.INVOKESTATIC, "Game/Client", "processChatCommand", "(Ljava/lang/String;)Ljava/lang/String;")); methodNode.instructions.insert(insertNode, new VarInsnNode(Opcodes.ALOAD, 2)); } } } } else if (methodNode.name.equals("h") && methodNode.desc.equals("(B)V")) { Iterator<AbstractInsnNode> insnNodeList = methodNode.instructions.iterator(); while (insnNodeList.hasNext()) { AbstractInsnNode insnNode = insnNodeList.next(); // Private chat command patch if (insnNode.getOpcode() == Opcodes.GETFIELD) { FieldInsnNode field = (FieldInsnNode) insnNode; if (field.owner.equals("client") && field.name.equals("Ob") && insnNode.getPrevious().getPrevious().getOpcode() != Opcodes.INVOKEVIRTUAL) { insnNode = insnNode.getPrevious().getPrevious(); methodNode.instructions.insert(insnNode, new FieldInsnNode(Opcodes.PUTFIELD, "client", "Ob", "Ljava/lang/String;")); methodNode.instructions.insert(insnNode, new MethodInsnNode(Opcodes.INVOKESTATIC, "Game/Client", "processPrivateCommand", "(Ljava/lang/String;)Ljava/lang/String;")); methodNode.instructions.insert(insnNode, new FieldInsnNode(Opcodes.GETFIELD, "client", "Ob", "Ljava/lang/String;")); methodNode.instructions.insert(insnNode, new VarInsnNode(Opcodes.ALOAD, 0)); methodNode.instructions.insert(insnNode, new VarInsnNode(Opcodes.ALOAD, 0)); break; } } } } else if (methodNode.name.equals("a") && methodNode.desc.equals("(IIIIIIII)V")) { // Draw NPC hook AbstractInsnNode insnNode = methodNode.instructions.getLast(); methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 8)); methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 1)); methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 7)); methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 4)); methodNode.instructions.insertBefore(insnNode, new FieldInsnNode(Opcodes.GETSTATIC, "e", "Mb", "[Ljava/lang/String;")); methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ALOAD, 0)); methodNode.instructions.insertBefore(insnNode, new FieldInsnNode(Opcodes.GETFIELD, "client", "Tb", "[Lta;")); methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 6)); methodNode.instructions.insertBefore(insnNode, new InsnNode(Opcodes.AALOAD)); methodNode.instructions.insertBefore(insnNode, new FieldInsnNode(Opcodes.GETFIELD, "ta", "t", "I")); methodNode.instructions.insertBefore(insnNode, new InsnNode(Opcodes.AALOAD)); methodNode.instructions.insertBefore(insnNode, new MethodInsnNode(Opcodes.INVOKESTATIC, "Game/Client", "drawNPC", "(IIIILjava/lang/String;)V")); } else if (methodNode.name.equals("b") && methodNode.desc.equals("(IIIIIIII)V")) { // Draw Player hook AbstractInsnNode insnNode = methodNode.instructions.getLast(); methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 5)); methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 6)); methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 2)); methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 7)); methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ALOAD, 0)); methodNode.instructions.insertBefore(insnNode, new FieldInsnNode(Opcodes.GETFIELD, "client", "rg", "[Lta;")); methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 8)); methodNode.instructions.insertBefore(insnNode, new InsnNode(Opcodes.AALOAD)); methodNode.instructions.insertBefore(insnNode, new FieldInsnNode(Opcodes.GETFIELD, "ta", "C", "Ljava/lang/String;")); methodNode.instructions.insertBefore(insnNode, new MethodInsnNode(Opcodes.INVOKESTATIC, "Game/Client", "drawPlayer", "(IIIILjava/lang/String;)V")); } else if (methodNode.name.equals("b") && methodNode.desc.equals("(IIIIIII)V")) { // Draw Item hook // ILOAD 4 is item id AbstractInsnNode insnNode = methodNode.instructions.getLast(); methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 3)); methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 7)); methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 5)); methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 1)); methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 4)); methodNode.instructions.insertBefore(insnNode, new MethodInsnNode(Opcodes.INVOKESTATIC, "Game/Client", "drawItem", "(IIIII)V")); } else if (methodNode.name.equals("L") && methodNode.desc.equals("(I)V")) { Iterator<AbstractInsnNode> insnNodeList = methodNode.instructions.iterator(); while (insnNodeList.hasNext()) { AbstractInsnNode insnNode = insnNodeList.next(); // Right click bounds fix if (insnNode.getOpcode() == Opcodes.SIPUSH) { IntInsnNode call = (IntInsnNode) insnNode; AbstractInsnNode nextNode = insnNode.getNext(); if (call.operand == 510) { call.operand = 512 - call.operand; methodNode.instructions.insertBefore(insnNode, new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "width", "I")); methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.ISUB)); } else if (call.operand == 315) { call.operand = 334 - call.operand; methodNode.instructions.insertBefore(insnNode, new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "height_client", "I")); methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.ISUB)); } else if (call.operand == -316) { call.operand = 334 - (call.operand * -1); methodNode.instructions.insertBefore(insnNode, new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "height_client", "I")); methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.INEG)); methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.ISUB)); } } } } else if (methodNode.name.equals("a") && methodNode.desc.equals("(ZZ)V")) { Iterator<AbstractInsnNode> insnNodeList = methodNode.instructions.iterator(); while (insnNodeList.hasNext()) { AbstractInsnNode insnNode = insnNodeList.next(); // Friends chat mouse fix if (insnNode.getOpcode() == Opcodes.SIPUSH) { IntInsnNode call = (IntInsnNode) insnNode; if (call.operand == 489 || call.operand == 429) { call.operand = 512 - call.operand; methodNode.instructions.insertBefore(insnNode, new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "width", "I")); methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.ISUB)); } if (call.operand == -430) { call.operand = 512 - (call.operand * -1); methodNode.instructions.insertBefore(insnNode, new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "width", "I")); methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.INEG)); methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.ISUB)); } } } } else if (methodNode.name.equals("i") && methodNode.desc.equals("(I)V")) { AbstractInsnNode lastNode = methodNode.instructions.getLast().getPrevious(); // Send combat style option LabelNode label = new LabelNode(); methodNode.instructions.insert(lastNode, label); // Format methodNode.instructions.insert(lastNode, new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "da", "b", "(I)V", false)); methodNode.instructions.insert(lastNode, new IntInsnNode(Opcodes.SIPUSH, 21294)); methodNode.instructions.insert(lastNode, new FieldInsnNode(Opcodes.GETFIELD, "client", "Jh", "Lda;")); methodNode.instructions.insert(lastNode, new VarInsnNode(Opcodes.ALOAD, 0)); // Write byte methodNode.instructions.insert(lastNode, new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "ja", "c", "(II)V", false)); methodNode.instructions.insert(lastNode, new IntInsnNode(Opcodes.BIPUSH, -80)); methodNode.instructions.insert(lastNode, new FieldInsnNode(Opcodes.GETSTATIC, "Client/Settings", "COMBAT_STYLE", "I")); methodNode.instructions.insert(lastNode, new FieldInsnNode(Opcodes.GETFIELD, "da", "f", "Lja;")); methodNode.instructions.insert(lastNode, new FieldInsnNode(Opcodes.GETFIELD, "client", "Jh", "Lda;")); methodNode.instructions.insert(lastNode, new VarInsnNode(Opcodes.ALOAD, 0)); // Create Packet methodNode.instructions.insert(lastNode, new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "da", "b", "(II)V", false)); methodNode.instructions.insert(lastNode, new InsnNode(Opcodes.ICONST_0)); methodNode.instructions.insert(lastNode, new IntInsnNode(Opcodes.BIPUSH, 29)); methodNode.instructions.insert(lastNode, new FieldInsnNode(Opcodes.GETFIELD, "client", "Jh", "Lda;")); methodNode.instructions.insert(lastNode, new VarInsnNode(Opcodes.ALOAD, 0)); // Skip combat packet if style is already controlled methodNode.instructions.insert(lastNode, new JumpInsnNode(Opcodes.IF_ICMPLE, label)); methodNode.instructions.insert(lastNode, new InsnNode(Opcodes.ICONST_0)); methodNode.instructions.insert(lastNode, new FieldInsnNode(Opcodes.GETSTATIC, "Client/Settings", "COMBAT_STYLE", "I")); // Client init_game methodNode.instructions.insert(lastNode, new MethodInsnNode(Opcodes.INVOKESTATIC, "Game/Client", "init_game", "()V", false)); } else if (methodNode.name.equals("o") && methodNode.desc.equals("(I)V")) { // Client.init_login patch AbstractInsnNode findNode = methodNode.instructions.getLast(); methodNode.instructions.insertBefore(findNode, new MethodInsnNode(Opcodes.INVOKESTATIC, "Game/Client", "init_login", "()V", false)); } else if (methodNode.name.equals("a") && methodNode.desc.equals("(B)V")) { Iterator<AbstractInsnNode> insnNodeList = methodNode.instructions.iterator(); while (insnNodeList.hasNext()) { AbstractInsnNode insnNode = insnNodeList.next(); // Camera view distance crash fix if (insnNode.getOpcode() == Opcodes.SIPUSH) { IntInsnNode call = (IntInsnNode) insnNode; if (call.operand == 15000) { call.operand = 32767; } } } // Client.init patch AbstractInsnNode findNode = methodNode.instructions.getFirst(); methodNode.instructions.insertBefore(findNode, new VarInsnNode(Opcodes.ALOAD, 0)); methodNode.instructions.insertBefore(findNode, new FieldInsnNode(Opcodes.PUTSTATIC, "Game/Client", "instance", "Ljava/lang/Object;")); methodNode.instructions.insertBefore(findNode, new MethodInsnNode(Opcodes.INVOKESTATIC, "Game/Client", "init", "()V", false)); } else if (methodNode.name.equals("G") && methodNode.desc.equals("(I)V")) { // TODO: This can be shortened, I'll fix it another time // NPC Dialogue keyboard AbstractInsnNode lastNode = methodNode.instructions.getLast().getPrevious(); LabelNode label = new LabelNode(); methodNode.instructions.insert(lastNode, label); // Hide dialogue methodNode.instructions.insert(lastNode, new FieldInsnNode(Opcodes.PUTFIELD, "client", "Ph", "Z")); methodNode.instructions.insert(lastNode, new InsnNode(Opcodes.ICONST_0)); methodNode.instructions.insert(lastNode, new VarInsnNode(Opcodes.ALOAD, 0)); // Format methodNode.instructions.insert(lastNode, new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "da", "b", "(I)V", false)); methodNode.instructions.insert(lastNode, new IntInsnNode(Opcodes.SIPUSH, 21294)); methodNode.instructions.insert(lastNode, new FieldInsnNode(Opcodes.GETFIELD, "client", "Jh", "Lda;")); methodNode.instructions.insert(lastNode, new VarInsnNode(Opcodes.ALOAD, 0)); // Write byte methodNode.instructions.insert(lastNode, new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "ja", "c", "(II)V", false)); methodNode.instructions.insert(lastNode, new IntInsnNode(Opcodes.BIPUSH, 115)); methodNode.instructions.insert(lastNode, new FieldInsnNode(Opcodes.GETSTATIC, "Game/KeyboardHandler", "dialogue_option", "I")); methodNode.instructions.insert(lastNode, new FieldInsnNode(Opcodes.GETFIELD, "da", "f", "Lja;")); methodNode.instructions.insert(lastNode, new FieldInsnNode(Opcodes.GETFIELD, "client", "Jh", "Lda;")); methodNode.instructions.insert(lastNode, new VarInsnNode(Opcodes.ALOAD, 0)); // Create Packet methodNode.instructions.insert(lastNode, new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "da", "b", "(II)V", false)); methodNode.instructions.insert(lastNode, new InsnNode(Opcodes.ICONST_0)); methodNode.instructions.insert(lastNode, new IntInsnNode(Opcodes.BIPUSH, 116)); methodNode.instructions.insert(lastNode, new FieldInsnNode(Opcodes.GETFIELD, "client", "Jh", "Lda;")); methodNode.instructions.insert(lastNode, new VarInsnNode(Opcodes.ALOAD, 0)); // Check if dialogue option is pressed methodNode.instructions.insert(lastNode, new JumpInsnNode(Opcodes.IF_ICMPGE, label)); // Menu option count methodNode.instructions.insert(lastNode, new FieldInsnNode(Opcodes.GETFIELD, "client", "Id", "I")); methodNode.instructions.insert(lastNode, new VarInsnNode(Opcodes.ALOAD, 0)); methodNode.instructions.insert(lastNode, new FieldInsnNode(Opcodes.GETSTATIC, "Game/KeyboardHandler", "dialogue_option", "I")); methodNode.instructions.insert(lastNode, new JumpInsnNode(Opcodes.IFLT, label)); methodNode.instructions.insert(lastNode, new FieldInsnNode(Opcodes.GETSTATIC, "Game/KeyboardHandler", "dialogue_option", "I")); } else if (methodNode.name.equals("f") && methodNode.desc.equals("(I)V")) { Iterator<AbstractInsnNode> insnNodeList = methodNode.instructions.iterator(); while (insnNodeList.hasNext()) { AbstractInsnNode insnNode = insnNodeList.next(); // Hide Roof option if (insnNode.getOpcode() == Opcodes.GETFIELD) { FieldInsnNode field = (FieldInsnNode) insnNode; if (field.owner.equals("client") && field.name.equals("yj")) { AbstractInsnNode nextNode = insnNode.getNext(); if (nextNode.getOpcode() == Opcodes.IFNE) { LabelNode label = ((JumpInsnNode) nextNode).label; methodNode.instructions.insert(nextNode, new JumpInsnNode(Opcodes.IFGT, label)); methodNode.instructions.insert(nextNode, new FieldInsnNode(Opcodes.GETSTATIC, "Client/Settings", "HIDE_ROOFS", "Z")); } } } // Move wilderness skull if (insnNode.getOpcode() == Opcodes.SIPUSH) { IntInsnNode call = (IntInsnNode) insnNode; if (call.operand == 465 || call.operand == 453) { call.operand = 512 - call.operand; methodNode.instructions.insertBefore(insnNode, new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "width", "I")); methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.ISUB)); } } } } else if (methodNode.name.equals("a") && methodNode.desc.equals("(IIZ)Z")) { Iterator<AbstractInsnNode> insnNodeList = methodNode.instructions.iterator(); while (insnNodeList.hasNext()) { AbstractInsnNode insnNode = insnNodeList.next(); // Move the load screen text dialogue if (insnNode.getOpcode() == Opcodes.SIPUSH) { IntInsnNode call = (IntInsnNode) insnNode; if (call.operand == 256) { call.operand = 2; methodNode.instructions.insertBefore(insnNode, new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "width", "I")); methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IDIV)); } else if (call.operand == 192) { call.operand = 2; methodNode.instructions.insertBefore(insnNode, new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "height", "I")); methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IADD)); methodNode.instructions.insert(insnNode, new IntInsnNode(Opcodes.SIPUSH, 19)); methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IDIV)); } } } } else if (methodNode.name.equals("d") && methodNode.desc.equals("(B)V")) { Iterator<AbstractInsnNode> insnNodeList = methodNode.instructions.iterator(); while (insnNodeList.hasNext()) { AbstractInsnNode insnNode = insnNodeList.next(); // Center logout dialogue if (insnNode.getOpcode() == Opcodes.SIPUSH || insnNode.getOpcode() == Opcodes.BIPUSH) { IntInsnNode call = (IntInsnNode) insnNode; if (call.operand == 256) { call.operand = 2; methodNode.instructions.insertBefore(insnNode, new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "width", "I")); methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IDIV)); } else if (call.operand == 173) { call.operand = 2; methodNode.instructions.insertBefore(insnNode, new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "height", "I")); methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IDIV)); } else if (call.operand == 126) { call.operand = 2; methodNode.instructions.insertBefore(insnNode, new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "width", "I")); methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.ISUB)); methodNode.instructions.insert(insnNode, new IntInsnNode(Opcodes.SIPUSH, 130)); methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IDIV)); } else if (call.operand == 137) { call.operand = 2; methodNode.instructions.insertBefore(insnNode, new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "height", "I")); methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.ISUB)); methodNode.instructions.insert(insnNode, new IntInsnNode(Opcodes.SIPUSH, 36)); methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IDIV)); } } } } else if (methodNode.name.equals("j") && methodNode.desc.equals("(I)V")) { Iterator<AbstractInsnNode> insnNodeList = methodNode.instructions.iterator(); while (insnNodeList.hasNext()) { AbstractInsnNode insnNode = insnNodeList.next(); // Center welcome box if (insnNode.getOpcode() == Opcodes.SIPUSH || insnNode.getOpcode() == Opcodes.BIPUSH) { IntInsnNode call = (IntInsnNode) insnNode; if (call.operand == 256) { call.operand = 2; methodNode.instructions.insertBefore(insnNode, new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "width", "I")); methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IDIV)); } else if (call.operand == 167) { call.operand = 2; methodNode.instructions.insertBefore(insnNode, new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "height", "I")); methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.ISUB)); methodNode.instructions.insert(insnNode, new IntInsnNode(Opcodes.SIPUSH, 6)); methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IDIV)); } else if (call.operand == 56) { call.operand = 2; methodNode.instructions.insertBefore(insnNode, new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "width", "I")); methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.ISUB)); methodNode.instructions.insert(insnNode, new IntInsnNode(Opcodes.SIPUSH, 200)); methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IDIV)); } else if (call.operand == -87) { call.operand = 2; methodNode.instructions.insertBefore(insnNode, new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "width", "I")); methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.INEG)); methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.ISUB)); methodNode.instructions.insert(insnNode, new IntInsnNode(Opcodes.SIPUSH, 169)); methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IDIV)); } else if (call.operand == 426) { call.operand = 2; methodNode.instructions.insertBefore(insnNode, new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "width", "I")); methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IADD)); methodNode.instructions.insert(insnNode, new IntInsnNode(Opcodes.SIPUSH, 170)); methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IDIV)); } else if (call.operand == 106) { call.operand = 2; methodNode.instructions.insertBefore(insnNode, new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "width", "I")); methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.ISUB)); methodNode.instructions.insert(insnNode, new IntInsnNode(Opcodes.SIPUSH, 150)); methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IDIV)); } else if (call.operand == 406) { call.operand = 2; methodNode.instructions.insertBefore(insnNode, new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "width", "I")); methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IADD)); methodNode.instructions.insert(insnNode, new IntInsnNode(Opcodes.SIPUSH, 150)); methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IDIV)); } } } } else if (methodNode.name.equals("k") && methodNode.desc.equals("(B)V")) { Iterator<AbstractInsnNode> insnNodeList = methodNode.instructions.iterator(); while (insnNodeList.hasNext()) { AbstractInsnNode insnNode = insnNodeList.next(); // Save settings from combat menu if (insnNode.getOpcode() == Opcodes.PUTFIELD) { FieldInsnNode field = (FieldInsnNode) insnNode; if (field.owner.equals("client") && field.name.equals("Fg")) { methodNode.instructions.insert(insnNode, new MethodInsnNode(Opcodes.INVOKESTATIC, "Client/Settings", "save", "()V", false)); methodNode.instructions.insert(insnNode, new FieldInsnNode(Opcodes.PUTSTATIC, "Client/Settings", "COMBAT_STYLE", "I")); methodNode.instructions.insert(insnNode, new FieldInsnNode(Opcodes.GETFIELD, "client", "Fg", "I")); methodNode.instructions.insert(insnNode, new VarInsnNode(Opcodes.ALOAD, 0)); } } } } else if (methodNode.name.equals("a") && methodNode.desc .equals("(ZLjava/lang/String;ILjava/lang/String;IILjava/lang/String;Ljava/lang/String;)V")) { AbstractInsnNode first = methodNode.instructions.getFirst(); methodNode.instructions.insertBefore(first, new VarInsnNode(Opcodes.ALOAD, 7)); methodNode.instructions.insertBefore(first, new VarInsnNode(Opcodes.ALOAD, 4)); methodNode.instructions.insertBefore(first, new VarInsnNode(Opcodes.ILOAD, 5)); methodNode.instructions.insertBefore(first, new MethodInsnNode(Opcodes.INVOKESTATIC, "Game/Client", "messageHook", "(Ljava/lang/String;Ljava/lang/String;I)V")); } } }
From source file:co.paralleluniverse.fibers.instrument.InstrumentMethod.java
License:Open Source License
public void accept(MethodVisitor mv, boolean hasAnnotation) { db.log(LogLevel.INFO, "Instrumenting method %s#%s%s", className, mn.name, mn.desc); mv.visitAnnotation(ALREADY_INSTRUMENTED_DESC, true); final boolean handleProxyInvocations = HANDLE_PROXY_INVOCATIONS & hasSuspendableSuperCalls; mv.visitCode();/* w w w. j a va 2 s .co m*/ Label lMethodStart = new Label(); Label lMethodStart2 = new Label(); Label lMethodEnd = new Label(); Label lCatchSEE = new Label(); Label lCatchUTE = new Label(); Label lCatchAll = new Label(); Label[] lMethodCalls = new Label[numCodeBlocks - 1]; for (int i = 1; i < numCodeBlocks; i++) lMethodCalls[i - 1] = new Label(); mv.visitInsn(Opcodes.ACONST_NULL); mv.visitVarInsn(Opcodes.ASTORE, lvarInvocationReturnValue); // if (verifyInstrumentation) { // mv.visitInsn(Opcodes.ICONST_0); // mv.visitVarInsn(Opcodes.ISTORE, lvarSuspendableCalled); // } mv.visitTryCatchBlock(lMethodStart, lMethodEnd, lCatchSEE, EXCEPTION_NAME); if (handleProxyInvocations) mv.visitTryCatchBlock(lMethodStart, lMethodEnd, lCatchUTE, UNDECLARED_THROWABLE_NAME); // Prepare visitTryCatchBlocks for InvocationTargetException. // With reflective invocations, the SuspendExecution exception will be wrapped in InvocationTargetException. We need to catch it and unwrap it. // Note that the InvocationTargetException will be regenrated on every park, adding further overhead on top of the reflective call. // This must be done here, before all other visitTryCatchBlock, because the exception's handler // will be matched according to the order of in which visitTryCatchBlock has been called. Earlier calls take precedence. Label[][] refInvokeTryCatch = new Label[numCodeBlocks - 1][]; for (int i = 1; i < numCodeBlocks; i++) { FrameInfo fi = codeBlocks[i]; AbstractInsnNode in = mn.instructions.get(fi.endInstruction); if (mn.instructions.get(fi.endInstruction) instanceof MethodInsnNode) { MethodInsnNode min = (MethodInsnNode) in; if (isReflectInvocation(min.owner, min.name)) { Label[] ls = new Label[3]; for (int k = 0; k < 3; k++) ls[k] = new Label(); refInvokeTryCatch[i - 1] = ls; mv.visitTryCatchBlock(ls[0], ls[1], ls[2], "java/lang/reflect/InvocationTargetException"); } } } for (Object o : mn.tryCatchBlocks) { TryCatchBlockNode tcb = (TryCatchBlockNode) o; if (EXCEPTION_NAME.equals(tcb.type) && !hasAnnotation) // we allow catch of SuspendExecution in method annotated with @Suspendable. throw new UnableToInstrumentException("catch for SuspendExecution", className, mn.name, mn.desc); if (handleProxyInvocations && UNDECLARED_THROWABLE_NAME.equals(tcb.type)) // we allow catch of SuspendExecution in method annotated with @Suspendable. throw new UnableToInstrumentException("catch for UndeclaredThrowableException", className, mn.name, mn.desc); // if (INTERRUPTED_EXCEPTION_NAME.equals(tcb.type)) // throw new UnableToInstrumentException("catch for " + InterruptedException.class.getSimpleName(), className, mn.name, mn.desc); tcb.accept(mv); } if (mn.visibleParameterAnnotations != null) dumpParameterAnnotations(mv, mn.visibleParameterAnnotations, true); if (mn.invisibleParameterAnnotations != null) dumpParameterAnnotations(mv, mn.invisibleParameterAnnotations, false); if (mn.visibleAnnotations != null) { for (Object o : mn.visibleAnnotations) { AnnotationNode an = (AnnotationNode) o; an.accept(mv.visitAnnotation(an.desc, true)); } } mv.visitTryCatchBlock(lMethodStart, lMethodEnd, lCatchAll, null); mv.visitMethodInsn(Opcodes.INVOKESTATIC, STACK_NAME, "getStack", "()L" + STACK_NAME + ";"); mv.visitInsn(Opcodes.DUP); mv.visitVarInsn(Opcodes.ASTORE, lvarStack); // println(mv, "STACK: ", lvarStack); // dumpStack(mv); if (DUAL) { mv.visitJumpInsn(Opcodes.IFNULL, lMethodStart); mv.visitVarInsn(Opcodes.ALOAD, lvarStack); } emitStoreResumed(mv, true); // we'll assume we have been resumed mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, STACK_NAME, "nextMethodEntry", "()I"); mv.visitTableSwitchInsn(1, numCodeBlocks - 1, lMethodStart2, lMethodCalls); mv.visitLabel(lMethodStart2); // the following code handles the case of an instrumented method called not as part of a suspendable code path // isFirstInStack will return false in that case. mv.visitVarInsn(Opcodes.ALOAD, lvarStack); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, STACK_NAME, "isFirstInStackOrPushed", "()Z"); mv.visitJumpInsn(Opcodes.IFNE, lMethodStart); // if true mv.visitInsn(Opcodes.ACONST_NULL); mv.visitVarInsn(Opcodes.ASTORE, lvarStack); mv.visitLabel(lMethodStart); emitStoreResumed(mv, false); // no, we have not been resumed dumpCodeBlock(mv, 0, 0); for (int i = 1; i < numCodeBlocks; i++) { FrameInfo fi = codeBlocks[i]; MethodInsnNode min = (MethodInsnNode) (mn.instructions.get(fi.endInstruction)); if (isYieldMethod(min.owner, min.name)) { // special case - call to yield if (min.getOpcode() != Opcodes.INVOKESTATIC) throw new UnableToInstrumentException("invalid call to suspending method.", className, mn.name, mn.desc); final int numYieldArgs = TypeAnalyzer.getNumArguments(min.desc); final boolean yieldReturnsValue = (Type.getReturnType(min.desc) != Type.VOID_TYPE); emitStoreState(mv, i, fi, numYieldArgs); // we preserve the arguments for the call to yield on the operand stack emitStoreResumed(mv, false); // we have not been resumed // emitSuspendableCalled(mv); min.accept(mv); // we call the yield method if (yieldReturnsValue) mv.visitInsn(Opcodes.POP); // we ignore the returned value... mv.visitLabel(lMethodCalls[i - 1]); // we resume AFTER the call final Label afterPostRestore = new Label(); mv.visitVarInsn(Opcodes.ILOAD, lvarResumed); mv.visitJumpInsn(Opcodes.IFEQ, afterPostRestore); emitPostRestore(mv); mv.visitLabel(afterPostRestore); emitRestoreState(mv, i, fi, numYieldArgs); if (yieldReturnsValue) mv.visitVarInsn(Opcodes.ILOAD, lvarResumed); // ... and replace the returned value with the value of resumed dumpCodeBlock(mv, i, 1); // skip the call } else { final Label lbl = new Label(); if (DUAL) { mv.visitVarInsn(Opcodes.ALOAD, lvarStack); mv.visitJumpInsn(Opcodes.IFNULL, lbl); } // normal case - call to a suspendable method - resume before the call emitStoreState(mv, i, fi, 0); emitStoreResumed(mv, false); // we have not been resumed // emitPreemptionPoint(mv, PREEMPTION_CALL); mv.visitLabel(lMethodCalls[i - 1]); emitRestoreState(mv, i, fi, 0); if (DUAL) mv.visitLabel(lbl); if (isReflectInvocation(min.owner, min.name)) { // We catch the InvocationTargetException and unwrap it if it wraps a SuspendExecution exception. Label[] ls = refInvokeTryCatch[i - 1]; final Label startTry = ls[0]; final Label endTry = ls[1]; final Label startCatch = ls[2]; final Label endCatch = new Label(); final Label notSuspendExecution = new Label(); // mv.visitTryCatchBlock(startTry, endTry, startCatch, "java/lang/reflect/InvocationTargetException"); mv.visitLabel(startTry); // try { min.accept(mv); // method.invoke() mv.visitVarInsn(Opcodes.ASTORE, lvarInvocationReturnValue); // save return value mv.visitLabel(endTry); // } mv.visitJumpInsn(Opcodes.GOTO, endCatch); mv.visitLabel(startCatch); // catch(InvocationTargetException ex) { mv.visitInsn(Opcodes.DUP); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Throwable", "getCause", "()Ljava/lang/Throwable;"); mv.visitTypeInsn(Opcodes.INSTANCEOF, EXCEPTION_NAME); mv.visitJumpInsn(Opcodes.IFEQ, notSuspendExecution); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Throwable", "getCause", "()Ljava/lang/Throwable;"); mv.visitLabel(notSuspendExecution); mv.visitInsn(Opcodes.ATHROW); mv.visitLabel(endCatch); mv.visitVarInsn(Opcodes.ALOAD, lvarInvocationReturnValue); // restore return value dumpCodeBlock(mv, i, 1); // skip the call } else { // emitSuspendableCalled(mv); dumpCodeBlock(mv, i, 0); } } } mv.visitLabel(lMethodEnd); if (handleProxyInvocations) { mv.visitLabel(lCatchUTE); mv.visitInsn(Opcodes.DUP); // println(mv, "CTCH: "); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Throwable", "getCause", "()Ljava/lang/Throwable;"); // println(mv, "CAUSE: "); mv.visitTypeInsn(Opcodes.INSTANCEOF, EXCEPTION_NAME); mv.visitJumpInsn(Opcodes.IFEQ, lCatchAll); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Throwable", "getCause", "()Ljava/lang/Throwable;"); mv.visitJumpInsn(Opcodes.GOTO, lCatchSEE); } mv.visitLabel(lCatchAll); emitPopMethod(mv); mv.visitLabel(lCatchSEE); // println(mv, "THROW: "); mv.visitInsn(Opcodes.ATHROW); // rethrow shared between catchAll and catchSSE if (mn.localVariables != null) { for (Object o : mn.localVariables) ((LocalVariableNode) o).accept(mv); } mv.visitMaxs(mn.maxStack + ADD_OPERANDS, mn.maxLocals + NUM_LOCALS + additionalLocals); mv.visitEnd(); }
From source file:com.alibaba.hotswap.processor.jdk.classloader.modifier.DefineClassMethodModifier.java
License:Open Source License
@Override public void visitInsn(int opcode) { if (opcode == Opcodes.ARETURN) { mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(HotswapRuntime.class), "hasClassMeta", "(Ljava/lang/String;)Z"); Label end = new Label(); mv.visitJumpInsn(Opcodes.IFEQ, end); mv.visitInsn(Opcodes.DUP);/*ww w . j a v a2 s.co m*/ mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitInsn(Opcodes.SWAP); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(HotswapRuntime.class), "updateClassMetaClass", "(Ljava/lang/String;Ljava/lang/Class;)V"); mv.visitLabel(end); } super.visitInsn(opcode); }
From source file:com.alibaba.hotswap.processor.jdk.lang.modifier.ClassNewInstanceModifier.java
License:Open Source License
@Override public void visitCode() { super.visitCode(); mv.visitVarInsn(Opcodes.ALOAD, 0);//from w ww. jav a 2 s .co m mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Class", "getName", "()Ljava/lang/String;"); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(HotswapRuntime.class), "hasClassMeta", "(Ljava/lang/String;)Z"); Label old = new Label(); mv.visitJumpInsn(Opcodes.IFEQ, old); // check it as a primary constructor mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Class", "getName", "()Ljava/lang/String;"); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(HotswapRuntime.class), "getClassMeta", "(Ljava/lang/String;)Lcom/alibaba/hotswap/meta/ClassMeta;"); mv.visitLdcInsn(HotswapConstants.INIT); mv.visitLdcInsn("()V"); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(ClassMeta.class), "isPrimaryInitMethod", "(Ljava/lang/String;Ljava/lang/String;)Z"); mv.visitJumpInsn(Opcodes.IFNE, old); // get uniform constructor mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(HotswapMethodUtil.class), "getConstructorParamTypes", "()[Ljava/lang/Class;"); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Class", "getConstructor", "([Ljava/lang/Class;)Ljava/lang/reflect/Constructor;"); // index and objs mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Class", "getName", "()Ljava/lang/String;"); mv.visitLdcInsn(HotswapConstants.INIT); mv.visitLdcInsn("()V"); loadArgs(); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(HotswapMethodUtil.class), "getMethodParams", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)[Ljava/lang/Object;"); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/reflect/Constructor", "newInstance", "([Ljava/lang/Object;)Ljava/lang/Object;"); mv.visitInsn(Opcodes.ARETURN); mv.visitLabel(old); }
From source file:com.alibaba.hotswap.processor.jdk.lang.modifier.PrivateGetDeclaredConstructors.java
License:Open Source License
@Override public void visitMethodInsn(int opcode, String owner, String name, String desc) { if (opcode == Opcodes.INVOKESPECIAL && owner.equals("java/lang/Class") && name.equals("getDeclaredConstructors0") && desc.equals("(Z)[Ljava/lang/reflect/Constructor;")) { mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Class", "getName", "()Ljava/lang/String;"); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(HotswapRuntime.class), "hasClassMeta", "(Ljava/lang/String;)Z"); Label old = new Label(); mv.visitJumpInsn(Opcodes.IFEQ, old); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(MethodReflectHelper.class), "getDeclaredConstructors0", "(Ljava/lang/Class;Z)[Ljava/lang/reflect/Constructor;"); Label end = new Label(); mv.visitJumpInsn(Opcodes.GOTO, end); mv.visitLabel(old);// w w w . ja va2 s .c o m super.visitMethodInsn(opcode, owner, name, desc); mv.visitLabel(end); } else { super.visitMethodInsn(opcode, owner, name, desc); } }
From source file:com.alibaba.hotswap.processor.jdk.lang.modifier.PrivateGetDeclaredFieldsModifier.java
License:Open Source License
@Override public void visitMethodInsn(int opcode, String owner, String name, String desc) { if (opcode == Opcodes.INVOKESPECIAL && owner.equals("java/lang/Class") && name.equals("getDeclaredFields0") && desc.equals("(Z)[Ljava/lang/reflect/Field;")) { mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Class", "getName", "()Ljava/lang/String;"); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(HotswapRuntime.class), "hasClassMeta", "(Ljava/lang/String;)Z"); Label old = new Label(); mv.visitJumpInsn(Opcodes.IFEQ, old); // mv.visitInsn(Opcodes.POP2); // mv.visitVarInsn(Opcodes.ALOAD, 0); // mv.visitVarInsn(Opcodes.ILOAD, 1); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(FieldReflectHelper.class), "privateGetDeclaredFields0", "(Ljava/lang/Class;Z)[Ljava/lang/reflect/Field;"); Label end = new Label(); mv.visitJumpInsn(Opcodes.GOTO, end); mv.visitLabel(old);/*from ww w. j av a 2 s .c o m*/ super.visitMethodInsn(opcode, owner, name, desc); mv.visitLabel(end); } else { super.visitMethodInsn(opcode, owner, name, desc); } }
From source file:com.alibaba.hotswap.processor.jdk.reflect.modifier.ConstructorNewInstanceModifier.java
License:Open Source License
@Override public void visitCode() { super.visitCode(); Label old = new Label(); mv.visitVarInsn(Opcodes.ALOAD, 0);/*ww w. j a v a 2 s . c o m*/ mv.visitFieldInsn(Opcodes.GETFIELD, "java/lang/reflect/Constructor", "parameterTypes", "[Ljava/lang/Class;"); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(MethodReflectHelper.class), "isUniformConstructorArgsType", "([Ljava/lang/Class;)Z"); ifZCmp(NE, old); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "java/lang/reflect/Constructor", "clazz", "Ljava/lang/Class;"); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Class", "getName", "()Ljava/lang/String;"); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(HotswapRuntime.class), "hasClassMeta", "(Ljava/lang/String;)Z"); mv.visitJumpInsn(Opcodes.IFEQ, old); // check it as a primary constructor mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "java/lang/reflect/Constructor", "clazz", "Ljava/lang/Class;"); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Class", "getName", "()Ljava/lang/String;"); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(HotswapRuntime.class), "getClassMeta", "(Ljava/lang/String;)Lcom/alibaba/hotswap/meta/ClassMeta;"); mv.visitLdcInsn(HotswapConstants.INIT); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Type.class), "getConstructorDescriptor", "(Ljava/lang/reflect/Constructor;)Ljava/lang/String;"); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(ClassMeta.class), "isPrimaryInitMethod", "(Ljava/lang/String;Ljava/lang/String;)Z"); mv.visitJumpInsn(Opcodes.IFNE, old); // get uniform constructor mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "java/lang/reflect/Constructor", "clazz", "Ljava/lang/Class;"); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(HotswapMethodUtil.class), "getConstructorParamTypes", "()[Ljava/lang/Class;"); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Class", "getConstructor", "([Ljava/lang/Class;)Ljava/lang/reflect/Constructor;"); // index and objs mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "java/lang/reflect/Constructor", "clazz", "Ljava/lang/Class;"); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Class", "getName", "()Ljava/lang/String;"); mv.visitLdcInsn(HotswapConstants.INIT); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Type.class), "getConstructorDescriptor", "(Ljava/lang/reflect/Constructor;)Ljava/lang/String;"); loadArgs(); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(HotswapMethodUtil.class), "getMethodParams", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)[Ljava/lang/Object;"); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/reflect/Constructor", "newInstance", "([Ljava/lang/Object;)Ljava/lang/Object;"); mv.visitInsn(Opcodes.ARETURN); mv.visitLabel(old); }
From source file:com.android.build.gradle.internal.incremental.StringSwitch.java
License:Apache License
/** * Emit code for a string if-else block. * * if (s.equals("collided_method1")) { * visit(s);//w w w . j a v a 2 s. c om * } else if (s.equals("collided_method2")) { * visit(s); * } * * In the most common case of just one string, this degenerates to: * * visit(s) * */ private void visitx(GeneratorAdapter mv, List<String> strings) { if (strings.size() == 1) { visitCase(strings.get(0)); return; } for (String string : strings) { Label label = new Label(); visitString(); mv.visitLdcInsn(string); mv.invokeVirtual(STRING_TYPE, Method.getMethod("boolean equals(Object)")); mv.visitJumpInsn(Opcodes.IFEQ, label); visitCase(string); mv.visitLabel(label); } visitDefault(); }