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

The following examples show how to use org.objectweb.asm.Opcodes#LOOKUPSWITCH . 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_checkLookupSwitch() throws Exception {
    List<BasicBlock> hashCodeBlocks = METHOD_BLOCKS.get("checkLookupSwitch(I)I");
    int[][] expectedHashCodeBlocks = new int[][]{
            {Opcodes.ICONST_5, Opcodes.ISTORE, Opcodes.ILOAD, Opcodes.LOOKUPSWITCH},
            {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: LookupSwitchInsnNode.java    From JByteMod-Beta with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a new {@link LookupSwitchInsnNode}.
 * 
 * @param dflt
 *          beginning of the default handler block.
 * @param keys
 *          the values of the keys.
 * @param labels
 *          beginnings of the handler blocks. <tt>labels[i]</tt> is the
 *          beginning of the handler block for the <tt>keys[i]</tt> key.
 */
public LookupSwitchInsnNode(final LabelNode dflt, final int[] keys, final LabelNode[] labels) {
  super(Opcodes.LOOKUPSWITCH);
  this.dflt = dflt;
  this.keys = new ArrayList<Integer>(keys == null ? 0 : keys.length);
  this.labels = new ArrayList<LabelNode>(labels == null ? 0 : labels.length);
  if (keys != null) {
    for (int i = 0; i < keys.length; ++i) {
      this.keys.add(keys[i]);
    }
  }
  if (labels != null) {
    this.labels.addAll(Arrays.asList(labels));
  }
}
 
Example 5
Source File: SAXCodeAdapter.java    From JByteMod-Beta with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final void visitLookupSwitchInsn(final Label dflt, final int[] keys, final Label[] labels) {
  AttributesImpl att = new AttributesImpl();
  att.addAttribute("", "dflt", "dflt", "", getLabel(dflt));
  String o = Printer.OPCODES[Opcodes.LOOKUPSWITCH];
  sa.addStart(o, att);
  for (int i = 0; i < labels.length; i++) {
    AttributesImpl att2 = new AttributesImpl();
    att2.addAttribute("", "name", "name", "", getLabel(labels[i]));
    att2.addAttribute("", "key", "key", "", Integer.toString(keys[i]));
    sa.addElement("label", att2);
  }
  sa.addEnd(o);
}
 
Example 6
Source File: LookupSwitchInsnNode.java    From JByteMod-Beta with GNU General Public License v2.0 4 votes vote down vote up
public LookupSwitchInsnNode() {
  super(Opcodes.LOOKUPSWITCH);
  keys = new ArrayList<>();
  labels = new ArrayList<>();
}
 
Example 7
Source File: LookupSwitchInsnNode.java    From Cafebabe with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Constructs a new {@link LookupSwitchInsnNode}.
 *
 * @param dflt
 *          beginning of the default handler block.
 * @param keys
 *          the values of the keys.
 * @param labels
 *          beginnings of the handler blocks. {@code labels[i]} is the beginning of the handler block for the {@code keys[i]} key.
 */
public LookupSwitchInsnNode(final LabelNode dflt, final int[] keys, final LabelNode[] labels) {
	super(Opcodes.LOOKUPSWITCH);
	this.dflt = dflt;
	this.keys = Util.asArrayList(keys);
	this.labels = Util.asArrayList(labels);
}
 
Example 8
Source File: LookupSwitchInsnNode.java    From Concurnas with MIT License 3 votes vote down vote up
/**
 * Constructs a new {@link LookupSwitchInsnNode}.
 *
 * @param dflt beginning of the default handler block.
 * @param keys the values of the keys.
 * @param labels beginnings of the handler blocks. {@code labels[i]} is the beginning of the
 *     handler block for the {@code keys[i]} key.
 */
public LookupSwitchInsnNode(final LabelNode dflt, final int[] keys, final LabelNode[] labels) {
  super(Opcodes.LOOKUPSWITCH);
  this.dflt = dflt;
  this.keys = Util.asArrayList(keys);
  this.labels = Util.asArrayList(labels);
}
 
Example 9
Source File: LookupSwitchInsnNode.java    From JReFrameworker with MIT License 3 votes vote down vote up
/**
 * Constructs a new {@link LookupSwitchInsnNode}.
 *
 * @param dflt beginning of the default handler block.
 * @param keys the values of the keys.
 * @param labels beginnings of the handler blocks. {@code labels[i]} is the beginning of the
 *     handler block for the {@code keys[i]} key.
 */
public LookupSwitchInsnNode(final LabelNode dflt, final int[] keys, final LabelNode[] labels) {
  super(Opcodes.LOOKUPSWITCH);
  this.dflt = dflt;
  this.keys = Util.asArrayList(keys);
  this.labels = Util.asArrayList(labels);
}
 
Example 10
Source File: LookupSwitchInsnNode.java    From JReFrameworker with MIT License 3 votes vote down vote up
/**
 * Constructs a new {@link LookupSwitchInsnNode}.
 *
 * @param dflt beginning of the default handler block.
 * @param keys the values of the keys.
 * @param labels beginnings of the handler blocks. {@code labels[i]} is the beginning of the
 *     handler block for the {@code keys[i]} key.
 */
public LookupSwitchInsnNode(final LabelNode dflt, final int[] keys, final LabelNode[] labels) {
  super(Opcodes.LOOKUPSWITCH);
  this.dflt = dflt;
  this.keys = Util.asArrayList(keys);
  this.labels = Util.asArrayList(labels);
}