void setInstruction(int pos, AbstractInsnNode insn) { flow.instructions.set(getInstruction(pos), insn); }
public void set(Object o) { if (remove != null) { InsnList.this.set(remove, (AbstractInsnNode) o); if (remove == prev) { prev = (AbstractInsnNode) o; } else { next = (AbstractInsnNode) o; } } else { throw new IllegalStateException(); } } }
@Override public void set(final Object o) { if (remove != null) { InsnList.this.set(remove, (AbstractInsnNode) o); if (remove == previousInsn) { previousInsn = (AbstractInsnNode) o; } else { nextInsn = (AbstractInsnNode) o; } } else { throw new IllegalStateException(); } } }
public void replace(int offset, AbstractInsnNode node) { list.set(get(offset), node); }
public static SpecificMethodNodeTransformer instructionsNodesTransformer(String target, int priority, Function<AbstractInsnNode, AbstractInsnNode> insnOld2new) { return instructionsTransformer(priority, target, instructions -> { for (AbstractInsnNode node : instructions.toArray()) { AbstractInsnNode res = insnOld2new.apply(node); if (res != null) instructions.set(node, res); else instructions.remove(node); } }); }
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)); } } }
private void replace(int opcode, ClassNode owner, FieldNode field, MethodNode m) { if (Modifier.isStatic(field.access)) opcode -= 2; for (ClassNode cn : classMap.values()) { for (MethodNode mn : cn.methods) { AbstractInsnNode[] instructions = mn.instructions.toArray(); for (AbstractInsnNode node : instructions) { if (node.getType() != AbstractInsnNode.METHOD_INSN) { continue; } MethodInsnNode min = (MethodInsnNode) node; List<String> owners = getChildNames(owner); if (owners.contains(min.owner) && min.name.equals(m.name) && min.desc.equals(m.desc)) { FieldInsnNode fin = new FieldInsnNode(opcode, min.owner, field.name, field.desc); log.debug(" replace {}.{}.{}, insn: {}", cn.name, mn.name, mn.desc, QueryUtil.query(fin, "index")); mn.instructions.set(min, fin); } } } } }
private void replaceWithActionWrapper(InstructionGraphNode node) { MethodInsnNode insn = createActionWrappingInsn(); method.instructions.set(node.getInstruction(), insn); node.setIsActionRoot(); node.setInstruction(insn); }
private void replaceWithActionWrapper(final InstructionGraphNode node) { final MethodInsnNode insn = createActionWrappingInsn(); method.instructions.set(node.getInstruction(), insn); node.setIsActionRoot(); node.setInstruction(insn); }
@Override public void transform() { AtomicInteger count = new AtomicInteger(); long current = System.currentTimeMillis(); getClassWrappers().parallelStream().filter(classWrapper -> !excluded(classWrapper)).forEach(classWrapper -> classWrapper.methods.parallelStream().filter(methodWrapper -> !excluded(methodWrapper) && hasInstructions(methodWrapper.methodNode)).forEach(methodWrapper -> { MethodNode methodNode = methodWrapper.methodNode; for (AbstractInsnNode insn : methodNode.instructions.toArray()) { if (insn.getOpcode() == GOTO) { JumpInsnNode gotoJump = (JumpInsnNode) insn; AbstractInsnNode insnAfterTarget = gotoJump.label.getNext(); if (insnAfterTarget != null && BytecodeUtils.isReturn(insnAfterTarget.getOpcode())) { methodNode.instructions.set(insn, new InsnNode(insnAfterTarget.getOpcode())); count.incrementAndGet(); } } } })); LoggerUtils.stdOut(String.format("Normalized %d GOTO->RETURN sequences. [%dms]", count.get(), tookThisLong(current))); }
@Override public boolean apply(NodeIt it) { if(it.matches(Pattern.LOAD, Pattern.LOAD)) { VarInsnNode load1 = it.get(0); VarInsnNode load2 = it.get(1); if(load1.var == load2.var) { it.getList().set(load2, dup(load2)); return true; } } return false; }
method.instructions.set(current, insn); current = insn;
protected void convertXLoads(InstructionGroup group) { String owner = group.getGroupClassType().getInternalName(); for (InstructionGraphNode node : group.getNodes()) { if (!node.isXLoad()) continue; VarInsnNode insn = (VarInsnNode) node.getInstruction(); FieldNode field = group.getFields().get(insn.var); // insert the correct GETFIELD after the xLoad group.getInstructions().insert(insn, new FieldInsnNode(GETFIELD, owner, field.name, field.desc)); // change the load to ALOAD 0 group.getInstructions().set(insn, new VarInsnNode(ALOAD, 0)); } }
classWrapper.classNode.name, fieldName, "[Ljava/lang/String;")); methodNode.instructions.insertBefore(insn, BytecodeUtils.getNumberInsn(indexNumber)); methodNode.instructions.set(insn, new InsnNode(AALOAD)); counter.incrementAndGet();
protected static void convertXLoads(final InstructionGroup group) { final String owner = group.getGroupClassType().getInternalName(); InsnList insnList; for (final InstructionGraphNode node : group.getNodes()) { if (!node.isXLoad()) continue; final VarInsnNode insn = (VarInsnNode) node.getInstruction(); final FieldNode field = group.getFields().get(insn.var); final FieldInsnNode fieldNode = new FieldInsnNode(GETFIELD, owner, field.name, field.desc); insnList = group.getInstructions(); // insert the correct GETFIELD after the xLoad insnList.insert(insn, fieldNode); // change the load to ALOAD 0 insnList.set(insn, new VarInsnNode(ALOAD, 0)); } } }
encrypt(methodInsnNode.name, 2038), encrypt(methodInsnNode.desc, 1928)); methodNode.instructions.set(insn, indy); if (returnType.getSort() == Type.ARRAY) { methodNode.instructions.insert(indy, new TypeInsnNode(CHECKCAST,
@Override public void transform() { AtomicInteger counter = new AtomicInteger(); this.getClassWrappers().parallelStream().filter(classWrapper -> !excluded(classWrapper)).forEach(classWrapper -> { ClassNode classNode = classWrapper.classNode; String fieldName = StringUtils.randomSpacesString(RandomUtils.getRandomInt(10)); classWrapper.methods.parallelStream().filter(methodWrapper -> !excluded(methodWrapper) && hasInstructions(methodWrapper.methodNode)).forEach(methodWrapper -> { MethodNode methodNode = methodWrapper.methodNode; int leeway = getSizeLeeway(methodNode); for (AbstractInsnNode insn : methodNode.instructions.toArray()) { if (leeway < 10000) { break; } if (insn.getOpcode() == GOTO) { methodNode.instructions.insertBefore(insn, new FieldInsnNode(GETSTATIC, classNode.name, fieldName, "Z")); methodNode.instructions.insert(insn, new InsnNode(ATHROW)); methodNode.instructions.insert(insn, new InsnNode(ACONST_NULL)); methodNode.instructions.set(insn, new JumpInsnNode(IFEQ, ((JumpInsnNode) insn).label)); leeway -= 7; counter.incrementAndGet(); } } }); classNode.fields.add(new FieldNode(ACC_PUBLIC + ACC_STATIC + ACC_FINAL, fieldName, "Z", null, null)); }); LoggerUtils.stdOut(String.format("Added %d fake throw-null sequences", counter.get())); }
methodNode.instructions.insert(insn, new InsnNode(ATHROW)); methodNode.instructions.insert(insn, new InsnNode(ACONST_NULL)); methodNode.instructions.set(insn, new JumpInsnNode(IFEQ, ((JumpInsnNode) insn).label)); leeway -= 7; counter.incrementAndGet();
public void process(ParserClassNode classNode, RuleMethod method) throws Exception { checkArgNotNull(classNode, "classNode"); checkArgNotNull(method, "method"); if (method.getNumberOfReturns() == 1) return; checkState(method.getNumberOfReturns() > 1); AbstractInsnNode current = method.instructions.getLast(); // find last return while (current.getOpcode() != ARETURN) { current = current.getPrevious(); } LabelNode lastReturnLabel = new LabelNode(); method.instructions.insertBefore(current, lastReturnLabel); // iterate backwards up to first instructions while ((current = current.getPrevious()) != null) { // replace returns with gotos if (current.getOpcode() == ARETURN) { JumpInsnNode gotoInstruction = new JumpInsnNode(GOTO, lastReturnLabel); method.instructions.set(current, gotoInstruction); current = gotoInstruction; } } }
insnList.set(newValue.insn, new OmittedInstruction(newValue.insn));