01: package net.sf.jdec.jvminstructions.commands;
02:
03: import net.sf.jdec.blockhelpers.BranchHelper;
04: import net.sf.jdec.core.OperandStack;
05: import net.sf.jdec.reflection.Behaviour;
06: import net.sf.jdec.util.Util;
07:
08: public class LookupswitchCommand extends AbstractInstructionCommand {
09:
10: public LookupswitchCommand(Behaviour context) {
11: super (context);
12:
13: }
14:
15: private int toSkip;
16:
17: public int getSkipBytes() {
18: return toSkip;
19: }
20:
21: public void execute() {
22: int i = getCurrentInstPosInCode();
23: int lookupSwitchPos = i;
24: int begin = i;
25: int leave_bytes = (4 - (i % 4)) - 1;
26: for (int indx = 0; indx < leave_bytes; indx++) {
27: i++;
28: }
29: byte[] info = getCode();
30: // Read Default
31: int Default = BranchHelper.getSwitchOffset(info, i, "");//(info[++i] << 24) | (info[++i] << 16) | (info[++i] << 8) |info[++i];
32: i = i + 4;
33: int numberOfLabels = BranchHelper.getSwitchOffset(info, i, "");//(info[++i] << 24) | (info[++i] << 16) | (info[++i] << 8) |info[++i];
34: i += 4;
35: //int high=(info[++i] << 24) | (info[++i] << 16) | (info[++i] << 8) |info[++i];
36: //int numberOfOffsets=(high-low)+1;
37: int offsetValues[] = new int[numberOfLabels];
38: int labels[] = new int[numberOfLabels];
39: for (int start = 0; start < numberOfLabels; start++) {
40: int label = BranchHelper.getSwitchOffset(info, i, "label");//(info[++i] << 24) | (info[++i] << 16) | (info[++i] << 8) |info[++i];
41: i += 4;
42: int offsetVal = BranchHelper.getSwitchOffset(info, i, "");//(info[++i] << 24) | (info[++i] << 16) | (info[++i] << 8) |info[++i];
43: i += 4;
44: labels[start] = label;
45: offsetValues[start] = offsetVal;
46:
47: }
48: OperandStack opStack = getStack();
49: Object ob = opStack.getTopOfStack().getOperandValue();
50: // Add to each offset
51: for (int start = 0; start < numberOfLabels; start++) {
52:
53: offsetValues[start] = offsetValues[start] + lookupSwitchPos;
54: }
55: Default += lookupSwitchPos;
56: int end = i;
57: //start=low;
58: String tempString = "switch(" + ob.toString() + ")\n{\n ";
59: Behaviour behavior = getContext();
60: behavior.appendToBuffer(Util
61: .formatDecompiledStatement(tempString));
62:
63: toSkip = end - begin;
64: }
65:
66: }
|