public AbstractInsnNode getInstruction(int pos) { return (AbstractInsnNode) flow.instructions.get(pos); }
for (int i = ex.nextSetBit(0); i >= 0; i = ex.nextSetBit(i + 1)) { mergeEx(frame, i); stack.push(insnList.get(i));
InsnListIterator(final int index) { if (index == size()) { nextInsn = null; previousInsn = getLast(); } else { nextInsn = get(index); previousInsn = nextInsn.previousInsn; } }
@SuppressWarnings({"rawtypes", "unchecked"}) public void forEach() { for (int i = 0; i < instructions.size(); i++) { AbstractInsnNode it = instructions.get(i); for (Entry<Predicate, Consumer> consumer : consumers.entrySet()) { if (consumer.getKey().test(it)) { consumer.getValue().accept(new Insn<>(method, it)); } } } }
public byte[] transformCode(byte[] b1, String className) throws IOException { ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); ClassReader cr = new ClassReader(b1); ClassNode classNode = new ClassNode(); Map<String, Boolean> methodInstructionTypeMap = new HashMap<>(); cr.accept(classNode, 0); final List<MethodNode> methods = classNode.methods; for (MethodNode m : methods) { InsnList inList = m.instructions; boolean isMethodInvoke = false; for (int i = 0; i < inList.size(); i++) { if (inList.get(i).getType() == AbstractInsnNode.METHOD_INSN) { isMethodInvoke = true; } } methodInstructionTypeMap.put(m.name + m.desc, isMethodInvoke); } InsertMethodBodyAdapter insertMethodBodyAdapter = new InsertMethodBodyAdapter(cw, className, methodInstructionTypeMap); cr.accept(insertMethodBodyAdapter, ClassReader.EXPAND_FRAMES); return cw.toByteArray(); }
private int findMethodCall(InsnList insns, LabelNode label) { boolean foundLabel = false; for (int i = 0; i < insns.size(); i++) { AbstractInsnNode n = insns.get(i); if (!foundLabel && n == label) { foundLabel = true; } else if (foundLabel && n.getOpcode() == Opcodes.INVOKEDYNAMIC) { return i; } } return -1; }
@Override public void visitMethodInsn(int opcode, String owner, String name, String desc,boolean itf) { super.visitMethodInsn(opcode, owner, name, desc, itf); // The only reason for adding to pausableMethods is to create a BB for pausable // method call sites. If the class is already woven, we don't need this // functionality. if (!classFlow.isWoven) { int methodStatus = detector.getPausableStatus(owner, name, desc); if (methodStatus == Detector.PAUSABLE_METHOD_FOUND) { MethodInsnNode min = (MethodInsnNode)instructions.get(instructions.size()-1); pausableMethods.add(min); } } }
String format = "%05d %-" + (method.maxStack + method.maxLocals + 6) + "s|%s"; for (int j = 0; j < method.instructions.size(); ++j) { method.instructions.get(j).accept(mv);
private void prepare(MethodNode method) { InsnList instructions = method.instructions; minLocal = 0; if ((method.access & Opcodes.ACC_STATIC) != 0) { minLocal = 1; } labelIndexes = new HashMap<>(); lineNumbers = new HashMap<>(); for (int i = 0; i < instructions.size(); ++i) { AbstractInsnNode node = instructions.get(i); if (node instanceof LabelNode) { labelIndexes.put(((LabelNode) node).getLabel(), i); } if (node instanceof LineNumberNode) { LineNumberNode lineNumberNode = (LineNumberNode) node; lineNumbers.put(lineNumberNode.start.getLabel(), lineNumberNode.line); } } for (LocalVariableNode localVar : method.localVariables) { int location = labelIndexes.get(localVar.start.getLabel()); localVariableMap.computeIfAbsent(location, k -> new ArrayList<>()).add(localVar); } targetInstructions = new ArrayList<>(instructions.size()); targetInstructions.addAll(Collections.nCopies(instructions.size(), null)); basicBlocks.addAll(Collections.nCopies(instructions.size(), null)); stackBefore = new StackFrame[instructions.size()]; stackAfter = new StackFrame[instructions.size()]; }
AbstractInsnNode insnNode = methodNode.instructions.get(i); if (insnNode instanceof LabelNode) { Label label = ((LabelNode) insnNode).getLabel();
AbstractInsnNode in = mn.instructions.get(j); if (in.getType() != AbstractInsnNode.LINE && in.getType() != AbstractInsnNode.FRAME) { if(in.getType()==AbstractInsnNode.LABEL){
Object insn = method.instructions.get(j); if (insn instanceof AbstractInsnNode) { ((AbstractInsnNode) insn).accept(mv);
flow.setLabel(newPos, l); extraInsns.add(instructions.get(i).clone(labelCopyMap));
static void printAnalyzerResult(MethodNode method, Analyzer a, final PrintWriter pw) throws IllegalArgumentException, IllegalAccessException { Frame[] frames = a.getFrames(); Textifier t = new Textifier(); TraceMethodVisitor mv = new TraceMethodVisitor(t); String format = "%05d %-" + (method.maxStack + method.maxLocals + 6) + "s|%s"; for (int j = 0; j < method.instructions.size(); ++j) { method.instructions.get(j).accept(mv); StringBuffer s = new StringBuffer(); Frame f = frames[j]; if (f == null) { s.append('?'); } else { for (int k = 0; k < f.getLocals(); ++k) { s.append(getShortName(f.getLocal(k).toString())); } s.append(" : "); for (int k = 0; k < f.getStackSize(); ++k) { s.append(getShortName(f.getStack(k).toString())); } } pw.printf(format, j, s, buf.get(t)); // mv.text.get(j)); } for (int j = 0; j < method.tryCatchBlocks.size(); ++j) { ((TryCatchBlockNode) method.tryCatchBlocks.get(j)).accept(mv); pw.print(" " + buf.get(t)); } pw.println(); pw.flush(); }
stmts.addAll(preEmit); for (int i = 0; i < insnList.size(); i++) { AbstractInsnNode p = insnList.get(i); if (access.get(i)) { List<Stmt> es = emitStmts[i]; JvmFrame frame = frames[i]; if (parentCount[i] > 1 && frame != null && access.get(i)) { AbstractInsnNode p = insnList.get(i); LabelStmt labelStmt = getLabel((LabelNode) p); List<AssignStmt> phis = new ArrayList<>();
public void restoreNonInstructionNodes() { InsnList newinsns = new InsnList(); int sz = instructions.size(); for (int i = 0; i < sz; i++) { LabelNode l = getLabelAt(i); if (l != null) { newinsns.add(l); } LineNumberNode ln = lineNumberNodes.get(i); if (ln != null) { newinsns.add(ln); } AbstractInsnNode ain = instructions.get(i); newinsns.add(ain); } LabelNode l = getLabelAt(sz); if (l != null) { newinsns.add(l); } LineNumberNode ln = lineNumberNodes.get(sz); if (ln != null) { newinsns.add(ln); } super.instructions = newinsns; }
instructions.get(index).accept(methodVisitor); stackAfter[index] = stack; flushInstructions();
int count = 0; for (int i = 0; i < insns.size(); i++) { AbstractInsnNode n = insns.get(i);
public void newControlFlowEdge(int instructionIndex, int successorIndex) { AbstractInsnNode fromInsn = method.instructions.get(instructionIndex); AbstractInsnNode toInsn = method.instructions.get(successorIndex); if (fromInsn.getType() == AbstractInsnNode.LABEL || fromInsn.getType() == AbstractInsnNode.JUMP_INSN || toInsn.getType() == AbstractInsnNode.LABEL || toInsn.getType() == AbstractInsnNode.JUMP_INSN) { additionalEdges.add(new Edge(fromInsn, toInsn)); } }
/** * Finds the line number closest to the given method declaration * * @param node the method node to get a line number for * @return the closest line number, or -1 if not known */ public static int findLineNumber(@NonNull MethodNode node) { if (node.instructions != null && node.instructions.size() > 0) { return findLineNumber(node.instructions.get(0)); } return -1; }