Java Code Examples for org.objectweb.asm.tree.AbstractInsnNode#getOpcode()
The following examples show how to use
org.objectweb.asm.tree.AbstractInsnNode#getOpcode() .
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: JumpInsnPoint.java From Mixin with MIT License | 6 votes |
@Override public boolean find(String desc, InsnList insns, Collection<AbstractInsnNode> nodes) { boolean found = false; int ordinal = 0; ListIterator<AbstractInsnNode> iter = insns.iterator(); while (iter.hasNext()) { AbstractInsnNode insn = iter.next(); if (insn instanceof JumpInsnNode && (this.opCode == -1 || insn.getOpcode() == this.opCode)) { if (this.ordinal == -1 || this.ordinal == ordinal) { nodes.add(insn); found = true; } ordinal++; } } return found; }
Example 2
Source File: LambdaClassFixer.java From bazel with Apache License 2.0 | 6 votes |
private void removeLastAllocation() { AbstractInsnNode insn = instructions.getLast(); while (insn != null && insn.getPrevious() != null) { AbstractInsnNode prev = insn.getPrevious(); if (prev.getOpcode() == Opcodes.NEW && insn.getOpcode() == Opcodes.DUP && ((TypeInsnNode) prev).desc.equals(lambdaInfo.methodReference().getOwner())) { instructions.remove(prev); instructions.remove(insn); return; } insn = prev; } throw new IllegalStateException( "Couldn't find allocation to rewrite ::new reference " + lambdaInfo.methodReference()); }
Example 3
Source File: ExceptionObfuscationTX.java From zelixkiller with GNU General Public License v3.0 | 6 votes |
private void check(ClassNode cn, MethodNode mn, TryCatchBlockNode tcb, LabelNode handler) { AbstractInsnNode ain = handler; while (ain.getOpcode() == -1) { // skip labels and frames ain = ain.getNext(); } if (ain.getOpcode() == ATHROW) { removeTCB(mn, tcb); } else if (ain instanceof MethodInsnNode && ain.getNext().getOpcode() == ATHROW) { MethodInsnNode min = (MethodInsnNode) ain; if (min.owner.equals(cn.name)) { MethodNode getter = ClassUtils.getMethod(cn, min.name, min.desc); AbstractInsnNode getterFirst = getter.instructions.getFirst(); while (getterFirst.getOpcode() == -1) { getterFirst = ain.getNext(); } if (getterFirst instanceof VarInsnNode && getterFirst.getNext().getOpcode() == ARETURN) { if (((VarInsnNode) getterFirst).var == 0) { removeTCB(mn, tcb); } } } } }
Example 4
Source File: KeyBindingPatch.java From seppuku with GNU General Public License v3.0 | 6 votes |
/** * This is where minecraft checks if a key is down * We need to patch it because forge adds a key conflicting * problem and doesn't allow us to keep keys pressed while * gui's are open * @param methodNode * @param env */ @MethodPatch( mcpName = "isKeyDown", notchName = "e", mcpDesc = "()Z") public void isKeyDown(MethodNode methodNode, PatchManager.Environment env) { AbstractInsnNode target = null; for (AbstractInsnNode insn : methodNode.instructions.toArray()) { if (insn.getOpcode() == ALOAD) { target = insn; break; } } if(target != null) { AbstractInsnNode next = target.getNext().getNext(); //If while(next.getOpcode() != IRETURN) { next = next.getNext(); methodNode.instructions.remove(next.getPrevious()); } } }
Example 5
Source File: KeyBindingPatch.java From ForgeHax with MIT License | 6 votes |
@Inject(description = "Shut down forge's shit for GuiMove") public void inject(MethodNode main) { AbstractInsnNode node = ASMHelper.findPattern( main.instructions.getFirst(), new int[]{ALOAD, GETFIELD, IFEQ}, "xxx"); Objects.requireNonNull(node, "Find pattern failed for getfield node"); // Delete forge code AbstractInsnNode iteratorNode = node.getNext().getNext(); // set the iterator to the IFEQ instruction while (iteratorNode.getOpcode() != IRETURN) { iteratorNode = iteratorNode.getNext(); main.instructions.remove(iteratorNode.getPrevious()); } }
Example 6
Source File: ConstInterpreter.java From pro with GNU General Public License v3.0 | 6 votes |
@Override public ConstValue newOperation(AbstractInsnNode insn) { switch (insn.getOpcode()) { case LCONST_0: case LCONST_1: case DCONST_0: case DCONST_1: return ConstValue.TWO_SLOT; case LDC: var constant = ((LdcInsnNode) insn).cst; if (constant instanceof Type) { // constant class return ConstValue.string(((Type)constant).getInternalName()); } return constant instanceof Long || constant instanceof Double ? ConstValue.TWO_SLOT: ConstValue.ONE_SLOT; case GETSTATIC: return ConstValue.slotForSize(Type.getType(((FieldInsnNode) insn).desc).getSize()); default: return ConstValue.ONE_SLOT; } }
Example 7
Source File: SourceInterpreter.java From Concurnas with MIT License | 6 votes |
@Override public SourceValue newOperation(final AbstractInsnNode insn) { int size; switch (insn.getOpcode()) { case LCONST_0: case LCONST_1: case DCONST_0: case DCONST_1: size = 2; break; case LDC: Object value = ((LdcInsnNode) insn).cst; size = value instanceof Long || value instanceof Double ? 2 : 1; break; case GETSTATIC: size = Type.getType(((FieldInsnNode) insn).desc).getSize(); break; default: size = 1; break; } return new SourceValue(size, insn); }
Example 8
Source File: MonitoringFrame.java From tascalate-javaflow with Apache License 2.0 | 5 votes |
@Override public void execute(AbstractInsnNode insn, Interpreter interpreter) throws AnalyzerException { boolean never = false; if (never) { super.execute(insn, interpreter); return; } int insnOpcode = insn.getOpcode(); if (insnOpcode == Opcodes.MONITORENTER || insnOpcode == Opcodes.MONITOREXIT) { Value pop = pop(); interpreter.unaryOperation(insn, pop); int local = -1; for (int i = 0; i < getLocals(); i++) { if (getLocal(i) == pop) local = i; } if (local > -1) { if (insnOpcode == Opcodes.MONITORENTER) { monitorEnter(local); } else { monitorExit(local); } } } else { super.execute(insn, interpreter); } }
Example 9
Source File: SourceInterpreter.java From JByteMod-Beta with GNU General Public License v2.0 | 5 votes |
@Override public SourceValue binaryOperation(final AbstractInsnNode insn, final SourceValue value1, final SourceValue value2) { int size; switch (insn.getOpcode()) { case LALOAD: case DALOAD: case LADD: case DADD: case LSUB: case DSUB: case LMUL: case DMUL: case LDIV: case DDIV: case LREM: case DREM: case LSHL: case LSHR: case LUSHR: case LAND: case LOR: case LXOR: size = 2; break; default: size = 1; } return new SourceValue(size, insn); }
Example 10
Source File: OverclockingClassTransformer.java From malmo with MIT License | 5 votes |
private static void overclockRenderer(ClassNode node, boolean isObfuscated) { // We're attempting to turn this line from Minecraft.runGameLoop: // this.updateDisplay(); // into this: // TimeHelper.updateDisplay(); // TimeHelper's method then decides whether or not to pass the call on to Minecraft.updateDisplay(). final String methodName = isObfuscated ? "as" : "runGameLoop"; final String methodDescriptor = "()V"; // No params, returns void. System.out.println("MALMO: Found Minecraft, attempting to transform it"); for (MethodNode method : node.methods) { if (method.name.equals(methodName) && method.desc.equals(methodDescriptor)) { System.out.println("MALMO: Found Minecraft.runGameLoop() method, attempting to transform it"); for (AbstractInsnNode instruction : method.instructions.toArray()) { if (instruction.getOpcode() == Opcodes.INVOKEVIRTUAL) { MethodInsnNode visitMethodNode = (MethodInsnNode)instruction; if (visitMethodNode.name.equals(isObfuscated ? "h" : "updateDisplay")) { visitMethodNode.owner = "com/microsoft/Malmo/Utils/TimeHelper"; if (isObfuscated) { visitMethodNode.name = "updateDisplay"; } visitMethodNode.setOpcode(Opcodes.INVOKESTATIC); method.instructions.remove(visitMethodNode.getPrevious()); // ALOAD 0 not needed for static invocation. System.out.println("MALMO: Hooked into call to Minecraft.updateDisplay()"); } } } } } }
Example 11
Source File: ContinuableMethodVisitor.java From tascalate-javaflow with Apache License 2.0 | 5 votes |
private static int getOwnerSize(AbstractInsnNode node) { if (node instanceof MethodInsnNode) { return node.getOpcode() == INVOKESTATIC ? 0 : 1; } else { // INVOKEDYNAMIC return 0; } }
Example 12
Source File: ApiDetector.java From javaide with GNU General Public License v3.0 | 5 votes |
private static boolean isSdkVersionLookup(@NonNull AbstractInsnNode instruction) { if (instruction.getOpcode() == Opcodes.GETSTATIC) { FieldInsnNode fieldNode = (FieldInsnNode) instruction; return (SDK_INT.equals(fieldNode.name) && ANDROID_OS_BUILD_VERSION.equals(fieldNode.owner)); } return false; }
Example 13
Source File: ApiDetector.java From javaide with GNU General Public License v3.0 | 5 votes |
private static boolean isSkippedEnumSwitch(ClassContext context, ClassNode classNode, MethodNode method, FieldInsnNode node, String owner, int api) { // Enum-style switches are handled in a different way: it generates // an innerclass where the class initializer creates a mapping from // the ordinals to the corresponding values. // Here we need to check to see if the call site which *used* the // table switch had a suppress node on it (or up that node's parent // chain AbstractInsnNode next = getNextInstruction(node); if (next != null && next.getOpcode() == Opcodes.INVOKEVIRTUAL && CLASS_CONSTRUCTOR.equals(method.name) && ORDINAL_METHOD.equals(((MethodInsnNode) next).name) && classNode.outerClass != null && isEnumSwitchInitializer(classNode)) { LintDriver driver = context.getDriver(); ClassNode outer = driver.getOuterClassNode(classNode); if (outer != null) { MethodNode switchUser = findEnumSwitchUsage(outer, owner); if (switchUser != null) { // Is the API check suppressed at the call site? if (driver.isSuppressed(UNSUPPORTED, outer, switchUser, null)) { return true; } // Is there a @TargetAPI annotation on the method or // class referencing this switch map class? if (getLocalMinSdk(switchUser.invisibleAnnotations) >= api || getLocalMinSdk(outer.invisibleAnnotations) >= api) { return true; } } } } return false; }
Example 14
Source File: BasicInterpreter.java From Cafebabe with GNU General Public License v3.0 | 4 votes |
@Override public BasicValue unaryOperation(final AbstractInsnNode insn, final BasicValue value) throws AnalyzerException { switch (insn.getOpcode()) { case INEG: case IINC: case L2I: case F2I: case D2I: case I2B: case I2C: case I2S: return BasicValue.INT_VALUE; case FNEG: case I2F: case L2F: case D2F: return BasicValue.FLOAT_VALUE; case LNEG: case I2L: case F2L: case D2L: return BasicValue.LONG_VALUE; case DNEG: case I2D: case L2D: case F2D: return BasicValue.DOUBLE_VALUE; case IFEQ: case IFNE: case IFLT: case IFGE: case IFGT: case IFLE: case TABLESWITCH: case LOOKUPSWITCH: case IRETURN: case LRETURN: case FRETURN: case DRETURN: case ARETURN: case PUTSTATIC: return null; case GETFIELD: return newValue(Type.getType(((FieldInsnNode) insn).desc)); case NEWARRAY: switch (((IntInsnNode) insn).operand) { case T_BOOLEAN: return newValue(Type.getType("[Z")); case T_CHAR: return newValue(Type.getType("[C")); case T_BYTE: return newValue(Type.getType("[B")); case T_SHORT: return newValue(Type.getType("[S")); case T_INT: return newValue(Type.getType("[I")); case T_FLOAT: return newValue(Type.getType("[F")); case T_DOUBLE: return newValue(Type.getType("[D")); case T_LONG: return newValue(Type.getType("[J")); default: break; } throw new AnalyzerException(insn, "Invalid array type"); case ANEWARRAY: return newValue(Type.getType("[" + Type.getObjectType(((TypeInsnNode) insn).desc))); case ARRAYLENGTH: return BasicValue.INT_VALUE; case ATHROW: return null; case CHECKCAST: return newValue(Type.getObjectType(((TypeInsnNode) insn).desc)); case INSTANCEOF: return BasicValue.INT_VALUE; case MONITORENTER: case MONITOREXIT: case IFNULL: case IFNONNULL: return null; default: throw new AssertionError(); } }
Example 15
Source File: BasicInterpreter.java From JReFrameworker with MIT License | 4 votes |
@Override public BasicValue unaryOperation(final AbstractInsnNode insn, final BasicValue value) throws AnalyzerException { switch (insn.getOpcode()) { case INEG: case IINC: case L2I: case F2I: case D2I: case I2B: case I2C: case I2S: return BasicValue.INT_VALUE; case FNEG: case I2F: case L2F: case D2F: return BasicValue.FLOAT_VALUE; case LNEG: case I2L: case F2L: case D2L: return BasicValue.LONG_VALUE; case DNEG: case I2D: case L2D: case F2D: return BasicValue.DOUBLE_VALUE; case IFEQ: case IFNE: case IFLT: case IFGE: case IFGT: case IFLE: case TABLESWITCH: case LOOKUPSWITCH: case IRETURN: case LRETURN: case FRETURN: case DRETURN: case ARETURN: case PUTSTATIC: return null; case GETFIELD: return newValue(Type.getType(((FieldInsnNode) insn).desc)); case NEWARRAY: switch (((IntInsnNode) insn).operand) { case T_BOOLEAN: return newValue(Type.getType("[Z")); case T_CHAR: return newValue(Type.getType("[C")); case T_BYTE: return newValue(Type.getType("[B")); case T_SHORT: return newValue(Type.getType("[S")); case T_INT: return newValue(Type.getType("[I")); case T_FLOAT: return newValue(Type.getType("[F")); case T_DOUBLE: return newValue(Type.getType("[D")); case T_LONG: return newValue(Type.getType("[J")); default: break; } throw new AnalyzerException(insn, "Invalid array type"); case ANEWARRAY: return newValue(Type.getType("[" + Type.getObjectType(((TypeInsnNode) insn).desc))); case ARRAYLENGTH: return BasicValue.INT_VALUE; case ATHROW: return null; case CHECKCAST: return newValue(Type.getObjectType(((TypeInsnNode) insn).desc)); case INSTANCEOF: return BasicValue.INT_VALUE; case MONITORENTER: case MONITOREXIT: case IFNULL: case IFNONNULL: return null; default: throw new AssertionError(); } }
Example 16
Source File: LambdaDesugaring.java From bazel with Apache License 2.0 | 4 votes |
/** * Tries to insert a new/dup for the given class name before expected existing instructions that * set up arguments for an invokedynamic factory method with the given types. * * <p>For lambda expressions and simple method references we can assume that arguments are set * up with loads of the captured (effectively) final variables. But method references, can in * general capture an expression, such as in {@code myObject.toString()::charAt} (a {@code * Function<Integer, Character>}), which can also cause null checks to be inserted. In * such more complicated cases this method may fail to insert a new/dup pair and returns {@code * false}. * * @param internalName internal name of the class to instantiate * @param paramTypes expected invokedynamic argument types, which also must be the parameters of * {@code internalName}'s constructor. * @return {@code true} if we were able to insert a new/dup, {@code false} otherwise */ private boolean attemptAllocationBeforeArgumentLoads(String internalName, Type[] paramTypes) { checkArgument(paramTypes.length > 0, "Expected at least one param for %s", internalName); // Walk backwards past loads corresponding to constructor arguments to find the instruction // after which we need to insert our NEW/DUP pair AbstractInsnNode insn = instructions.getLast(); for (int i = paramTypes.length - 1; 0 <= i; --i) { if (insn.getOpcode() == Opcodes.GETFIELD) { // Lambdas in anonymous inner classes have to load outer scope variables from fields, // which manifest as an ALOAD followed by one or more GETFIELDs FieldInsnNode getfield = (FieldInsnNode) insn; checkState( getfield.desc.length() == 1 ? getfield.desc.equals(paramTypes[i].getDescriptor()) : paramTypes[i].getDescriptor().length() > 1, "Expected getfield for %s to set up parameter %s for %s but got %s : %s", paramTypes[i], i, internalName, getfield.name, getfield.desc); insn = insn.getPrevious(); while (insn.getOpcode() == Opcodes.GETFIELD) { // Nested inner classes can cause a cascade of getfields from the outermost one inwards checkState( ((FieldInsnNode) insn).desc.startsWith("L"), "expect object type getfields to get to %s to set up parameter %s for %s, not: %s", paramTypes[i], i, internalName, ((FieldInsnNode) insn).desc); insn = insn.getPrevious(); } checkState( insn.getOpcode() == Opcodes.ALOAD, // should be a this pointer to be precise "Expected aload before getfield for %s to set up parameter %s for %s but got %s", getfield.name, i, internalName, insn.getOpcode()); } else if (!isPushForType(insn, paramTypes[i])) { // Otherwise expect load of a (effectively) final local variable or a constant. Not seeing // that means we're dealing with a method reference on some arbitrary expression, // <expression>::m. In that case we give up and keep using the factory method for now, // since inserting the NEW/DUP so the new object ends up in the right stack slot is hard // in that case. Note this still covers simple cases such as this::m or x::m, where x is a // local. checkState( paramTypes.length == 1, "Expected a load for %s to set up parameter %s for %s but got %s", paramTypes[i], i, internalName, insn.getOpcode()); return false; } insn = insn.getPrevious(); } TypeInsnNode newInsn = new TypeInsnNode(Opcodes.NEW, internalName); if (insn == null) { // Ran off the front of the instruction list instructions.insert(newInsn); } else { instructions.insert(insn, newInsn); } instructions.insert(newInsn, new InsnNode(Opcodes.DUP)); return true; }
Example 17
Source File: BasicInterpreter.java From JReFrameworker with MIT License | 4 votes |
@Override public BasicValue binaryOperation( final AbstractInsnNode insn, final BasicValue value1, final BasicValue value2) throws AnalyzerException { switch (insn.getOpcode()) { case IALOAD: case BALOAD: case CALOAD: case SALOAD: case IADD: case ISUB: case IMUL: case IDIV: case IREM: case ISHL: case ISHR: case IUSHR: case IAND: case IOR: case IXOR: return BasicValue.INT_VALUE; case FALOAD: case FADD: case FSUB: case FMUL: case FDIV: case FREM: return BasicValue.FLOAT_VALUE; case LALOAD: case LADD: case LSUB: case LMUL: case LDIV: case LREM: case LSHL: case LSHR: case LUSHR: case LAND: case LOR: case LXOR: return BasicValue.LONG_VALUE; case DALOAD: case DADD: case DSUB: case DMUL: case DDIV: case DREM: return BasicValue.DOUBLE_VALUE; case AALOAD: return BasicValue.REFERENCE_VALUE; case LCMP: case FCMPL: case FCMPG: case DCMPL: case DCMPG: return BasicValue.INT_VALUE; case IF_ICMPEQ: case IF_ICMPNE: case IF_ICMPLT: case IF_ICMPGE: case IF_ICMPGT: case IF_ICMPLE: case IF_ACMPEQ: case IF_ACMPNE: case PUTFIELD: return null; default: throw new AssertionError(); } }
Example 18
Source File: InfiniteForLoopFilter.java From pitest with Apache License 2.0 | 4 votes |
@Override boolean couldCauseInfiniteLoop(MethodTree method, MutationDetails each) { final AbstractInsnNode instruction = method.instruction(each.getInstructionIndex()); return instruction.getOpcode() == Opcodes.IINC; }
Example 19
Source File: MethodEntryExitAdapter.java From jumbune with GNU Lesser General Public License v3.0 | 4 votes |
/** * visit end method for intrumentation */ @Override public void visitEnd() { for (Object o : methods) { MethodNode mn = (MethodNode) o; // filtering the methods if (!(validateMapReduceClinitMethod(mn.name,MAP_METHOD , REDUCE_METHOD,CLINIT_METHOD) || checkMethodNameAndArgumentLength(mn) || (mn.access & Opcodes.ACC_SYNTHETIC) == Opcodes.ACC_SYNTHETIC)) { InsnList insnList = mn.instructions; AbstractInsnNode[] insnArr = insnList.toArray(); // adding entry logging logger.debug(MessageFormat.format(InstrumentationMessageLoader .getMessage(MessageConstants.LOG_METHOD_ENTRY), getClassName() + "##" + mn.name + "##" + mn.desc)); String logMsg = InstrumentationMessageLoader .getMessage(MessageConstants.ENTERED_METHOD); String cSymbol = env.getClassSymbol(getClassName()); String mSymbol = env.getMethodSymbol(getClassName(),cSymbol, mn.name); InsnList il = InstrumentUtil.addLogMessage(cSymbol, mSymbol, logMsg); insnList.insertBefore(insnList.getFirst(), il); for (AbstractInsnNode abstractInsnNode : insnArr) { if (Opcodes.RETURN >= abstractInsnNode.getOpcode() && Opcodes.IRETURN <= abstractInsnNode.getOpcode()) { // adding exit logging logger.debug(MessageFormat.format( InstrumentationMessageLoader .getMessage(MessageConstants.LOG_METHOD_EXIT), getClassName() + "##" + mn.name)); logMsg = InstrumentationMessageLoader .getMessage(MessageConstants.EXITING_METHOD); cSymbol = env.getClassSymbol(getClassName()); mSymbol = env.getMethodSymbol(getClassName(),cSymbol,mn.name); il = InstrumentUtil.addLogMessage(cSymbol, mSymbol, logMsg); // inserting the list at the associated label node AbstractInsnNode prevNode = abstractInsnNode .getPrevious(); while (!(prevNode instanceof LabelNode)) { prevNode = prevNode.getPrevious(); } insnList.insert(prevNode, il); } } } mn.visitMaxs(0, 0); } accept(cv); }
Example 20
Source File: BasicVerifier.java From Concurnas with MIT License | 4 votes |
@Override public BasicValue unaryOperation(final AbstractInsnNode insn, final BasicValue value) throws AnalyzerException { BasicValue expected; switch (insn.getOpcode()) { case INEG: case IINC: case I2F: case I2L: case I2D: case I2B: case I2C: case I2S: case IFEQ: case IFNE: case IFLT: case IFGE: case IFGT: case IFLE: case TABLESWITCH: case LOOKUPSWITCH: case IRETURN: case NEWARRAY: case ANEWARRAY: expected = BasicValue.INT_VALUE; break; case FNEG: case F2I: case F2L: case F2D: case FRETURN: expected = BasicValue.FLOAT_VALUE; break; case LNEG: case L2I: case L2F: case L2D: case LRETURN: expected = BasicValue.LONG_VALUE; break; case DNEG: case D2I: case D2F: case D2L: case DRETURN: expected = BasicValue.DOUBLE_VALUE; break; case GETFIELD: expected = newValue(Type.getObjectType(((FieldInsnNode) insn).owner)); break; case ARRAYLENGTH: if (!isArrayValue(value)) { throw new AnalyzerException(insn, null, "an array reference", value); } return super.unaryOperation(insn, value); case CHECKCAST: case ARETURN: case ATHROW: case INSTANCEOF: case MONITORENTER: case MONITOREXIT: case IFNULL: case IFNONNULL: if (!value.isReference()) { throw new AnalyzerException(insn, null, "an object reference", value); } return super.unaryOperation(insn, value); case PUTSTATIC: expected = newValue(Type.getType(((FieldInsnNode) insn).desc)); break; default: throw new AssertionError(); } if (!isSubTypeOf(value, expected)) { throw new AnalyzerException(insn, null, expected, value); } return super.unaryOperation(insn, value); }