01: package net.sf.jdec.jvminstructions.commands;
02:
03: import net.sf.jdec.constantpool.ClassDescription;
04: import net.sf.jdec.constantpool.ClassInfo;
05: import net.sf.jdec.constantpool.FieldRef;
06: import net.sf.jdec.core.DecompilerHelper;
07: import net.sf.jdec.core.GlobalVariableStore;
08: import net.sf.jdec.core.Operand;
09: import net.sf.jdec.core.OperandStack;
10: import net.sf.jdec.reflection.Behaviour;
11: import net.sf.jdec.util.Util;
12:
13: public class PutstaticCommand extends AbstractInstructionCommand {
14:
15: public PutstaticCommand(Behaviour context) {
16: super (context);
17:
18: }
19:
20: public int getSkipBytes() {
21: return 2;
22: }
23:
24: public void execute() {
25: boolean doNotPop = GlobalVariableStore.isDoNotPop();
26: Behaviour behavior = getContext();
27: byte[] info = getCode();
28: if (doNotPop == false) {
29: int i = getCurrentInstPosInCode();
30: int pos = getGenericFinder().getOffset(i);
31: i += 2;
32: /*
33: * parsedString+="PUTSTATIC\t"; parsedString+="#"+pos;
34: * parsedString+="\n"; parsedString+="\t";parsedString+="\t";
35: */
36: ClassDescription cd = getContext().getClassRef().getCd();
37: OperandStack opStack = getStack();
38: FieldRef fref = cd.getFieldRefAtCPoolPosition(pos);
39: Operand value = opStack.getTopOfStack();
40: java.lang.String freftype = fref.getTypeoffield();
41:
42: // For the code statement
43: int classpointer = fref.getClassPointer();
44: ClassInfo cinfo = cd
45: .getClassInfoAtCPoolPosition(classpointer);
46: java.lang.String classname = cd.getUTF8String(cinfo
47: .getUtf8pointer());
48: java.lang.String v = value.getOperandValue().toString();
49: if (v.indexOf("(") == -1 && v.indexOf(")") != -1) {
50: v = v.replaceAll("\\)", "");
51:
52: }
53: v = v.trim();
54: StringBuffer sb = new StringBuffer("");
55: DecompilerHelper.checkForImport(classname, sb);
56: v = value.getOperandValue();
57: if (fref.isBooleanField()) {
58: if (v != null && v.equals("1")) {
59: v = "true";
60: }
61: if (v != null && v.equals("0")) {
62: v = "false";
63: }
64: }
65:
66: java.lang.String temp = sb.toString().replaceAll("/", ".")
67: + "." + fref.getFieldName() + " = " + v + ";";
68: behavior.appendToBuffer("\n"
69: + Util.formatDecompiledStatement(temp) + "\n");
70: }
71: if (doNotPop)
72: doNotPop = false;
73: GlobalVariableStore.setDoNotPop(doNotPop);
74:
75: }
76:
77: }
|