@Override public void apply(MethodPatcher.PatchData patch, MethodNode methodNode, AbstractInsnNode location, Method method) { methodNode.instructions.insertBefore(location, method.insnList); } },
private void insert(AbstractInsnNode instruction) { instructions.insertBefore(current, instruction); }
private void insertBranchIdPlaceholder(MethodNode mn, JumpInsnNode jumpNode, int branchId) { Label label = new Label(); LabelNode labelNode = new LabelNode(label); //BooleanTestabilityPlaceholderTransformer.addBranchPlaceholder(label, jumpNode); mn.instructions.insertBefore(jumpNode, labelNode); //mn.instructions.insertBefore(jumpNode, new LdcInsnNode(0)); mn.instructions.insertBefore(jumpNode, new LdcInsnNode(branchId)); }
private void generateMarkerCall(InsnList instructions, AbstractInsnNode ret, String call) { instructions.insertBefore(ret, new MethodInsnNode(INVOKEINTERFACE, Types.RULE.getInternalName(), call, "()" + Types.RULE.getDescriptor(), true)); }
@Override public void apply(MethodPatcher.PatchData patch, MethodNode methodNode, AbstractInsnNode location, Method method) { methodNode.instructions.insertBefore(location, method.insnList); methodNode.instructions.remove(location); } };
private void insertBranchIdPlaceholder(MethodNode mn, JumpInsnNode jumpNode) { Label label = new Label(); LabelNode labelNode = new LabelNode(label); //BooleanTestabilityPlaceholderTransformer.addBranchPlaceholder(label, jumpNode); mn.instructions.insertBefore(jumpNode, labelNode); //mn.instructions.insertBefore(jumpNode, new LdcInsnNode(0)); mn.instructions.insertBefore(jumpNode, new LdcInsnNode(getBranchID(mn, jumpNode))); }
public static SpecificMethodNodeTransformer instructionsInserter(String target, int priority, Function<InsnList, AbstractInsnNode> where, InsnList insn, boolean before) { return instructionsTransformer(priority, target, instructions -> { if (before) instructions.insertBefore(where.apply(instructions), insn); else instructions.insert(where.apply(instructions), insn); }); }
public static SpecificMethodNodeTransformer instructionsInserter(String target, int priority, Function<AbstractInsnNode, Pair<InsnList, Boolean>> inserter) { return instructionsTransformer(priority, target, instructions -> { for (AbstractInsnNode node : instructions.toArray()) { Pair<InsnList, Boolean> pair = inserter.apply(node); if (pair != null) if (pair.getRight()) instructions.insertBefore(node, pair.getLeft()); else instructions.insert(node, pair.getLeft()); } }); }
@Override public void transform() { AtomicInteger counter = new AtomicInteger(); getClassWrappers().parallelStream().filter(classWrapper -> !excluded(classWrapper)).forEach(classWrapper -> { ClassNode classNode = classWrapper.classNode; classNode.methods.stream().filter(methodNode -> "<init>".equals(methodNode.name)).forEach(methodNode -> { InsnList expirationCode = createExpirationInstructions(); methodNode.instructions.insertBefore(methodNode.instructions.getFirst(), expirationCode); counter.incrementAndGet(); }); }); LoggerUtils.stdOut(String.format("Added %d expiration code blocks.", counter.get())); }
@Override public void add(final Object o) { if (nextInsn != null) { InsnList.this.insertBefore(nextInsn, (AbstractInsnNode) o); } else if (previousInsn != null) { InsnList.this.insert(previousInsn, (AbstractInsnNode) o); } else { InsnList.this.add((AbstractInsnNode) o); } previousInsn = (AbstractInsnNode) o; remove = null; }
public void add(Object o) { if (next != null) { InsnList.this.insertBefore(next, (AbstractInsnNode) o); } else if (prev != null) { InsnList.this.insert(prev, (AbstractInsnNode) o); } else { InsnList.this.add((AbstractInsnNode) o); } prev = (AbstractInsnNode) o; remove = null; }
private void addTraceThrow() { val it = methodNode.instructions.iterator(); while (it.hasNext()) { val insnNode = (AbstractInsnNode) it.next(); switch (insnNode.getOpcode()) { case ATHROW: methodNode.instructions.insertBefore(insnNode, getThrowTraceInsts()); break; } } }
private void addTraceThrow() { InsnList il = this.mn.instructions; Iterator<AbstractInsnNode> it = il.iterator(); while (it.hasNext()) { AbstractInsnNode abstractInsnNode = it.next(); switch (abstractInsnNode.getOpcode()) { case Opcodes.ATHROW: il.insertBefore(abstractInsnNode, getThrowTraceInstructions()); break; } } }
private void addTraceReturn() { InsnList il = this.mn.instructions; Iterator<AbstractInsnNode> it = il.iterator(); while (it.hasNext()) { AbstractInsnNode abstractInsnNode = it.next(); switch (abstractInsnNode.getOpcode()) { case Opcodes.RETURN: il.insertBefore(abstractInsnNode, getVoidReturnTraceInstructions()); break; case Opcodes.IRETURN: case Opcodes.LRETURN: case Opcodes.FRETURN: case Opcodes.ARETURN: case Opcodes.DRETURN: il.insertBefore(abstractInsnNode, getReturnTraceInstructions()); } } }
private void addTraceReturn() { val insnList = methodNode.instructions; val it = insnList.iterator(); while (it.hasNext()) { val insnNode = (AbstractInsnNode) it.next(); switch (insnNode.getOpcode()) { case RETURN: insnList.insertBefore(insnNode, getVoidReturnTraceInsts()); break; case IRETURN: case LRETURN: case FRETURN: case ARETURN: case DRETURN: insnList.insertBefore(insnNode, getReturnTraceInsts()); } } }
private void insert(AbstractInsnNode insn) { method.instructions.insertBefore(group.getRoot().getInstruction(), insn); }
private void insertControlDependencyPlaceholder(MethodNode mn, AbstractInsnNode insnNode) { Label label = new Label(); LabelNode labelNode = new LabelNode(label); //BooleanTestabilityPlaceholderTransformer.addControlDependencyPlaceholder(label, // insnNode); mn.instructions.insertBefore(insnNode, labelNode); //instructions.insertBefore(insnNode, new LdcInsnNode(0)); //mn.instructions.insertBefore(insnNode, new LdcInsnNode(0)); mn.instructions.insertBefore(insnNode, new LdcInsnNode( getControlDependentBranchID(mn, insnNode))); mn.instructions.insertBefore(insnNode, new LdcInsnNode(getApproximationLevel(mn, insnNode))); logger.info("Control dependent branch id: " + getControlDependentBranchID(mn, insnNode)); logger.info("Approximation level: " + getApproximationLevel(mn, insnNode)); }
private void scramble(ClassNode cn, MethodNode mn) { List<LdcInsnNode> ldcNodes = new LinkedList<>(); BytecodeHelper.forEach(mn.instructions, LdcInsnNode.class, ldcNodes::add); for (LdcInsnNode node : ldcNodes) { if (node.cst instanceof String) { int index = stringList.indexOf(node.cst); if (index == -1) continue; log.debug("Replacing string constant \"{}\" at {}.{}{}", node.cst, cn.name, mn.name, mn.desc); MethodInsnNode call = new MethodInsnNode(Opcodes.INVOKESTATIC, unscrambleClass.name, CALL_NAME, CALL_DESC, false); mn.instructions.set(node, call); mn.instructions.insertBefore(call, BytecodeHelper.newIntegerNode(index)); } } }
@Override protected AbstractInsnNode transformTypeInsnNode(MethodNode mn, TypeInsnNode typeNode) { if (frames == null) return typeNode; if (typeNode.getOpcode() == Opcodes.CHECKCAST) { Frame current = frames[mn.instructions.indexOf(typeNode)]; int size = current.getStackSize(); if (current.getStack(size - 1) == BooleanArrayInterpreter.INT_ARRAY) { BooleanTestabilityTransformation.logger.info("Array is of boolean type, changing CHECKCAST to [I"); TypeInsnNode replacement = new TypeInsnNode(Opcodes.CHECKCAST, "[I"); mn.instructions.insertBefore(typeNode, replacement); mn.instructions.remove(typeNode); return replacement; } } return typeNode; } }
private static byte[] transformModelBiped(byte[] basicClass) { log("Transforming ModelBiped"); MethodSignature sig = new MethodSignature("setRotationAngles", "func_78087_a", "a", "(FFFFFFLnet/minecraft/entity/Entity;)V"); return transform(basicClass, Pair.of(sig, combine( (AbstractInsnNode node) -> { // Filter return node.getOpcode() == Opcodes.RETURN; }, (MethodNode method, AbstractInsnNode node) -> { // Action InsnList newInstructions = new InsnList(); newInstructions.add(new VarInsnNode(Opcodes.ALOAD, 7)); newInstructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, ASM_HOOKS, "updateEmotes", "(Lnet/minecraft/entity/Entity;)V")); method.instructions.insertBefore(node, newInstructions); return true; }))); }