org.objectweb.asm.tree.InsnList.insertBefore()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(130)

本文整理了Java中org.objectweb.asm.tree.InsnList.insertBefore()方法的一些代码示例,展示了InsnList.insertBefore()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。InsnList.insertBefore()方法的具体详情如下:
包路径:org.objectweb.asm.tree.InsnList
类名称:InsnList
方法名:insertBefore

InsnList.insertBefore介绍

[英]Inserts the given instruction before the specified instruction.
[中]在指定指令之前插入给定指令。

代码示例

代码示例来源:origin: iLexiconn/LLibrary

@Override
  public void apply(MethodPatcher.PatchData patch, MethodNode methodNode, AbstractInsnNode location, Method method) {
    methodNode.instructions.insertBefore(location, method.insnList);
  }
},

代码示例来源:origin: org.parboiled/parboiled-java

private void insert(AbstractInsnNode instruction) {
  instructions.insertBefore(current, instruction);
}

代码示例来源:origin: EvoSuite/evosuite

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));
}

代码示例来源:origin: org.parboiled/parboiled-java

private void generateMarkerCall(InsnList instructions, AbstractInsnNode ret, String call) {
  instructions.insertBefore(ret, new MethodInsnNode(INVOKEINTERFACE, Types.RULE.getInternalName(), call,
      "()" + Types.RULE.getDescriptor(), true));
}

代码示例来源:origin: iLexiconn/LLibrary

@Override
  public void apply(MethodPatcher.PatchData patch, MethodNode methodNode, AbstractInsnNode location, Method method) {
    methodNode.instructions.insertBefore(location, method.insnList);
    methodNode.instructions.remove(location);
  }
};

代码示例来源:origin: EvoSuite/evosuite

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)));
}

代码示例来源:origin: ValkyrienWarfare/Valkyrien-Warfare-Revamped

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);
  });
}

代码示例来源:origin: ValkyrienWarfare/Valkyrien-Warfare-Revamped

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());
    }
  });
}

代码示例来源:origin: ItzSomebody/Radon

@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()));
}

代码示例来源:origin: org.ow2.asm/asm-tree

@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;
}

代码示例来源:origin: org.ow2.asm/asm-debug-all

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;
}

代码示例来源:origin: com.github.bingoohuang/blackcat-instrument

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;
    }
  }
}

代码示例来源:origin: brutusin/instrumentation

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;
    }
  }
}

代码示例来源:origin: brutusin/instrumentation

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());
    }
  }
}

代码示例来源:origin: com.github.bingoohuang/blackcat-instrument

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());
    }
  }
}

代码示例来源:origin: org.parboiled/parboiled-java

private void insert(AbstractInsnNode insn) {
  method.instructions.insertBefore(group.getRoot().getInstruction(), insn);
}

代码示例来源:origin: EvoSuite/evosuite

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));
}

代码示例来源:origin: CalebWhiting/java-asm-obfuscator

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));
    }
  }
}

代码示例来源:origin: EvoSuite/evosuite

@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;
  }
}

代码示例来源:origin: Vazkii/Quark

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;
      })));
}

相关文章