Java Code Examples for org.objectweb.asm.Opcodes#TABLESWITCH

The following examples show how to use org.objectweb.asm.Opcodes#TABLESWITCH . 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: StackHelper.java    From zelixkiller with GNU General Public License v3.0 6 votes vote down vote up
public InsnValue getSwitchValue(AbstractInsnNode insn, InsnValue value) {
	if (value.getValue() == null) {
		return InsnValue.intValue(-1);
	}
	int i = (int) value.getValue();
	switch (insn.getOpcode()) {
	case Opcodes.TABLESWITCH:
		TableSwitchInsnNode tsin = (TableSwitchInsnNode) insn;
		if (i < tsin.min || i > tsin.max) {
			return InsnValue.intValue(-1);
		}
		return InsnValue.intValue(i);
	case Opcodes.LOOKUPSWITCH:
		LookupSwitchInsnNode lsin = (LookupSwitchInsnNode) insn;
		for (Object o : lsin.keys) {
			if (o.equals(i)) {
				return InsnValue.intValue(i);
			}
		}
		return InsnValue.intValue(-1);
	}

	return null;
}
 
Example 2
Source File: CaseAdapter.java    From jumbune with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * <p>
 * This method finds Switch block in a method and processes it
 * </p>.
 *
 * @param scanStartIndex Start index for the scan
 * @param scanEndIndex End index for the scan
 */
private void instrumentswitchBlock(int scanStartIndex,
		int scanEndIndex) {
	for (scanIndexForswitch = scanStartIndex; scanIndexForswitch <= scanEndIndex; scanIndexForswitch++) {
		AbstractInsnNode currentInsnNode = insnArr[scanIndexForswitch];

		if (currentInsnNode instanceof TableSwitchInsnNode
				&& Opcodes.TABLESWITCH == currentInsnNode.getOpcode()) {
			processTableSwitchBlock((TableSwitchInsnNode) currentInsnNode);
		} else if (currentInsnNode instanceof LookupSwitchInsnNode
				&& Opcodes.LOOKUPSWITCH == currentInsnNode.getOpcode()) {
			processLookupSwitchBlock((LookupSwitchInsnNode) currentInsnNode);
		}

	}
}
 
Example 3
Source File: BlockBuildingMethodVisitorTest.java    From AVM with MIT License 5 votes vote down vote up
@Test
public void test_checkTableSwitch() throws Exception {
    List<BasicBlock> hashCodeBlocks = METHOD_BLOCKS.get("checkTableSwitch(I)I");
    int[][] expectedHashCodeBlocks = new int[][]{
            {Opcodes.ICONST_5, Opcodes.ISTORE, Opcodes.ILOAD, Opcodes.TABLESWITCH},
            {Opcodes.ICONST_1, Opcodes.ISTORE, Opcodes.GOTO},
            {Opcodes.ICONST_2, Opcodes.ISTORE, Opcodes.GOTO},
            {Opcodes.ICONST_3, Opcodes.ISTORE, Opcodes.GOTO},
            {Opcodes.ICONST_0, Opcodes.ISTORE},
            {Opcodes.ILOAD, Opcodes.IRETURN},
    };
    int[][] expectedSwitchCounts = new int[][]{
        {4},
        {},
        {},
        {},
        {},
        {},
    };
    
    // Verify the shape of the blocks.
    boolean didMatch = compareBlocks(expectedHashCodeBlocks, hashCodeBlocks);
    Assert.assertTrue(didMatch);
    
    // Verify the switch option value.
    didMatch = compareSwitches(expectedSwitchCounts, hashCodeBlocks);
    Assert.assertTrue(didMatch);
}
 
Example 4
Source File: SAXCodeAdapter.java    From JByteMod-Beta with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final void visitTableSwitchInsn(final int min, final int max, final Label dflt, final Label... labels) {
  AttributesImpl attrs = new AttributesImpl();
  attrs.addAttribute("", "min", "min", "", Integer.toString(min));
  attrs.addAttribute("", "max", "max", "", Integer.toString(max));
  attrs.addAttribute("", "dflt", "dflt", "", getLabel(dflt));
  String o = Printer.OPCODES[Opcodes.TABLESWITCH];
  sa.addStart(o, attrs);
  for (int i = 0; i < labels.length; i++) {
    AttributesImpl att2 = new AttributesImpl();
    att2.addAttribute("", "name", "name", "", getLabel(labels[i]));
    sa.addElement("label", att2);
  }
  sa.addEnd(o);
}
 
