001: /*
002: * AstoreCommand.java Copyright (c) 2006,07 Swaroop Belur
003: *
004: * This program is free software; you can redistribute it and/itor
005: * modify it under the terms of the GNU General Public License
006: * as published by the Free Software Foundation; either version 2
007: * of the License, or (at your option) any later version.
008:
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013:
014: * You should have received a copy of the GNU General Public License
015: * along with this program; if not, write to the Free Software
016: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
017: *
018: */
019: package net.sf.jdec.jvminstructions.commands;
020:
021: import java.util.ArrayList;
022:
023: import net.sf.jdec.core.DecompilerHelper;
024: import net.sf.jdec.core.GlobalVariableStore;
025: import net.sf.jdec.core.LocalVariable;
026: import net.sf.jdec.core.Operand;
027: import net.sf.jdec.core.OperandStack;
028: import net.sf.jdec.main.ConsoleLauncher;
029: import net.sf.jdec.reflection.Behaviour;
030: import net.sf.jdec.util.Util;
031:
032: public class AstoreCommand extends AbstractInstructionCommand {
033:
034: public AstoreCommand(Behaviour context) {
035: super (context);
036:
037: }
038:
039: public int getSkipBytes() {
040:
041: return 1;
042: }
043:
044: public void execute() {
045:
046: int i = getCurrentInstPosInCode();
047: int currentForIndex = i;
048: int instructionPos = i;
049: Behaviour behaviour = getContext();
050: boolean doNotPop = GlobalVariableStore.isDoNotPop();
051: boolean multinewfound = GlobalVariableStore.isMultinewfound();
052: ArrayList methodTries = getContext().getAllTriesForMethod();
053: byte[] info = getContext().getCode();
054: int classIndex = info[++i];
055: boolean add = DecompilerHelper.checkForStartOfCatch(
056: instructionPos, methodTries);
057: OperandStack opStack = getContext().getOpStack();
058:
059: ArrayList ternList = GlobalVariableStore.getTernList();
060: boolean dupnothandled = GlobalVariableStore.isDupnothandled();
061: if (add == true && !doNotPop) {
062:
063: LocalVariable local = DecompilerHelper.getLocalVariable(
064: classIndex, "store", "java.lang.Object", false,
065: currentForIndex);
066: if (local != null) {
067:
068: // temp has new <Class Name>[<size>]
069: boolean push = getGenericFinder().isPrevInstDup(
070: currentForIndex);
071: if (!push) {
072: Operand objref = (Operand) opStack.pop(); // Pop The Object Ref
073: if (local.wasCreated()
074: && objref != null
075: && objref.getClassType().trim().length() > 0)
076: local.setDataType(objref.getClassType());
077: java.lang.String temp = (java.lang.String) objref
078: .getOperandValue();
079: if (!local.isDeclarationGenerated()) {
080: local.setBlockIndex(i - 1);
081: boolean yes = true;
082: if (!multinewfound) {
083: StringBuffer m = new StringBuffer("");
084: DecompilerHelper
085: .checkForImport(local.getDataType()
086: .replace('/', '.'), m);
087: Object vaf = DecompilerHelper
088: .newVariableAtFront(local
089: .getVarName(),
090: m.toString(), "null");
091: GlobalVariableStore.getVariablesatfront()
092: .add(vaf);
093: temp = local.getVarName() + "=" + temp;
094: if (local.getVarName().equals(temp) == true) {
095: yes = false;
096: }
097: } else {
098: multinewfound = false;
099: if (GlobalVariableStore
100: .getVariablesatfront() != null) {
101: Integer n = (Integer) GlobalVariableStore
102: .getVariablesatfront().get(
103: new Integer(classIndex)
104: .intValue());
105: java.lang.String bracks = "";
106: if (n != null) {
107: for (int o = 0; o < n.intValue(); o++) {
108: bracks += "[]";
109: }
110: }
111: StringBuffer m = new StringBuffer("");
112: DecompilerHelper.checkForImport(local
113: .getDataType()
114: .replace('/', '.'), m);
115: Object vaf = DecompilerHelper
116: .newVariableAtFront(local
117: .getVarName(), m + " "
118: + bracks + " ", "null");
119: GlobalVariableStore
120: .getVariablesatfront().add(vaf);
121: temp = local.getVarName() + "=" + temp;
122: } else {
123: // TODO: IMPORTANT FIXME
124: Object vaf = DecompilerHelper
125: .newVariableAtFront(local
126: .getVarName(), local
127: .getDataType().replace(
128: '/', '.'),
129: "null");
130: GlobalVariableStore
131: .getVariablesatfront().add(vaf);
132: temp = local.getVarName() + "=" + temp;
133: }
134: }
135: local.setDeclarationGenerated(true);
136: if (yes) {
137: behaviour.appendToBuffer(Util
138: .formatDecompiledStatement(temp
139: + ";\n"));
140:
141: }
142: } else {
143:
144: if (temp != null
145: && temp.trim().equalsIgnoreCase("this")) {
146:
147: java.lang.String classname = ConsoleLauncher
148: .getClazzRef().getClassName();
149: temp = classname + " "
150: + local.getVarName() + " =" + temp;
151: behaviour.appendToBuffer(Util
152: .formatDecompiledStatement(temp
153: + ";\n"));
154: //behaviour.appendToBuffer( ";\n";
155: } else {
156: temp = " " + local.getVarName() + " ="
157: + temp;
158: behaviour.appendToBuffer(Util
159: .formatDecompiledStatement(temp
160: + ";\n"));
161: //behaviour.appendToBuffer( ";\n";
162: }
163: }
164: } else {
165:
166: Operand top = opStack.getTopOfStack();
167: if (!dupnothandled)
168: opStack.getTopOfStack();
169: else
170: dupnothandled = false;
171: if (local.wasCreated() && top != null
172: && top.getClassType().trim().length() > 0)
173: local.setDataType(top.getClassType());
174: java.lang.String temp = top.getOperandValue();
175: temp = local.getVarName() + " =" + "(" + temp + ")";
176: if (!DecompilerHelper.isTernaryCondition(
177: currentForIndex, info)) {
178: if (newfound() == false) {
179: behaviour.appendToBuffer(Util
180: .formatDecompiledStatement(temp
181: + ";\n"));
182: //behaviour.appendToBuffer( ";\n";
183: Operand op6 = createOperand(local
184: .getVarName());
185: opStack.push(op6);
186: } else {
187: Operand op6 = createOperand(temp);
188: opStack.push(op6);
189: }
190: } else {
191: boolean ternEndfoundForParentIF = false;//isThisTernaryListEndForParentIF(currentForIndex);
192: boolean ternEndfound = false;//isThisTernaryListEnd(currentForIndex);
193:
194: boolean dupStoreForTerIf = false;//isThisDUPSTOREAtEndOFTernaryIF(currentForIndex,info,"store");
195: boolean n = DecompilerHelper
196: .anydupstoreinternarybesidesthis (
197: currentForIndex, info);
198: if (ternEndfound && n) {
199: opStack.push(top);
200: } else {
201: Operand p = opStack.getTopOfStack();
202: boolean end = false;//isTernaryEnd(currentForIndex);
203: if (dupStoreForTerIf) {
204: if (!end)
205: p.setOperandValue(p
206: .getOperandValue()
207: + "("
208: + local.getVarName()
209: + "="
210: + top.getOperandValue()
211: + ")");
212: else
213: p.setOperandValue(p
214: .getOperandValue()
215: + "("
216: + local.getVarName()
217: + "="
218: + top.getOperandValue()
219: + "))");
220: }
221: if (!dupStoreForTerIf) {
222: if (!end)
223: p.setOperandValue(p
224: .getOperandValue()
225: + "("
226: + top.getOperandValue()
227: + ")");
228: else
229: p.setOperandValue(p
230: .getOperandValue()
231: + top.getOperandValue()
232: + "))");
233: }
234: opStack.push(p);
235: }
236: if (ternEndfoundForParentIF)
237: ternList = new ArrayList();
238:
239: }
240: }
241:
242: }
243:
244: }
245: if (doNotPop)
246: doNotPop = false;
247: GlobalVariableStore.setDoNotPop(doNotPop);
248: GlobalVariableStore.setMultinewfound(multinewfound);
249: GlobalVariableStore.setTernList(ternList);
250: GlobalVariableStore.setDupnothandled(dupnothandled);
251: }
252:
253: }
|