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 TableSwitchCommand extends AbstractInstructionCommand {
09:
10: public TableSwitchCommand(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 tableSwitchPos = 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: // Read Default
30: byte[] info = getCode();
31: int Default = BranchHelper.getSwitchOffset(info, i, "");// (info[++i]
32: // <<
33: // 24) |
34: // (info[++i] << 16) |
35: // (info[++i] << 8) |info[++i];
36: i += 4;
37: int low = BranchHelper.getSwitchOffset(info, i, "label");// (info[++i]
38: // << 24) |
39: // (info[++i] << 16) |
40: // (info[++i] << 8)
41: // |info[++i];
42: i += 4;
43: int high = BranchHelper.getSwitchOffset(info, i, "label");// (info[++i]
44: // <<
45: // 24) |
46: // (info[++i] << 16) |
47: // (info[++i] << 8)
48: // |info[++i];
49: i += 4;
50: int numberOfOffsets = (high - low) + 1;
51:
52: int[] offsetValues = new int[numberOfOffsets];
53: int start;
54: for (start = 0; start < numberOfOffsets; start++) {
55: int offsetVal = BranchHelper.getSwitchOffset(info, i, "");// (info[++i] << 24)
56: // | (info[++i] <<
57: // 16) | (info[++i]
58: // << 8) |info[++i];
59: i = i + 4;
60: offsetValues[start] = offsetVal;
61:
62: }
63: OperandStack opStack = getStack();
64: String ob = opStack.getTopOfStack().getOperandValue();
65: Integer Index = null;
66: // Add to each offset
67: for (start = 0; start < numberOfOffsets; start++) {
68:
69: offsetValues[start] = offsetValues[start] + tableSwitchPos;
70: }
71: Default += tableSwitchPos;
72: // parsedString+="\ntableswitch\t"+low+" "+high+": default
73: // "+Default+"\n";
74: start = low;
75: String tempString = "switch(" + ob.toString() + ")\n{\n";
76: Behaviour behavior = getContext();
77: behavior.appendToBuffer(Util
78: .formatDecompiledStatement(tempString));
79:
80: int end = i;
81: toSkip = end - begin;
82: }
83:
84: }
|