@Override public void execute(AbstractInsnNode insn, Interpreter<JvmValue> interpreter) throws AnalyzerException { if (insn.getType() == AbstractInsnNode.FRAME || insn.getType() == AbstractInsnNode.LINE || insn.getType() == AbstractInsnNode.LABEL) { return; } if (insn.getOpcode() == Opcodes.RETURN) { interpreter.returnOperation(insn, null, null); } else if (insn.getOpcode() == Opcodes.GOTO) { interpreter.unaryOperation(insn, null); } else if (insn.getOpcode() == RET) { throw new RuntimeException("not support yet!"); } else { super.execute(insn, interpreter); } } }
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 void cleanDebug(MethodNode mn) { for (AbstractInsnNode p = mn.instructions.getFirst(); p != null; ) { if (p.getType() == AbstractInsnNode.LINE) { AbstractInsnNode q = p.getNext(); mn.instructions.remove(p); p = q; } else { p = p.getNext(); } } mn.localVariables = null; }
if (p.getType() == AbstractInsnNode.LABEL) { stmts.add(getLabel((LabelNode) p));
edge.stack = null; do { int type = insn.getType(); if (type == FIELD_INSN) { convertFieldInsn((FieldInsnNode) insn);
private void initParentCount(int[] parentCount) { parentCount[0] = 1; for (AbstractInsnNode p = insnList.getFirst(); p != null; p = p.getNext()) { if (p.getType() == AbstractInsnNode.JUMP_INSN) { JumpInsnNode jump = (JumpInsnNode) p; parentCount[insnList.indexOf(jump.label)]++;
// Assuming you have loaded classNode for (MethodNode method : classNode.methods){ for (AbstractInsnNode ain : method.instructions.toArray()) { if (ain.getType() == AbstractInsnNode.FIELD_INSN) { FieldInsnNode fin = (FieldInsnNode) ain; //fin.name = Field name //fin.owner = ClassNode's name } } }
@Override public int getType() { return orgInsn.getType(); }
/** * Returns first instruction from given and following it that is not * {@link AbstractInsnNode#FRAME}, {@link AbstractInsnNode#LABEL}, * {@link AbstractInsnNode#LINE}. */ static AbstractInsnNode skipNonOpcodes(AbstractInsnNode cursor) { while (cursor != null && (cursor.getType() == AbstractInsnNode.FRAME || cursor.getType() == AbstractInsnNode.LABEL || cursor.getType() == AbstractInsnNode.LINE)) { cursor = cursor.getNext(); } return cursor; }
public static AbstractInsnNode getFirstInstruction(AbstractInsnNode insn) { for (AbstractInsnNode instruction = insn; instruction != null; instruction = instruction.getNext()) { if (instruction.getType() != AbstractInsnNode.LABEL && instruction.getType() != AbstractInsnNode.LINE) { return instruction; } } return null; }
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)); } }
public AbstractInsnNode getOrFindInstruction(AbstractInsnNode firstInsnToCheck, boolean reverseDirection) { for (AbstractInsnNode instruction = firstInsnToCheck; instruction != null; instruction = reverseDirection ? instruction.getPrevious() : instruction.getNext()) { if (instruction.getType() != AbstractInsnNode.LABEL && instruction.getType() != AbstractInsnNode.LINE) return instruction; } return null; }
static String getOpcodeName(final AbstractInsnNode insn) { final String op = OPCODE_TO_NAME.get(insn.getOpcode()); return INSNTYPE_TO_NAME.get(insn.getType()) + ": " + insn.getOpcode() + (op == null ? "" : " [" + OPCODE_TO_NAME.get(insn.getOpcode()) + "]"); }
private boolean hasLineNumber(final MethodNode methodNode) { for (AbstractInsnNode i = methodNode.instructions .getFirst(); i != null; i = i.getNext()) { if (AbstractInsnNode.LINE == i.getType()) { return true; } } return false; }
@SuppressWarnings({"SuspiciousMethodCalls"}) public void process(ParserClassNode classNode, RuleMethod method) throws Exception { checkArgNotNull(classNode, "classNode"); checkArgNotNull(method, "method"); AbstractInsnNode current = method.instructions.getFirst(); while (current != null) { AbstractInsnNode next = current.getNext(); if (current.getType() == AbstractInsnNode.LABEL && !method.getUsedLabels().contains(current)) { method.instructions.remove(current); } current = next; } }