org.objectweb.asm.tree.FrameNode Java Examples
The following examples show how to use
org.objectweb.asm.tree.FrameNode.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CodeBlock.java From grappa with Apache License 2.0 | 6 votes |
/** * adds a compressed frame to the stack * * @param stackArguments the argument types on the stack, represented as * "class path names" e.g java/lang/RuntimeException */ public CodeBlock frame_same(final Object... stackArguments) { final int type; switch (stackArguments.length) { case 0: type = Opcodes.F_SAME; break; case 1: type = Opcodes.F_SAME1; break; default: throw new IllegalArgumentException("same frame should have 0" + " or 1 arguments on stack"); } instructionList.add(new FrameNode(type, 0, null, stackArguments.length, stackArguments)); return this; }
Example #2
Source File: InsnEditDialogue.java From JByteMod-Beta with GNU General Public License v2.0 | 6 votes |
@Override protected void addSpecialInputs(Object obj, JPanel leftText, JPanel rightInput) { if (obj instanceof AbstractInsnNode) { AbstractInsnNode ain = (AbstractInsnNode) obj; String[] arr = opc.get(ain.getClass().getSimpleName()); if (arr != null) { leftText.add(new JLabel("Opcode: ")); JComboBox<String> opcode = new JComboBox<String>(arr); opcode.setSelectedItem(OpUtils.getOpcodeText(ain.getOpcode()).toLowerCase()); rightInput.add(wrap("opc", opcode)); } } if (obj instanceof FrameNode) { FrameNode fn = (FrameNode) obj; leftText.add(new JLabel("Local / Stack: ")); JButton edit = new JButton(JByteMod.res.getResource("edit")); edit.addActionListener(e -> { new JFrameList(fn.local, fn.stack).open(); }); rightInput.add(wrap("editframe", edit)); } }
Example #3
Source File: StackFramesRemover.java From bytecode-viewer with GNU General Public License v3.0 | 6 votes |
@Override public void execute(ArrayList<ClassNode> classNodeList) { AtomicInteger counter = new AtomicInteger(); PluginConsole frame = new PluginConsole("StackFrames Remover"); for (ClassNode cn : classNodeList) { for (MethodNode mn : cn.methods) { for (AbstractInsnNode insn : mn.instructions.toArray()) { if (insn instanceof FrameNode) { mn.instructions.remove(insn); counter.incrementAndGet(); } } } } frame.appendText(String.format("Removed %s stackframes.", counter)); frame.setVisible(true); }
Example #4
Source File: BeforeConstant.java From Mixin with MIT License | 5 votes |
@Override public boolean find(String desc, InsnList insns, Collection<AbstractInsnNode> nodes) { boolean found = false; this.log("BeforeConstant is searching for constants in method with descriptor {}", desc); ListIterator<AbstractInsnNode> iter = insns.iterator(); for (int ordinal = 0, last = 0; iter.hasNext();) { AbstractInsnNode insn = iter.next(); boolean matchesInsn = this.expand ? this.matchesConditionalInsn(last, insn) : this.matchesConstantInsn(insn); if (matchesInsn) { this.log(" BeforeConstant found a matching constant{} at ordinal {}", this.matchByType != null ? " TYPE" : " value", ordinal); if (this.ordinal == -1 || this.ordinal == ordinal) { this.log(" BeforeConstant found {}", Bytecode.describeNode(insn).trim()); nodes.add(insn); found = true; } ordinal++; } if (!(insn instanceof LabelNode) && !(insn instanceof FrameNode)) { last = insn.getOpcode(); } } return found; }
Example #5
Source File: ClassInfo.java From Mixin with MIT License | 5 votes |
private List<FrameData> gatherFrames(MethodNode method) { List<FrameData> frames = new ArrayList<FrameData>(); for (Iterator<AbstractInsnNode> iter = method.instructions.iterator(); iter.hasNext();) { AbstractInsnNode insn = iter.next(); if (insn instanceof FrameNode) { frames.add(new FrameData(method.instructions.indexOf(insn), (FrameNode)insn)); } } return frames; }
Example #6
Source File: CodeBlock.java From grappa with Apache License 2.0 | 5 votes |
public CodeBlock visitFrame(final int opcode, final int nrLocals, final Object[] localTypes, final int nrStackElements, final Object[] stackElements) { instructionList.add(new FrameNode(opcode, nrLocals, localTypes, nrStackElements, stackElements)); return this; }
Example #7
Source File: OpcodeFormatting.java From Cafebabe with GNU General Public License v3.0 | 5 votes |
public static String toString(AbstractInsnNode ain) { String s = getOpcodeText(ain.getOpcode()); switch (ain.getType()) { case AbstractInsnNode.FIELD_INSN: FieldInsnNode fin = (FieldInsnNode) ain; return s + " " + fin.owner + "#" + fin.name + " " + fin.desc; case AbstractInsnNode.METHOD_INSN: MethodInsnNode min = (MethodInsnNode) ain; return s + " " + min.owner + "#" + min.name + min.desc; case AbstractInsnNode.VAR_INSN: VarInsnNode vin = (VarInsnNode) ain; return s + " " + vin.var; case AbstractInsnNode.TYPE_INSN: TypeInsnNode tin = (TypeInsnNode) ain; return s + " " + tin.desc; case AbstractInsnNode.MULTIANEWARRAY_INSN: MultiANewArrayInsnNode mnin = (MultiANewArrayInsnNode) ain; return s + " " + mnin.dims + " " + mnin.desc; case AbstractInsnNode.JUMP_INSN: JumpInsnNode jin = (JumpInsnNode) ain; return s + " " + getIndex(jin.label); case AbstractInsnNode.LDC_INSN: LdcInsnNode ldc = (LdcInsnNode) ain; return s + " " + ldc.cst.toString(); case AbstractInsnNode.INT_INSN: return s + " " + getIntValue(ain); case AbstractInsnNode.IINC_INSN: IincInsnNode iinc = (IincInsnNode) ain; return s + " " + iinc.var + " +" + iinc.incr; case AbstractInsnNode.FRAME: FrameNode fn = (FrameNode) ain; return s + " " + getOpcodeText(fn.type) + " " + fn.local.size() + " " + fn.stack.size(); case AbstractInsnNode.LABEL: LabelNode ln = (LabelNode) ain; return s + " " + getIndex(ln); } return s; }
Example #8
Source File: OpUtils.java From JByteMod-Beta with GNU General Public License v2.0 | 5 votes |
public static String toString(AbstractInsnNode ain) { String s = getOpcodeText(ain.getOpcode()); switch (ain.getType()) { case AbstractInsnNode.FIELD_INSN: FieldInsnNode fin = (FieldInsnNode) ain; return s + " " + fin.owner + "#" + fin.name + " " + fin.desc; case AbstractInsnNode.METHOD_INSN: MethodInsnNode min = (MethodInsnNode) ain; return s + " " + min.owner + "#" + min.name + min.desc; case AbstractInsnNode.VAR_INSN: VarInsnNode vin = (VarInsnNode) ain; return s + " " + vin.var; case AbstractInsnNode.TYPE_INSN: TypeInsnNode tin = (TypeInsnNode) ain; return s + " " + tin.desc; case AbstractInsnNode.MULTIANEWARRAY_INSN: MultiANewArrayInsnNode mnin = (MultiANewArrayInsnNode) ain; return s + " " + mnin.dims + " " + mnin.desc; case AbstractInsnNode.JUMP_INSN: JumpInsnNode jin = (JumpInsnNode) ain; return s + " " + getIndex(jin.label); case AbstractInsnNode.LDC_INSN: LdcInsnNode ldc = (LdcInsnNode) ain; return s + " " + ldc.cst.toString(); case AbstractInsnNode.INT_INSN: return s + " " + getIntValue(ain); case AbstractInsnNode.IINC_INSN: IincInsnNode iinc = (IincInsnNode) ain; return s + " " + iinc.var + " +" + iinc.incr; case AbstractInsnNode.FRAME: FrameNode fn = (FrameNode) ain; return s + " " + getOpcodeText(fn.type) + " " + fn.local.size() + " " + fn.stack.size(); case AbstractInsnNode.LABEL: LabelNode ln = (LabelNode) ain; return s + " " + getIndex(ln); } return s; }
Example #9
Source File: InstructionSearcher.java From bytecode-viewer with GNU General Public License v3.0 | 5 votes |
public boolean search() { for (AbstractInsnNode ain : insns.toArray()) { if (ain instanceof LineNumberNode || ain instanceof FrameNode) continue; if (pattern.accept(ain)) { matches.add(pattern.getLastMatch()); pattern.resetMatch(); } } return size() != 0; }
Example #10
Source File: AsmPattern.java From ForgeHax with MIT License | 5 votes |
public InsnPattern test(AbstractInsnNode start) { return ASMHelper.findPattern( start, insnPredicates.size(), // isValidNode (node) -> !testFlag(node, FrameNode.class, IGNORE_FRAMES) && !testFlag(node, LabelNode.class, IGNORE_LABELS) && !testFlag(node, LineNumberNode.class, IGNORE_LINENUMBERS), // nodePredicate (found, node) -> insnPredicates.get(found).test(node), InsnPattern::new); }
Example #11
Source File: ASMUtilsTest.java From radon with GNU General Public License v3.0 | 5 votes |
@Test public void testIsInstruction() { Assert.assertFalse(ASMUtils.isInstruction( PowerMockito.mock(FrameNode.class))); Assert.assertFalse(ASMUtils.isInstruction( PowerMockito.mock(LabelNode.class))); Assert.assertFalse(ASMUtils.isInstruction( PowerMockito.mock(LineNumberNode.class))); Assert.assertTrue(ASMUtils.isInstruction( PowerMockito.mock(InsnNode.class))); }
Example #12
Source File: StackFrame.java From jphp with Apache License 2.0 | 5 votes |
public StackFrame(FrameNode node, LabelNode start, LabelNode end){ this.node = node; if (this.node.local == null) this.node.local = new ArrayList(); this.start = start; this.end = end; this.variables = new HashMap<Integer, LocalVariable>(); }
Example #13
Source File: OpUtils.java From zelixkiller with GNU General Public License v3.0 | 5 votes |
public static String toString(AbstractInsnNode ain) { String s = getOpcodeText(ain.getOpcode()); switch (ain.getType()) { case AbstractInsnNode.FIELD_INSN: FieldInsnNode fin = (FieldInsnNode) ain; return s + " " + fin.owner + "#" + fin.name + " " + fin.desc; case AbstractInsnNode.METHOD_INSN: MethodInsnNode min = (MethodInsnNode) ain; return s + " " + min.owner + "#" + min.name + min.desc; case AbstractInsnNode.VAR_INSN: VarInsnNode vin = (VarInsnNode) ain; return s + " " + vin.var; case AbstractInsnNode.TYPE_INSN: TypeInsnNode tin = (TypeInsnNode) ain; return s + " " + tin.desc; case AbstractInsnNode.JUMP_INSN: JumpInsnNode jin = (JumpInsnNode) ain; return s + " " + getIndex(jin.label); case AbstractInsnNode.LDC_INSN: LdcInsnNode ldc = (LdcInsnNode) ain; return s + " " + ldc.cst.toString(); case AbstractInsnNode.INT_INSN: return s + " " + getIntValue(ain); case AbstractInsnNode.IINC_INSN: IincInsnNode iinc = (IincInsnNode) ain; return s + " " + iinc.var + " +" + iinc.incr; case AbstractInsnNode.FRAME: FrameNode fn = (FrameNode) ain; return s + " " + getOpcodeText(fn.type) + " " + fn.local.size() + " " + fn.stack.size(); case AbstractInsnNode.LABEL: LabelNode ln = (LabelNode) ain; return s + " " + getIndex(ln); } return s; }
Example #14
Source File: StackFrame.java From zelixkiller with GNU General Public License v3.0 | 5 votes |
public FrameNode toFrame(){ List stack = new ArrayList(); for (int s = 0; s < this.getStackSize(); s++){ stack.add(this.getStack(s)); } List locals = new ArrayList(); for (int l = 0; l< this.locals; l++){ stack.add(this.getLocal(l)); } return new FrameNode(Opcodes.F_FULL, stack.size(),stack.toArray(), locals.size(), locals.toArray()); }
Example #15
Source File: FrameNodeSerializer.java From maple-ir with GNU General Public License v3.0 | 5 votes |
@Override public JsonElement serialize(FrameNode src, Type typeOfSrc, JsonSerializationContext context) { JsonObject object = new JsonObject(); object.add("opcode", context.serialize(src.getOpcode())); object.add("type", context.serialize(src.type)); object.add("local", context.serialize(src.local)); object.add("stack", context.serialize(src.stack)); return object; }
Example #16
Source File: FrameNodeSerializer.java From maple-ir with GNU General Public License v3.0 | 5 votes |
@Override public FrameNode deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObject = (JsonObject) json; int opcode; int type; List<?> local = null, stack = null; opcode = jsonObject.get("opcode").getAsInt(); type = jsonObject.get("type").getAsInt(); local = context.deserialize(jsonObject.get("local"), List.class); stack = context.deserialize(jsonObject.get("stack"), List.class); FrameNode node = new FrameNode(opcode, local.size(), local.toArray(), stack.size(), stack.toArray()); node.type = type; return node; }
Example #17
Source File: FeatureStructureClassGen.java From uima-uimaj with Apache License 2.0 | 4 votes |
private void makeTypedSwitchGetterSetter(TypeImpl featureRangeType) { List<FeatureImpl> features = type.getFeaturesSharingRange(featureRangeType); if (null == features || features.size() == 0) { return; } final int nbrFeats = features.size(); String rangeName = featureRangeType.isArray() ? ((TypeImplArray) featureRangeType).getComponentType().getName() + "Array" : featureRangeType.getShortName(); String javaDesc = featureRangeType.getJavaDescriptor(); // these two are for the method calls to the actual getters/setters String getterJavaDesc = "()" + javaDesc; String setterJavaDesc = "(" + javaDesc + ")V"; LabelNode[] labelNodesGet = new LabelNode[nbrFeats]; LabelNode[] labelNodesSet = new LabelNode[nbrFeats]; int[] keys = new int[nbrFeats]; for (int i = 0; i < nbrFeats; i++) { labelNodesGet[i] = new LabelNode(new Label()); labelNodesSet[i] = new LabelNode(new Label()); keys[i] = features.get(i).getOffsetForGenerics(); } Arrays.sort(keys); LabelNode defaultLabelNodeGet = new LabelNode(new Label()); LabelNode defaultLabelNodeSet = new LabelNode(new Label()); for (boolean isGet : GET_SET) { MethodNode mn = new MethodNode(ASM5, ACC_PUBLIC, "_" + (isGet ? "get" : "set") + rangeName, // _ avoids name collision with other getters/setters isGet ? ("(I)" + javaDesc) : ("(I" + javaDesc + ")V"), null, null); InsnList il = mn.instructions; il.add(new VarInsnNode(ILOAD, 1)); // load the switch int il.add(new LookupSwitchInsnNode(isGet ? defaultLabelNodeGet : defaultLabelNodeSet, keys, isGet ? labelNodesGet : labelNodesSet)); for (int i = 0; i < nbrFeats; i++) { final FeatureImpl fi = features.get(i); il.add((isGet ? labelNodesGet : labelNodesSet)[i]); il.add(new FrameNode(F_SAME, 0, null, 0, null)); il.add(new VarInsnNode(ALOAD, 0)); // load this if (isGet) { il.add(new MethodInsnNode(INVOKEVIRTUAL, typeJavaClassName, fi.getGetterSetterName(GET), getterJavaDesc, false)); il.add(new InsnNode(getReturnInst(fi))); } else { // setter - here we might insert code to do index corruption fixup il.add(new VarInsnNode(getLoadInst(fi), 2)); // load the value or value ref il.add(new MethodInsnNode(INVOKEVIRTUAL, typeJavaClassName, fi.getGetterSetterName(SET), setterJavaDesc, false)); il.add(new InsnNode(RETURN)); } } // default - throw il.add(isGet? defaultLabelNodeGet : defaultLabelNodeSet); il.add(new FrameNode(F_SAME, 0, null, 0, null)); il.add(new TypeInsnNode(NEW, CAS_RUN_EX)); il.add(new InsnNode(DUP)); il.add(new LdcInsnNode("INAPPROP_FEAT_X")); il.add(new MethodInsnNode(INVOKESPECIAL, CAS_RUN_EX, "<init>", "(Ljava/lang/String;)V", false)); il.add(new InsnNode(ATHROW)); boolean is2slotValue = featureRangeType.isLongOrDouble(); mn.maxStack = 3; // for throw mn.maxLocals = isGet ? 2 : (is2slotValue ? 4 : 3); cn.methods.add(mn); } }
Example #18
Source File: ControlFlowAnalyser.java From pitest with Apache License 2.0 | 4 votes |
private static boolean isInstruction(final AbstractInsnNode ins) { return !((ins instanceof LabelNode) || (ins instanceof FrameNode)); }
Example #19
Source File: InstructionMatchers.java From pitest with Apache License 2.0 | 4 votes |
/** * Matches nodes that do not represent an instruction or label */ public static Match<AbstractInsnNode> notAnInstruction() { return isA(LineNumberNode.class).or(isA(FrameNode.class)); }
Example #20
Source File: TryCatchBlockHandler.java From copper-engine with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") public void instrument(ClassNode cn) { // if (1 == 1) return; for (MethodNode m : (List<MethodNode>) cn.methods) { if (!m.exceptions.contains(INTERRUPT_EXCEPTION_NAME) || m.tryCatchBlocks.isEmpty()) { continue; } logger.debug("Instrument " + cn.name + "." + m.name); HashSet<Label> labels = new HashSet<Label>(); for (TryCatchBlockNode catchNode : (List<TryCatchBlockNode>) m.tryCatchBlocks) { if (labels.contains(catchNode.handler.getLabel())) { // some handlers share their handling code - check it out to prevent double instrumentation logger.debug("skipping node"); continue; } labels.add(catchNode.handler.getLabel()); LabelNode labelNode = catchNode.handler; AbstractInsnNode lineNumberNode = labelNode.getNext() instanceof LineNumberNode ? labelNode.getNext() : labelNode; FrameNode frameNode = (FrameNode) lineNumberNode.getNext(); VarInsnNode varInsnNode = (VarInsnNode) frameNode.getNext(); AbstractInsnNode insertPoint = varInsnNode; if (catchNode.type == null) { // this is probably a finally block; if (insertPoint.getNext() != null && insertPoint.getNext() instanceof LabelNode) { insertPoint = insertPoint.getNext(); } } LabelNode labelNode4ifeg = new LabelNode(); InsnList newCode = new InsnList(); newCode.add(new VarInsnNode(Opcodes.ALOAD, varInsnNode.var)); newCode.add(new TypeInsnNode(Opcodes.INSTANCEOF, INTERRUPT_EXCEPTION_NAME)); newCode.add(new JumpInsnNode(Opcodes.IFEQ, labelNode4ifeg)); newCode.add(new VarInsnNode(Opcodes.ALOAD, varInsnNode.var)); newCode.add(new TypeInsnNode(Opcodes.CHECKCAST, INTERRUPT_EXCEPTION_NAME)); newCode.add(new InsnNode(Opcodes.ATHROW)); newCode.add(labelNode4ifeg); m.instructions.insert(insertPoint, newCode); } } }
Example #21
Source File: ClassInfo.java From Mixin with MIT License | 4 votes |
FrameData(int index, FrameNode frameNode) { this.index = index; this.type = frameNode.type; this.locals = frameNode.local != null ? frameNode.local.size() : 0; this.size = Locals.computeFrameSize(frameNode); }
Example #22
Source File: InsnListPrinter.java From NOVA-Core with GNU Lesser General Public License v3.0 | 4 votes |
private void _visitInsn(AbstractInsnNode insn) { switch (insn.getType()) { case 0: visitInsn(insn.getOpcode()); break; case 1: IntInsnNode iinsn = (IntInsnNode) insn; visitIntInsn(iinsn.getOpcode(), iinsn.operand); break; case 2: VarInsnNode vinsn = (VarInsnNode) insn; visitVarInsn(vinsn.getOpcode(), vinsn.var); break; case 3: TypeInsnNode tinsn = (TypeInsnNode) insn; visitTypeInsn(tinsn.getOpcode(), tinsn.desc); break; case 4: FieldInsnNode finsn = (FieldInsnNode) insn; visitFieldInsn(finsn.getOpcode(), finsn.owner, finsn.name, finsn.desc); break; case 5: MethodInsnNode minsn = (MethodInsnNode) insn; visitMethodInsn(minsn.getOpcode(), minsn.owner, minsn.name, minsn.desc); break; case 6: InvokeDynamicInsnNode idinsn = (InvokeDynamicInsnNode) insn; visitInvokeDynamicInsn(idinsn.name, idinsn.desc, idinsn.bsm, idinsn.bsmArgs); break; case 7: JumpInsnNode jinsn = (JumpInsnNode) insn; visitJumpInsn(jinsn.getOpcode(), jinsn.label.getLabel()); break; case 8: LabelNode linsn = (LabelNode) insn; visitLabel(linsn.getLabel()); break; case 9: LdcInsnNode ldcinsn = (LdcInsnNode) insn; visitLdcInsn(ldcinsn.cst); break; case 10: IincInsnNode iiinsn = (IincInsnNode) insn; visitIincInsn(iiinsn.var, iiinsn.incr); break; case 11: TableSwitchInsnNode tsinsn = (TableSwitchInsnNode) insn; Label[] tslables = new Label[tsinsn.labels.size()]; for (int i = 0; i < tslables.length; i++) { tslables[i] = tsinsn.labels.get(i).getLabel(); } visitTableSwitchInsn(tsinsn.min, tsinsn.max, tsinsn.dflt.getLabel(), tslables); break; case 12: LookupSwitchInsnNode lsinsn = (LookupSwitchInsnNode) insn; Label[] lslables = new Label[lsinsn.labels.size()]; for (int i = 0; i < lslables.length; i++) { lslables[i] = lsinsn.labels.get(i).getLabel(); } int[] lskeys = new int[lsinsn.keys.size()]; for (int i = 0; i < lskeys.length; i++) { lskeys[i] = lsinsn.keys.get(i); } visitLookupSwitchInsn(lsinsn.dflt.getLabel(), lskeys, lslables); break; case 13: MultiANewArrayInsnNode ainsn = (MultiANewArrayInsnNode) insn; visitMultiANewArrayInsn(ainsn.desc, ainsn.dims); break; case 14: FrameNode fnode = (FrameNode) insn; switch (fnode.type) { case -1: case 0: visitFrame(fnode.type, fnode.local.size(), fnode.local.toArray(), fnode.stack.size(), fnode.stack.toArray()); break; case 1: visitFrame(fnode.type, fnode.local.size(), fnode.local.toArray(), 0, null); break; case 2: visitFrame(fnode.type, fnode.local.size(), null, 0, null); break; case 3: visitFrame(fnode.type, 0, null, 0, null); break; case 4: visitFrame(fnode.type, 0, null, 1, fnode.stack.toArray()); } break; case 15: LineNumberNode lnode = (LineNumberNode) insn; visitLineNumber(lnode.line, lnode.start.getLabel()); break; } }
Example #23
Source File: ControlFlowAnalyser.java From QuickTheories with Apache License 2.0 | 4 votes |
private static boolean isInstruction(final AbstractInsnNode ins) { return !((ins instanceof LabelNode) || (ins instanceof FrameNode)); }
Example #24
Source File: InsnListPrinter.java From NOVA-Core with GNU Lesser General Public License v3.0 | 4 votes |
@SuppressWarnings("deprecation") private void _visitInsn(AbstractInsnNode insn) { switch (insn.getType()) { case 0: visitInsn(insn.getOpcode()); break; case 1: IntInsnNode iinsn = (IntInsnNode) insn; visitIntInsn(iinsn.getOpcode(), iinsn.operand); break; case 2: VarInsnNode vinsn = (VarInsnNode) insn; visitVarInsn(vinsn.getOpcode(), vinsn.var); break; case 3: TypeInsnNode tinsn = (TypeInsnNode) insn; visitTypeInsn(tinsn.getOpcode(), tinsn.desc); break; case 4: FieldInsnNode finsn = (FieldInsnNode) insn; visitFieldInsn(finsn.getOpcode(), finsn.owner, finsn.name, finsn.desc); break; case 5: MethodInsnNode minsn = (MethodInsnNode) insn; visitMethodInsn(minsn.getOpcode(), minsn.owner, minsn.name, minsn.desc); break; case 6: InvokeDynamicInsnNode idinsn = (InvokeDynamicInsnNode) insn; visitInvokeDynamicInsn(idinsn.name, idinsn.desc, idinsn.bsm, idinsn.bsmArgs); break; case 7: JumpInsnNode jinsn = (JumpInsnNode) insn; visitJumpInsn(jinsn.getOpcode(), jinsn.label.getLabel()); break; case 8: LabelNode linsn = (LabelNode) insn; visitLabel(linsn.getLabel()); break; case 9: LdcInsnNode ldcinsn = (LdcInsnNode) insn; visitLdcInsn(ldcinsn.cst); break; case 10: IincInsnNode iiinsn = (IincInsnNode) insn; visitIincInsn(iiinsn.var, iiinsn.incr); break; case 11: TableSwitchInsnNode tsinsn = (TableSwitchInsnNode) insn; Label[] tslables = new Label[tsinsn.labels.size()]; for (int i = 0; i < tslables.length; i++) { tslables[i] = tsinsn.labels.get(i).getLabel(); } visitTableSwitchInsn(tsinsn.min, tsinsn.max, tsinsn.dflt.getLabel(), tslables); break; case 12: LookupSwitchInsnNode lsinsn = (LookupSwitchInsnNode) insn; Label[] lslables = new Label[lsinsn.labels.size()]; for (int i = 0; i < lslables.length; i++) { lslables[i] = lsinsn.labels.get(i).getLabel(); } int[] lskeys = new int[lsinsn.keys.size()]; for (int i = 0; i < lskeys.length; i++) { lskeys[i] = lsinsn.keys.get(i); } visitLookupSwitchInsn(lsinsn.dflt.getLabel(), lskeys, lslables); break; case 13: MultiANewArrayInsnNode ainsn = (MultiANewArrayInsnNode) insn; visitMultiANewArrayInsn(ainsn.desc, ainsn.dims); break; case 14: FrameNode fnode = (FrameNode) insn; switch (fnode.type) { case -1: case 0: visitFrame(fnode.type, fnode.local.size(), fnode.local.toArray(), fnode.stack.size(), fnode.stack.toArray()); break; case 1: visitFrame(fnode.type, fnode.local.size(), fnode.local.toArray(), 0, null); break; case 2: visitFrame(fnode.type, fnode.local.size(), null, 0, null); break; case 3: visitFrame(fnode.type, 0, null, 0, null); break; case 4: visitFrame(fnode.type, 0, null, 1, fnode.stack.toArray()); } break; case 15: LineNumberNode lnode = (LineNumberNode) insn; visitLineNumber(lnode.line, lnode.start.getLabel()); break; } }
Example #25
Source File: InsnListPrinter.java From NOVA-Core with GNU Lesser General Public License v3.0 | 4 votes |
@SuppressWarnings("deprecation") private void _visitInsn(AbstractInsnNode insn) { switch (insn.getType()) { case 0: visitInsn(insn.getOpcode()); break; case 1: IntInsnNode iinsn = (IntInsnNode) insn; visitIntInsn(iinsn.getOpcode(), iinsn.operand); break; case 2: VarInsnNode vinsn = (VarInsnNode) insn; visitVarInsn(vinsn.getOpcode(), vinsn.var); break; case 3: TypeInsnNode tinsn = (TypeInsnNode) insn; visitTypeInsn(tinsn.getOpcode(), tinsn.desc); break; case 4: FieldInsnNode finsn = (FieldInsnNode) insn; visitFieldInsn(finsn.getOpcode(), finsn.owner, finsn.name, finsn.desc); break; case 5: MethodInsnNode minsn = (MethodInsnNode) insn; visitMethodInsn(minsn.getOpcode(), minsn.owner, minsn.name, minsn.desc); break; case 6: InvokeDynamicInsnNode idinsn = (InvokeDynamicInsnNode) insn; visitInvokeDynamicInsn(idinsn.name, idinsn.desc, idinsn.bsm, idinsn.bsmArgs); break; case 7: JumpInsnNode jinsn = (JumpInsnNode) insn; visitJumpInsn(jinsn.getOpcode(), jinsn.label.getLabel()); break; case 8: LabelNode linsn = (LabelNode) insn; visitLabel(linsn.getLabel()); break; case 9: LdcInsnNode ldcinsn = (LdcInsnNode) insn; visitLdcInsn(ldcinsn.cst); break; case 10: IincInsnNode iiinsn = (IincInsnNode) insn; visitIincInsn(iiinsn.var, iiinsn.incr); break; case 11: TableSwitchInsnNode tsinsn = (TableSwitchInsnNode) insn; Label[] tslables = new Label[tsinsn.labels.size()]; for (int i = 0; i < tslables.length; i++) { tslables[i] = tsinsn.labels.get(i).getLabel(); } visitTableSwitchInsn(tsinsn.min, tsinsn.max, tsinsn.dflt.getLabel(), tslables); break; case 12: LookupSwitchInsnNode lsinsn = (LookupSwitchInsnNode) insn; Label[] lslables = new Label[lsinsn.labels.size()]; for (int i = 0; i < lslables.length; i++) { lslables[i] = lsinsn.labels.get(i).getLabel(); } int[] lskeys = new int[lsinsn.keys.size()]; for (int i = 0; i < lskeys.length; i++) { lskeys[i] = lsinsn.keys.get(i); } visitLookupSwitchInsn(lsinsn.dflt.getLabel(), lskeys, lslables); break; case 13: MultiANewArrayInsnNode ainsn = (MultiANewArrayInsnNode) insn; visitMultiANewArrayInsn(ainsn.desc, ainsn.dims); break; case 14: FrameNode fnode = (FrameNode) insn; switch (fnode.type) { case -1: case 0: visitFrame(fnode.type, fnode.local.size(), fnode.local.toArray(), fnode.stack.size(), fnode.stack.toArray()); break; case 1: visitFrame(fnode.type, fnode.local.size(), fnode.local.toArray(), 0, null); break; case 2: visitFrame(fnode.type, fnode.local.size(), null, 0, null); break; case 3: visitFrame(fnode.type, 0, null, 0, null); break; case 4: visitFrame(fnode.type, 0, null, 1, fnode.stack.toArray()); } break; case 15: LineNumberNode lnode = (LineNumberNode) insn; visitLineNumber(lnode.line, lnode.start.getLabel()); break; } }
Example #26
Source File: ASMUtils.java From rembulan with Apache License 2.0 | 4 votes |
public static FrameNode frameSame1(Class clazz) { return new FrameNode(F_SAME1, 0, null, 1, new Object[] { Type.getInternalName(clazz) }); }
Example #27
Source File: ASMUtils.java From rembulan with Apache License 2.0 | 4 votes |
public static FrameNode frameSame() { return new FrameNode(F_SAME, 0, null, 0, null); }
Example #28
Source File: InstrUtils.java From JByteMod-Beta with GNU General Public License v2.0 | 4 votes |
public static String toEasyString(AbstractInsnNode ain) { String opc = OpUtils.getOpcodeText(ain.getOpcode()).toLowerCase() + " "; switch (ain.getType()) { case AbstractInsnNode.LABEL: opc = "label " + OpUtils.getLabelIndex((LabelNode) ain); break; case AbstractInsnNode.LINE: opc = "line " + ((LineNumberNode) ain).line; break; case AbstractInsnNode.FIELD_INSN: FieldInsnNode fin = (FieldInsnNode) ain; opc += getDisplayType(fin.desc, false) + " " + getDisplayClassEasy(fin.owner) + "." + fin.name; break; case AbstractInsnNode.METHOD_INSN: MethodInsnNode min = (MethodInsnNode) ain; opc += getDisplayType(min.desc.split("\\)")[1], false) + " " + getDisplayClassEasy(min.owner) + "." + min.name + "(" + getDisplayArgsEasy(min.desc) + ")"; break; case AbstractInsnNode.VAR_INSN: VarInsnNode vin = (VarInsnNode) ain; opc += vin.var; break; case AbstractInsnNode.MULTIANEWARRAY_INSN: MultiANewArrayInsnNode mnin = (MultiANewArrayInsnNode) ain; opc += mnin.dims + " " + getDisplayType(mnin.desc, false); break; case AbstractInsnNode.TYPE_INSN: TypeInsnNode tin = (TypeInsnNode) ain; String esc = tin.desc; if (esc.endsWith(";") && esc.startsWith("L")) { opc += esc; } else { opc += getDisplayClassEasy(esc); } break; case AbstractInsnNode.JUMP_INSN: JumpInsnNode jin = (JumpInsnNode) ain; opc += OpUtils.getLabelIndex(jin.label); break; case AbstractInsnNode.LDC_INSN: LdcInsnNode ldc = (LdcInsnNode) ain; opc += ldc.cst.getClass().getSimpleName() + " "; if (ldc.cst instanceof String) opc += "\"" + ldc.cst.toString() + "\""; else { opc += ldc.cst.toString(); } break; case AbstractInsnNode.INT_INSN: opc += OpUtils.getIntValue(ain); break; case AbstractInsnNode.IINC_INSN: IincInsnNode iinc = (IincInsnNode) ain; opc += iinc.var + " " + iinc.incr; break; case AbstractInsnNode.FRAME: FrameNode fn = (FrameNode) ain; opc = OpUtils.getOpcodeText(fn.type).toLowerCase() + " " + fn.local.size() + " " + fn.stack.size(); break; case AbstractInsnNode.TABLESWITCH_INSN: TableSwitchInsnNode tsin = (TableSwitchInsnNode) ain; if (tsin.dflt != null) { opc += "L" + OpUtils.getLabelIndex(tsin.dflt); } if (tsin.labels.size() < 20) { for (LabelNode l : tsin.labels) { opc += " " + "L" + OpUtils.getLabelIndex(l); } } else { opc += " " + tsin.labels.size() + " cases"; } break; case AbstractInsnNode.INVOKE_DYNAMIC_INSN: InvokeDynamicInsnNode idin = (InvokeDynamicInsnNode) ain; opc += idin.name + " " + idin.desc; break; } return opc; }
Example #29
Source File: InstrUtils.java From JByteMod-Beta with GNU General Public License v2.0 | 4 votes |
public static String toString(AbstractInsnNode ain) { String opc = TextUtils.toBold(OpUtils.getOpcodeText(ain.getOpcode()).toLowerCase()) + " "; switch (ain.getType()) { case AbstractInsnNode.LABEL: opc = TextUtils.toLight("label " + OpUtils.getLabelIndex((LabelNode) ain)); break; case AbstractInsnNode.LINE: opc = TextUtils.toLight("line " + ((LineNumberNode) ain).line); break; case AbstractInsnNode.FIELD_INSN: FieldInsnNode fin = (FieldInsnNode) ain; opc += getDisplayType(TextUtils.escape(fin.desc), true) + " " + getDisplayClassRed(TextUtils.escape(fin.owner)) + "." + fin.name; break; case AbstractInsnNode.METHOD_INSN: MethodInsnNode min = (MethodInsnNode) ain; if (min.desc.contains(")")) { opc += getDisplayType(min.desc.split("\\)")[1], true); } else { opc += min.desc; } opc += " " + getDisplayClassRed(TextUtils.escape(min.owner)) + "." + TextUtils.escape(min.name) + "(" + getDisplayArgs(TextUtils.escape(min.desc)) + ")"; break; case AbstractInsnNode.VAR_INSN: VarInsnNode vin = (VarInsnNode) ain; opc += vin.var; break; case AbstractInsnNode.TYPE_INSN: TypeInsnNode tin = (TypeInsnNode) ain; String esc = TextUtils.escape(tin.desc); if (esc.endsWith(";") && esc.startsWith("L")) { opc += TextUtils.addTag(esc, "font color=" + primColor.getString()); } else { opc += getDisplayClass(esc); } break; case AbstractInsnNode.MULTIANEWARRAY_INSN: MultiANewArrayInsnNode mnin = (MultiANewArrayInsnNode) ain; opc += mnin.dims + " " + getDisplayType(TextUtils.escape(mnin.desc), true); break; case AbstractInsnNode.JUMP_INSN: JumpInsnNode jin = (JumpInsnNode) ain; opc += OpUtils.getLabelIndex(jin.label); break; case AbstractInsnNode.LDC_INSN: LdcInsnNode ldc = (LdcInsnNode) ain; opc += TextUtils.addTag(ldc.cst.getClass().getSimpleName(), "font color=" + primColor.getString()) + " "; if (ldc.cst instanceof String) opc += TextUtils.addTag("\"" + TextUtils.escape(ldc.cst.toString()) + "\"", "font color=#559955"); else { opc += ldc.cst.toString(); } break; case AbstractInsnNode.INT_INSN: opc += OpUtils.getIntValue(ain); break; case AbstractInsnNode.IINC_INSN: IincInsnNode iinc = (IincInsnNode) ain; opc += iinc.var + " " + iinc.incr; break; case AbstractInsnNode.FRAME: FrameNode fn = (FrameNode) ain; opc = TextUtils .toLight(OpUtils.getFrameType(fn.type).toLowerCase() + " " + fn.local.size() + " " + fn.stack.size()); break; case AbstractInsnNode.TABLESWITCH_INSN: TableSwitchInsnNode tsin = (TableSwitchInsnNode) ain; if (tsin.dflt != null) { opc += TextUtils.addTag("L" + OpUtils.getLabelIndex(tsin.dflt), "font color=" + secColor.getString()); } if (tsin.labels.size() < 20) { for (LabelNode l : tsin.labels) { opc += " " + TextUtils.addTag("L" + OpUtils.getLabelIndex(l), "font color=" + primColor.getString()); } } else { opc += " " + TextUtils.addTag(tsin.labels.size() + " cases", "font color=" + primColor.getString()); } break; case AbstractInsnNode.INVOKE_DYNAMIC_INSN: InvokeDynamicInsnNode idin = (InvokeDynamicInsnNode) ain; Object[] arr = idin.bsmArgs; if (arr.length > 1) { Object o = arr[1]; if (o instanceof Handle) { Handle h = (Handle) o; opc += getDisplayType(h.getDesc().split("\\)")[1], true) + " " + getDisplayClassRed(TextUtils.escape(h.getOwner())) + "." + TextUtils.escape(h.getName()) + "(" + getDisplayArgs(TextUtils.escape(h.getDesc())) + ")"; } } else { opc += TextUtils.addTag(TextUtils.escape(idin.name), "font color=" + primColor.getString()) + " " + TextUtils.escape(idin.desc); } break; } return opc; }
Example #30
Source File: ControlFlowGraph.java From javaide with GNU General Public License v3.0 | 4 votes |
/** * Represents this instruction as a string, for debugging purposes * * @param includeAdjacent whether it should include a display of * adjacent nodes as well * @return a string representation */ @NonNull public String toString(boolean includeAdjacent) { StringBuilder sb = new StringBuilder(100); sb.append(getId(instruction)); sb.append(':'); if (instruction instanceof LabelNode) { //LabelNode l = (LabelNode) instruction; //sb.append('L' + l.getLabel().getOffset() + ":"); //sb.append('L' + l.getLabel().info + ":"); sb.append("LABEL"); } else if (instruction instanceof LineNumberNode) { sb.append("LINENUMBER ").append(((LineNumberNode)instruction).line); } else if (instruction instanceof FrameNode) { sb.append("FRAME"); } else { int opcode = instruction.getOpcode(); String opcodeName = getOpcodeName(opcode); sb.append(opcodeName); if (instruction.getType() == AbstractInsnNode.METHOD_INSN) { sb.append('(').append(((MethodInsnNode)instruction).name).append(')'); } } if (includeAdjacent) { if (successors != null && !successors.isEmpty()) { sb.append(" Next:"); for (Node successor : successors) { sb.append(' '); sb.append(successor.toString(false)); } } if (exceptions != null && !exceptions.isEmpty()) { sb.append(" Exceptions:"); for (Node exception : exceptions) { sb.append(' '); sb.append(exception.toString(false)); } } sb.append('\n'); } return sb.toString(); }