Example 5
Source File: SwitchInstruction.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public SwitchInstruction(Label dflt, int[] keys, Label[] labels) {
    super(Opcodes.TABLESWITCH);
    this.dflt = dflt;
    this.keys = keys;
    this.labels = labels;
    for(int iter = 0 ; iter < keys.length ; iter++) {
        LabelInstruction.labelIsUsed(labels[iter]);
    }
    LabelInstruction.labelIsUsed(dflt);
}
 
Example 6
Source File: TableSwitchInsnNode.java    From JByteMod-Beta with GNU General Public License v2.0 4 votes vote down vote up
public TableSwitchInsnNode() {
  super(Opcodes.TABLESWITCH);
  labels = new ArrayList<>();
}
 
Example 7
Source File: TableSwitchInsnNode.java    From Cafebabe with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Constructs a new {@link TableSwitchInsnNode}.
 *
 * @param min
 *          the minimum key value.
 * @param max
 *          the maximum key value.
 * @param dflt
 *          beginning of the default handler block.
 * @param labels
 *          beginnings of the handler blocks. {@code labels[i]} is the beginning of the handler block for the {@code min + i} key.
 */
public TableSwitchInsnNode(final int min, final int max, final LabelNode dflt, final LabelNode... labels) {
	super(Opcodes.TABLESWITCH);
	this.min = min;
	this.max = max;
	this.dflt = dflt;
	this.labels = Util.asArrayList(labels);
}
 
Example 8
Source File: TableSwitchInsnNode.java    From Concurnas with MIT License 3 votes vote down vote up
/**
 * Constructs a new {@link TableSwitchInsnNode}.
 *
 * @param min the minimum key value.
 * @param max the maximum key value.
 * @param dflt beginning of the default handler block.
 * @param labels beginnings of the handler blocks. {@code labels[i]} is the beginning of the
 *     handler block for the {@code min + i} key.
 */
public TableSwitchInsnNode(
    final int min, final int max, final LabelNode dflt, final LabelNode... labels) {
  super(Opcodes.TABLESWITCH);
  this.min = min;
  this.max = max;
  this.dflt = dflt;
  this.labels = Util.asArrayList(labels);
}
 
Example 9
Source File: TableSwitchInsnNode.java    From JByteMod-Beta with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Constructs a new {@link TableSwitchInsnNode}.
 * 
 * @param min
 *          the minimum key value.
 * @param max
 *          the maximum key value.
 * @param dflt
 *          beginning of the default handler block.
 * @param labels
 *          beginnings of the handler blocks. <tt>labels[i]</tt> is the
 *          beginning of the handler block for the <tt>min + i</tt> key.
 */
public TableSwitchInsnNode(final int min, final int max, final LabelNode dflt, final LabelNode... labels) {
  super(Opcodes.TABLESWITCH);
  this.min = min;
  this.max = max;
  this.dflt = dflt;
  this.labels = new ArrayList<LabelNode>();
  if (labels != null) {
    this.labels.addAll(Arrays.asList(labels));
  }
}
 
Example 10
Source File: TableSwitchInsnNode.java    From JReFrameworker with MIT License 3 votes vote down vote up
/**
 * Constructs a new {@link TableSwitchInsnNode}.
 *
 * @param min the minimum key value.
 * @param max the maximum key value.
 * @param dflt beginning of the default handler block.
 * @param labels beginnings of the handler blocks. {@code labels[i]} is the beginning of the
 *     handler block for the {@code min + i} key.
 */
public TableSwitchInsnNode(
    final int min, final int max, final LabelNode dflt, final LabelNode... labels) {
  super(Opcodes.TABLESWITCH);
  this.min = min;
  this.max = max;
  this.dflt = dflt;
  this.labels = Util.asArrayList(labels);
}
 
Example 11
Source File: TableSwitchInsnNode.java    From JReFrameworker with MIT License 3 votes vote down vote up
/**
 * Constructs a new {@link TableSwitchInsnNode}.
 *
 * @param min the minimum key value.
 * @param max the maximum key value.
 * @param dflt beginning of the default handler block.
 * @param labels beginnings of the handler blocks. {@code labels[i]} is the beginning of the
 *     handler block for the {@code min + i} key.
 */
public TableSwitchInsnNode(
    final int min, final int max, final LabelNode dflt, final LabelNode... labels) {
  super(Opcodes.TABLESWITCH);
  this.min = min;
  this.max = max;
  this.dflt = dflt;
  this.labels = Util.asArrayList(labels);
}