00001: /*
00002: * Disassembler.java Copyright (c) 2006,07 Swaroop Belur
00003: *
00004: * This program is free software; you can redistribute it and/or
00005: * modify it under the terms of the GNU General Public License
00006: * as published by the Free Software Foundation; either version 2
00007: * of the License, or (at your option) any later version.
00008:
00009: * This program is distributed in the hope that it will be useful,
00010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00012: * GNU General Public License for more details.
00013:
00014: * You should have received a copy of the GNU General Public License
00015: * along with this program; if not, write to the Free Software
00016: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017: *
00018: */
00019: package net.sf.jdec.core;
00020:
00021: import java.io.IOException;
00022: import java.io.File;
00023: import java.util.*;
00024: import java.math.BigInteger;
00025:
00026: import net.sf.jdec.io.Writer;
00027: import net.sf.jdec.blocks.CatchBlock;
00028: import net.sf.jdec.blocks.FinallyBlock;
00029: import net.sf.jdec.blocks.IFBlock;
00030: import net.sf.jdec.blocks.Loop;
00031: import net.sf.jdec.blocks.Switch;
00032: import net.sf.jdec.blocks.TryBlock;
00033: import net.sf.jdec.blocks.TryCatchFinally;
00034: import net.sf.jdec.blocks.Switch.Case;
00035: import net.sf.jdec.constantpool.ClassDescription;
00036: import net.sf.jdec.constantpool.ClassInfo;
00037: import net.sf.jdec.constantpool.DoublePrimitive;
00038: import net.sf.jdec.constantpool.FieldRef;
00039: import net.sf.jdec.constantpool.FloatPrimitive;
00040: import net.sf.jdec.constantpool.IntPrimitive;
00041: import net.sf.jdec.constantpool.InterfaceMethodRef;
00042: import net.sf.jdec.constantpool.LongPrimitive;
00043: import net.sf.jdec.constantpool.MethodRef;
00044: import net.sf.jdec.constantpool.NameAndType;
00045: import net.sf.jdec.constantpool.CPString;
00046: import net.sf.jdec.constantpool.MethodInfo.ExceptionTable;
00047: import net.sf.jdec.main.ConsoleLauncher;
00048: import net.sf.jdec.reflection.Behaviour;
00049: import net.sf.jdec.reflection.ConstructorMember;
00050: import net.sf.jdec.util.AllExceptionHandler;
00051: import net.sf.jdec.config.Configuration;
00052: import net.sf.jdec.util.Constants;
00053: import net.sf.jdec.util.Util;
00054:
00055: public class Disassembler {
00056:
00057: Behaviour behaviour;
00058: ClassDescription cd;
00059: OperandStack opStack;
00060: boolean prevInstInvokeVirtual = false;
00061: private boolean hasIfBeenGenerated = false;
00062: private int ifCloseLineNo = -1;
00063: private boolean hasElseBeenGenerated = false;
00064: private int elseCloseLineNo = -1;
00065: private boolean isPrevInstructionIf = false;
00066: private boolean isWhileInScope = false;
00067: private boolean isIfInScope = false;
00068: private Hashtable ifHashTable = new Hashtable();
00069: private Hashtable elseHashTable = new Hashtable();
00070: private int whileIndex = 0;
00071: private int ifLevel = 0;
00072: private int blockLevel = -1;
00073: private LocalVariable prevLocalGenerated = null;
00074: private boolean elsehasbegun = false;
00075: private boolean ifhasbegun = false;
00076: private Hashtable synchSkips = null;
00077:
00078: /***
00079: *
00080: * @param behaviour Represents Either an Instance
00081: * of Method of a class or a constructor of a class
00082: */
00083:
00084: public Disassembler(Behaviour behaviour, ClassDescription cd) {
00085: Util.resetCurrentSpace();
00086: StringBuffer t = new StringBuffer("");
00087: Util.checkForImport(behaviour.getReturnType(), t);
00088: this .behaviour = behaviour;
00089: this .cd = cd;
00090: //opStack = new OperandStack();
00091: opStack = behaviour.getOpStack();
00092: if (cd.isClassCompiledWithMinusG() == false) {
00093:
00094: storeDataTypesForMethodParams(this .behaviour, this .cd);
00095: createLocalVariablesForMethodParams(this .behaviour, this .cd);
00096: if (this .behaviour.getCode() != null) {
00097: //BigInteger b
00098: storeDataTypesWRTConversionInst(this .behaviour, this .cd);
00099: storeDataTypesWRTMethodParams(this .behaviour, this .cd);
00100: storeDataTypesWRTLoadNStoreCombinations(this .behaviour,
00101: this .cd);
00102: long l = -1, l2 = -1;
00103: try {
00104: anewarrayrefpos = new Hashtable();
00105: problematicInvokes = new ArrayList();
00106: storeDataTypesWRTInvokeInst(this .behaviour, this .cd);
00107:
00108: } catch (RuntimeException re) {
00109: //AllExceptionHandler handler=new AllExceptionHandler(re,"Runtime Exception while handling storeDataTypesWRTInvokeInst");
00110: //handler.setBehaviour(behaviour);
00111: //handler.reportException(); // TODO: Uncomment This later
00112: // ConsoleLauncher.addCouldNotFinish(behaviour);
00113: //l2=System.currentTimeMillis();
00114: // System.out.println("After Invoke Catch"+(l2-l)/1000);
00115: return;
00116: }
00117:
00118: }
00119: //java.lang.String s="sdfasdf";
00120:
00121: }
00122: if (cd.isClassCompiledWithMinusG()) {
00123: // storeDataTypesWRTInvokeInst(this.behaviour,this.cd);
00124: }
00125:
00126: findSkipRangesWRTSynchronizedBlocks();
00127:
00128: }
00129:
00130: public void disassembleCode() {
00131: StringBuffer buffer = new StringBuffer();
00132: try {
00133: if (behaviour == null) {
00134: java.lang.String mesg = "Exception Occured while Disassembling Code\n";
00135: mesg += "The behaviour Object was null";
00136: AllExceptionHandler handler = new AllExceptionHandler(
00137: new NullPointerException(mesg));
00138: handler.reportException();
00139:
00140: } else {
00141: // Log Message
00142:
00143: java.lang.String mesg = "\n[INFO]Attempting to generate code represented By\n";
00144: mesg += "[INFO]Method Name :\t"
00145: + behaviour.getBehaviourName() + "\n";
00146: Writer writer = Writer.getWriter("log");
00147: writer.writeLog(mesg, Configuration.getLogLevel());
00148: writer.flush();
00149:
00150: // Write to ConsoleDetail file For UI....
00151:
00152: // Attempt to Dis
00153:
00154: byte[] bytecodes = behaviour.getCode();
00155:
00156: /** NOTE:
00157: *
00158: * opcodes below represents the disassembled String
00159: * for the behaviour...
00160: * This Disasembler Object has the object ref to
00161: * the behaviour passed.
00162: * Since the opcode is the complete disassembled
00163: * code for this behaviour, we can go and set
00164: * it for the behaviour object using Reflection API.
00165: * Later on The code to print out the complete
00166: * representation of the Class can access the
00167: * Reflection API to print out the class...
00168: *
00169: *
00170: */
00171:
00172: long l1 = System.currentTimeMillis();
00173: parseJVMOpCodes(bytecodes);
00174: long l2 = System.currentTimeMillis();
00175: double duration = (double) (l2 - l1) / 1000;
00176:
00177: }
00178:
00179: } catch (IOException ioe) {
00180: AllExceptionHandler handler = new AllExceptionHandler(ioe);
00181: handler.setBehaviour(behaviour);
00182: handler.reportException();
00183: // Just in Case Code Returns from
00184: // reportException method
00185:
00186: }
00187:
00188: }
00189:
00190: int currentForIndex;
00191: LocalVariableStructure structure = null;
00192: boolean createdLocalVariableStructure;
00193: //java.lang.String //codeStatements = "";
00194: //private boolean createdLocalVariableStructure=false;
00195: HashMap returnsAtI = null;
00196: boolean multinewound;
00197: ArrayList returnsaddedAtIfElse = null;
00198:
00199: public void parseJVMOpCodes(byte[] info) {
00200:
00201: continue_JumpOffsets = new ArrayList();
00202: break_JumpOffsets = new ArrayList();
00203: labelAssociated = new Hashtable();
00204: retAtIfElseEnd = new Hashtable();
00205: ConsoleLauncher.setCurrentMethodBeingExecuted(this .behaviour);
00206: createdLocalVariableStructure = false; // for -g:none option
00207: returnsAtI = new HashMap();
00208: boolean newfound = false;
00209: ArrayList methodTries = behaviour.getAllTriesForMethod();
00210: Operand tempOperand = null;
00211: java.lang.String tempString = "";
00212:
00213: //codeStatements = "";
00214: int opValueI = Integer.MIN_VALUE;
00215: byte opValueB = Byte.MIN_VALUE;
00216: float opValueF = Float.MIN_VALUE;
00217: double opValueD = Double.NEGATIVE_INFINITY;
00218: long opValueL = Long.MIN_VALUE;
00219: java.lang.String errorMesg = "";
00220: IntPrimitive constInt = null;
00221: FloatPrimitive constFloat = null;
00222: DoublePrimitive constDouble = null;
00223: LongPrimitive constLong = null;
00224: ClassInfo constCInfo = null;
00225: CPString constString = null;
00226: MethodRef mref = null;
00227: FieldRef fref = null;
00228: NameAndType ninfo = null;
00229: java.lang.String stringLiteral = null;
00230:
00231: Operand op = null;
00232: Operand op1 = null;
00233: Operand op2 = null;
00234: Operand op3 = null;
00235: Operand op4 = null;
00236:
00237: IFBlock ifst = null;
00238:
00239: Behaviour b = null;
00240:
00241: java.lang.String funcCall = "";
00242:
00243: int type = -1;
00244:
00245: Hashtable methodLookUp = cd.getMethodLookUp();
00246:
00247: LocalVariableTable table = LocalVariableTable.getInstance();
00248: boolean cons = false;
00249: if (behaviour instanceof ConstructorMember) {
00250: cons = true;
00251: }
00252:
00253: structure = table.getLocaVarStructure(behaviour
00254: .getBehaviourName().concat(
00255: behaviour.getStringifiedParameters()).concat(
00256: "" + cons));
00257: if (structure != null)
00258: behaviour.setMethodLocalVariables(structure);
00259: LocalVariable local = null;
00260: LABELS = new Hashtable();
00261: returnsaddedAtIfElse = new ArrayList();
00262:
00263: // TODO:
00264: /*
00265: * Decide when that infinite loop should be added to //codeStatements
00266: *
00267: */
00268: boolean invokevirtualFound = false;
00269: multinewound = false;
00270: for (int i = 0; i < info.length; i++) {
00271: // Shutdown se;
00272: resetEndOfSynchBlockIfNecessary(i);
00273: //emitStackContent(opStack,i,info);
00274:
00275: // checkEndOfLoops(ifHashTable,behaviour);
00276:
00277: boolean skip;
00278:
00279: currentForIndex = i;
00280:
00281: /*skip=skipCurrentIteraton(i,false,info);
00282: if(skip && Configuration.getDecompileroption().equals("dc")) {
00283: continue;
00284: } */
00285: /*int instructionAtI=info[i];
00286: java.lang.String fromExceptionTable=pollExcepionTables(i,instructionAtI);
00287: //codeStatements+=fromExceptionTable+((fromExceptionTable.trim().length()==0)?"":"\n");
00288:
00289: java.lang.String switchStmt=pollSwitchBlksForMethod(i);
00290: //codeStatements+=switchStmt+((switchStmt.trim().length()==0)?"":"\n");*/
00291:
00292: try {
00293:
00294: //if(ifLevel >= 1) {
00295:
00296: boolean needtoresetelsehasbugun = false;
00297: StringBuffer ifelsecode = new StringBuffer("");
00298: StringBuffer reset = new StringBuffer("");
00299: int prevstart = getPrevStartCodePos(info, i);
00300: checkForIFElseEndStatement(info, ifHashTable, i, reset,
00301: opStack, ifelsecode, "if");
00302:
00303: /*if(prevstart >= 0)
00304: {
00305: ifelsecode=new StringBuffer("");
00306: checkForIFElseEndStatement(info,ifHashTable,prevstart,reset,opStack,ifelsecode,"else");
00307: } */
00308: if (reset.toString().equals("true")) {
00309: //System.out.println("Reset for "+i+ behaviour);
00310: elsehasbegun = false;
00311: }
00312: //codeStatements+= ifelsecode.toString();
00313: //}
00314:
00315: java.lang.String brlbl = getAnyLabelAtI(LABELS, i);
00316: if (brlbl != null && brlbl.trim().length() > 0) {
00317: //codeStatements+="\n"+brlbl+":\n";
00318: } else {
00319: //codeStatements+="\n"+"#FORINDEX"+i+"#"+"\n";
00320: }
00321:
00322: java.lang.String printLater = "";
00323: Iterator loopIterator = behaviour.getBehaviourLoops()
00324: .iterator();
00325: /* while(loopIterator.hasNext())
00326: {
00327: Loop iloop = (Loop)loopIterator.next();
00328: if(iloop.getStartIndex() == i && iloop.isInfinite())
00329: {
00330: boolean clash=doesthisClashWithCaseBegin(behaviour.getAllSwitchBlks(),i);
00331: if(clash)printLater="while(true)\n{\n";
00332: if(!clash){
00333: tempString = "while(true)\n{\n";
00334: //codeStatements += Util.formatDecompiledStatement(tempString);
00335: printLater="";
00336: }
00337: }
00338: if(iloop.getEndIndex() == i)
00339: {
00340: tempString=anyWhileBodyHere(i,iloop,opStack);
00341: if(tempString.trim().length() > 0)
00342: {
00343: tempString =tempString+"}\n";
00344: iloop.setWasLoopClosedInCode(true);
00345: i=i+2;
00346: //codeStatements += Util.formatDecompiledStatement(tempString); // TODO: BUg in formatting
00347: continue;
00348: }
00349: else
00350: {
00351: if(iloop.wasLoopClosedInCode()==false)
00352: {
00353: tempString ="}\n";
00354: //codeStatements += Util.formatDecompiledStatement(tempString);
00355: iloop.setWasLoopClosedInCode(true);
00356: }
00357: }
00358: }
00359: else if(iloop.getLoopEndForBracket()==i && iloop.wasLoopClosedInCode()==false)
00360: {
00361:
00362: tempString ="}\n";// Loop End\n";
00363: //codeStatements += Util.formatDecompiledStatement(tempString);
00364: iloop.setWasLoopClosedInCode(true);
00365: }
00366:
00367:
00368: }
00369:
00370: java.lang.String switchStmt=pollSwitchBlksForMethod(i);
00371:
00372: //codeStatements+=switchStmt;
00373: //codeStatements+=((switchStmt.trim().length()==0)?"":"\n"); // Moved switch before Try
00374:
00375:
00376: // OK in all cases?
00377:
00378: if(printLater.trim().length() > 0)
00379: {
00380: //codeStatements += Util.formatDecompiledStatement(printLater);
00381: }
00382:
00383:
00384:
00385: int instructionAtI=info[i];
00386: java.lang.String fromExceptionTable=pollExcepionTables(i,instructionAtI); */
00387:
00388: printAnyReturnATEndOfGuard(i, info);
00389: /* boolean end=isIEndOfGuard(i,behaviour);
00390: boolean returnadded=false;
00391: int returnposincode=-1;
00392: if(end)
00393: {
00394: StringBuffer sb=new StringBuffer("");
00395: java.lang.String returnString=isAnyReturnPresentInSkipRegion(info,i,behaviour,sb);
00396: java.lang.String str=sb.toString();
00397: try
00398: {
00399: returnposincode=Integer.parseInt(str);
00400: }
00401: catch(NumberFormatException ne){}
00402:
00403: if(returnString!=null && returnString.trim().length()==0)
00404: {
00405: if(i==(info.length-1))
00406: {
00407: returnString=getReturnTypeInst(info,i);
00408: returnposincode=i;
00409:
00410: }
00411: }
00412: java.lang.Object val=null;
00413:
00414:
00415: if(returnString!=null && returnString.trim().length() > 0)
00416: {
00417: int loadIndex=-1;
00418: StringBuffer stb=new StringBuffer("");
00419: if(returnposincode!=-1)
00420: loadIndex=getLoadIndexForReturn(info,returnposincode,stb);
00421: if(loadIndex!=-1)
00422: {
00423: LocalVariableStructure struck=behaviour.getLocalVariables();
00424: int rangeinx=Integer.parseInt(stb.toString());
00425: if(rangeinx!=-1)
00426: {
00427: if(cd.isClassCompiledWithMinusG())
00428: {
00429: LocalVariable temp=struck.getVariabelAtIndex(loadIndex,rangeinx);
00430: if(temp!=null)
00431: {
00432: op=new Operand();
00433: op.setOperandValue(temp.getVarName());
00434: op.setOperandName(temp.getVarName());
00435: opStack.push(op);
00436: }
00437:
00438: }
00439: else
00440: {
00441: LocalVariable temp=struck.getVariabelAtIndex(loadIndex);
00442: if(temp!=null)
00443: {
00444: op=new Operand();
00445: op.setOperandValue(temp.getVarName());
00446: op.setOperandName(temp.getVarName());
00447: opStack.push(op);
00448: }
00449: }
00450: }
00451: }
00452: int returnPos=getReturnStringPosInCode(info,i,behaviour);
00453: if(returnString.equals("return")==false && opStack.size() > 0)
00454: {
00455: // StackTop=opStack.peekTopOfStack();
00456: Operand StackTop=opStack.getTopOfStack();
00457: if(StackTop!=null)
00458: {
00459: val=StackTop.getOperandValue();
00460: if(val!=null)val=val.toString();
00461: }
00462: if(StackTop!=null)
00463: {
00464:
00465:
00466:
00467: if(val!=null)tempString="return "+val;
00468: else tempString="return ";
00469: //codeStatements+=Util.formatDecompiledStatement(tempString);
00470:
00471:
00472: returnadded=true;
00473: }
00474:
00475: }
00476: else if(returnString.equals("return")==true)
00477: {
00478: tempString="return ";
00479: //codeStatements+=Util.formatDecompiledStatement(tempString);
00480:
00481:
00482: returnadded=true;
00483: }
00484: returnsAtI.put(new Integer(returnPos),"true");
00485: }
00486:
00487: } */
00488:
00489: /*if(returnadded)//codeStatements+=";\n";
00490: tempString=fromExceptionTable;
00491: //codeStatements+=Util.formatDecompiledStatement(tempString);
00492: //codeStatements+=((fromExceptionTable.trim().length()==0)?"":"\n");
00493:
00494:
00495: java.lang.String synch=pollsynchblocks(i);
00496: //codeStatements+=Util.formatDecompiledStatement(synch);
00497:
00498:
00499: skip=skipCurrentIteraton(i,true,info);
00500: if(skip)continue; */
00501: this Loop = null;
00502:
00503: /* java.lang.String brlbl=getAnyLabelAtI(LABELS,i);
00504: if(brlbl!=null && brlbl.trim().length() > 0)
00505: {
00506: //codeStatements+="\n"+brlbl+":\n";
00507: }
00508: else
00509: {
00510: //codeStatements+="\n"+"#FORINDEX"+i+"#"+"\n";
00511: } */
00512:
00513: switch (info[i]) {
00514: case JvmOpCodes.AALOAD:
00515: handleAALOAD(opStack);
00516:
00517: continue;
00518: case JvmOpCodes.AASTORE:
00519:
00520: handleAASTORECase();
00521:
00522: continue;
00523: case JvmOpCodes.ACONST_NULL:
00524: handleACONSTNULL();
00525:
00526: continue;
00527: case JvmOpCodes.ALOAD:
00528: handleAloadCase(info, i, opStack);
00529: i = i + 1;
00530: continue;
00531:
00532: case JvmOpCodes.ALOAD_0:
00533:
00534: handlesimpleaload(0);
00535:
00536: //parsedString += "ALOAD_0\n";
00537: //parsedString+="\t";//parsedString+="\t";
00538: continue;
00539: case JvmOpCodes.ALOAD_1:
00540:
00541: handlesimpleaload(1);
00542: //parsedString += "ALOAD_1\n";
00543: //parsedString+="\t";//parsedString+="\t";
00544: continue;
00545: case JvmOpCodes.ALOAD_2:
00546:
00547: handlesimpleaload(2);
00548: //parsedString += "ALOAD_2\n";
00549: //parsedString+="\t";//parsedString+="\t";
00550: continue;
00551: case JvmOpCodes.ALOAD_3:
00552: handlesimpleaload(3);
00553:
00554: //parsedString += "ALOAD_3\n";
00555: continue;
00556:
00557: case JvmOpCodes.ANEWARRAY:
00558: //parsedString += "ANEWARRAY\t";
00559: //int classIndex=((info[++i] << 8) | info[++i]);
00560: handleANEWARRAYCase(info);
00561: i++;
00562: i++;
00563: continue;
00564: case JvmOpCodes.ARETURN:
00565:
00566: boolean oktoadd = true;
00567: addParsedOutput("Instruction Pos "
00568: + currentForIndex + "\t:- " + " areturn\n");
00569: handleARETURNCase(currentForIndex, returnsAtI);
00570:
00571: continue;
00572: case JvmOpCodes.ARRAYLENGTH:
00573: handleARRAYLENGTHCase();
00574:
00575: continue;
00576: case JvmOpCodes.ASTORE:
00577: handleComplexAStore(info, i);
00578: i++;
00579:
00580: continue;
00581: case JvmOpCodes.ASTORE_0:
00582: handleSimpleASTORECase(i, 0);
00583: //parsedString += "ASTORE_0\n";
00584: //parsedString+="\t";parsedString+="\t";
00585: continue;
00586: case JvmOpCodes.ASTORE_1:
00587: // parsedString += "ASTORE_1\n";
00588: // parsedString+="\t";parsedString+="\t";
00589: handleSimpleASTORECase(i, 1);
00590: continue;
00591: case JvmOpCodes.ASTORE_2:
00592: handleSimpleASTORECase(i, 2);
00593:
00594: //parsedString += "ASTORE_2\n";
00595: //parsedString+="\t";parsedString+="\t";
00596: continue;
00597: case JvmOpCodes.ASTORE_3:
00598: handleSimpleASTORECase(i, 3);
00599: //parsedString += "ASTORE_3\n";
00600: //parsedString+="\t";parsedString+="\t";
00601: continue;
00602: case JvmOpCodes.ATHROW:
00603:
00604: //parsedString += "ATHROW "+"\n";
00605: //parsedString+="\t";parsedString+="\t";
00606: boolean add = true;
00607: addParsedOutput("Instruction Pos "
00608: + currentForIndex + "\t:- " + " athrow\n");
00609: boolean aloadPresent = isPrevInstructionAload(i,
00610: info);
00611:
00612: //Problem:
00613: // Some Defect Here. If Exception thrown as the last stmt in finally in java code
00614: // Then it will not show it...
00615: // TODO: Keep Testing This.
00616:
00617: if (aloadPresent == true) // Is this enough to make add=false ?
00618: {
00619: // The following is just to confirm that this is indeed the end of finally
00620: if (methodTries != null) {
00621: for (int st = 0; st < methodTries.size(); st++) {
00622: TryBlock tryblk = (TryBlock) methodTries
00623: .get(st);
00624: if (tryblk != null) {
00625: FinallyBlock fin = tryblk
00626: .getFinallyBlock();
00627: if (fin != null) {
00628:
00629: int finEnd = fin.getEnd();
00630: if (finEnd == i) {
00631: add = false;
00632: break;
00633: } else if (finEnd != i) {
00634: int finStart = fin
00635: .getStart();
00636: int fromWhere = i;
00637: int tillWhere = finStart;
00638: while (fromWhere >= tillWhere) {
00639: int inst = info[fromWhere];
00640: if (inst == JvmOpCodes.JSR) // TODO : Check for Jsr_w
00641: {
00642: add = false;
00643: break;
00644: }
00645: fromWhere--;
00646: }
00647:
00648: } else
00649: add = true;
00650: }
00651: }
00652:
00653: }
00654: }
00655: }
00656:
00657: if (add && addATHROWOutput(currentForIndex)) {
00658: op = (Operand) opStack.pop();
00659: opStack.push(op);
00660: tempString = "throw " + op.getOperandValue()
00661: + ";\n";
00662: //codeStatements+=Util.formatDecompiledStatement(tempString);
00663: }
00664:
00665: continue;
00666:
00667: //LETTER B
00668: case JvmOpCodes.BALOAD:
00669:
00670: handleBALOAD(opStack);
00671:
00672: continue;
00673: case JvmOpCodes.BASTORE:
00674: addParsedOutput("Instruction Pos "
00675: + currentForIndex + "\t:- " + " bastore\n");
00676: handleBASTORE(opStack);
00677: continue;
00678: case JvmOpCodes.BIPUSH:
00679: handleBIPush(info);
00680: i = i + 1;
00681:
00682: continue;
00683:
00684: //LETTER C
00685: case JvmOpCodes.CALOAD:
00686: addParsedOutput("Instruction Pos "
00687: + currentForIndex + "\t:- " + " caload\n");
00688: handleCALOAD(opStack);
00689:
00690: //parsedString+="\t";parsedString+="\t";
00691: continue;
00692: case JvmOpCodes.CASTORE:
00693: addParsedOutput("Instruction Pos "
00694: + currentForIndex + "\t:- " + " castore\n");
00695: handleCASTORE(opStack);
00696: //parsedString+="\t";parsedString+="\t";
00697: continue;
00698: case JvmOpCodes.CHECKCAST:
00699:
00700: handleCheckCast(opStack, info);
00701: i = i + 2;
00702: continue;
00703:
00704: //LETTER D
00705: case JvmOpCodes.D2F:
00706: addParsedOutput("Instruction Pos "
00707: + currentForIndex + "\t:- " + " d2f\n");
00708: op = (Operand) opStack.pop();
00709: op.setOperandValue("(float)" + "("
00710: + op.getOperandValue() + ")");
00711: op.setOperandType(Constants.IS_CONSTANT_FLOAT);
00712: opStack.push(op);
00713: // TODO : Did not push / pop the operands as we need to
00714: // convert the double to float and then push it back to the stack.
00715: //parsedString += "D2F\n";
00716: //parsedString+="\t";parsedString+="\t";
00717: continue;
00718: case JvmOpCodes.D2I:
00719: addParsedOutput("Instruction Pos "
00720: + currentForIndex + "\t:- " + " d2i\n");
00721: op = (Operand) opStack.pop();
00722: op.setOperandValue("(int)" + "("
00723: + op.getOperandValue() + ")");
00724: op.setOperandType(Constants.IS_CONSTANT_INT);
00725: opStack.push(op);
00726: // TODO : Did not push / pop the operands as we need to
00727: // convert the double to int and then push it back to the stack.
00728: //parsedString += "D2I\n";
00729: //parsedString+="\t";parsedString+="\t";
00730: continue;
00731: case JvmOpCodes.D2L:
00732: addParsedOutput("Instruction Pos "
00733: + currentForIndex + "\t:- " + " d2l\n");
00734: op = (Operand) opStack.pop();
00735: op.setOperandValue("(long)" + "("
00736: + op.getOperandValue() + ")");
00737: op.setOperandType(Constants.IS_CONSTANT_LONG);
00738: opStack.push(op);
00739:
00740: continue;
00741: case JvmOpCodes.DADD:
00742: addParsedOutput("Instruction Pos "
00743: + currentForIndex + "\t:- " + " dadd\n");
00744: op = (Operand) opStack.pop();
00745: op1 = (Operand) opStack.pop();
00746:
00747: op2 = new Operand();
00748: //op2.setOperandValue(new Double(((Double)op.getOperandValue()).doubleValue()+((Double)op.getOperandValue()).doubleValue()));
00749: op2.setOperandValue("(" + op1.getOperandValue()
00750: + ")" + "+" + "(" + op.getOperandValue()
00751: + ")");
00752: op2.setOperandType(Constants.IS_CONSTANT_DOUBLE);
00753:
00754: opStack.push(op2);
00755:
00756: continue;
00757: case JvmOpCodes.DALOAD:
00758: addParsedOutput("Instruction Pos "
00759: + currentForIndex + "\t:- " + " daload\n");
00760: handleDALOAD(opStack);
00761:
00762: //parsedString+="\t";parsedString+="\t";
00763: continue;
00764: case JvmOpCodes.DASTORE:
00765: addParsedOutput("Instruction Pos "
00766: + currentForIndex + "\t:- " + " dastore\n");
00767: handleDASTORE(opStack);
00768:
00769: continue;
00770: case JvmOpCodes.DCMPG:
00771: addParsedOutput("Instruction Pos "
00772: + currentForIndex + "\t:- " + " dcmpg\n");
00773: handleDCMPG(opStack, info);
00774:
00775: continue;
00776: case JvmOpCodes.DCMPL:
00777: addParsedOutput("Instruction Pos "
00778: + currentForIndex + "\t:- " + " dcmpl\n");
00779: handleDCMPL(opStack, info);
00780: continue;
00781: case JvmOpCodes.DCONST_0:
00782: addParsedOutput("Instruction Pos "
00783: + currentForIndex + "\t:- " + " dconst_0\n");
00784: handleDCONST(opStack, 0.0);
00785: //parsedString += "DCONST_0\n";
00786: //parsedString+="\t";parsedString+="\t";
00787: continue;
00788: case JvmOpCodes.DCONST_1:
00789: addParsedOutput("Instruction Pos "
00790: + currentForIndex + "\t:- " + " dconst_1\n");
00791: handleDCONST(opStack, 1.0);
00792: //parsedString += "DCONST_1\n";
00793: //parsedString+="\t";parsedString+="\t";
00794: continue;
00795:
00796: case JvmOpCodes.DDIV:
00797: addParsedOutput("Instruction Pos "
00798: + currentForIndex + "\t:- " + " ddiv\n");
00799: handleDDIV(opStack);
00800:
00801: //parsedString += "DDIV\n";
00802: //parsedString+="\t";parsedString+="\t";
00803: continue;
00804: case JvmOpCodes.DLOAD:
00805: opValueI = info[++i];
00806: addParsedOutput("Instruction Pos "
00807: + currentForIndex + "\t:- " + " dload "
00808: + opValueI);
00809: handleDLOADCase(opValueI, opStack, false);
00810:
00811: //parsedString += "DLOAD";
00812: // parsedString += " "+opValueI+"\n";
00813: //parsedString+="\t";parsedString+="\t";
00814: continue;
00815: case JvmOpCodes.DLOAD_0:
00816:
00817: addParsedOutput("Instruction Pos "
00818: + currentForIndex + "\t:- " + " dload_0");
00819: handleDLOADCase(0, opStack, true);
00820:
00821: continue;
00822: case JvmOpCodes.DLOAD_1:
00823:
00824: addParsedOutput("Instruction Pos "
00825: + currentForIndex + "\t:- " + " dload_1");
00826: handleDLOADCase(1, opStack, true);
00827:
00828: continue;
00829: case JvmOpCodes.DLOAD_2:
00830:
00831: addParsedOutput("Instruction Pos "
00832: + currentForIndex + "\t:- " + " dload_2");
00833: handleDLOADCase(2, opStack, true);
00834:
00835: continue;
00836: case JvmOpCodes.DLOAD_3:
00837:
00838: addParsedOutput("Instruction Pos "
00839: + currentForIndex + "\t:- " + " dload_3");
00840: handleDLOADCase(3, opStack, true);
00841:
00842: continue;
00843: case JvmOpCodes.DMUL:
00844: addParsedOutput("Instruction Pos "
00845: + currentForIndex + "\t:- " + " dmul\n");
00846: handleDMUL(opStack);
00847:
00848: continue;
00849: case JvmOpCodes.DNEG:
00850: addParsedOutput("Instruction Pos "
00851: + currentForIndex + "\t:- " + " dneg\n");
00852: handleDNEG(opStack);
00853:
00854: continue;
00855: case JvmOpCodes.DREM:
00856: addParsedOutput("Instruction Pos "
00857: + currentForIndex + "\t:- " + " drem\n");
00858: handleDREM(opStack);
00859:
00860: continue;
00861: case JvmOpCodes.DRETURN:
00862: oktoadd = true;
00863: addParsedOutput("Instruction Pos "
00864: + currentForIndex + "\t:- " + " dreturn\n");
00865: Iterator mapIT = returnsAtI.entrySet().iterator();
00866: while (mapIT.hasNext()) {
00867: Map.Entry entry = (Map.Entry) mapIT.next();
00868: Object key = entry.getKey();
00869: Object retStatus = entry.getValue().toString();
00870: if (key instanceof Integer) {
00871: Integer pos = (Integer) key;
00872: int temp = pos.intValue();
00873: if (temp == i) {
00874: if (retStatus.equals("true")) {
00875:
00876: oktoadd = false;
00877: break;
00878: }
00879: }
00880: }
00881:
00882: }
00883:
00884: if (!oktoadd) {
00885: returnsAtI.remove(new Integer(i));
00886: }
00887:
00888: if (oktoadd && opStack.size() > 0) {
00889: //System.out.println(currentForIndex+"i"+behaviour.getBehaviourName());
00890: op = (Operand) opStack.pop();
00891: tempString = "return "
00892: + op.getOperandValue().toString()
00893: + ";\n";
00894: //codeStatements+=Util.formatDecompiledStatement(tempString);
00895: }
00896:
00897: //behaviour.getParentBehaviour().getOpStack().push(op);
00898: /*parsedString += "DRETURN";
00899: parsedString+="\n";
00900: parsedString+="\t";parsedString+="\t";*/
00901: continue;
00902: case JvmOpCodes.DSTORE:
00903: int classIndex = info[++i];
00904:
00905: local = getLocalVariable(classIndex, "store",
00906: "double", false, currentForIndex);
00907: if (cd.isClassCompiledWithMinusG() && local != null)
00908: addParsedOutput("Instruction Pos "
00909: + currentForIndex + "\t:- "
00910: + " dstore " + classIndex
00911: + " THIS LOCALVARIABLE :- "
00912: + local.getVarName() + "\n");
00913: else
00914: addParsedOutput("Instruction Pos "
00915: + currentForIndex + "\t:- "
00916: + " dstore " + classIndex);
00917: if (local != null && !doNotPop) {
00918: op = (Operand) opStack.pop();
00919: prevLocalGenerated = local;
00920: boolean push = isPrevInstDup(info,
00921: currentForIndex);
00922: if (!push) {
00923: if (!local.isDeclarationGenerated()) {
00924: //if(local.wasCreated())local.setDataType(op.getClassType());
00925: local.setBlockIndex(blockLevel);
00926: tempString = local.getDataType() + " "
00927: + local.getVarName() + "="
00928: + op.getOperandValue() + ";\n";
00929: //codeStatements += Util.formatDecompiledStatement(tempString);
00930: local.setDeclarationGenerated(true);
00931: } else {
00932: tempString = local.getVarName() + "="
00933: + op.getOperandValue() + ";\n";
00934: //codeStatements += Util.formatDecompiledStatement(tempString);
00935: }
00936: } else {
00937: if (((currentForIndex - 1) >= 0)
00938: && info[currentForIndex - 1] == JvmOpCodes.DUP)
00939: opStack.getTopOfStack();
00940: if (((currentForIndex - 1) >= 0)
00941: && info[currentForIndex - 1] == JvmOpCodes.DUP2) {
00942: opStack.getTopOfStack();
00943: opStack.getTopOfStack();
00944: }
00945: //codeStatements += Util.formatDecompiledStatement(local.getVarName()+"=("+op.getOperandValue()+");\n");
00946: op2 = createOperand(local.getVarName());
00947: opStack.push(op2);
00948: }
00949: }
00950:
00951: if (doNotPop == true)
00952: doNotPop = false;
00953:
00954: continue;
00955: case JvmOpCodes.DSTORE_0:
00956:
00957: StringBuffer codes = new StringBuffer("");
00958: handleSimpleDstoreCaseInst(opStack, info, 0, codes);
00959: //codeStatements+=codes.toString();
00960:
00961: continue;
00962: case JvmOpCodes.DSTORE_1:
00963: codes = new StringBuffer("");
00964: handleSimpleDstoreCaseInst(opStack, info, 1, codes);
00965: //codeStatements+=codes.toString();
00966:
00967: continue;
00968: case JvmOpCodes.DSTORE_2:
00969: codes = new StringBuffer("");
00970: handleSimpleDstoreCaseInst(opStack, info, 2, codes);
00971: //codeStatements+=codes.toString();
00972: continue;
00973: case JvmOpCodes.DSTORE_3:
00974: codes = new StringBuffer("");
00975: handleSimpleDstoreCaseInst(opStack, info, 3, codes);
00976: //codeStatements+=codes.toString();
00977: continue;
00978: case JvmOpCodes.DSUB:
00979: addParsedOutput("Instruction Pos "
00980: + currentForIndex + "\t:- " + " dsub\n");
00981: op = (Operand) opStack.pop();
00982: op1 = (Operand) opStack.pop();
00983:
00984: op2 = new Operand();
00985: op2.setOperandType(Constants.IS_CONSTANT_DOUBLE);
00986: op2.setOperandValue("(" + op.getOperandValue()
00987: + "- " + op1.getOperandValue() + ")");
00988: //op2.setCategory(Constants.CATEGORY1);
00989:
00990: opStack.push(op2);
00991:
00992: continue;
00993: case JvmOpCodes.DUP:
00994: addParsedOutput("Instruction Pos "
00995: + currentForIndex + "\t:- " + " dup\n");
00996: op1 = (Operand) opStack.pop();
00997: opStack.push(op1);
00998: opStack.push(op1);
00999:
01000: continue;
01001: case JvmOpCodes.DUP_X1:
01002: addParsedOutput("Instruction Pos "
01003: + currentForIndex + "\t:- " + " dup_x1\n");
01004: op1 = (Operand) opStack.pop();
01005: op2 = (Operand) opStack.pop();
01006: opStack.push(op1);
01007: opStack.push(op2);
01008: opStack.push(op1);
01009: continue;
01010: case JvmOpCodes.DUP_X2:
01011: addParsedOutput("Instruction Pos "
01012: + currentForIndex + "\t:- " + " dup_x2\n");
01013: op1 = (Operand) opStack.pop();
01014: op2 = (Operand) opStack.pop();
01015: op3 = (Operand) opStack.pop();
01016: opStack.push(op1);
01017: opStack.push(op3);
01018: opStack.push(op2);
01019: opStack.push(op1);
01020: continue;
01021: case JvmOpCodes.DUP2:
01022: addParsedOutput("Instruction Pos "
01023: + currentForIndex + "\t:- " + " dup2\n");
01024: op1 = (Operand) opStack.pop();
01025: op2 = (Operand) opStack.pop();
01026:
01027: opStack.push(op2);
01028: opStack.push(op1);
01029: opStack.push(op2);
01030: opStack.push(op1);
01031:
01032: continue;
01033: case JvmOpCodes.DUP2_X1:
01034: addParsedOutput("Instruction Pos "
01035: + currentForIndex + "\t:- " + " dup2_x1\n");
01036: op1 = (Operand) opStack.pop();
01037: op2 = (Operand) opStack.pop();
01038: op3 = (Operand) opStack.pop();
01039: opStack.push(op2);
01040: opStack.push(op1);
01041: opStack.push(op3);
01042: opStack.push(op2);
01043: opStack.push(op1);
01044: continue;
01045: case JvmOpCodes.DUP2_X2:
01046: addParsedOutput("Instruction Pos "
01047: + currentForIndex + "\t:- " + " dup2_x2\n");
01048: handleDUP2X2(opStack);
01049:
01050: continue;
01051:
01052: // LETTER F
01053: case JvmOpCodes.F2D:
01054: addParsedOutput("Instruction Pos "
01055: + currentForIndex + "\t:- " + " f2d\n");
01056: op = (Operand) opStack.pop();
01057: op.setOperandValue("(double)" + "("
01058: + op.getOperandValue() + ")");
01059: op.setOperandType(Constants.IS_CONSTANT_DOUBLE);
01060: opStack.push(op);
01061: continue;
01062: case JvmOpCodes.F2I:
01063: addParsedOutput("Instruction Pos "
01064: + currentForIndex + "\t:- " + " f2i\n");
01065: op = (Operand) opStack.pop();
01066: op.setOperandValue("(int)" + "("
01067: + op.getOperandValue() + ")");
01068: op.setOperandType(Constants.IS_CONSTANT_INT);
01069: opStack.push(op);
01070: continue;
01071: case JvmOpCodes.F2L:
01072: addParsedOutput("Instruction Pos "
01073: + currentForIndex + "\t:- " + " f2l\n");
01074: op = (Operand) opStack.pop();
01075: op.setOperandValue("(long)" + "("
01076: + op.getOperandValue() + ")");
01077: op.setOperandType(Constants.IS_CONSTANT_LONG);
01078: opStack.push(op);
01079: continue;
01080: case JvmOpCodes.FADD:
01081: addParsedOutput("Instruction Pos "
01082: + currentForIndex + "\t:- " + " fadd\n");
01083: op = (Operand) opStack.pop();
01084: op1 = (Operand) opStack.pop();
01085: op2 = new Operand();
01086: op2.setOperandValue("(" + op.getOperandValue()
01087: + " + " + op1.getOperandValue() + ")");
01088: op2.setOperandType(Constants.IS_CONSTANT_FLOAT);
01089: // op2.setCategory(Constants.CATEGORY1);
01090: opStack.push(op2);
01091:
01092: continue;
01093: case JvmOpCodes.FALOAD:
01094: addParsedOutput("Instruction Pos "
01095: + currentForIndex + "\t:- " + " faload\n");
01096: op = (Operand) opStack.pop();
01097: op1 = (Operand) opStack.pop();
01098: op2 = new Operand();
01099: op2.setOperandValue(op1.getOperandValue() + "["
01100: + op.getOperandValue() + "]");
01101: //op2.setCategory(Constants.CATEGORY1);
01102: op2.setOperandType(Constants.IS_CONSTANT_FLOAT);
01103: opStack.push(op2);
01104: continue;
01105: case JvmOpCodes.FASTORE:
01106: addParsedOutput("Instruction Pos "
01107: + currentForIndex + "\t:- " + " fastore\n");
01108: op = (Operand) opStack.pop();
01109: op1 = (Operand) opStack.pop();
01110: op2 = (Operand) opStack.pop();
01111:
01112: tempString = op2.getOperandValue() + "["
01113: + op1.getOperandValue() + "]="
01114: + op.getOperandValue();
01115: if (tempString.indexOf(";") == -1)
01116: tempString += ";\n";
01117: //codeStatements+=Util.formatDecompiledStatement(tempString);
01118:
01119: continue;
01120: case JvmOpCodes.FCMPG:
01121: addParsedOutput("Instruction Pos "
01122: + currentForIndex + "\t:- " + " fcmpg\n");
01123: handleFCMPG(opStack, info);
01124: continue;
01125: case JvmOpCodes.FCMPL:
01126: addParsedOutput("Instruction Pos "
01127: + currentForIndex + "\t:- " + " fcmpl\n");
01128: handleFCMPL(opStack, info);
01129: continue;
01130: case JvmOpCodes.FCONST_0:
01131: addParsedOutput("Instruction Pos "
01132: + currentForIndex + "\t:- " + " fonst_0\n");
01133: handleFCONST(opStack, "0.0f");
01134:
01135: continue;
01136: case JvmOpCodes.FCONST_1:
01137: addParsedOutput("Instruction Pos "
01138: + currentForIndex + "\t:- " + " fonst_1\n");
01139: handleFCONST(opStack, "1.0f");
01140: continue;
01141: case JvmOpCodes.FCONST_2:
01142: addParsedOutput("Instruction Pos "
01143: + currentForIndex + "\t:- " + " fonst_2\n");
01144: handleFCONST(opStack, "2.0f");
01145: continue;
01146: case JvmOpCodes.FDIV:
01147: addParsedOutput("Instruction Pos "
01148: + currentForIndex + "\t:- " + " fdiv\n");
01149: handleFDIV(opStack);
01150:
01151: continue;
01152: case JvmOpCodes.FLOAD:
01153: opValueI = info[++i];
01154:
01155: handleFLOAD(opValueI, opStack, false);
01156:
01157: //opStack.push(element);
01158: ;
01159: continue;
01160: case JvmOpCodes.FLOAD_0:
01161:
01162: handleFLOAD(0, opStack, true);
01163:
01164: continue;
01165: case JvmOpCodes.FLOAD_1:
01166:
01167: handleFLOAD(1, opStack, true);
01168:
01169: //opStack.push(element);
01170: continue;
01171: case JvmOpCodes.FLOAD_2:
01172: handleFLOAD(2, opStack, true);
01173:
01174: //opStack.push(element);
01175: continue;
01176: case JvmOpCodes.FLOAD_3:
01177:
01178: handleFLOAD(3, opStack, true);
01179:
01180: //opStack.push(element);
01181: continue;
01182: case JvmOpCodes.FMUL:
01183: addParsedOutput("Instruction Pos "
01184: + currentForIndex + "\t:- " + " fmul\n");
01185: op = (Operand) opStack.pop();
01186: op1 = (Operand) opStack.pop();
01187:
01188: op2 = new Operand();
01189: op2.setOperandValue("(" + op.getOperandValue()
01190: + " * " + op1.getOperandValue() + ")");
01191: op2.setOperandType(Constants.IS_CONSTANT_FLOAT);
01192: // op2.setCategory(Constants.CATEGORY1);
01193:
01194: opStack.push(op2);
01195:
01196: continue;
01197: case JvmOpCodes.FNEG:
01198: addParsedOutput("Instruction Pos "
01199: + currentForIndex + "\t:- " + " fneg\n");
01200: op = (Operand) opStack.pop();
01201: op1 = new Operand();
01202: op1.setOperandValue("-" + "("
01203: + op.getOperandValue() + ")");
01204: //op1.setCategory(Constants.CATEGORY1);
01205: op1.setOperandType(Constants.IS_CONSTANT_FLOAT);
01206: opStack.push(op1);
01207: continue;
01208: case JvmOpCodes.FREM:
01209: addParsedOutput("Instruction Pos "
01210: + currentForIndex + "\t:- " + " frem\n");
01211: op = (Operand) opStack.pop();
01212: op1 = (Operand) opStack.pop();
01213:
01214: op2 = new Operand();
01215: //op2.setCategory(Constants.CATEGORY1);
01216: op2.setOperandType(Constants.IS_CONSTANT_FLOAT);
01217: op2.setOperandValue("(" + op.getOperandValue()
01218: + "% " + op1.getOperandValue() + ")");
01219:
01220: opStack.push(op2);
01221: continue;
01222: case JvmOpCodes.FRETURN:
01223: addParsedOutput("Instruction Pos "
01224: + currentForIndex + "\t:- " + " frerturn\n");
01225: oktoadd = true;
01226: mapIT = returnsAtI.entrySet().iterator();
01227: while (mapIT.hasNext()) {
01228: Map.Entry entry = (Map.Entry) mapIT.next();
01229: Object key = entry.getKey();
01230: Object retStatus = entry.getValue().toString();
01231: if (key instanceof Integer) {
01232: Integer pos = (Integer) key;
01233: int temp = pos.intValue();
01234: if (temp == i) {
01235: if (retStatus.equals("true")) {
01236:
01237: oktoadd = false;
01238: break;
01239: }
01240: }
01241: }
01242:
01243: }
01244:
01245: if (!oktoadd) {
01246: returnsAtI.remove(new Integer(i));
01247: }
01248:
01249: if (oktoadd && opStack.size() > 0) {
01250: op = (Operand) opStack.pop();
01251: tempString = "return "
01252: + op.getOperandValue().toString()
01253: + ";\n";
01254: //codeStatements+=Util.formatDecompiledStatement(tempString);
01255: }
01256:
01257: //behaviour.getParentBehaviour().getOpStack().push(op);
01258: continue;
01259: case JvmOpCodes.FSTORE:
01260: classIndex = info[++i];
01261:
01262: local = getLocalVariable(classIndex, "store",
01263: "float", false, currentForIndex);
01264: if (cd.isClassCompiledWithMinusG() && local != null) {
01265: addParsedOutput("Instruction Pos "
01266: + currentForIndex + "\t:- "
01267: + " fstore " + classIndex
01268: + " THIS localVariable:- "
01269: + local.getVarName() + "\n");
01270: } else
01271: addParsedOutput("Instruction Pos "
01272: + currentForIndex + "\t:- "
01273: + " fstore " + classIndex + "\n");
01274:
01275: if (local != null && !doNotPop) {
01276: op = (Operand) opStack.pop();
01277: prevLocalGenerated = local;
01278: boolean push = isPrevInstDup(info,
01279: currentForIndex);
01280: if (!push) {
01281: if (!local.isDeclarationGenerated()) {
01282: local.setBlockIndex(blockLevel);
01283: tempString = local.getDataType() + " "
01284: + local.getVarName() + "="
01285: + op.getOperandValue() + ";\n";
01286: //codeStatements +=Util.formatDecompiledStatement(tempString);
01287: local.setDeclarationGenerated(true);
01288: } else {
01289: tempString = local.getVarName() + "="
01290: + op.getOperandValue() + ";\n";
01291: //codeStatements +=Util.formatDecompiledStatement(tempString);
01292: }
01293: }
01294:
01295: else {
01296: if (isThisInstrStart(behaviour
01297: .getInstructionStartPositions(),
01298: currentForIndex - 1)
01299: && info[currentForIndex - 1] == JvmOpCodes.DUP)
01300: opStack.getTopOfStack();
01301: if (isThisInstrStart(behaviour
01302: .getInstructionStartPositions(),
01303: currentForIndex - 1)
01304: && info[currentForIndex - 1] == JvmOpCodes.DUP2) {
01305: opStack.getTopOfStack();
01306: opStack.getTopOfStack();
01307: }
01308: //codeStatements +=Util.formatDecompiledStatement(local.getVarName()+"=("+op.getOperandValue()+");\n");
01309: Operand op5 = createOperand(local
01310: .getVarName());
01311: opStack.push(op5);
01312: }
01313: }
01314: if (doNotPop == true)
01315: doNotPop = false;
01316: continue;
01317: case JvmOpCodes.FSTORE_0:
01318:
01319: StringBuffer srb = new StringBuffer("");
01320: handleSimpleFstoreCaseInst(opStack, info, 0, srb);
01321: //codeStatements+=srb.toString();
01322:
01323: continue;
01324: case JvmOpCodes.FSTORE_1:
01325: srb = new StringBuffer("");
01326: handleSimpleFstoreCaseInst(opStack, info, 1, srb);
01327: //codeStatements+=srb.toString();
01328:
01329: continue;
01330:
01331: case JvmOpCodes.FSTORE_2:
01332: srb = new StringBuffer("");
01333: handleSimpleFstoreCaseInst(opStack, info, 2, srb);
01334: //codeStatements+=srb.toString();
01335:
01336: continue;
01337: case JvmOpCodes.FSTORE_3:
01338: srb = new StringBuffer("");
01339: handleSimpleFstoreCaseInst(opStack, info, 3, srb);
01340: //codeStatements+=srb.toString();
01341: continue;
01342: case JvmOpCodes.FSUB:
01343: addParsedOutput("Instruction Pos "
01344: + currentForIndex + "\t:- " + " fsub\n");
01345: op = (Operand) opStack.pop();
01346: op1 = (Operand) opStack.pop();
01347:
01348: op2 = new Operand();
01349: op2.setOperandType(Constants.IS_CONSTANT_FLOAT);
01350: op2.setOperandValue("(" + op.getOperandValue()
01351: + ") - (" + op1.getOperandValue() + ")");
01352: //op2.setCategory(Constants.CATEGORY1);
01353:
01354: opStack.push(op2);
01355: continue;
01356:
01357: // LETTER G
01358: case JvmOpCodes.GETFIELD: // TODO: check whether this needs to push classtype intp stack
01359: addParsedOutput("Instruction Pos "
01360: + currentForIndex + "\t:- " + " getField");
01361: op = (Operand) opStack.pop();
01362: //temp1=info[++i];
01363: //temp2=info[++i];
01364: classIndex = getOffset(info, i);//(temp1 << 8) | temp2);
01365: i += 2;
01366: //if(classIndex < 0)classIndex=(temp1+1)*256-Math.abs(temp2);
01367: fref = cd.getFieldRefAtCPoolPosition(classIndex);
01368:
01369: //NameAndType ninfo=cd.getNameAndTypeAtCPoolPosition(classIndex);
01370: op2 = new Operand();
01371: //(Constants.CATEGORY1);
01372: op2.setOperandType(Constants.IS_ARRAY_REF);
01373: op2.setOperandValue(op.getOperandValue() + "."
01374: + fref.getFieldName());
01375: opStack.push(op2);
01376: Util.parseReturnType(fref.getTypeoffield());
01377: ArrayList returntype = Util
01378: .getreturnSignatureAsList();
01379: if (returntype.size() > 0) {
01380: addParsedOutput("Field :- "
01381: + fref.getFieldName() + " TYPE:- "
01382: + (java.lang.String) returntype.get(0)
01383: + "\n");
01384: op2.setClassType((java.lang.String) returntype
01385: .get(0));
01386: }
01387:
01388: continue;
01389: case JvmOpCodes.GETSTATIC:
01390:
01391: addParsedOutput("Instruction Pos "
01392: + currentForIndex + "\t:- " + " getStatic");
01393: classIndex = getOffset(info, i);
01394: i += 2;
01395: fref = cd.getFieldRefAtCPoolPosition(classIndex);
01396: op = new Operand();
01397: //(Constants.CATEGORY1);
01398: if (opStack.size() > 0
01399: && isThisInstrStart(behaviour
01400: .getInstructionStartPositions(),
01401: (currentForIndex - 1))
01402: && (info[currentForIndex - 1] == JvmOpCodes.POP || info[currentForIndex - 1] == JvmOpCodes.POP2
01403: && opStack.size() > 0)) {
01404: java.lang.String opv = opStack.getTopOfStack()
01405: .getOperandValue();
01406: if (opv != null)
01407: op.setOperandValue(opv.replace('/', '.')
01408: + "." + fref.getFieldName());
01409: else
01410: op.setOperandValue(fref.getClassname()
01411: .replace('/', '.')
01412: + "." + fref.getFieldName());
01413: } else
01414: op.setOperandValue(fref.getClassname().replace(
01415: '/', '.')
01416: + "." + fref.getFieldName());
01417: Util.parseReturnType(fref.getTypeoffield());
01418: returntype = Util.getreturnSignatureAsList();
01419:
01420: if (returntype.size() > 0) {
01421: java.lang.Object tempv = returntype.get(0);
01422: addParsedOutput("Field :- "
01423: + fref.getFieldName() + " TYPE:- "
01424: + tempv + "\n");
01425: op.setClassType((java.lang.String) tempv);
01426: }
01427: opStack.push(op);
01428: continue;
01429: case JvmOpCodes.GOTO: // Mistake here. GOTO of switch not taken into consideration
01430: // Also goto can occur at the end of try block also or a catch block
01431: int instructionPos = i;
01432:
01433: int b1 = info[++i]; // TODO: Replace by jumpaddress
01434: int b2 = info[++i];
01435: int z;
01436: if (b1 < 0)
01437: b1 = (256 + b1);
01438: if (b2 < 0)
01439: b2 = (256 + b2);
01440:
01441: int indexInst = ((((b1 << 8) | b2)) + (i - 2));
01442: if (indexInst > 65535)
01443: indexInst = indexInst - 65536;
01444: if (indexInst < 0)
01445: indexInst = 256 + indexInst;
01446: addParsedOutput("Instruction Pos "
01447: + currentForIndex + "\t:- " + " goto "
01448: + indexInst + "\n");
01449: if (isIfInScope) {
01450: Iterator iterIfHash = ifHashTable.keySet()
01451: .iterator();
01452: while (iterIfHash.hasNext()) {
01453: Object key = iterIfHash.next();
01454: IFBlock ifs = (IFBlock) ifHashTable
01455: .get(key);
01456: boolean prevGotoPresent = false;
01457: int if_start = ifs.getIfStart();
01458: boolean loop_start = isThisLoopStart(ifs,
01459: behaviour.getBehaviourLoops(), info);
01460: int this ifclose = ifs
01461: .getIfCloseLineNumber();
01462: boolean donotgeneratelese = false;
01463: if (isThisInstrStart(behaviour
01464: .getInstructionStartPositions(),
01465: (this ifclose - 3))
01466: && isInstructionIF(info[this ifclose - 3])) {
01467: donotgeneratelese = true;
01468: }
01469: if ((ifs.getIfCloseLineNumber() - (i - 2)) == 0
01470: && !loop_start
01471: && !donotgeneratelese) { // Removed Math.abs : belurs
01472: elseCloseLineNo = indexInst;
01473: // System.out.println("elseCloseLineNo "+elseCloseLineNo);
01474: java.lang.String checkAgain = "";
01475: // if(elseCloseLineNo > i)
01476: // {
01477: this .getCurrentIFStructues();
01478: Object ifsSorted[] = sortIFStructures();
01479: IFBlock parent = getParentBlock(
01480: ifsSorted, ifs.getIfStart());
01481: ArrayList loopList = behaviour
01482: .getBehaviourLoops();
01483: int loopSize = loopList.size();
01484: java.lang.String checkSwitch = "";
01485: StringBuffer again = new StringBuffer(
01486: "");
01487: if (parent == null) {
01488: ifs.setHasElse(true);
01489: if (loopSize > 0) {
01490: ifs
01491: .setElseCloseLineNumber(elseCloseLineNo);
01492: checkAgain = "true";
01493: } else
01494: ifs
01495: .setElseCloseLineNumber(elseCloseLineNo);
01496:
01497: //ifs.setHasMatchingElseBeenGenerated(true);
01498: if (!checkAgain
01499: .equalsIgnoreCase("true")
01500: && behaviour
01501: .getAllSwitchBlks() != null
01502: && behaviour
01503: .getAllSwitchBlks()
01504: .size() > 0)
01505: checkSwitch = "true";
01506: elseCloseLineNo = ifs
01507: .getElseCloseLineNumber();
01508: }
01509:
01510: else {
01511: ifs.setHasElse(true);
01512: ifs
01513: .setElseCloseLineNumber(elseCloseLineNo); // Check This logic
01514: //ifs.setHasMatchingElseBeenGenerated(true);
01515:
01516: int tmpend = checkElseCloseLineNumber(
01517: ifsSorted, parent, ifs, ifs
01518: .getIfStart(),
01519: elseCloseLineNo, again);
01520: if (tmpend != -1
01521: && !again.toString()
01522: .equals("true")) {
01523: ifs
01524: .setElseCloseLineNumber(tmpend);
01525: elseCloseLineNo = ifs
01526: .getElseCloseLineNumber();
01527: }
01528:
01529: }
01530: if (checkAgain.equals("true")
01531: || again.toString().equals(
01532: "true")) {
01533: elseCloseLineNo = ifs
01534: .getElseCloseLineNumber(); //
01535: elseCloseLineNo = resetElseCloseNumber(
01536: loopList, ifs,
01537: currentForIndex);
01538: ifs
01539: .setElseCloseLineNumber(elseCloseLineNo);
01540:
01541: }
01542: ArrayList switches = behaviour
01543: .getAllSwitchBlks();
01544:
01545: int newelseend = -1;
01546: if (switches != null
01547: && switches.size() > 0) {
01548: newelseend = resetEndofIFElseWRTSwitch(
01549: switches,
01550: ifs,
01551: ifs
01552: .getElseCloseLineNumber(),
01553: currentForIndex, "else");
01554: boolean valid = isNewEndValid(
01555: newelseend,
01556: ifs,
01557: "else",
01558: ifs
01559: .getElseCloseLineNumber());
01560: if (valid) {
01561: ifs
01562: .setElseCloseLineNumber(newelseend);
01563: elseCloseLineNo = ifs
01564: .getElseCloseLineNumber();
01565: }
01566: }
01567:
01568: //
01569: if (continue_JumpOffsets.size() > 0) {
01570: elseCloseLineNo = resetElseCloseNumber(
01571: currentForIndex,
01572: elseCloseLineNo);
01573: ifs
01574: .setElseCloseLineNumber(elseCloseLineNo);
01575: }
01576:
01577: if (elseCloseLineNo < (currentForIndex + 3)
01578: && behaviour.getAllSwitchBlks() != null
01579: && behaviour.getAllSwitchBlks()
01580: .size() > 0) {
01581: Case caseblk = null;
01582: caseblk = isIFInCase(behaviour,
01583: currentForIndex, ifs);
01584: if (caseblk != null) {
01585: elseCloseLineNo = getElseEndwrtcaseblk(
01586: caseblk, info,
01587: currentForIndex + 3);
01588: ifs
01589: .setElseCloseLineNumber(elseCloseLineNo);
01590: }
01591:
01592: }
01593: // }
01594: /* else if(elseCloseLineNo < i) // TODO: DOUBLE CHECK IF THIS IS REQD!!!
01595: {
01596: elseCloseLineNo = findElseCloseLineNumber(i,elseCloseLineNo,info);
01597: }*/
01598: // TOFIX Problem of generating an else when it is not reqd
01599: boolean loopEndalso = isThisLoopEndAlso(
01600: behaviour.getBehaviourLoops(),
01601: currentForIndex, ifs
01602: .getIfStart());
01603: if (loopEndalso)
01604: ifs.setElseCloseLineNumber(-1);
01605: ArrayList gotos = cd.getGotoStarts();
01606: ArrayList gotoj = cd.getGotojumps();
01607: boolean skipElse = skipGeneratingElse(
01608: gotos, gotoj, currentForIndex,
01609: ifs);
01610: if (skipElse)
01611: ifs.setElseCloseLineNumber(-1);
01612: if (!loopEndalso && !skipElse) {
01613: if ((elseCloseLineNo > ifs
01614: .getIfCloseLineNumber()) == false) {
01615:
01616: elseCloseLineNo = getElseCloseFromInRangeIfStructures(
01617: ifs, currentForIndex);
01618: if (elseCloseLineNo != -1) {
01619: ifs
01620: .setElseCloseLineNumber(elseCloseLineNo);
01621: }
01622: }
01623: if (elseCloseLineNo == -1) {
01624: elseCloseLineNo = checkElseCloseWRTAnyParentLoop(
01625: ifs, currentForIndex,
01626: info);
01627: }
01628: boolean addelsestart = addElseStart(currentForIndex);
01629: if (addelsestart
01630: && elseCloseLineNo != -1
01631: && elseCloseLineNo != ifs
01632: .getIfCloseLineNumber()
01633: && elseCloseLineNo > ifs
01634: .getIfCloseLineNumber()) // changed by belurs
01635: {
01636: ifs
01637: .setHasMatchingElseBeenGenerated(true);
01638: ifs
01639: .setElseCloseLineNumber(elseCloseLineNo);
01640: java.lang.String s = "";
01641: int x = getReqdGoto(
01642: currentForIndex,
01643: info,
01644: ifs
01645: .getElseCloseLineNumber());
01646: StringBuffer sb = new StringBuffer(
01647: "");
01648: if (x != -1)
01649: s = getBranchType(
01650: currentForIndex,
01651: x,
01652: info,
01653: behaviour
01654: .getBehaviourLoops(),
01655: sb);
01656: branchLabels
01657: .put(
01658: new BranchLabel(
01659: ifst,
01660: s,
01661: sb
01662: .toString()),
01663: new Integer(
01664: ifs
01665: .getElseCloseLineNumber()));
01666: //codeStatements += "\n";
01667: tempString = "else\n{\n";
01668: elsestartadded.add(new Integer(
01669: currentForIndex));
01670: //codeStatements+=Util.formatDecompiledStatement(tempString);
01671: elsehasbegun = true;
01672: //System.out.println("else has begun for else at "+currentForIndex);
01673: } else // TODO : Recheck this else blk
01674: {
01675: if (elseCloseLineNo > ifs
01676: .getIfCloseLineNumber()) {
01677: //ifs.setHasMatchingElseBeenGenerated(true);
01678: ifs
01679: .setElseCloseLineNumber(elseCloseLineNo);
01680: }
01681: }
01682: }
01683: // ifs.setIfCloseLineNumber(-1);
01684:
01685: ifs.setIfHasBeenClosed(true);
01686: blockLevel++;
01687: }
01688:
01689: ifHashTable.put(key, ifs);
01690: }
01691: }
01692: if (isWhileInScope) // TODO: Check if this can be removed
01693: {
01694: if (whileIndex == 1)
01695: isWhileInScope = false;
01696: whileIndex--;
01697: // Changed by belurs ..This line was producing an extra bracket in output
01698: //tempString="\n}\n";
01699: ////codeStatements += Util.formatDecompiledStatement(tempString); // Definitly source of bug
01700: }
01701:
01702: continue;
01703: case JvmOpCodes.GOTO_W: // TODO Need to do Test vigorously and find a goto_w in any program
01704:
01705: classIndex = ((info[++i] << 24) | (info[++i] << 16)
01706: | (info[++i] << 8) | info[++i]);
01707: addParsedOutput("Instruction Pos "
01708: + currentForIndex + "\t:- " + " goto_w"
01709: + classIndex + "\n");
01710: //parsedString+=classIndex+"\n";
01711: //parsedString+="\t";parsedString+="\t";continue;
01712:
01713: // LETTER I
01714: case JvmOpCodes.I2B:
01715: addParsedOutput("Instruction Pos "
01716: + currentForIndex + "\t:- " + " i2b\n");
01717:
01718: op = (Operand) opStack.pop();
01719: op.setOperandValue("(byte)" + "("
01720: + op.getOperandValue() + ")");
01721: op.setOperandType(Constants.IS_CONSTANT_BYTE);
01722: opStack.push(op);
01723: continue;
01724: case JvmOpCodes.I2C:
01725: addParsedOutput("Instruction Pos "
01726: + currentForIndex + "\t:- " + " i2c\n");
01727: op = (Operand) opStack.pop();
01728: op.setOperandValue("(char)" + "("
01729: + op.getOperandValue() + ")");
01730: op.setOperandType(Constants.IS_CONSTANT_CHARACTER);
01731: opStack.push(op);
01732: continue;
01733: case JvmOpCodes.I2D:
01734: addParsedOutput("Instruction Pos "
01735: + currentForIndex + "\t:- " + " i2d\n");
01736: op = (Operand) opStack.pop();
01737: op.setOperandValue(op.getOperandValue());
01738: op.setOperandType(Constants.IS_CONSTANT_DOUBLE);
01739: opStack.push(op);
01740: continue;
01741: case JvmOpCodes.I2F:
01742: addParsedOutput("Instruction Pos "
01743: + currentForIndex + "\t:- " + " i2f\n");
01744: op = (Operand) opStack.pop();
01745: op.setOperandValue(op.getOperandValue());
01746: op.setOperandType(Constants.IS_CONSTANT_FLOAT);
01747: opStack.push(op);
01748: continue;
01749: case JvmOpCodes.I2L:
01750: addParsedOutput("Instruction Pos "
01751: + currentForIndex + "\t:- " + " i2l\n");
01752:
01753: op = (Operand) opStack.pop();
01754: op.setOperandValue(op.getOperandValue());
01755: op.setOperandType(Constants.IS_CONSTANT_LONG);
01756: opStack.push(op);
01757: continue;
01758: case JvmOpCodes.I2S:
01759: addParsedOutput("Instruction Pos "
01760: + currentForIndex + "\t:- " + " i2s\n");
01761:
01762: op = (Operand) opStack.pop();
01763: op.setOperandValue("(short)" + "("
01764: + op.getOperandValue() + ")");
01765: op.setOperandType(Constants.IS_CONSTANT_SHORT);
01766: opStack.push(op);
01767: continue;
01768: case JvmOpCodes.IADD:
01769: addParsedOutput("Instruction Pos "
01770: + currentForIndex + "\t:- " + " iadd\n");
01771: op = (Operand) opStack.pop();
01772: op1 = (Operand) opStack.pop();
01773: op2 = new Operand();
01774: op2.setOperandValue("(" + op.getOperandValue()
01775: + " + " + op1.getOperandValue() + ")");
01776: op2.setOperandType(Constants.IS_CONSTANT_INT);
01777: //op2.setCategory(Constants.CATEGORY1);
01778: opStack.push(op2);
01779: continue;
01780: case JvmOpCodes.IALOAD:
01781: addParsedOutput("Instruction Pos "
01782: + currentForIndex + "\t:- " + " iaload\n");
01783: op = (Operand) opStack.pop();
01784: op1 = (Operand) opStack.pop();
01785: op2 = new Operand();
01786: op2.setOperandValue(op1.getOperandValue() + "["
01787: + op.getOperandValue() + "]");
01788: op2.setCategory(Constants.IS_CONSTANT_INT);
01789: opStack.push(op2);
01790: continue;
01791: case JvmOpCodes.IAND:
01792: addParsedOutput("Instruction Pos "
01793: + currentForIndex + "\t:- " + " iand\n");
01794: op = (Operand) opStack.pop();
01795: op1 = (Operand) opStack.pop();
01796: op2 = new Operand();
01797: op2.setOperandValue("(" + op1.getOperandValue()
01798: + " & " + op.getOperandValue() + ")");
01799: op2.setOperandType(Constants.IS_CONSTANT_INT);
01800: op2.setCategory(Constants.CATEGORY1);
01801: opStack.push(op2);
01802: continue;
01803: case JvmOpCodes.IASTORE:
01804: addParsedOutput("Instruction Pos "
01805: + currentForIndex + "\t:- " + " iastore\n");
01806: op = (Operand) opStack.pop();
01807: op1 = (Operand) opStack.pop();
01808: op2 = (Operand) opStack.pop();
01809:
01810: tempString = op2.getOperandValue() + "["
01811: + op1.getOperandValue() + "]="
01812: + op.getOperandValue() + ";\n";
01813: //codeStatements+=Util.formatDecompiledStatement(tempString);
01814:
01815: continue;
01816: case JvmOpCodes.ICONST_0:
01817: addParsedOutput("Instruction Pos "
01818: + currentForIndex + "\t:- " + " iconst_0\n");
01819: op = new Operand();
01820: op.setOperandValue(new Integer(0));
01821: op.setOperandType(Constants.IS_CONSTANT_INT);
01822: //(Constants.CATEGORY1);
01823: opStack.push(op);
01824: continue;
01825: case JvmOpCodes.ICONST_1:
01826: addParsedOutput("Instruction Pos "
01827: + currentForIndex + "\t:- " + " iconst_1\n");
01828: op = new Operand();
01829: op.setOperandValue(new Integer(1));
01830: op.setOperandType(Constants.IS_CONSTANT_INT);
01831: //(Constants.CATEGORY1);
01832: opStack.push(op);
01833: continue;
01834: case JvmOpCodes.ICONST_2:
01835: addParsedOutput("Instruction Pos "
01836: + currentForIndex + "\t:- " + " iconst_2\n");
01837: op = new Operand();
01838: op.setOperandValue(new Integer(2));
01839: op.setOperandType(Constants.IS_CONSTANT_INT);
01840: //(Constants.CATEGORY1);
01841: opStack.push(op);
01842: continue;
01843:
01844: case JvmOpCodes.ICONST_3:
01845: addParsedOutput("Instruction Pos "
01846: + currentForIndex + "\t:- " + " iconst_3\n");
01847: op = new Operand();
01848: op.setOperandValue(new Integer(3));
01849: op.setOperandType(Constants.IS_CONSTANT_INT);
01850: //(Constants.CATEGORY1);
01851: opStack.push(op);
01852: continue;
01853: case JvmOpCodes.ICONST_4:
01854: addParsedOutput("Instruction Pos "
01855: + currentForIndex + "\t:- " + " iconst_4\n");
01856: op = new Operand();
01857: op.setOperandValue(new Integer(4));
01858: op.setOperandType(Constants.IS_CONSTANT_INT);
01859: //(Constants.CATEGORY1);
01860: opStack.push(op);
01861: continue;
01862: case JvmOpCodes.ICONST_5:
01863: addParsedOutput("Instruction Pos "
01864: + currentForIndex + "\t:- " + " iconst_5\n");
01865: op = new Operand();
01866: op.setOperandValue(new Integer(5));
01867: op.setOperandType(Constants.IS_CONSTANT_INT);
01868: //(Constants.CATEGORY1);
01869: opStack.push(op);
01870: continue;
01871: case JvmOpCodes.ICONST_M1:
01872: addParsedOutput("Instruction Pos "
01873: + currentForIndex + "\t:- "
01874: + " iconst_M1\n");
01875: op = new Operand();
01876: op.setOperandValue(new Integer(-1));
01877: op.setOperandType(Constants.IS_CONSTANT_INT);
01878: //(Constants.CATEGORY1);
01879: opStack.push(op);
01880: continue;
01881: case JvmOpCodes.IDIV:
01882: addParsedOutput("Instruction Pos "
01883: + currentForIndex + "\t:- " + " idiv\n");
01884: op = (Operand) opStack.pop();
01885: op1 = (Operand) opStack.pop();
01886: op2 = new Operand();
01887: op2.setOperandValue("(" + op1.getOperandValue()
01888: + ")" + "/" + "(" + op.getOperandValue()
01889: + ")");
01890: op2.setOperandType(Constants.IS_CONSTANT_INT);
01891: op2.setCategory(Constants.CATEGORY1);
01892: opStack.push(op2);
01893: continue;
01894: case JvmOpCodes.IF_ACMPEQ:
01895:
01896: op = (Operand) opStack.pop();
01897: op1 = (Operand) opStack.pop();
01898: /*classIndex = ((info[++i] << 8) | info[++i]);
01899: classIndex += i - 2;*/
01900: classIndex = getJumpAddress(info, i);
01901: addParsedOutput("Instruction Pos "
01902: + currentForIndex + "\t:- " + " if_acmpeq "
01903: + classIndex + "\n");
01904: i++;
01905: i++;
01906:
01907: blockLevel++;
01908: ArrayList list = behaviour.getBehaviourLoops();
01909: ifLevel++;
01910: ifst = new IFBlock();
01911: ifst.setIfStart(currentForIndex);
01912: ifst.setHasIfBeenGenerated(true);
01913: ifHashTable.put("" + (ifLevel), ifst);
01914: addBranchLabel(classIndex, i, ifst,
01915: currentForIndex, info);
01916: boolean isEndOfLoop = isIndexEndOfLoop(list, ifst
01917: .getIfCloseLineNumber());
01918: int loopstart = -1;
01919: boolean correctIf = false;
01920: boolean beyondLoop = isBeyondLoop(ifst
01921: .getIfCloseLineNumber(), list, info);
01922: if (isEndOfLoop) {
01923: loopstart = getLoopStartForEnd(ifst
01924: .getIfCloseLineNumber(), list);
01925: if (currentForIndex > loopstart) {
01926: boolean ifinstcodepresent = getIfinst(
01927: loopstart, info, currentForIndex);
01928: if (ifinstcodepresent) {
01929: correctIf = false;
01930: } else
01931: correctIf = true;
01932: }
01933: }
01934:
01935: if (info[ifst.getIfCloseLineNumber()] == JvmOpCodes.GOTO
01936: && isEndOfLoop && correctIf) {
01937: int t = ifst.getIfCloseLineNumber();
01938: int gotoIndex = getJumpAddress(info, t);//(info[t+1] << 8) | info[t+2]) + (ifst.getIfCloseLineNumber());
01939: if (gotoIndex < (t + 3)) {
01940: boolean isInfiniteLoop = false;
01941: Iterator infLoop = behaviour
01942: .getBehaviourLoops().iterator();
01943: while (infLoop.hasNext()) {
01944: Loop iloop = (Loop) infLoop.next();
01945: if (iloop.getStartIndex() == gotoIndex
01946: && iloop.isInfinite()) {
01947: isInfiniteLoop = true;
01948: /*ifLevel++;
01949: ifst = new IFBlock();
01950: ifst.setIfStart(currentForIndex);
01951: ifst.setHasIfBeenGenerated(true);*/
01952: //ifst.setIfCloseLineNumber(classIndex-3);
01953: ifst
01954: .setElseCloseLineNumber(gotoIndex);
01955: /*ifHashTable.put(""+(ifLevel),ifst);
01956: addBranchLabel(classIndex,i,ifst,currentForIndex,info);*/
01957: boolean bb = isBeyondLoop(
01958: getJumpAddress(info,
01959: currentForIndex),
01960: behaviour
01961: .getBehaviourLoops(),
01962: info);
01963: boolean print = true;
01964: if (bb && this Loop != null
01965: && this Loop.isInfinite()
01966: && !encounteredOrComp) {
01967: tempString = "\nif("
01968: + op1.getOperandValue()
01969: + "=="
01970: + op.getOperandValue()
01971: + ")\n{\nbreak;\n}\n";
01972: //codeStatements +=Util.formatDecompiledStatement(tempString);
01973: //ifst.setIfHasBeenClosed(true);
01974: print = false;
01975: }
01976: isIfInScope = true;
01977: boolean c;
01978: boolean last = lastIFinShortCutChain(
01979: info, ifst, currentForIndex);
01980: c = addCodeStatementWRTShortcutOR(
01981: ifst,
01982: op1.getOperandValue()
01983: + " == "
01984: + op
01985: .getOperandValue(),
01986: print,
01987: "if",
01988: last,
01989: op1.getOperandValue()
01990: + " != "
01991: + op
01992: .getOperandValue());
01993: if (c) {
01994: tempString = "\nif(!"
01995: + op1.getOperandValue()
01996: + "=="
01997: + op.getOperandValue()
01998: + "))\n{\n";
01999: //codeStatements +=Util.formatDecompiledStatement(tempString);
02000: }
02001: break;
02002: }
02003: }
02004: if (isInfiniteLoop) {
02005: continue;
02006: }
02007: boolean last = lastIFinShortCutChain(info,
02008: ifst, currentForIndex);
02009: boolean c = addCodeStatementWRTShortcutOR(
02010: ifst, op1.getOperandValue()
02011: + " == "
02012: + op.getOperandValue(),
02013: true, "while", last, op1
02014: .getOperandValue()
02015: + " != "
02016: + op.getOperandValue());
02017: if (c) {
02018: tempString = "\nwhile(!"
02019: + op1.getOperandValue() + "=="
02020: + op.getOperandValue()
02021: + "))\n{\n";
02022: //codeStatements +=Util.formatDecompiledStatement(tempString);
02023: }
02024: isWhileInScope = true;
02025: whileIndex++;
02026:
02027: }
02028: //int x = 0;
02029: else {
02030:
02031: /* ifLevel++;
02032: ifst = new IFBlock();
02033: ifst.setIfStart(currentForIndex);
02034: ifst.setHasIfBeenGenerated(true);
02035: //ifst.setIfCloseLineNumber(classIndex-3);*/
02036:
02037: ifst.setElseCloseLineNumber(gotoIndex);
02038: /*ifHashTable.put(""+(ifLevel),ifst);
02039: isIfInScope = true;*/
02040:
02041: // addBranchLabel(classIndex,i,ifst,currentForIndex,info);
02042: isIfInScope = true;
02043: boolean bb = isBeyondLoop(getJumpAddress(
02044: info, currentForIndex), behaviour
02045: .getBehaviourLoops(), info);
02046: boolean print = true;
02047: if (bb && this Loop != null
02048: && this Loop.isInfinite()
02049: && !encounteredOrComp) {
02050: tempString = "\nif("
02051: + op1.getOperandValue() + "=="
02052: + op.getOperandValue()
02053: + ")\n{\nbreak;\n}\n";
02054: //codeStatements +=Util.formatDecompiledStatement(tempString);
02055: print = false;
02056:
02057: }
02058: boolean last = lastIFinShortCutChain(info,
02059: ifst, currentForIndex);
02060: boolean c = addCodeStatementWRTShortcutOR(
02061: ifst, op1.getOperandValue()
02062: + " == "
02063: + op.getOperandValue(),
02064: print, "if", last, op1
02065: .getOperandValue()
02066: + " != "
02067: + op.getOperandValue());
02068: if (c) {
02069: tempString = "\nif(!"
02070: + op1.getOperandValue() + "=="
02071: + op.getOperandValue()
02072: + "))\n{\n";
02073: //codeStatements +=Util.formatDecompiledStatement(tempString);
02074: }
02075:
02076: }
02077: } else {
02078: /* ifLevel++;
02079: ifst = new IFBlock();
02080: ifst.setIfStart(currentForIndex);
02081: ifst.setHasIfBeenGenerated(true);
02082: isIfInScope = true;
02083: ifHashTable.put(""+(ifLevel),ifst);
02084:
02085: addBranchLabel(classIndex,i,ifst,currentForIndex,info); */
02086: isIfInScope = true;
02087: boolean bb = isBeyondLoop(getJumpAddress(info,
02088: currentForIndex), behaviour
02089: .getBehaviourLoops(), info);
02090: boolean print = true;
02091: if (bb && this Loop != null
02092: && this Loop.isInfinite()
02093: && !encounteredOrComp) {
02094: tempString = "\nif("
02095: + op1.getOperandValue() + "=="
02096: + op.getOperandValue()
02097: + ")\n{\nbreak;\n}\n";
02098: //codeStatements +=Util.formatDecompiledStatement(tempString);
02099: print = false;
02100: // ifst.setIfHasBeenClosed(true);
02101:
02102: }
02103: boolean last = lastIFinShortCutChain(info,
02104: ifst, currentForIndex);
02105: boolean c = addCodeStatementWRTShortcutOR(ifst,
02106: op1.getOperandValue() + " == "
02107: + op.getOperandValue(), print,
02108: "if", last, op1.getOperandValue()
02109: + " != " + op.getOperandValue());
02110: if (c) {
02111: tempString = "\nif(!"
02112: + op1.getOperandValue() + "=="
02113: + op.getOperandValue() + "))\n{\n";
02114: //codeStatements += Util.formatDecompiledStatement(tempString);
02115: }
02116: }
02117:
02118: continue;
02119: case JvmOpCodes.IF_ACMPNE:
02120: op = (Operand) opStack.pop();
02121: op1 = (Operand) opStack.pop();
02122: classIndex = getJumpAddress(info, i);
02123: addParsedOutput("Instruction Pos "
02124: + currentForIndex + "\t:- " + " if_acmpne "
02125: + classIndex + "\n");
02126: i++;
02127: i++;
02128: blockLevel++;
02129: list = behaviour.getBehaviourLoops();
02130: ifLevel++;
02131: ifst = new IFBlock();
02132: ifst.setIfStart(currentForIndex);
02133: ifst.setHasIfBeenGenerated(true);
02134: ifHashTable.put("" + (ifLevel), ifst);
02135: addBranchLabel(classIndex, i, ifst,
02136: currentForIndex, info);
02137:
02138: isEndOfLoop = isIndexEndOfLoop(list, ifst
02139: .getIfCloseLineNumber());
02140: loopstart = -1;
02141: correctIf = false;
02142: beyondLoop = isBeyondLoop(ifst
02143: .getIfCloseLineNumber(), list, info);
02144: //
02145: if (isEndOfLoop) {
02146: loopstart = getLoopStartForEnd(ifst
02147: .getIfCloseLineNumber(), list);
02148: if (currentForIndex > loopstart) {
02149: boolean ifinstcodepresent = getIfinst(
02150: loopstart, info, currentForIndex);
02151: if (ifinstcodepresent) {
02152: correctIf = false;
02153: } else
02154: correctIf = true;
02155: }
02156: }
02157: if (info[ifst.getIfCloseLineNumber()] == JvmOpCodes.GOTO
02158: && isEndOfLoop && correctIf)
02159:
02160: {
02161: int t = ifst.getIfCloseLineNumber();
02162: int gotoIndex = getJumpAddress(info, t);//(info[t+1] << 8) | info[t+2]) + (ifst.getIfCloseLineNumber());
02163: if (gotoIndex < (t + 3)) {
02164: boolean isInfiniteLoop = false;
02165: Iterator infLoop = behaviour
02166: .getBehaviourLoops().iterator();
02167: while (infLoop.hasNext()) {
02168: Loop iloop = (Loop) infLoop.next();
02169: if (iloop.getStartIndex() == gotoIndex
02170: && iloop.isInfinite()) {
02171: isInfiniteLoop = true;
02172: /*ifLevel++;
02173: ifst = new IFBlock();
02174: ifst.setIfStart(currentForIndex);
02175: ifst.setHasIfBeenGenerated(true);
02176: // ifst.setIfCloseLineNumber(classIndex-3);*/
02177: ifst
02178: .setElseCloseLineNumber(gotoIndex);
02179: /*ifHashTable.put(""+(ifLevel),ifst);
02180:
02181: addBranchLabel(classIndex,i,ifst,currentForIndex,info);*/
02182: boolean bb = isBeyondLoop(
02183: getJumpAddress(info,
02184: currentForIndex),
02185: behaviour
02186: .getBehaviourLoops(),
02187: info);
02188: isIfInScope = true;
02189: boolean print = true;
02190: if (bb && this Loop != null
02191: && this Loop.isInfinite()
02192: && !encounteredOrComp) {
02193: tempString = "\nif(!"
02194: + op1.getOperandValue()
02195: + "=="
02196: + op.getOperandValue()
02197: + ")\n{\nbreak;\n}\n";
02198: //codeStatements +=Util.formatDecompiledStatement(tempString);
02199: print = false;
02200: }
02201: boolean last = lastIFinShortCutChain(
02202: info, ifst, currentForIndex);
02203: boolean c = addCodeStatementWRTShortcutOR(
02204: ifst,
02205: op1.getOperandValue()
02206: + " != "
02207: + op
02208: .getOperandValue(),
02209: print,
02210: "if",
02211: last,
02212: op1.getOperandValue()
02213: + " == "
02214: + op
02215: .getOperandValue());
02216: if (c) {
02217: tempString = "\nif("
02218: + op1.getOperandValue()
02219: + "=="
02220: + op.getOperandValue()
02221: + "))\n{\n";
02222: //codeStatements +=Util.formatDecompiledStatement(tempString);
02223: }
02224: ifhasbegun = true;
02225: break;
02226: }
02227: }
02228: if (isInfiniteLoop) {
02229: continue;
02230: }
02231: boolean last = lastIFinShortCutChain(info,
02232: ifst, currentForIndex);
02233: boolean c = addCodeStatementWRTShortcutOR(
02234: ifst, op1.getOperandValue()
02235: + " != "
02236: + op.getOperandValue(),
02237: true, "while", last, op1
02238: .getOperandValue()
02239: + " == "
02240: + op.getOperandValue());
02241: if (c) {
02242: tempString = "\nwhile("
02243: + op1.getOperandValue() + "=="
02244: + op.getOperandValue()
02245: + "))\n{\n";
02246: //codeStatements +=Util.formatDecompiledStatement(tempString);
02247: }
02248: isWhileInScope = true;
02249: whileIndex++;
02250:
02251: }
02252: //int x = 0;
02253: else {
02254:
02255: /*ifLevel++;
02256: ifst = new IFBlock();
02257: ifst.setIfStart(currentForIndex);
02258: ifst.setHasIfBeenGenerated(true);
02259: //ifst.setIfCloseLineNumber(classIndex-3);
02260: isIfInScope=true; */
02261: ifst.setElseCloseLineNumber(gotoIndex);
02262: /*ifHashTable.put(""+(ifLevel),ifst);
02263: addBranchLabel(classIndex,i,ifst,currentForIndex,info);*/
02264: boolean bb = isBeyondLoop(getJumpAddress(
02265: info, currentForIndex), behaviour
02266: .getBehaviourLoops(), info);
02267: isIfInScope = true;
02268: boolean print = true;
02269: if (bb && this Loop != null
02270: && this Loop.isInfinite()
02271: && !encounteredOrComp) {
02272: tempString = "\nif(!"
02273: + op1.getOperandValue() + "=="
02274: + op.getOperandValue()
02275: + ")\n{\nbreak;\n}\n";
02276: //codeStatements +=Util.formatDecompiledStatement(tempString);
02277: print = false;
02278: // ifst.setIfHasBeenClosed(true);
02279: }
02280: boolean last = lastIFinShortCutChain(info,
02281: ifst, currentForIndex);
02282: boolean c = addCodeStatementWRTShortcutOR(
02283: ifst, op1.getOperandValue()
02284: + " != "
02285: + op.getOperandValue(),
02286: print, "if", last, op1
02287: .getOperandValue()
02288: + " == "
02289: + op.getOperandValue());
02290: if (c) {
02291: tempString = "\nif("
02292: + op1.getOperandValue() + "==("
02293: + op.getOperandValue()
02294: + "))\n{\n";
02295: //codeStatements +=Util.formatDecompiledStatement(tempString);
02296: }
02297: ifhasbegun = true;
02298:
02299: }
02300: } else {
02301: /*ifLevel++;
02302: ifst = new IFBlock();
02303: ifst.setIfStart(currentForIndex);
02304: ifst.setHasIfBeenGenerated(true);
02305: ifHashTable.put(""+(ifLevel),ifst);
02306: isIfInScope=true;
02307: addBranchLabel(classIndex,i,ifst,currentForIndex,info);*/
02308: boolean bb = isBeyondLoop(getJumpAddress(info,
02309: currentForIndex), behaviour
02310: .getBehaviourLoops(), info);
02311: isIfInScope = true;
02312: boolean print = true;
02313: if (bb && this Loop != null
02314: && this Loop.isInfinite()
02315: && !encounteredOrComp) {
02316: tempString = "\nif(!"
02317: + op1.getOperandValue() + "=="
02318: + op.getOperandValue()
02319: + ")\n{\nbreak;\n}\n";
02320: //codeStatements +=Util.formatDecompiledStatement(tempString);
02321: print = false;
02322: //ifst.setIfHasBeenClosed(true);
02323: }
02324: boolean last = lastIFinShortCutChain(info,
02325: ifst, currentForIndex);
02326: boolean c = addCodeStatementWRTShortcutOR(ifst,
02327: op1.getOperandValue() + " != "
02328: + op.getOperandValue(), print,
02329: "if", last, op1.getOperandValue()
02330: + " == " + op.getOperandValue());
02331: if (c) {
02332: tempString = "\nif("
02333: + op1.getOperandValue() + "=="
02334: + op.getOperandValue() + "))\n{\n";
02335: //codeStatements +=Util.formatDecompiledStatement(tempString);
02336: }
02337: ifhasbegun = true;
02338: }
02339:
02340: continue;
02341: case JvmOpCodes.IF_ICMPEQ:
02342: op = (Operand) opStack.pop();
02343: op1 = (Operand) opStack.pop();
02344:
02345: /* classIndex = ((i4 << 8) | i5);
02346: if(classIndex < 0)classIndex=(i4+1)*256-Math.abs(i5);*/
02347: classIndex = getJumpAddress(info, i);
02348: i++;
02349: i++;
02350: addParsedOutput("Instruction Pos "
02351: + currentForIndex + "\t:- " + " if_icmpeq "
02352: + classIndex + "\n");
02353:
02354: blockLevel++;
02355: list = behaviour.getBehaviourLoops();
02356: ifLevel++;
02357: ifst = new IFBlock();
02358: ifst.setIfStart(currentForIndex);
02359: ifst.setHasIfBeenGenerated(true);
02360: ifHashTable.put("" + (ifLevel), ifst);
02361: isIfInScope = true;
02362: addBranchLabel(classIndex, i, ifst,
02363: currentForIndex, info);
02364:
02365: //isEndOfLoop=isIndexEndOfLoop(list,(classIndex-3));
02366: isEndOfLoop = isIndexEndOfLoop(list, ifst
02367: .getIfCloseLineNumber());
02368: loopstart = -1;
02369: correctIf = false;
02370: beyondLoop = isBeyondLoop(ifst
02371: .getIfCloseLineNumber(), list, info);
02372: if (isEndOfLoop) {
02373: loopstart = getLoopStartForEnd(ifst
02374: .getIfCloseLineNumber(), list);
02375: if (currentForIndex > loopstart) {
02376: boolean ifinstcodepresent = getIfinst(
02377: loopstart, info, currentForIndex);
02378: if (ifinstcodepresent) {
02379: correctIf = false;
02380: } else
02381: correctIf = true;
02382: }
02383: }
02384:
02385: if (info[ifst.getIfCloseLineNumber()] == JvmOpCodes.GOTO
02386: && isEndOfLoop && correctIf)
02387:
02388: {
02389: int t = ifst.getIfCloseLineNumber();
02390: int gotoIndex = getJumpAddress(info, t);//(info[t+1] << 8) | info[t+2]) + (ifst.getIfCloseLineNumber());
02391: if (gotoIndex < (t + 3)) {
02392: boolean isInfiniteLoop = false;
02393: Iterator infLoop = behaviour
02394: .getBehaviourLoops().iterator();
02395: while (infLoop.hasNext()) {
02396: Loop iloop = (Loop) infLoop.next();
02397: if (iloop.getStartIndex() == gotoIndex
02398: && iloop.isInfinite()) {
02399: isInfiniteLoop = true;
02400: /* ifLevel++;
02401: ifst = new IFBlock();
02402: ifst.setIfStart(currentForIndex);
02403: ifst.setHasIfBeenGenerated(true);*/
02404: //ifst.setIfCloseLineNumber(classIndex-3);
02405: ifst
02406: .setElseCloseLineNumber(gotoIndex);
02407: //ifHashTable.put(""+(ifLevel),ifst);
02408: // isIfInScope=true;
02409: //addBranchLabel(classIndex,i,ifst,currentForIndex,info);
02410: boolean bb = isBeyondLoop(
02411: getJumpAddress(info,
02412: currentForIndex),
02413: behaviour
02414: .getBehaviourLoops(),
02415: info);
02416: isIfInScope = true;
02417: boolean print = true;
02418: if (bb && this Loop != null
02419: && this Loop.isInfinite()
02420: && !encounteredOrComp) {
02421: tempString = "\nif("
02422: + op1.getOperandValue()
02423: + " == "
02424: + op.getOperandValue()
02425: + ")\n{\nbreak;\n}\n";
02426: //codeStatements +=Util.formatDecompiledStatement(tempString);
02427: print = false;
02428: // ifst.setIfHasBeenClosed(true);
02429: }
02430: boolean last = lastIFinShortCutChain(
02431: info, ifst, currentForIndex);
02432: boolean c = addCodeStatementWRTShortcutOR(
02433: ifst,
02434: op1.getOperandValue()
02435: + " == "
02436: + op
02437: .getOperandValue(),
02438: print,
02439: "if",
02440: last,
02441: op1.getOperandValue()
02442: + " != "
02443: + op
02444: .getOperandValue());
02445: if (c) {
02446: tempString = "\nif("
02447: + op1.getOperandValue()
02448: + " != "
02449: + op.getOperandValue()
02450: + ")\n{\n";
02451: //codeStatements +=Util.formatDecompiledStatement(tempString);
02452: }
02453: ifhasbegun = true;
02454: break;
02455: }
02456: }
02457: if (isInfiniteLoop) {
02458: continue;
02459: }
02460: boolean last = lastIFinShortCutChain(info,
02461: ifst, currentForIndex);
02462: boolean c = addCodeStatementWRTShortcutOR(
02463: ifst, op1.getOperandValue()
02464: + " == "
02465: + op.getOperandValue(),
02466: true, "while", last, op1
02467: .getOperandValue()
02468: + " != "
02469: + op.getOperandValue());
02470: if (c) {
02471: tempString = "\nwhile("
02472: + op1.getOperandValue() + "!= "
02473: + op.getOperandValue()
02474: + ")\n{\n";
02475: //codeStatements +=Util.formatDecompiledStatement(tempString);
02476: }
02477: isWhileInScope = true;
02478: whileIndex++;
02479:
02480: }
02481: // int x = 0;
02482: else {
02483:
02484: /* ifLevel++;
02485: ifst = new IFBlock();
02486: ifst.setIfStart(currentForIndex);
02487: ifst.setHasIfBeenGenerated(true);
02488: // ifst.setIfCloseLineNumber(classIndex-3);*/
02489: ifst.setElseCloseLineNumber(gotoIndex);
02490: // ifHashTable.put(""+(ifLevel),ifst);
02491: isIfInScope = true;
02492: // addBranchLabel(classIndex,i,ifst,currentForIndex,info);
02493: boolean bb = isBeyondLoop(getJumpAddress(
02494: info, currentForIndex), behaviour
02495: .getBehaviourLoops(), info);
02496: boolean print = true;
02497: if (bb && this Loop != null
02498: && this Loop.isInfinite()
02499: && !encounteredOrComp) {
02500: tempString = "\nif("
02501: + op1.getOperandValue()
02502: + " == " + op.getOperandValue()
02503: + ")\n{\n" + "break;\n" + "}\n";
02504: //codeStatements +=Util.formatDecompiledStatement(tempString);
02505: print = false;
02506: // ifst.setIfHasBeenClosed(true);
02507: }
02508: boolean last = lastIFinShortCutChain(info,
02509: ifst, currentForIndex);
02510: boolean c = addCodeStatementWRTShortcutOR(
02511: ifst, op1.getOperandValue()
02512: + " == "
02513: + op.getOperandValue(),
02514: print, "if", last, op1
02515: .getOperandValue()
02516: + " != "
02517: + op.getOperandValue());
02518: if (c) {
02519: tempString = "\nif("
02520: + op1.getOperandValue()
02521: + " != " + op.getOperandValue()
02522: + ")\n{\n";
02523: //codeStatements +=Util.formatDecompiledStatement(tempString);
02524: }
02525: ifhasbegun = true;
02526:
02527: }
02528: } else {
02529: /* ifLevel++;
02530: ifst = new IFBlock();
02531: ifst.setIfStart(currentForIndex);
02532: ifst.setHasIfBeenGenerated(true);
02533: ifHashTable.put(""+(ifLevel),ifst);
02534: isIfInScope=true;
02535: addBranchLabel(classIndex,i,ifst,currentForIndex,info);*/
02536: isIfInScope = true;
02537: boolean bb = isBeyondLoop(getJumpAddress(info,
02538: currentForIndex), behaviour
02539: .getBehaviourLoops(), info);
02540: boolean print = true;
02541: if (bb && this Loop != null
02542: && this Loop.isInfinite()
02543: && !encounteredOrComp) {
02544: tempString = "\nif("
02545: + op1.getOperandValue() + " == "
02546: + op.getOperandValue() + ")\n{\n"
02547: + "break;\n" + "}\n";
02548: //codeStatements +=Util.formatDecompiledStatement(tempString);
02549: print = false;
02550: //ifst.setIfHasBeenClosed(true);
02551: }
02552: boolean last = lastIFinShortCutChain(info,
02553: ifst, currentForIndex);
02554: boolean c = addCodeStatementWRTShortcutOR(ifst,
02555: op1.getOperandValue() + " == "
02556: + op.getOperandValue(), print,
02557: "if", last, op1.getOperandValue()
02558: + " != " + op.getOperandValue());
02559: if (c) {
02560: tempString = "\nif("
02561: + op1.getOperandValue() + " != "
02562: + op.getOperandValue() + ")\n{\n";
02563: //codeStatements +=Util.formatDecompiledStatement(tempString);
02564: }
02565: ifhasbegun = true;
02566: }
02567:
02568: continue;
02569:
02570: case JvmOpCodes.IF_ICMPNE:
02571: op = (Operand) opStack.pop();
02572: op1 = (Operand) opStack.pop();
02573: classIndex = getJumpAddress(info, i);
02574: i++;
02575: i++;
02576: addParsedOutput("Instruction Pos "
02577: + currentForIndex + "\t:- " + " if_icmpne "
02578: + classIndex + "\n");
02579: blockLevel++;
02580: list = behaviour.getBehaviourLoops();
02581: ifLevel++;
02582: ifst = new IFBlock();
02583: ifst.setIfStart(currentForIndex);
02584: ifst.setHasIfBeenGenerated(true);
02585: ifHashTable.put("" + (ifLevel), ifst);
02586: addBranchLabel(classIndex, i, ifst,
02587: currentForIndex, info);
02588: isEndOfLoop = isIndexEndOfLoop(list, (ifst
02589: .getIfCloseLineNumber()));
02590: loopstart = -1;
02591: correctIf = false;
02592: beyondLoop = isBeyondLoop(ifst
02593: .getIfCloseLineNumber(), list, info);
02594: if (isEndOfLoop) {
02595: loopstart = getLoopStartForEnd(ifst
02596: .getIfCloseLineNumber(), list);
02597: if (currentForIndex > loopstart) {
02598: boolean ifinstcodepresent = getIfinst(
02599: loopstart, info, currentForIndex);
02600: if (ifinstcodepresent) {
02601: correctIf = false;
02602: } else
02603: correctIf = true;
02604: }
02605: }
02606:
02607: if (info[ifst.getIfCloseLineNumber()] == JvmOpCodes.GOTO
02608: && isEndOfLoop && correctIf) {
02609: int t = ifst.getIfCloseLineNumber();
02610: int gotoIndex = getJumpAddress(info, t);//((info[t+1] << 8) | info[t+2]) + (ifst.getIfCloseLineNumber());
02611: if (gotoIndex < classIndex) {
02612: boolean isInfiniteLoop = false;
02613: Iterator infLoop = behaviour
02614: .getBehaviourLoops().iterator();
02615: while (infLoop.hasNext()) {
02616: Loop iloop = (Loop) infLoop.next();
02617: if (iloop.getStartIndex() == gotoIndex
02618: && iloop.isInfinite()) {
02619: isInfiniteLoop = true;
02620: /* ifLevel++;
02621: ifst = new IFBlock();
02622: ifst.setIfStart(currentForIndex);
02623: ifst.setHasIfBeenGenerated(true);*/
02624: //ifst.setIfCloseLineNumber(classIndex-3);
02625: ifst
02626: .setElseCloseLineNumber(gotoIndex);
02627: //ifHashTable.put(""+(ifLevel),ifst);
02628:
02629: isIfInScope = true;
02630: //addBranchLabel(classIndex,i,ifst,currentForIndex,info);
02631: boolean bb = isBeyondLoop(
02632: getJumpAddress(info,
02633: currentForIndex),
02634: behaviour
02635: .getBehaviourLoops(),
02636: info);
02637: boolean print = true;
02638: if (bb && this Loop != null
02639: && this Loop.isInfinite()
02640: && !encounteredOrComp) {
02641: tempString = "\nif("
02642: + op1.getOperandValue()
02643: + " != "
02644: + op.getOperandValue()
02645: + ")\n{\n" + "break;\n"
02646: + "}\n";
02647: //codeStatements +=Util.formatDecompiledStatement(tempString);
02648: print = false;
02649: //ifst.setIfHasBeenClosed(true);
02650: }
02651: boolean last = lastIFinShortCutChain(
02652: info, ifst, currentForIndex);
02653: boolean c = addCodeStatementWRTShortcutOR(
02654: ifst,
02655: op1.getOperandValue()
02656: + " != "
02657: + op
02658: .getOperandValue(),
02659: print,
02660: "if",
02661: last,
02662: op1.getOperandValue()
02663: + " == "
02664: + op
02665: .getOperandValue());
02666: if (c) {
02667: tempString = "\nif("
02668: + op1.getOperandValue()
02669: + " == "
02670: + op.getOperandValue()
02671: + ")\n{\n";
02672: //codeStatements +=Util.formatDecompiledStatement(tempString);
02673: }
02674: ifhasbegun = true;
02675: break;
02676: }
02677: }
02678: if (isInfiniteLoop) {
02679: continue;
02680: }
02681: boolean last = lastIFinShortCutChain(info,
02682: ifst, currentForIndex);
02683: boolean c = addCodeStatementWRTShortcutOR(
02684: ifst, op1.getOperandValue()
02685: + " != "
02686: + op.getOperandValue(),
02687: true, "while", last, op1
02688: .getOperandValue()
02689: + " == "
02690: + op.getOperandValue());
02691: if (c) {
02692: tempString = "\nwhile("
02693: + op1.getOperandValue()
02694: + " == " + op.getOperandValue()
02695: + ")\n{\n";
02696: //codeStatements +=Util.formatDecompiledStatement(tempString);
02697: }
02698: isWhileInScope = true;
02699: whileIndex++;
02700:
02701: }
02702: //int x = 0;
02703: else {
02704:
02705: /* ifLevel++;
02706: ifst = new IFBlock();
02707: ifst.setIfStart(currentForIndex);
02708: ifst.setHasIfBeenGenerated(true); */
02709: //ifst.setIfCloseLineNumber(classIndex-3);
02710: ifst.setElseCloseLineNumber(gotoIndex);
02711: /* ifHashTable.put(""+(ifLevel),ifst);
02712: isIfInScope=true;
02713: addBranchLabel(classIndex,i,ifst,currentForIndex,info);*/
02714: isIfInScope = true;
02715: boolean bb = isBeyondLoop(getJumpAddress(
02716: info, currentForIndex), behaviour
02717: .getBehaviourLoops(), info);
02718: boolean print = true;
02719: if (bb && this Loop != null
02720: && this Loop.isInfinite()
02721: && !encounteredOrComp) {
02722: tempString = "\nif("
02723: + op1.getOperandValue()
02724: + " != " + op.getOperandValue()
02725: + ")\n{\nbreak;\n}\n";
02726: //codeStatements +=Util.formatDecompiledStatement(tempString);
02727: print = false;
02728: //ifst.setIfHasBeenClosed(true);
02729: }
02730: boolean last = lastIFinShortCutChain(info,
02731: ifst, currentForIndex);
02732: boolean c = addCodeStatementWRTShortcutOR(
02733: ifst, op1.getOperandValue()
02734: + " != "
02735: + op.getOperandValue(),
02736: print, "if", last, op1
02737: .getOperandValue()
02738: + " == "
02739: + op.getOperandValue());
02740: if (c) {
02741: tempString = "\nif("
02742: + op1.getOperandValue()
02743: + " == " + op.getOperandValue()
02744: + ")\n{\n";
02745: //codeStatements +=Util.formatDecompiledStatement(tempString);
02746: }
02747: ifhasbegun = true;
02748:
02749: }
02750: } else {
02751: /* ifLevel++;
02752: ifst = new IFBlock();
02753: ifst.setIfStart(currentForIndex);
02754: ifst.setHasIfBeenGenerated(true);
02755: ifHashTable.put(""+(ifLevel),ifst);
02756: isIfInScope=true;
02757: addBranchLabel(classIndex,i,ifst,currentForIndex,info);*/
02758: isIfInScope = true;
02759: boolean bb = isBeyondLoop(getJumpAddress(info,
02760: currentForIndex), behaviour
02761: .getBehaviourLoops(), info);
02762: boolean print = true;
02763: if (bb && this Loop != null
02764: && this Loop.isInfinite()
02765: && !encounteredOrComp) {
02766: tempString = "\nif("
02767: + op1.getOperandValue() + " != "
02768: + op.getOperandValue() + ")\n{\n"
02769: + "break;\n" + "}\n";
02770: //codeStatements +=Util.formatDecompiledStatement(tempString);
02771: print = false;
02772: //ifst.setIfHasBeenClosed(true);
02773: }
02774: boolean last = lastIFinShortCutChain(info,
02775: ifst, currentForIndex);
02776: boolean c = addCodeStatementWRTShortcutOR(ifst,
02777: op1.getOperandValue() + " != "
02778: + op.getOperandValue(), print,
02779: "if", last, op1.getOperandValue()
02780: + " == " + op.getOperandValue());
02781: if (c) {
02782: tempString = "\nif("
02783: + op1.getOperandValue() + " == "
02784: + op.getOperandValue() + ")\n{\n";
02785: //codeStatements +=Util.formatDecompiledStatement(tempString);
02786: }
02787: ifhasbegun = true;
02788: }
02789:
02790: continue;
02791:
02792: case JvmOpCodes.IF_ICMPLT:
02793:
02794: op = (Operand) opStack.pop();
02795: op1 = (Operand) opStack.pop();
02796: classIndex = getJumpAddress(info, i);
02797: i += 2;
02798: addParsedOutput("Instruction Pos "
02799: + currentForIndex + "\t:- " + " if_icmplt "
02800: + classIndex + "\n");
02801: blockLevel++;
02802: list = behaviour.getBehaviourLoops();
02803: ifLevel++;
02804: ifst = new IFBlock();
02805: ifst.setIfStart(currentForIndex);
02806: ifst.setHasIfBeenGenerated(true);
02807: ifHashTable.put("" + (ifLevel), ifst);
02808: addBranchLabel(classIndex, i, ifst,
02809: currentForIndex, info);
02810:
02811: beyondLoop = isBeyondLoop(ifst
02812: .getIfCloseLineNumber(), list, info);
02813: isEndOfLoop = isIndexEndOfLoop(list, ifst
02814: .getIfCloseLineNumber());
02815: loopstart = -1;
02816: correctIf = false;
02817: if (isEndOfLoop) {
02818: loopstart = getLoopStartForEnd(ifst
02819: .getIfCloseLineNumber(), list);
02820: if (currentForIndex > loopstart) {
02821: boolean ifinstcodepresent = getIfinst(
02822: loopstart, info, currentForIndex);
02823: if (ifinstcodepresent) {
02824: correctIf = false;
02825: } else {
02826: correctIf = true;
02827: }
02828: }
02829: }
02830: if (info[ifst.getIfCloseLineNumber()] == JvmOpCodes.GOTO
02831: && isEndOfLoop && correctIf) {
02832: int t = ifst.getIfCloseLineNumber();
02833: int gotoIndex = getJumpAddress(info, t);//((info[t+1] << 8) | info[t+2]) + (ifst.getIfCloseLineNumber());
02834: if (gotoIndex <= (t + 3))
02835:
02836: {
02837: boolean isInfiniteLoop = false;
02838: Iterator infLoop = behaviour
02839: .getBehaviourLoops().iterator();
02840: while (infLoop.hasNext()) {
02841: Loop iloop = (Loop) infLoop.next();
02842: if (iloop.getStartIndex() == gotoIndex
02843: && iloop.isInfinite()) {
02844: isInfiniteLoop = true;
02845: /* ifLevel++;
02846: ifst = new IFBlock();
02847: ifst.setIfStart(currentForIndex);
02848: ifst.setHasIfBeenGenerated(true);
02849: // ifst.setIfCloseLineNumber(classIndex-3);*/
02850: ifst
02851: .setElseCloseLineNumber(gotoIndex);
02852: //ifHashTable.put(""+(ifLevel),ifst);
02853: isIfInScope = true;
02854: //addBranchLabel(classIndex,i,ifst,currentForIndex,info);
02855: boolean bb = isBeyondLoop(
02856: getJumpAddress(info,
02857: currentForIndex),
02858: behaviour
02859: .getBehaviourLoops(),
02860: info);
02861: boolean print = true;
02862: if (bb && this Loop != null
02863: && this Loop.isInfinite()
02864: && !encounteredOrComp) {
02865: tempString = "\nif("
02866: + op1.getOperandValue()
02867: + " < "
02868: + op.getOperandValue()
02869: + ")\n{\nbreak;\n}\n";
02870: //codeStatements +=Util.formatDecompiledStatement(tempString);
02871: print = false;
02872: // ifst.setIfHasBeenClosed(true);
02873: }
02874: boolean last = lastIFinShortCutChain(
02875: info, ifst, currentForIndex);
02876: boolean c = addCodeStatementWRTShortcutOR(
02877: ifst,
02878: op1.getOperandValue()
02879: + " < "
02880: + op
02881: .getOperandValue(),
02882: print,
02883: "if",
02884: last,
02885: op1.getOperandValue()
02886: + " >= "
02887: + op
02888: .getOperandValue());
02889: if (c) {
02890: tempString = "\nif("
02891: + op1.getOperandValue()
02892: + " >= "
02893: + op.getOperandValue()
02894: + ")\n{";
02895: //codeStatements +=Util.formatDecompiledStatement(tempString);
02896: }
02897: ifhasbegun = true;
02898: break;
02899: }
02900: }
02901: if (isInfiniteLoop) {
02902: continue;
02903: }
02904: boolean last = lastIFinShortCutChain(info,
02905: ifst, currentForIndex);
02906: boolean c = addCodeStatementWRTShortcutOR(
02907: ifst, op1.getOperandValue() + " < "
02908: + op.getOperandValue(),
02909: true, "while", last, op1
02910: .getOperandValue()
02911: + " >= "
02912: + op.getOperandValue());
02913: if (c) {
02914: tempString = "\nwhile("
02915: + op1.getOperandValue()
02916: + " >= " + op.getOperandValue()
02917: + ")\n{\n";
02918: //codeStatements +=Util.formatDecompiledStatement(tempString);
02919: }
02920: isWhileInScope = true;
02921: whileIndex++;
02922:
02923: }
02924:
02925: else {
02926:
02927: /*ifLevel++;
02928: ifst = new IFBlock();
02929: ifst.setIfStart(currentForIndex);
02930: ifst.setHasIfBeenGenerated(true);
02931: // ifst.setIfCloseLineNumber(classIndex-3);*/
02932: ifst.setElseCloseLineNumber(gotoIndex);
02933: //ifHashTable.put(""+(ifLevel),ifst);
02934: isIfInScope = true;
02935: //addBranchLabel(classIndex,i,ifst,currentForIndex,info);
02936: boolean bb = isBeyondLoop(getJumpAddress(
02937: info, currentForIndex), behaviour
02938: .getBehaviourLoops(), info);
02939: boolean print = true;
02940: if (bb && this Loop != null
02941: && this Loop.isInfinite()
02942: && !encounteredOrComp) {
02943: tempString = "\nif("
02944: + op1.getOperandValue() + " < "
02945: + op.getOperandValue()
02946: + ")\n{\nbreak;\n}\n";
02947: //codeStatements +=Util.formatDecompiledStatement(tempString);
02948: print = false;
02949: // ifst.setIfHasBeenClosed(true);
02950: }
02951: boolean last = lastIFinShortCutChain(info,
02952: ifst, currentForIndex);
02953: boolean c = addCodeStatementWRTShortcutOR(
02954: ifst, op1.getOperandValue() + " < "
02955: + op.getOperandValue(),
02956: print, "if", last, op1
02957: .getOperandValue()
02958: + " >= "
02959: + op.getOperandValue());
02960: if (c) {
02961: tempString = "\nif("
02962: + op1.getOperandValue()
02963: + " >= " + op.getOperandValue()
02964: + ")\n{";
02965: //codeStatements +=Util.formatDecompiledStatement(tempString);
02966: }
02967: ifhasbegun = true;
02968:
02969: }
02970:
02971: } else {
02972: /*ifLevel++;
02973: ifst = new IFBlock();
02974: ifst.setIfStart(currentForIndex);
02975: ifst.setHasIfBeenGenerated(true);
02976: ifHashTable.put(""+(ifLevel),ifst);*/
02977: isIfInScope = true;
02978: //addBranchLabel(classIndex,i,ifst,currentForIndex,info);
02979: boolean bb = isBeyondLoop(getJumpAddress(info,
02980: currentForIndex), behaviour
02981: .getBehaviourLoops(), info);
02982: boolean print = true;
02983: if (bb && this Loop != null
02984: && this Loop.isInfinite()
02985: && !encounteredOrComp) {
02986: tempString = "\nif("
02987: + op1.getOperandValue() + " < "
02988: + op.getOperandValue() + ")\n{\n"
02989: + "break;\n" + "}\n";
02990: //codeStatements +=Util.formatDecompiledStatement(tempString);
02991: print = false;
02992: // ifst.setIfHasBeenClosed(true);
02993: }
02994: boolean last = lastIFinShortCutChain(info,
02995: ifst, currentForIndex);
02996: boolean c = addCodeStatementWRTShortcutOR(ifst,
02997: op1.getOperandValue() + " < "
02998: + op.getOperandValue(), print,
02999: "if", last, op1.getOperandValue()
03000: + " >= " + op.getOperandValue());
03001: if (c) {
03002: tempString = "\nif("
03003: + op1.getOperandValue() + " >= "
03004: + op.getOperandValue() + ")\n{";
03005: //codeStatements +=Util.formatDecompiledStatement(tempString);
03006: }
03007: ifhasbegun = true;
03008: }
03009:
03010: continue;
03011: case JvmOpCodes.IF_ICMPGE:
03012: op = (Operand) opStack.pop();
03013: op1 = (Operand) opStack.pop();
03014: classIndex = getJumpAddress(info, i);
03015: i += 2;
03016: addParsedOutput("Instruction Pos "
03017: + currentForIndex + "\t:- " + " if_icmpge "
03018: + classIndex + "\n");
03019: blockLevel++;
03020: list = behaviour.getBehaviourLoops();
03021: //
03022: ifLevel++;
03023: ifst = new IFBlock();
03024: ifst.setIfStart(currentForIndex);
03025: ifst.setHasIfBeenGenerated(true);
03026: // ifst.setIfCloseLineNumber(classIndex-3);
03027:
03028: ifHashTable.put("" + (ifLevel), ifst);
03029:
03030: addBranchLabel(classIndex, i, ifst,
03031: currentForIndex, info);
03032:
03033: isEndOfLoop = isIndexEndOfLoop(list, ifst
03034: .getIfCloseLineNumber());
03035: correctIf = false;
03036: beyondLoop = isBeyondLoop(ifst
03037: .getIfCloseLineNumber(), list, info);
03038: loopstart = -1;
03039: if (isEndOfLoop) {
03040: loopstart = getLoopStartForEnd(ifst
03041: .getIfCloseLineNumber(), list);
03042: if (currentForIndex > loopstart) {
03043: boolean ifinstcodepresent = getIfinst(
03044: loopstart, info, currentForIndex);
03045: if (ifinstcodepresent) {
03046: correctIf = false;
03047: } else
03048: correctIf = true;
03049: }
03050: }
03051: if (info[ifst.getIfCloseLineNumber()] == JvmOpCodes.GOTO
03052: && isEndOfLoop && correctIf) {
03053: int t = ifst.getIfCloseLineNumber();
03054: int gotoIndex = getJumpAddress(info, t);// ((info[t+1] << 8) | info[t+2]) + (ifst.getIfCloseLineNumber());
03055: if (gotoIndex < (t + 3))
03056:
03057: {
03058: boolean isInfiniteLoop = false;
03059: Iterator infLoop = behaviour
03060: .getBehaviourLoops().iterator();
03061: while (infLoop.hasNext()) {
03062: Loop iloop = (Loop) infLoop.next();
03063: if (iloop.getStartIndex() == gotoIndex
03064: && iloop.isInfinite()) {
03065: isInfiniteLoop = true;
03066: /* ifLevel++;
03067: ifst = new IFBlock();
03068: ifst.setIfStart(currentForIndex);
03069: ifst.setHasIfBeenGenerated(true);
03070: // ifst.setIfCloseLineNumber(classIndex-3);*/
03071: ifst
03072: .setElseCloseLineNumber(gotoIndex);
03073: //ifHashTable.put(""+(ifLevel),ifst);
03074: isIfInScope = true;
03075: //addBranchLabel(classIndex,i,ifst,currentForIndex,info);
03076: // System.out.println("First param "+getJumpAddress(info,currentForIndex));
03077: //System.out.println(currentForIndex+" "+behaviour.getBehaviourName());
03078:
03079: boolean bb = isBeyondLoop(
03080: getJumpAddress(info,
03081: currentForIndex),
03082: behaviour
03083: .getBehaviourLoops(),
03084: info);
03085: boolean print = true;
03086: if (bb && this Loop != null
03087: && this Loop.isInfinite()
03088: && !encounteredOrComp) {
03089: tempString = "\nif("
03090: + op1.getOperandValue()
03091: + " >= "
03092: + op.getOperandValue()
03093: + ")\n{\nbreak;\n}\n";
03094: //codeStatements +=Util.formatDecompiledStatement(tempString);
03095: print = false;
03096:
03097: }
03098: boolean last = lastIFinShortCutChain(
03099: info, ifst, currentForIndex);
03100: boolean c = addCodeStatementWRTShortcutOR(
03101: ifst,
03102: op1.getOperandValue()
03103: + " >= "
03104: + op
03105: .getOperandValue(),
03106: print,
03107: "if",
03108: last,
03109: op1.getOperandValue()
03110: + " < "
03111: + op
03112: .getOperandValue());
03113: if (c) {
03114: tempString = "\nif("
03115: + op1.getOperandValue()
03116: + " < "
03117: + op.getOperandValue()
03118: + ")\n{\n";
03119: //codeStatements +=Util.formatDecompiledStatement(tempString);
03120: }
03121: ifhasbegun = true;
03122: break;
03123: }
03124: }
03125: if (isInfiniteLoop) {
03126: continue;
03127: }
03128: boolean last = lastIFinShortCutChain(info,
03129: ifst, currentForIndex);
03130: boolean c = addCodeStatementWRTShortcutOR(
03131: ifst, op1.getOperandValue()
03132: + " >= "
03133: + op.getOperandValue(),
03134: true, "while", last, op1
03135: .getOperandValue()
03136: + " < "
03137: + op.getOperandValue());
03138: if (c) {
03139: tempString = "\nwhile("
03140: + op1.getOperandValue() + " < "
03141: + op.getOperandValue()
03142: + ")\n{\n";
03143: //codeStatements +=Util.formatDecompiledStatement(tempString);
03144: }
03145: isWhileInScope = true;
03146: whileIndex++;
03147:
03148: }
03149: //int x = 0; Added by belurs: NO else was here
03150: else {
03151: /* ifLevel++;
03152: ifst = new IFBlock();
03153: ifst.setIfStart(currentForIndex);
03154: ifst.setHasIfBeenGenerated(true);
03155: // ifst.setIfCloseLineNumber(classIndex-3);*/
03156: ifst.setElseCloseLineNumber(gotoIndex);
03157: //ifHashTable.put(""+(ifLevel),ifst);
03158: isIfInScope = true;
03159: //addBranchLabel(classIndex,i,ifst,currentForIndex,info);
03160: boolean bb = isBeyondLoop(getJumpAddress(
03161: info, currentForIndex), behaviour
03162: .getBehaviourLoops(), info);
03163: boolean print = true;
03164: if (bb && this Loop != null
03165: && this Loop.isInfinite()
03166: && !encounteredOrComp) {
03167: tempString = "\nif("
03168: + op1.getOperandValue()
03169: + " >= " + op.getOperandValue()
03170: + ")\n{\nbreak;\n}\n";
03171: //codeStatements +=Util.formatDecompiledStatement(tempString);
03172: print = false;
03173: }
03174: boolean last = lastIFinShortCutChain(info,
03175: ifst, currentForIndex);
03176: boolean c = addCodeStatementWRTShortcutOR(
03177: ifst, op1.getOperandValue()
03178: + " >= "
03179: + op.getOperandValue(),
03180: print, "if", last, op1
03181: .getOperandValue()
03182: + " < "
03183: + op.getOperandValue());
03184: if (c) {
03185: tempString = "\nif("
03186: + op1.getOperandValue() + " <"
03187: + op.getOperandValue()
03188: + ")\n{\n";
03189: //codeStatements +=Util.formatDecompiledStatement(tempString);
03190: }
03191: ifhasbegun = true;
03192: }
03193: } else {
03194: /* ifLevel++;
03195: ifst = new IFBlock();
03196: ifst.setIfStart(currentForIndex);
03197: ifst.setHasIfBeenGenerated(true);
03198: ifHashTable.put(""+(ifLevel),ifst);*/
03199: isIfInScope = true;
03200: //addBranchLabel(classIndex,i,ifst,currentForIndex,info);
03201: boolean bb = isBeyondLoop(getJumpAddress(info,
03202: currentForIndex), behaviour
03203: .getBehaviourLoops(), info);
03204: boolean print = true;
03205: if (bb && this Loop != null
03206: && this Loop.isInfinite()
03207: && !encounteredOrComp) {
03208: tempString = "\nif("
03209: + op1.getOperandValue() + " >= "
03210: + op.getOperandValue() + ")\n{\n"
03211: + "break;\n" + "}\n";
03212: //codeStatements +=Util.formatDecompiledStatement(tempString);
03213: // ifst.setIfHasBeenClosed(true);
03214: print = false;
03215: }
03216: boolean last = lastIFinShortCutChain(info,
03217: ifst, currentForIndex);
03218: boolean c = addCodeStatementWRTShortcutOR(ifst,
03219: op1.getOperandValue() + " >= "
03220: + op.getOperandValue(), print,
03221: "if", last, op1.getOperandValue()
03222: + " <" + op.getOperandValue());
03223: if (c) {
03224: tempString = "\nif("
03225: + op1.getOperandValue() + " <"
03226: + op.getOperandValue() + ")\n{\n";
03227: //codeStatements +=Util.formatDecompiledStatement(tempString);
03228: }
03229: ifhasbegun = true;
03230: }
03231:
03232: continue;
03233: case JvmOpCodes.IF_ICMPGT:
03234: op = (Operand) opStack.pop();
03235: op1 = (Operand) opStack.pop();
03236: classIndex = getJumpAddress(info, i);
03237: i += 2;
03238: addParsedOutput("Instruction Pos "
03239: + currentForIndex + "\t:- " + " if_icmpgt "
03240: + classIndex + "\n");
03241: blockLevel++;
03242: list = behaviour.getBehaviourLoops();
03243: ifLevel++;
03244: ifst = new IFBlock();
03245: ifst.setIfStart(currentForIndex);
03246: ifst.setHasIfBeenGenerated(true);
03247: ifHashTable.put("" + (ifLevel), ifst);
03248: addBranchLabel(classIndex, i, ifst,
03249: currentForIndex, info);
03250:
03251: beyondLoop = isBeyondLoop(ifst
03252: .getIfCloseLineNumber(), list, info);
03253: isEndOfLoop = isIndexEndOfLoop(list, ifst
03254: .getIfCloseLineNumber());
03255: correctIf = false;
03256: loopstart = -1;
03257: if (isEndOfLoop) {
03258: loopstart = getLoopStartForEnd(ifst
03259: .getIfCloseLineNumber(), list);
03260: if (currentForIndex > loopstart) {
03261: boolean ifinstcodepresent = getIfinst(
03262: loopstart, info, currentForIndex);
03263: if (ifinstcodepresent) {
03264: correctIf = false;
03265: } else
03266: correctIf = true;
03267: }
03268: }
03269: if (info[ifst.getIfCloseLineNumber()] == JvmOpCodes.GOTO
03270: && isEndOfLoop && correctIf) {
03271: int t = ifst.getIfCloseLineNumber();
03272: int gotoIndex = getJumpAddress(info, t);//((info[t+1] << 8) | info[t+2]) + (ifst.getIfCloseLineNumber());
03273: if (gotoIndex < (t + 3))
03274:
03275: {
03276: boolean isInfiniteLoop = false;
03277: Iterator infLoop = behaviour
03278: .getBehaviourLoops().iterator();
03279: while (infLoop.hasNext()) {
03280: Loop iloop = (Loop) infLoop.next();
03281: if (iloop.getStartIndex() == gotoIndex
03282: && iloop.isInfinite()) {
03283: isInfiniteLoop = true;
03284: /* ifLevel++;
03285: ifst = new IFBlock();
03286: ifst.setIfStart(currentForIndex);
03287: ifst.setHasIfBeenGenerated(true);
03288: //fst.setIfCloseLineNumber(classIndex-3);*/
03289: ifst
03290: .setElseCloseLineNumber(gotoIndex);
03291: isIfInScope = true;
03292: //addBranchLabel(classIndex,i,ifst,currentForIndex,info);
03293: boolean bb = isBeyondLoop(
03294: getJumpAddress(info,
03295: currentForIndex),
03296: behaviour
03297: .getBehaviourLoops(),
03298: info);
03299: boolean print = true;
03300: if (bb && this Loop != null
03301: && this Loop.isInfinite()
03302: && !encounteredOrComp) {
03303: tempString = "\nif("
03304: + op1.getOperandValue()
03305: + " > "
03306: + op.getOperandValue()
03307: + ")\n{\n" + "break;\n"
03308: + "}\n";
03309: //codeStatements +=Util.formatDecompiledStatement(tempString);
03310: //ifst.setIfHasBeenClosed(true);
03311: print = false;
03312: }
03313: boolean last = lastIFinShortCutChain(
03314: info, ifst, currentForIndex);
03315: boolean c = addCodeStatementWRTShortcutOR(
03316: ifst,
03317: op1.getOperandValue()
03318: + " > "
03319: + op
03320: .getOperandValue(),
03321: print,
03322: "if",
03323: last,
03324: op1.getOperandValue()
03325: + " <= "
03326: + op
03327: .getOperandValue());
03328: if (c) {
03329: tempString = "\nif("
03330: + op1.getOperandValue()
03331: + " <= "
03332: + op.getOperandValue()
03333: + ")\n{\n";
03334: //codeStatements +=Util.formatDecompiledStatement(tempString);
03335: }
03336: ifhasbegun = true;
03337: break;
03338: }
03339: }
03340: if (isInfiniteLoop) {
03341: continue;
03342: }
03343: boolean last = lastIFinShortCutChain(info,
03344: ifst, currentForIndex);
03345: boolean c = addCodeStatementWRTShortcutOR(
03346: ifst, op1.getOperandValue() + " > "
03347: + op.getOperandValue(),
03348: true, "while", last, op1
03349: .getOperandValue()
03350: + " <= "
03351: + op.getOperandValue());
03352: if (c) {
03353: tempString = "\nwhile("
03354: + op1.getOperandValue()
03355: + " <= " + op.getOperandValue()
03356: + ")\n{\n";
03357: //codeStatements +=Util.formatDecompiledStatement(tempString);
03358: }
03359: isWhileInScope = true;
03360: whileIndex++;
03361:
03362: }
03363: //int x = 0;
03364: // Added by belurs: There was no else here
03365: else {
03366:
03367: /* ifLevel++;
03368: ifst = new IFBlock();
03369: ifst.setIfStart(currentForIndex);
03370: ifst.setHasIfBeenGenerated(true);
03371: // ifst.setIfCloseLineNumber(classIndex-3); */
03372: ifst.setElseCloseLineNumber(gotoIndex);
03373: // ifHashTable.put(""+(ifLevel),ifst);
03374: isIfInScope = true;
03375: //addBranchLabel(classIndex,i,ifst,currentForIndex,info);
03376: boolean bb = isBeyondLoop(getJumpAddress(
03377: info, currentForIndex), behaviour
03378: .getBehaviourLoops(), info);
03379: boolean print = true;
03380: if (bb && this Loop != null
03381: && this Loop.isInfinite()
03382: && !encounteredOrComp) {
03383: tempString = "\nif("
03384: + op1.getOperandValue() + " > "
03385: + op.getOperandValue()
03386: + ")\n{\n" + "break;\n" + "}\n";
03387: //codeStatements +=Util.formatDecompiledStatement(tempString);
03388: // ifst.setIfHasBeenClosed(true);
03389: print = false;
03390: }
03391: boolean last = lastIFinShortCutChain(info,
03392: ifst, currentForIndex);
03393: boolean c = addCodeStatementWRTShortcutOR(
03394: ifst, op1.getOperandValue() + " > "
03395: + op.getOperandValue(),
03396: print, "if", last, op1
03397: .getOperandValue()
03398: + " <= "
03399: + op.getOperandValue());
03400: if (c) {
03401: tempString = "\nif("
03402: + op1.getOperandValue() + " <="
03403: + op.getOperandValue()
03404: + ")\n{\n";
03405: //codeStatements +=Util.formatDecompiledStatement(tempString);
03406: }
03407: ifhasbegun = true;
03408:
03409: }
03410: } else {
03411: /* ifLevel++;
03412: ifst = new IFBlock();
03413: ifst.setIfStart(currentForIndex);
03414: ifst.setHasIfBeenGenerated(true);
03415: ifHashTable.put(""+(ifLevel),ifst); */
03416: isIfInScope = true;
03417: // addBranchLabel(classIndex,i,ifst,currentForIndex,info);
03418: boolean bb = isBeyondLoop(getJumpAddress(info,
03419: currentForIndex), behaviour
03420: .getBehaviourLoops(), info);
03421: boolean print = true;
03422: if (bb && this Loop != null
03423: && this Loop.isInfinite()
03424: && !encounteredOrComp) {
03425: tempString = "\nif("
03426: + op1.getOperandValue() + " > "
03427: + op.getOperandValue() + ")\n{\n"
03428: + "break;\n" + "}\n";
03429: //codeStatements +=Util.formatDecompiledStatement(tempString);
03430: print = false;
03431: // ifst.setIfHasBeenClosed(true);
03432: }
03433: boolean last = lastIFinShortCutChain(info,
03434: ifst, currentForIndex);
03435: boolean c = addCodeStatementWRTShortcutOR(ifst,
03436: op1.getOperandValue() + " > "
03437: + op.getOperandValue(), print,
03438: "if", last, op1.getOperandValue()
03439: + " <= " + op.getOperandValue());
03440: if (c) {
03441: tempString = "\nif("
03442: + op1.getOperandValue() + " <= "
03443: + op.getOperandValue() + ")\n{\n";
03444: //codeStatements +=Util.formatDecompiledStatement(tempString);
03445: }
03446: ifhasbegun = true;
03447: }
03448:
03449: continue;
03450: case JvmOpCodes.IF_ICMPLE:
03451: op = (Operand) opStack.pop();
03452: op1 = (Operand) opStack.pop();
03453: classIndex = getJumpAddress(info, i);
03454: i += 2;
03455: addParsedOutput("Instruction Pos "
03456: + currentForIndex + "\t:- " + " if_icmple "
03457: + classIndex + "\n");
03458: blockLevel++;
03459: list = behaviour.getBehaviourLoops();
03460:
03461: ifLevel++;
03462: ifst = new IFBlock();
03463: ifst.setIfStart(currentForIndex);
03464: ifst.setHasIfBeenGenerated(true);
03465: //ifst.setIfCloseLineNumber(classIndex-3); // changed by belurs
03466:
03467: ifHashTable.put("" + (ifLevel), ifst);
03468:
03469: addBranchLabel(classIndex, i, ifst,
03470: currentForIndex, info);
03471: beyondLoop = isBeyondLoop(ifst
03472: .getIfCloseLineNumber(), list, info);
03473: isEndOfLoop = isIndexEndOfLoop(list, ifst
03474: .getIfCloseLineNumber());
03475: loopstart = -1;
03476: correctIf = false;
03477: if (isEndOfLoop) {
03478: loopstart = getLoopStartForEnd(ifst
03479: .getIfCloseLineNumber(), list);
03480: if (currentForIndex > loopstart) {
03481: boolean ifinstcodepresent = getIfinst(
03482: loopstart, info, currentForIndex);
03483: if (ifinstcodepresent) {
03484: correctIf = false;
03485: } else
03486: correctIf = true;
03487: }
03488: }
03489: if (info[ifst.getIfCloseLineNumber()] == JvmOpCodes.GOTO
03490: && isEndOfLoop && correctIf) {
03491: int t = ifst.getIfCloseLineNumber();
03492: int gotoIndex = getJumpAddress(info, t);//((info[t+1] << 8) | info[t+2]) + (ifst.getIfCloseLineNumber());
03493: if (gotoIndex < (t + 3)) {
03494: boolean isInfiniteLoop = false;
03495: Iterator infLoop = behaviour
03496: .getBehaviourLoops().iterator();
03497: while (infLoop.hasNext()) {
03498: Loop iloop = (Loop) infLoop.next();
03499: if (iloop.getStartIndex() == gotoIndex
03500: && iloop.isInfinite()) {
03501: isInfiniteLoop = true;
03502: /* ifLevel++;
03503: ifst = new IFBlock();
03504: ifst.setIfStart(currentForIndex);
03505: ifst.setHasIfBeenGenerated(true);
03506: //ifst.setIfCloseLineNumber(classIndex-3); // changed by belurs*/
03507: ifst
03508: .setElseCloseLineNumber(gotoIndex);
03509: //ifHashTable.put(""+(ifLevel),ifst);
03510: isIfInScope = true;
03511: //addBranchLabel(classIndex,i,ifst,currentForIndex,info);
03512: boolean bb = isBeyondLoop(
03513: getJumpAddress(info,
03514: currentForIndex),
03515: behaviour
03516: .getBehaviourLoops(),
03517: info);
03518: boolean print = true;
03519: if (bb && this Loop != null
03520: && this Loop.isInfinite()
03521: && !encounteredOrComp) {
03522: tempString = "\nif("
03523: + op1.getOperandValue()
03524: + " <= "
03525: + op.getOperandValue()
03526: + ")\n{\n" + "break;\n"
03527: + "}\n";
03528: //codeStatements +=Util.formatDecompiledStatement(tempString);
03529: print = false;
03530: // ifst.setIfHasBeenClosed(true);
03531: }
03532: boolean last = lastIFinShortCutChain(
03533: info, ifst, currentForIndex);
03534: boolean c = addCodeStatementWRTShortcutOR(
03535: ifst,
03536: op1.getOperandValue()
03537: + " <= "
03538: + op
03539: .getOperandValue(),
03540: print,
03541: "if",
03542: last,
03543: op1.getOperandValue()
03544: + " > "
03545: + op
03546: .getOperandValue());
03547: if (c) {
03548: tempString = "\nif("
03549: + op1.getOperandValue()
03550: + " > "
03551: + op.getOperandValue()
03552: + ")\n{\n";
03553: //codeStatements +=Util.formatDecompiledStatement(tempString);
03554: }
03555: ifhasbegun = true;
03556: break;
03557: }
03558: }
03559: if (isInfiniteLoop) {
03560: continue;
03561: }
03562: boolean last = lastIFinShortCutChain(info,
03563: ifst, currentForIndex);
03564: boolean c = addCodeStatementWRTShortcutOR(
03565: ifst, op1.getOperandValue()
03566: + " <= "
03567: + op.getOperandValue(),
03568: true, "while", last, op1
03569: .getOperandValue()
03570: + " > "
03571: + op.getOperandValue());
03572: if (c) {
03573: tempString = "\nwhile("
03574: + op1.getOperandValue() + " > "
03575: + op.getOperandValue()
03576: + ")\n{\n";
03577: //codeStatements +=Util.formatDecompiledStatement(tempString);
03578: }
03579: isWhileInScope = true;
03580: whileIndex++;
03581:
03582: }
03583: //int x = 0;
03584: else {
03585:
03586: /*ifLevel++;
03587: ifst = new IFBlock();
03588: ifst.setIfStart(currentForIndex);
03589: ifst.setHasIfBeenGenerated(true);
03590: // ifst.setIfCloseLineNumber(classIndex-3); */
03591: ifst.setElseCloseLineNumber(gotoIndex);
03592: // ifHashTable.put(""+(ifLevel),ifst);
03593: isIfInScope = true;
03594: // addBranchLabel(classIndex,i,ifst,currentForIndex,info);
03595: boolean bb = isBeyondLoop(getJumpAddress(
03596: info, currentForIndex), behaviour
03597: .getBehaviourLoops(), info);
03598: boolean print = true;
03599: if (bb && this Loop != null
03600: && this Loop.isInfinite()
03601: && !encounteredOrComp) {
03602: tempString = "\nif("
03603: + op1.getOperandValue()
03604: + " <= " + op.getOperandValue()
03605: + ")\n{\n" + "break;\n" + "}\n";
03606: //codeStatements +=Util.formatDecompiledStatement(tempString);
03607: print = false;
03608: // ifst.setIfHasBeenClosed(true);
03609: }
03610: boolean last = lastIFinShortCutChain(info,
03611: ifst, currentForIndex);
03612: boolean c = addCodeStatementWRTShortcutOR(
03613: ifst, op1.getOperandValue()
03614: + " <= "
03615: + op.getOperandValue(),
03616: print, "if", last, op1
03617: .getOperandValue()
03618: + " > "
03619: + op.getOperandValue());
03620: if (c) {
03621: tempString = "\nif("
03622: + op1.getOperandValue() + " > "
03623: + op.getOperandValue()
03624: + ")\n{\n";
03625: //codeStatements +=Util.formatDecompiledStatement(tempString);
03626: }
03627: ifhasbegun = true;
03628:
03629: }
03630: } else {
03631: /* ifLevel++;
03632: ifst = new IFBlock();
03633: ifst.setIfStart(currentForIndex);
03634: ifst.setHasIfBeenGenerated(true);
03635:
03636: ifHashTable.put(""+(ifLevel),ifst); */
03637: isIfInScope = true;
03638:
03639: // addBranchLabel(classIndex,i,ifst,currentForIndex,info);
03640: boolean bb = isBeyondLoop(getJumpAddress(info,
03641: currentForIndex), behaviour
03642: .getBehaviourLoops(), info);
03643: boolean print = true;
03644: if (bb && this Loop != null
03645: && this Loop.isInfinite()
03646: && !encounteredOrComp) {
03647: tempString = "\nif("
03648: + op1.getOperandValue() + " <= "
03649: + op.getOperandValue() + ")\n{\n"
03650: + "break;\n" + "}\n";
03651: //codeStatements +=Util.formatDecompiledStatement(tempString);
03652: print = false;
03653: // ifst.setIfHasBeenClosed(true);
03654: }
03655: boolean last = lastIFinShortCutChain(info,
03656: ifst, currentForIndex);
03657: boolean c = addCodeStatementWRTShortcutOR(ifst,
03658: op1.getOperandValue() + " <= "
03659: + op.getOperandValue(), print,
03660: "if", last, op1.getOperandValue()
03661: + " > " + op.getOperandValue());
03662: if (c) {
03663: tempString = "\nif("
03664: + op1.getOperandValue() + " > "
03665: + op.getOperandValue() + ")\n{\n";
03666: //codeStatements +=Util.formatDecompiledStatement(tempString);
03667: }
03668: ifhasbegun = true;
03669: }
03670:
03671: continue;
03672: case JvmOpCodes.IFEQ:
03673: java.lang.String previnstret = getReturnTypeIfPreviousInvoke(
03674: currentForIndex, info);
03675:
03676: op = (Operand) opStack.pop();
03677: classIndex = getJumpAddress(info, i);
03678: addParsedOutput("Instruction Pos "
03679: + currentForIndex + "\t:- " + " ifeq "
03680: + classIndex + "\n");
03681: i += 2;
03682: blockLevel++;
03683: list = behaviour.getBehaviourLoops();
03684: ifLevel++;
03685: ifst = new IFBlock();
03686: ifst.setIfStart(currentForIndex);
03687: ifst.setHasIfBeenGenerated(true);
03688: //ifst.setIfCloseLineNumber(classIndex-3);
03689:
03690: ifHashTable.put("" + (ifLevel), ifst);
03691:
03692: addBranchLabel(classIndex, i, ifst,
03693: currentForIndex, info);
03694: beyondLoop = isBeyondLoop(ifst
03695: .getIfCloseLineNumber(), list, info);
03696: isEndOfLoop = isIndexEndOfLoop(list, ifst
03697: .getIfCloseLineNumber());
03698: correctIf = false;
03699: if (isEndOfLoop) {
03700: loopstart = getLoopStartForEnd(ifst
03701: .getIfCloseLineNumber(), list);
03702: if (currentForIndex > loopstart) {
03703: boolean ifinstcodepresent = getIfinst(
03704: loopstart, info, currentForIndex);
03705: if (ifinstcodepresent) {
03706: correctIf = false;
03707: } else
03708: correctIf = true;
03709: }
03710: }
03711:
03712: if (info[ifst.getIfCloseLineNumber()] == JvmOpCodes.GOTO
03713: && isEndOfLoop && correctIf) {
03714: int t = ifst.getIfCloseLineNumber();
03715: int gotoIndex = getJumpAddress(info, t);//((info[t+1] << 8) | info[t+2]) + (ifst.getIfCloseLineNumber());
03716: if (gotoIndex < (t + 3)) {
03717: boolean isInfiniteLoop = false;
03718: Iterator infLoop = behaviour
03719: .getBehaviourLoops().iterator();
03720: while (infLoop.hasNext()) {
03721: Loop iloop = (Loop) infLoop.next();
03722: if (iloop.getStartIndex() == gotoIndex
03723: && iloop.isInfinite()) {
03724: isInfiniteLoop = true;
03725: /*ifLevel++;
03726: ifst = new IFBlock();
03727: ifst.setIfStart(currentForIndex);
03728: ifst.setHasIfBeenGenerated(true);
03729: //ifst.setIfCloseLineNumber(classIndex-3); */
03730: ifst
03731: .setElseCloseLineNumber(gotoIndex);
03732: // ifHashTable.put(""+(ifLevel),ifst);
03733:
03734: isIfInScope = true;
03735: //addBranchLabel(classIndex,i,ifst,currentForIndex,info);
03736: boolean bb = isBeyondLoop(
03737: getJumpAddress(info,
03738: currentForIndex),
03739: behaviour
03740: .getBehaviourLoops(),
03741: info);
03742: boolean print = true;
03743: if (bb && this Loop != null
03744: && this Loop.isInfinite()
03745: && !encounteredOrComp) {
03746: //info[currentForIndex-3]!=JvmOpCodes.INSTANCEOF &&
03747: if (isThisInstrStart(
03748: behaviour
03749: .getInstructionStartPositions(),
03750: currentForIndex - 1)
03751: && (info[currentForIndex - 1] != JvmOpCodes.DCMPG)
03752: && (info[currentForIndex - 1] != JvmOpCodes.DCMPL)
03753: && info[currentForIndex - 1] != JvmOpCodes.FCMPG
03754: && info[currentForIndex - 1] != JvmOpCodes.FCMPL
03755: && info[currentForIndex - 1] != JvmOpCodes.LCMP)
03756: tempString = "\nif("
03757: + op
03758: .getOperandValue()
03759: + "=="
03760: + previnstret
03761: + ")\n{\nbreak;\n}\n";
03762: else if (isThisInstrStart(
03763: behaviour
03764: .getInstructionStartPositions(),
03765: currentForIndex - 3)
03766: && info[currentForIndex - 3] != JvmOpCodes.INSTANCEOF
03767: && isPreviousInst(
03768: info,
03769: currentForIndex,
03770: currentForIndex - 3)) {
03771: tempString = "\nif("
03772: + op
03773: .getOperandValue()
03774: + "=="
03775: + previnstret
03776: + ")\n{\nbreak;\n}\n";
03777: } else
03778: tempString = "\nif("
03779: + op
03780: .getOperandValue()
03781: + ")\n{\nbreak;\n}\n";
03782: //codeStatements +=Util.formatDecompiledStatement(tempString);
03783: print = false;
03784: }
03785: java.lang.String tempstr = "";
03786: boolean last = lastIFinShortCutChain(
03787: info, ifst, currentForIndex);
03788: if (isThisInstrStart(
03789: behaviour
03790: .getInstructionStartPositions(),
03791: currentForIndex - 1)
03792: && info[currentForIndex - 1] != JvmOpCodes.DCMPG
03793: && info[currentForIndex - 1] != JvmOpCodes.DCMPL
03794: && info[currentForIndex - 1] != JvmOpCodes.FCMPG
03795: && info[currentForIndex - 1] != JvmOpCodes.FCMPL
03796: && info[currentForIndex - 1] != JvmOpCodes.LCMP) {
03797: tempString = "\nif("
03798: + op.getOperandValue()
03799: + "!=" + previnstret
03800: + ")\n{\n";
03801: tempstr = op.getOperandValue()
03802: + "==" + previnstret;
03803: } else if (isThisInstrStart(
03804: behaviour
03805: .getInstructionStartPositions(),
03806: currentForIndex - 3)
03807: && info[currentForIndex - 3] != JvmOpCodes.INSTANCEOF
03808: && isPreviousInst(info,
03809: currentForIndex,
03810: currentForIndex - 3)) {
03811: tempString = "\nif("
03812: + op.getOperandValue()
03813: + "!=" + previnstret
03814: + ")\n{\n";
03815: tempstr = op.getOperandValue()
03816: + "==" + previnstret;
03817: } else {
03818: tempString = "\nif("
03819: + op.getOperandValue()
03820: + ")\n{\n";
03821: tempstr = op.getOperandValue();
03822: }
03823:
03824: boolean c = addCodeStatementWRTShortcutOR(
03825: ifst, tempstr, print, "if",
03826: last, op.getOperandValue()
03827: + "!="
03828: + previnstret);
03829: if (c)
03830: //codeStatements +=Util.formatDecompiledStatement(tempString);
03831: ifhasbegun = true;
03832: break;
03833: }
03834: }
03835: if (isInfiniteLoop) {
03836: continue;
03837: }
03838: java.lang.String tempstr = "";
03839: if (isThisInstrStart(behaviour
03840: .getInstructionStartPositions(),
03841: currentForIndex - 1)
03842: && info[currentForIndex - 1] != JvmOpCodes.DCMPG
03843: && info[currentForIndex - 1] != JvmOpCodes.DCMPL
03844: && info[currentForIndex - 1] != JvmOpCodes.FCMPG
03845: && info[currentForIndex - 1] != JvmOpCodes.FCMPL
03846: && info[currentForIndex - 1] != JvmOpCodes.LCMP) {
03847: tempString = "\nwhile("
03848: + op.getOperandValue() + "!="
03849: + previnstret + ")\n{\n";
03850: tempstr = op.getOperandValue() + "=="
03851: + previnstret;
03852: } else if (isThisInstrStart(behaviour
03853: .getInstructionStartPositions(),
03854: currentForIndex - 3)
03855: && info[currentForIndex - 3] != JvmOpCodes.INSTANCEOF
03856: && isPreviousInst(info,
03857: currentForIndex,
03858: currentForIndex - 3)) {
03859: tempString = "\nwhile("
03860: + op.getOperandValue() + "!="
03861: + previnstret + ")\n{\n";
03862: tempstr = op.getOperandValue() + "=="
03863: + previnstret;
03864: } else {
03865: tempString = "\nwhile("
03866: + op.getOperandValue()
03867: + ")\n{\n";
03868: tempstr = op.getOperandValue();
03869: }
03870: boolean last = lastIFinShortCutChain(info,
03871: ifst, currentForIndex);
03872: boolean c = addCodeStatementWRTShortcutOR(
03873: ifst, tempstr, true, "while", last,
03874: op.getOperandValue() + "!="
03875: + previnstret);
03876: if (c)
03877: //codeStatements +=Util.formatDecompiledStatement(tempString);
03878: isWhileInScope = true;
03879: whileIndex++;
03880:
03881: } else {
03882: /* ifLevel++;
03883: ifst = new IFBlock();
03884: ifst.setIfStart(currentForIndex);
03885: ifst.setHasIfBeenGenerated(true);
03886: // ifst.setIfCloseLineNumber(classIndex-3); */
03887: ifst.setElseCloseLineNumber(gotoIndex);
03888: // ifHashTable.put(""+(ifLevel),ifst);
03889:
03890: isIfInScope = true;
03891: // addBranchLabel(classIndex,i,ifst,currentForIndex,info);
03892: boolean bb = isBeyondLoop(getJumpAddress(
03893: info, currentForIndex), behaviour
03894: .getBehaviourLoops(), info);
03895: boolean print = true;
03896: if (bb && this Loop != null
03897: && this Loop.isInfinite()
03898: && !encounteredOrComp) {
03899: if (isThisInstrStart(
03900: behaviour
03901: .getInstructionStartPositions(),
03902: currentForIndex - 1)
03903: && (info[currentForIndex - 1] != JvmOpCodes.DCMPG)
03904: && (info[currentForIndex - 1] != JvmOpCodes.DCMPL)
03905: && info[currentForIndex - 1] != JvmOpCodes.FCMPG
03906: && info[currentForIndex - 1] != JvmOpCodes.FCMPL
03907: && info[currentForIndex - 1] != JvmOpCodes.LCMP)
03908: tempString = "\nif("
03909: + op.getOperandValue()
03910: + "==" + previnstret
03911: + ")\n{\nbreak;\n}\n";
03912: else if (isThisInstrStart(
03913: behaviour
03914: .getInstructionStartPositions(),
03915: currentForIndex - 3)
03916: && info[currentForIndex - 3] != JvmOpCodes.INSTANCEOF
03917: && isPreviousInst(info,
03918: currentForIndex,
03919: currentForIndex - 3)) {
03920: tempString = "\nif("
03921: + op.getOperandValue()
03922: + "==" + previnstret
03923: + ")\n{\nbreak;\n}\n";
03924: } else
03925: tempString = "\nif("
03926: + op.getOperandValue()
03927: + ")\n{\nbreak;\n}\n";
03928: //codeStatements +=Util.formatDecompiledStatement(tempString);
03929: print = false;
03930: }
03931: java.lang.String tempstr = "";
03932: if (isThisInstrStart(behaviour
03933: .getInstructionStartPositions(),
03934: currentForIndex - 1)
03935: && info[currentForIndex - 1] != JvmOpCodes.DCMPG
03936: && info[currentForIndex - 1] != JvmOpCodes.DCMPL
03937: && info[currentForIndex - 1] != JvmOpCodes.FCMPG
03938: && info[currentForIndex - 1] != JvmOpCodes.FCMPL
03939: && info[currentForIndex - 1] != JvmOpCodes.LCMP) {
03940: tempString = "\nif("
03941: + op.getOperandValue() + "!="
03942: + previnstret + ")\n{\n";
03943: tempstr = op.getOperandValue() + "=="
03944: + previnstret;
03945: } else if (isThisInstrStart(behaviour
03946: .getInstructionStartPositions(),
03947: currentForIndex - 3)
03948: && info[currentForIndex - 3] != JvmOpCodes.INSTANCEOF
03949: && isPreviousInst(info,
03950: currentForIndex,
03951: currentForIndex - 3)) {
03952: tempString = "\nif("
03953: + op.getOperandValue() + "!="
03954: + previnstret + ")\n{\n";
03955: tempstr = op.getOperandValue() + "=="
03956: + previnstret;
03957: }
03958:
03959: else {
03960: tempString = "\nif("
03961: + op.getOperandValue()
03962: + ")\n{\n";
03963: tempstr = op.getOperandValue();
03964: }
03965: boolean last = lastIFinShortCutChain(info,
03966: ifst, currentForIndex);
03967: boolean c = addCodeStatementWRTShortcutOR(
03968: ifst, tempstr, print, "if", last,
03969: op.getOperandValue() + "!="
03970: + previnstret);
03971: if (c)
03972: //codeStatements +=Util.formatDecompiledStatement(tempString);
03973: ifhasbegun = true;
03974: }
03975:
03976: } else {
03977: /* ifLevel++;
03978: ifst = new IFBlock();
03979: ifst.setIfStart(currentForIndex);
03980: ifst.setHasIfBeenGenerated(true);
03981: ifHashTable.put(""+(ifLevel),ifst); */
03982: isIfInScope = true;
03983: addBranchLabel(classIndex, i, ifst,
03984: currentForIndex, info);
03985: boolean bb = isBeyondLoop(getJumpAddress(info,
03986: currentForIndex), behaviour
03987: .getBehaviourLoops(), info);
03988: boolean print = true;
03989: if (bb && this Loop != null
03990: && this Loop.isInfinite()
03991: && !encounteredOrComp) {
03992: if (isThisInstrStart(behaviour
03993: .getInstructionStartPositions(),
03994: currentForIndex - 1)
03995: && (info[currentForIndex - 1] != JvmOpCodes.DCMPG)
03996: && (info[currentForIndex - 1] != JvmOpCodes.DCMPL)
03997: && info[currentForIndex - 1] != JvmOpCodes.FCMPG
03998: && info[currentForIndex - 1] != JvmOpCodes.FCMPL
03999: && info[currentForIndex - 1] != JvmOpCodes.LCMP)
04000: tempString = "\nif("
04001: + op.getOperandValue() + "=="
04002: + previnstret
04003: + ")\n{\nbreak;\n}\n";
04004: else if (isThisInstrStart(behaviour
04005: .getInstructionStartPositions(),
04006: currentForIndex - 3)
04007: && info[currentForIndex - 3] != JvmOpCodes.INSTANCEOF
04008: && isPreviousInst(info,
04009: currentForIndex,
04010: currentForIndex - 3)) {
04011: tempString = "\nif("
04012: + op.getOperandValue() + "=="
04013: + previnstret
04014: + ")\n{\nbreak;\n}\n";
04015: } else
04016: tempString = "\nif("
04017: + op.getOperandValue()
04018: + ")\n{\nbreak;\n}\n";
04019: //codeStatements +=Util.formatDecompiledStatement(tempString);
04020: print = false;
04021: }
04022: java.lang.String tempstr = "";
04023: if (isThisInstrStart(behaviour
04024: .getInstructionStartPositions(),
04025: currentForIndex - 1)
04026: && info[currentForIndex - 1] != JvmOpCodes.DCMPG
04027: && info[currentForIndex - 1] != JvmOpCodes.DCMPL
04028: && info[currentForIndex - 1] != JvmOpCodes.FCMPG
04029: && info[currentForIndex - 1] != JvmOpCodes.FCMPL
04030: && info[currentForIndex - 1] != JvmOpCodes.LCMP) {
04031: tempString = "\nif(" + op.getOperandValue()
04032: + "!=" + previnstret + ")\n{\n";
04033: tempstr = op.getOperandValue() + "=="
04034: + previnstret;
04035: } else if (isThisInstrStart(behaviour
04036: .getInstructionStartPositions(),
04037: currentForIndex - 3)
04038: && info[currentForIndex - 3] != JvmOpCodes.INSTANCEOF
04039: && isPreviousInst(info,
04040: currentForIndex,
04041: currentForIndex - 3)) {
04042: tempString = "\nif(" + op.getOperandValue()
04043: + "!=" + previnstret + ")\n{\n";
04044: tempstr = op.getOperandValue() + "=="
04045: + previnstret;
04046: } else {
04047: tempString = "\nif(" + op.getOperandValue()
04048: + ")\n{\n";
04049: tempstr = op.getOperandValue();
04050: }
04051: boolean last = lastIFinShortCutChain(info,
04052: ifst, currentForIndex);
04053: boolean c = addCodeStatementWRTShortcutOR(ifst,
04054: tempstr, print, "if", last, op
04055: .getOperandValue()
04056: + "!=" + previnstret);
04057: if (c)
04058: //codeStatements +=Util.formatDecompiledStatement(tempString);
04059: ifhasbegun = true;
04060: }
04061:
04062: continue;
04063: case JvmOpCodes.IFNE:
04064: previnstret = getReturnTypeIfPreviousInvoke(
04065: currentForIndex, info);
04066: op = (Operand) opStack.pop();
04067: classIndex = getJumpAddress(info, i);
04068: addParsedOutput("Instruction Pos "
04069: + currentForIndex + "\t:- " + " ifne "
04070: + classIndex + "\n");
04071: i += 2;
04072: blockLevel++;
04073: list = behaviour.getBehaviourLoops();
04074: ifLevel++;
04075: ifst = new IFBlock();
04076: ifst.setIfStart(currentForIndex);
04077: ifst.setHasIfBeenGenerated(true);
04078: //ifst.setIfCloseLineNumber(classIndex-3);
04079:
04080: ifHashTable.put("" + (ifLevel), ifst);
04081:
04082: addBranchLabel(classIndex, i, ifst,
04083: currentForIndex, info);
04084: beyondLoop = isBeyondLoop(ifst
04085: .getIfCloseLineNumber(), list, info);
04086: isEndOfLoop = isIndexEndOfLoop(list, ifst
04087: .getIfCloseLineNumber());
04088: correctIf = false;
04089: if (isEndOfLoop) {
04090: loopstart = getLoopStartForEnd(ifst
04091: .getIfCloseLineNumber(), list);
04092: if (currentForIndex > loopstart) {
04093: boolean ifinstcodepresent = getIfinst(
04094: loopstart, info, currentForIndex);
04095: if (ifinstcodepresent) {
04096: correctIf = false;
04097: } else
04098: correctIf = true;
04099: }
04100: }
04101: if (info[ifst.getIfCloseLineNumber()] == JvmOpCodes.GOTO
04102: && isEndOfLoop && correctIf) {
04103: int t = ifst.getIfCloseLineNumber();
04104: int gotoIndex = getJumpAddress(info, t);//((info[t+1] << 8) | info[t+2]) + (ifst.getIfCloseLineNumber());
04105: if (gotoIndex < (t + 3))
04106: if (gotoIndex < classIndex) {
04107: boolean isInfiniteLoop = false;
04108: Iterator infLoop = behaviour
04109: .getBehaviourLoops().iterator();
04110: while (infLoop.hasNext()) {
04111: Loop iloop = (Loop) infLoop.next();
04112: if (iloop.getStartIndex() == gotoIndex
04113: && iloop.isInfinite()) {
04114: isInfiniteLoop = true;
04115: /* ifLevel++;
04116: ifst = new IFBlock();
04117: ifst.setIfStart(currentForIndex);
04118: ifst.setHasIfBeenGenerated(true);
04119: //ifst.setIfCloseLineNumber(classIndex-3); */
04120: ifst
04121: .setElseCloseLineNumber(gotoIndex);
04122: // ifHashTable.put(""+(ifLevel),ifst);
04123: isIfInScope = true;
04124: // addBranchLabel(classIndex,i,ifst,currentForIndex,info);
04125: boolean bb = isBeyondLoop(
04126: getJumpAddress(info,
04127: currentForIndex),
04128: behaviour
04129: .getBehaviourLoops(),
04130: info);
04131: boolean print = true;
04132: if (bb
04133: && this Loop != null
04134: && this Loop
04135: .isInfinite()
04136: && !encounteredOrComp) {
04137: if (isThisInstrStart(
04138: behaviour
04139: .getInstructionStartPositions(),
04140: currentForIndex - 1)
04141: && (info[currentForIndex - 1] != JvmOpCodes.DCMPG)
04142: && (info[currentForIndex - 1] != JvmOpCodes.DCMPL)
04143: && info[currentForIndex - 1] != JvmOpCodes.FCMPG
04144: && info[currentForIndex - 1] != JvmOpCodes.FCMPL
04145: && info[currentForIndex - 1] != JvmOpCodes.LCMP)
04146: tempString = "\nif("
04147: + op
04148: .getOperandValue()
04149: + "!="
04150: + previnstret
04151: + ")\n{\nbreak;\n}\n";
04152: else if (isThisInstrStart(
04153: behaviour
04154: .getInstructionStartPositions(),
04155: currentForIndex - 3)
04156: && info[currentForIndex - 3] != JvmOpCodes.INSTANCEOF
04157: && isPreviousInst(
04158: info,
04159: currentForIndex,
04160: currentForIndex - 3))
04161: tempString = "\nif("
04162: + op
04163: .getOperandValue()
04164: + "!="
04165: + previnstret
04166: + ")\n{\nbreak;\n}\n";
04167: else
04168: tempString = "\nif("
04169: + op
04170: .getOperandValue()
04171: + ")\n{\nbreak;\n}\n";
04172: //codeStatements +=Util.formatDecompiledStatement(tempString);
04173: print = false;
04174: //ifst.setIfHasBeenClosed(true);
04175: }
04176: java.lang.String tempstr = "";
04177: boolean last = lastIFinShortCutChain(
04178: info, ifst,
04179: currentForIndex);
04180: if (isThisInstrStart(
04181: behaviour
04182: .getInstructionStartPositions(),
04183: currentForIndex - 1)
04184: && (info[currentForIndex - 1] != JvmOpCodes.DCMPG)
04185: && (info[currentForIndex - 1] != JvmOpCodes.DCMPL)
04186: && info[currentForIndex - 1] != JvmOpCodes.FCMPG
04187: && info[currentForIndex - 1] != JvmOpCodes.FCMPL
04188: && info[currentForIndex - 1] != JvmOpCodes.LCMP) {
04189: tempString = "\nif("
04190: + op
04191: .getOperandValue()
04192: + "=="
04193: + previnstret
04194: + ")\n{\n";
04195: tempstr = op
04196: .getOperandValue()
04197: + "!="
04198: + previnstret;
04199: } else if (isThisInstrStart(
04200: behaviour
04201: .getInstructionStartPositions(),
04202: currentForIndex - 3)
04203: && info[currentForIndex - 3] != JvmOpCodes.INSTANCEOF
04204: && isPreviousInst(
04205: info,
04206: currentForIndex,
04207: currentForIndex - 3)) {
04208: tempString = "\nif("
04209: + op
04210: .getOperandValue()
04211: + "=="
04212: + previnstret
04213: + ")\n{\n";
04214: tempstr = op
04215: .getOperandValue()
04216: + "!="
04217: + previnstret;
04218: } else {
04219: tempString = "\nif("
04220: + op
04221: .getOperandValue()
04222: + ")\n{\n";
04223: tempstr = op
04224: .getOperandValue();
04225: }
04226:
04227: boolean c = addCodeStatementWRTShortcutOR(
04228: ifst, tempstr, print,
04229: "if", last,
04230: op.getOperandValue()
04231: + "=="
04232: + previnstret);
04233: if (c)
04234: //codeStatements +=Util.formatDecompiledStatement(tempString);
04235: ifhasbegun = true;
04236: break;
04237: }
04238: }
04239: if (isInfiniteLoop) {
04240: continue;
04241: }
04242: java.lang.String tempstr = "";
04243: if (isThisInstrStart(
04244: behaviour
04245: .getInstructionStartPositions(),
04246: currentForIndex - 1)
04247: && info[currentForIndex - 1] != JvmOpCodes.DCMPG
04248: && info[currentForIndex - 1] != JvmOpCodes.DCMPL
04249: && info[currentForIndex - 1] != JvmOpCodes.FCMPG
04250: && info[currentForIndex - 1] != JvmOpCodes.FCMPL
04251: && info[currentForIndex - 1] != JvmOpCodes.LCMP) {
04252: tempString = "\nwhile("
04253: + op.getOperandValue()
04254: + "==" + previnstret
04255: + ")\n{\n";
04256: tempstr = op.getOperandValue()
04257: + "!=" + previnstret;
04258: } else if (isThisInstrStart(
04259: behaviour
04260: .getInstructionStartPositions(),
04261: currentForIndex - 3)
04262: && info[currentForIndex - 3] != JvmOpCodes.INSTANCEOF
04263: && isPreviousInst(info,
04264: currentForIndex,
04265: currentForIndex - 3)) {
04266: tempString = "\nwhile("
04267: + op.getOperandValue()
04268: + "==" + previnstret
04269: + ")\n{\n";
04270: tempstr = op.getOperandValue()
04271: + "!=" + previnstret;
04272: }
04273:
04274: else {
04275: tempString = "\nwhile("
04276: + op.getOperandValue()
04277: + ")\n{\n";
04278: tempstr = op.getOperandValue();
04279: }
04280: boolean last = lastIFinShortCutChain(
04281: info, ifst, currentForIndex);
04282: boolean c = addCodeStatementWRTShortcutOR(
04283: ifst, tempstr, true, "while",
04284: last, op.getOperandValue()
04285: + "==" + previnstret);
04286: if (c)
04287: //codeStatements +=Util.formatDecompiledStatement(tempString);
04288: isWhileInScope = true;
04289: whileIndex++;
04290:
04291: } else {
04292: /* ifLevel++;
04293: ifst = new IFBlock();
04294: ifst.setIfStart(currentForIndex);
04295: ifst.setHasIfBeenGenerated(true);
04296: //ifst.setIfCloseLineNumber(classIndex-3); */
04297: ifst.setElseCloseLineNumber(gotoIndex);
04298: // ifHashTable.put(""+(ifLevel),ifst);
04299: isIfInScope = true;
04300: // addBranchLabel(classIndex,i,ifst,currentForIndex,info);
04301: boolean bb = isBeyondLoop(
04302: getJumpAddress(info,
04303: currentForIndex),
04304: behaviour.getBehaviourLoops(),
04305: info);
04306: boolean print = true;
04307: if (bb && this Loop != null
04308: && this Loop.isInfinite()
04309: && !encounteredOrComp) {
04310: if (isThisInstrStart(
04311: behaviour
04312: .getInstructionStartPositions(),
04313: currentForIndex - 1)
04314: && (info[currentForIndex - 1] != JvmOpCodes.DCMPG)
04315: && (info[currentForIndex - 1] != JvmOpCodes.DCMPL)
04316: && info[currentForIndex - 1] != JvmOpCodes.FCMPG
04317: && info[currentForIndex - 1] != JvmOpCodes.FCMPL
04318: && info[currentForIndex - 1] != JvmOpCodes.LCMP)
04319: tempString = "\nif("
04320: + op.getOperandValue()
04321: + "!=" + previnstret
04322: + ")\n{\nbreak;\n}\n";
04323: else if (isThisInstrStart(
04324: behaviour
04325: .getInstructionStartPositions(),
04326: currentForIndex - 3)
04327: && info[currentForIndex - 3] != JvmOpCodes.INSTANCEOF
04328: && isPreviousInst(info,
04329: currentForIndex,
04330: currentForIndex - 3))
04331: tempString = "\nif("
04332: + op.getOperandValue()
04333: + "!=" + previnstret
04334: + ")\n{\nbreak;\n}\n";
04335: else
04336: tempString = "\nif("
04337: + op.getOperandValue()
04338: + ")\n{\nbreak;\n}\n";
04339: //codeStatements +=Util.formatDecompiledStatement(tempString);
04340: print = false;
04341: //ifst.setIfHasBeenClosed(true);
04342: }
04343: java.lang.String tempstr = "";
04344: if (isThisInstrStart(
04345: behaviour
04346: .getInstructionStartPositions(),
04347: currentForIndex - 1)
04348: && info[currentForIndex - 1] != JvmOpCodes.DCMPG
04349: && info[currentForIndex - 1] != JvmOpCodes.DCMPL
04350: && info[currentForIndex - 1] != JvmOpCodes.FCMPG
04351: && info[currentForIndex - 1] != JvmOpCodes.FCMPL
04352: && info[currentForIndex - 1] != JvmOpCodes.LCMP) {
04353: tempString = "\nif("
04354: + op.getOperandValue()
04355: + "==" + previnstret
04356: + ")\n{\n";
04357: tempstr = op.getOperandValue()
04358: + "!=" + previnstret;
04359: } else if (isThisInstrStart(
04360: behaviour
04361: .getInstructionStartPositions(),
04362: currentForIndex - 3)
04363: && info[currentForIndex - 3] != JvmOpCodes.INSTANCEOF
04364: && isPreviousInst(info,
04365: currentForIndex,
04366: currentForIndex - 3)) {
04367: tempString = "\nif("
04368: + op.getOperandValue()
04369: + "==" + previnstret
04370: + ")\n{\n";
04371: tempstr = op.getOperandValue()
04372: + "!=" + previnstret;
04373: } else {
04374: tempString = "\nif("
04375: + op.getOperandValue()
04376: + ")\n{\n";
04377: tempstr = op.getOperandValue();
04378: }
04379: boolean last = lastIFinShortCutChain(
04380: info, ifst, currentForIndex);
04381: boolean c = addCodeStatementWRTShortcutOR(
04382: ifst, tempstr, print, "if",
04383: last, op.getOperandValue()
04384: + "==" + previnstret);
04385: if (c)
04386: //codeStatements +=Util.formatDecompiledStatement(tempString);
04387: ifhasbegun = true;
04388: }
04389:
04390: } else {
04391: /* ifLevel++;
04392: ifst = new IFBlock();
04393: ifst.setIfStart(currentForIndex);
04394: ifst.setHasIfBeenGenerated(true);
04395: ifHashTable.put(""+(ifLevel),ifst);
04396: isIfInScope=true;
04397: addBranchLabel(classIndex,i,ifst,currentForIndex,info); */
04398: isIfInScope = true;
04399: boolean bb = isBeyondLoop(getJumpAddress(info,
04400: currentForIndex), behaviour
04401: .getBehaviourLoops(), info);
04402: boolean print = true;
04403: if (bb && this Loop != null
04404: && this Loop.isInfinite()
04405: && !encounteredOrComp) {
04406: if (isThisInstrStart(behaviour
04407: .getInstructionStartPositions(),
04408: currentForIndex - 1)
04409: && (info[currentForIndex - 1] != JvmOpCodes.DCMPG)
04410: && (info[currentForIndex - 1] != JvmOpCodes.DCMPL)
04411: && info[currentForIndex - 1] != JvmOpCodes.FCMPG
04412: && info[currentForIndex - 1] != JvmOpCodes.FCMPL
04413: && info[currentForIndex - 1] != JvmOpCodes.LCMP)
04414: tempString = "\nif("
04415: + op.getOperandValue() + "!="
04416: + previnstret
04417: + ")\n{\nbreak;\n}\n";
04418: else if (isThisInstrStart(behaviour
04419: .getInstructionStartPositions(),
04420: currentForIndex - 3)
04421: && info[currentForIndex - 3] != JvmOpCodes.INSTANCEOF
04422: && isPreviousInst(info,
04423: currentForIndex,
04424: currentForIndex - 3))
04425: tempString = "\nif("
04426: + op.getOperandValue() + "!="
04427: + previnstret
04428: + ")\n{\nbreak;\n}\n";
04429:
04430: else
04431: tempString = "\nif("
04432: + op.getOperandValue()
04433: + ")\n{\nbreak;\n}\n";
04434: //codeStatements +=Util.formatDecompiledStatement(tempString);
04435: print = false;
04436: // ifst.setIfHasBeenClosed(true);
04437: }
04438: boolean last = lastIFinShortCutChain(info,
04439: ifst, currentForIndex);
04440: java.lang.String tempstr = "";
04441: if (isThisInstrStart(behaviour
04442: .getInstructionStartPositions(),
04443: currentForIndex - 1)
04444: && info[currentForIndex - 1] != JvmOpCodes.DCMPG
04445: && info[currentForIndex - 1] != JvmOpCodes.DCMPL
04446: && info[currentForIndex - 1] != JvmOpCodes.FCMPG
04447: && info[currentForIndex - 1] != JvmOpCodes.FCMPL
04448: && info[currentForIndex - 1] != JvmOpCodes.LCMP) {
04449: tempString = "\nif(" + op.getOperandValue()
04450: + "==" + previnstret + ")\n{\n";
04451: tempstr = op.getOperandValue() + "!="
04452: + previnstret;
04453: } else if (isThisInstrStart(behaviour
04454: .getInstructionStartPositions(),
04455: currentForIndex - 3)
04456: && info[currentForIndex - 3] != JvmOpCodes.INSTANCEOF
04457: && isPreviousInst(info,
04458: currentForIndex,
04459: currentForIndex - 3)) {
04460: tempString = "\nif(" + op.getOperandValue()
04461: + "==" + previnstret + ")\n{\n";
04462: tempstr = op.getOperandValue() + "!="
04463: + previnstret;
04464: } else {
04465: tempString = "\nif(" + op.getOperandValue()
04466: + ")\n{\n";
04467: tempstr = op.getOperandValue();
04468: }
04469:
04470: boolean c = addCodeStatementWRTShortcutOR(ifst,
04471: tempstr, print, "if", last, op
04472: .getOperandValue()
04473: + "==" + previnstret);
04474: if (c)
04475: //codeStatements +=Util.formatDecompiledStatement(tempString);
04476: ifhasbegun = true;
04477: }
04478:
04479: continue;
04480: case JvmOpCodes.IFLT:
04481: //previnstret=getReturnTypeIfPreviousInvoke(currentForIndex,info);
04482: op = (Operand) opStack.pop();
04483: //op1 = (Operand)opStack.pop();
04484: classIndex = getJumpAddress(info, i);
04485: i += 2;
04486: addParsedOutput("Instruction Pos "
04487: + currentForIndex + "\t:- " + " iflt "
04488: + classIndex + "\n");
04489: blockLevel++;
04490: list = behaviour.getBehaviourLoops();
04491: ifLevel++;
04492: ifst = new IFBlock();
04493: ifst.setIfStart(currentForIndex);
04494: ifst.setHasIfBeenGenerated(true);
04495: // ifst.setIfCloseLineNumber(classIndex-3);
04496:
04497: ifHashTable.put("" + (ifLevel), ifst);
04498:
04499: addBranchLabel(classIndex, i, ifst,
04500: currentForIndex, info);
04501: beyondLoop = isBeyondLoop(ifst
04502: .getIfCloseLineNumber(), list, info);
04503: isEndOfLoop = isIndexEndOfLoop(list, (ifst
04504: .getIfCloseLineNumber()));
04505: correctIf = false;
04506: if (isEndOfLoop) {
04507: loopstart = getLoopStartForEnd(ifst
04508: .getIfCloseLineNumber(), list);
04509: if (currentForIndex > loopstart) {
04510: boolean ifinstcodepresent = getIfinst(
04511: loopstart, info, currentForIndex);
04512: if (ifinstcodepresent) {
04513: correctIf = false;
04514: } else
04515: correctIf = true;
04516: } else
04517: correctIf = false;
04518: }
04519: if (info[ifst.getIfCloseLineNumber()] == JvmOpCodes.GOTO
04520: && isEndOfLoop && correctIf) {
04521: int t = ifst.getIfCloseLineNumber();
04522: int gotoIndex = getJumpAddress(info, t);//((info[t+1] << 8) | info[t+2]) + (ifst.getIfCloseLineNumber());
04523: if (gotoIndex < (t + 3))
04524: if (gotoIndex < classIndex) {
04525: boolean isInfiniteLoop = false;
04526: Iterator infLoop = behaviour
04527: .getBehaviourLoops().iterator();
04528: while (infLoop.hasNext()) {
04529: Loop iloop = (Loop) infLoop.next();
04530: if (iloop.getStartIndex() == gotoIndex
04531: && iloop.isInfinite()) {
04532: isInfiniteLoop = true;
04533: /* ifLevel++;
04534: ifst = new IFBlock();
04535: ifst.setIfStart(currentForIndex);
04536: ifst.setHasIfBeenGenerated(true);
04537: // ifst.setIfCloseLineNumber(classIndex-3); */
04538: ifst
04539: .setElseCloseLineNumber(gotoIndex);
04540: // ifHashTable.put(""+(ifLevel),ifst);
04541: isIfInScope = true;
04542: //addBranchLabel(classIndex,i,ifst,currentForIndex,info);
04543: boolean bb = isBeyondLoop(
04544: getJumpAddress(info,
04545: currentForIndex),
04546: behaviour
04547: .getBehaviourLoops(),
04548: info);
04549: boolean print = true;
04550: if (bb
04551: && this Loop != null
04552: && this Loop
04553: .isInfinite()
04554: && !encounteredOrComp) {
04555: if ((info[currentForIndex - 1] != JvmOpCodes.DCMPG)
04556: && (info[currentForIndex - 1] != JvmOpCodes.DCMPL)
04557: && info[currentForIndex - 1] != JvmOpCodes.FCMPG
04558: && info[currentForIndex - 1] != JvmOpCodes.FCMPL
04559: && info[currentForIndex - 1] != JvmOpCodes.LCMP)
04560: tempString = "\nif("
04561: + op
04562: .getOperandValue()
04563: + "<0)\n{\nbreak;\n}\n";
04564: else
04565: tempString = "\nif("
04566: + op
04567: .getOperandValue()
04568: + ")\n{\nbreak;\n}\n";
04569: //codeStatements +=Util.formatDecompiledStatement(tempString);
04570: print = false;
04571: }
04572: java.lang.String tempstr = "";
04573: if (info[currentForIndex - 1] != JvmOpCodes.DCMPG
04574: && info[currentForIndex - 1] != JvmOpCodes.DCMPL
04575: && info[currentForIndex - 1] != JvmOpCodes.FCMPG
04576: && info[currentForIndex - 1] != JvmOpCodes.FCMPL
04577: && info[currentForIndex - 1] != JvmOpCodes.LCMP) {
04578: tempString = "\nif("
04579: + op
04580: .getOperandValue()
04581: + ">=0)\n{\n";
04582: tempstr = op
04583: .getOperandValue()
04584: + "<0";
04585: } else {
04586: tempString = "\nif("
04587: + op
04588: .getOperandValue()
04589: + ")\n{\n";
04590: tempstr = op
04591: .getOperandValue();
04592: }
04593: boolean last = lastIFinShortCutChain(
04594: info, ifst,
04595: currentForIndex);
04596: boolean c = addCodeStatementWRTShortcutOR(
04597: ifst, tempstr, print,
04598: "if", last,
04599: op.getOperandValue()
04600: + ">=0");
04601: if (c)
04602: //codeStatements +=Util.formatDecompiledStatement(tempString);
04603: ifhasbegun = true;
04604: break;
04605: }
04606: }
04607: if (isInfiniteLoop) {
04608: continue;
04609: }
04610: java.lang.String tempstr = "";
04611: if (info[currentForIndex - 1] != JvmOpCodes.DCMPG
04612: && info[currentForIndex - 1] != JvmOpCodes.DCMPL
04613: && info[currentForIndex - 1] != JvmOpCodes.FCMPG
04614: && info[currentForIndex - 1] != JvmOpCodes.FCMPL
04615: && info[currentForIndex - 1] != JvmOpCodes.LCMP) {
04616: tempString = "\nwhile("
04617: + op.getOperandValue()
04618: + " >= 0)\n{\n";
04619: tempstr = op.getOperandValue()
04620: + " < 0";
04621: } else {
04622: tempString = "\nwhile("
04623: + op.getOperandValue()
04624: + ")\n{\n";
04625: tempstr = op.getOperandValue();
04626: }
04627: boolean last = lastIFinShortCutChain(
04628: info, ifst, currentForIndex);
04629: boolean c = addCodeStatementWRTShortcutOR(
04630: ifst, tempstr, true, "while",
04631: last, op.getOperandValue()
04632: + " >= 0");
04633: if (c)
04634: //codeStatements +=Util.formatDecompiledStatement(tempString);
04635: isWhileInScope = true;
04636: whileIndex++;
04637:
04638: } else {
04639: /* ifLevel++;
04640: ifst = new IFBlock();
04641: ifst.setIfStart(currentForIndex);
04642: ifst.setHasIfBeenGenerated(true);
04643: // ifst.setIfCloseLineNumber(classIndex-3); */
04644: ifst.setElseCloseLineNumber(gotoIndex);
04645: // ifHashTable.put(""+(ifLevel),ifst);
04646: isIfInScope = true;
04647: // addBranchLabel(classIndex,i,ifst,currentForIndex,info);
04648: boolean bb = isBeyondLoop(
04649: getJumpAddress(info,
04650: currentForIndex),
04651: behaviour.getBehaviourLoops(),
04652: info);
04653: boolean print = true;
04654: java.lang.String tempstr = "";
04655: if (bb && this Loop != null
04656: && this Loop.isInfinite()
04657: && !encounteredOrComp) {
04658: if ((info[currentForIndex - 1] != JvmOpCodes.DCMPG)
04659: && (info[currentForIndex - 1] != JvmOpCodes.DCMPL)
04660: && info[currentForIndex - 1] != JvmOpCodes.FCMPG
04661: && info[currentForIndex - 1] != JvmOpCodes.FCMPL
04662: && info[currentForIndex - 1] != JvmOpCodes.LCMP) {
04663: tempString = "\nif("
04664: + op.getOperandValue()
04665: + "<0)\n{\nbreak;\n}\n";
04666: } else
04667: tempString = "\nif("
04668: + op.getOperandValue()
04669: + ")\n{\nbreak;\n}\n";
04670: //codeStatements +=Util.formatDecompiledStatement(tempString);
04671: print = false;
04672: // ifst.setIfHasBeenClosed(true);
04673: }
04674: if (info[currentForIndex - 1] != JvmOpCodes.DCMPG
04675: && info[currentForIndex - 1] != JvmOpCodes.DCMPL
04676: && info[currentForIndex - 1] != JvmOpCodes.FCMPG
04677: && info[currentForIndex - 1] != JvmOpCodes.FCMPL
04678: && info[currentForIndex - 1] != JvmOpCodes.LCMP) {
04679: tempString = "\nif("
04680: + op.getOperandValue()
04681: + ">=0)\n{\n";
04682: tempstr = op.getOperandValue()
04683: + "<0";
04684: } else {
04685: tempString = "\nif("
04686: + op.getOperandValue()
04687: + ")\n{\n";
04688: tempstr = op.getOperandValue();
04689: }
04690: boolean last = lastIFinShortCutChain(
04691: info, ifst, currentForIndex);
04692: boolean c = addCodeStatementWRTShortcutOR(
04693: ifst, tempstr, print, "if",
04694: last, op.getOperandValue()
04695: + ">=0");
04696: if (c)
04697: //codeStatements +=Util.formatDecompiledStatement(tempString);
04698: ifhasbegun = true;
04699: }
04700:
04701: } else {
04702: /* ifLevel++;
04703: ifst = new IFBlock();
04704: ifst.setHasIfBeenGenerated(true);
04705: ifHashTable.put(""+(ifLevel),ifst);
04706: isIfInScope=true;
04707: ifst.setIfStart(currentForIndex);
04708: addBranchLabel(classIndex,i,ifst,currentForIndex,info); */
04709: isIfInScope = true;
04710: boolean bb = isBeyondLoop(getJumpAddress(info,
04711: currentForIndex), behaviour
04712: .getBehaviourLoops(), info);
04713: boolean print = true;
04714: if (bb && this Loop != null
04715: && this Loop.isInfinite()
04716: && !encounteredOrComp) {
04717: if ((info[currentForIndex - 1] != JvmOpCodes.DCMPG)
04718: && (info[currentForIndex - 1] != JvmOpCodes.DCMPL)
04719: && info[currentForIndex - 1] != JvmOpCodes.FCMPG
04720: && info[currentForIndex - 1] != JvmOpCodes.FCMPL
04721: && info[currentForIndex - 1] != JvmOpCodes.LCMP)
04722: tempString = "\nif("
04723: + op.getOperandValue()
04724: + "<0)\n{\nbreak;\n}\n";
04725: else
04726: tempString = "\nif("
04727: + op.getOperandValue()
04728: + ")\n{\nbreak;\n}\n";
04729: //codeStatements +=Util.formatDecompiledStatement(tempString);
04730: print = false;
04731: // ifst.setIfHasBeenClosed(true);
04732: }
04733: java.lang.String tempstr = "";
04734: if (info[currentForIndex - 1] != JvmOpCodes.DCMPG
04735: && info[currentForIndex - 1] != JvmOpCodes.DCMPL
04736: && info[currentForIndex - 1] != JvmOpCodes.FCMPG
04737: && info[currentForIndex - 1] != JvmOpCodes.FCMPL
04738: && info[currentForIndex - 1] != JvmOpCodes.LCMP) {
04739: tempString = "\nif(" + op.getOperandValue()
04740: + ">=0)\n{\n";
04741: tempstr = op.getOperandValue() + "<0";
04742: } else {
04743: tempString = "\nif(" + op.getOperandValue()
04744: + ")\n{\n";
04745: tempstr = op.getOperandValue();
04746: }
04747: boolean last = lastIFinShortCutChain(info,
04748: ifst, currentForIndex);
04749: boolean c = addCodeStatementWRTShortcutOR(ifst,
04750: tempstr, print, "if", last, op
04751: .getOperandValue()
04752: + ">=0");
04753: if (c)
04754: //codeStatements +=Util.formatDecompiledStatement(tempString);
04755: ifhasbegun = true;
04756: }
04757: // Continue from here
04758: continue;
04759: case JvmOpCodes.IFGE:
04760: op = (Operand) opStack.pop();
04761: //op1 = (Operand)opStack.pop();
04762: classIndex = getJumpAddress(info, i);
04763: i += 2;
04764: addParsedOutput("Instruction Pos "
04765: + currentForIndex + "\t:- " + " ifge "
04766: + classIndex + "\n");
04767: blockLevel++;
04768: list = behaviour.getBehaviourLoops();
04769: ifLevel++;
04770: ifst = new IFBlock();
04771: ifst.setIfStart(currentForIndex);
04772: ifst.setHasIfBeenGenerated(true);
04773: ifHashTable.put("" + (ifLevel), ifst);
04774: addBranchLabel(classIndex, i, ifst,
04775: currentForIndex, info);
04776: isEndOfLoop = isIndexEndOfLoop(list, (ifst
04777: .getIfCloseLineNumber()));
04778: beyondLoop = isBeyondLoop(ifst
04779: .getIfCloseLineNumber(), list, info);
04780: correctIf = false;
04781: if (isEndOfLoop) {
04782: loopstart = getLoopStartForEnd(ifst
04783: .getIfCloseLineNumber(), list);
04784: if (currentForIndex > loopstart) {
04785: boolean ifinstcodepresent = getIfinst(
04786: loopstart, info, currentForIndex);
04787: if (ifinstcodepresent) {
04788: correctIf = false;
04789: } else
04790: correctIf = true;
04791: }
04792: }
04793:
04794: if (info[ifst.getIfCloseLineNumber()] == JvmOpCodes.GOTO
04795: && isEndOfLoop && correctIf) {
04796: int t = ifst.getIfCloseLineNumber();
04797: int gotoIndex = getJumpAddress(info, t);// ((info[t+1] << 8) | info[t+2]) + (ifst.getIfCloseLineNumber());
04798: if (gotoIndex < (t + 3)) {
04799: boolean isInfiniteLoop = false;
04800: Iterator infLoop = behaviour
04801: .getBehaviourLoops().iterator();
04802: while (infLoop.hasNext()) {
04803: Loop iloop = (Loop) infLoop.next();
04804: if (iloop.getStartIndex() == gotoIndex
04805: && iloop.isInfinite()) {
04806: isInfiniteLoop = true;
04807: /* ifLevel++;
04808: ifst = new IFBlock();
04809: ifst.setIfStart(currentForIndex);
04810: ifst.setHasIfBeenGenerated(true);*/
04811: // ifst.setIfCloseLineNumber(classIndex-3);
04812: ifst
04813: .setElseCloseLineNumber(gotoIndex);
04814: //ifHashTable.put(""+(ifLevel),ifst);
04815:
04816: isIfInScope = true;
04817:
04818: boolean bb = isBeyondLoop(
04819: getJumpAddress(info,
04820: currentForIndex),
04821: behaviour
04822: .getBehaviourLoops(),
04823: info);
04824: boolean print = true;
04825: java.lang.String tempstr = "";
04826: if (bb && this Loop != null
04827: && this Loop.isInfinite()
04828: && !encounteredOrComp) {
04829: if ((info[currentForIndex - 1] != JvmOpCodes.DCMPG)
04830: && (info[currentForIndex - 1] != JvmOpCodes.DCMPL)
04831: && info[currentForIndex - 1] != JvmOpCodes.FCMPG
04832: && info[currentForIndex - 1] != JvmOpCodes.FCMPL
04833: && info[currentForIndex - 1] != JvmOpCodes.LCMP)
04834: tempString = "\nif("
04835: + op
04836: .getOperandValue()
04837: + ">=0)\n{\nbreak;\n}\n";
04838: else
04839: tempString = "\nif("
04840: + op
04841: .getOperandValue()
04842: + ")\n{\nbreak;\n}\n";
04843: //codeStatements +=Util.formatDecompiledStatement(tempString);
04844: print = false;
04845: // ifst.setIfHasBeenClosed(true);
04846: }
04847: if (info[currentForIndex - 1] != JvmOpCodes.DCMPG
04848: && info[currentForIndex - 1] != JvmOpCodes.DCMPL
04849: && info[currentForIndex - 1] != JvmOpCodes.FCMPG
04850: && info[currentForIndex - 1] != JvmOpCodes.FCMPL
04851: && info[currentForIndex - 1] != JvmOpCodes.LCMP) {
04852: tempString = "\nif("
04853: + op.getOperandValue()
04854: + "<0)\n{\n";
04855: tempstr = op.getOperandValue()
04856: + ">=0";
04857: } else {
04858: tempString = "\nif("
04859: + op.getOperandValue()
04860: + ")\n{\n";
04861: tempstr = op.getOperandValue();
04862: }
04863: boolean last = lastIFinShortCutChain(
04864: info, ifst, currentForIndex);
04865: boolean c = addCodeStatementWRTShortcutOR(
04866: ifst, tempstr, print, "if",
04867: last, op.getOperandValue()
04868: + "<0");
04869: if (c)
04870: //codeStatements +=Util.formatDecompiledStatement(tempString);
04871: ifhasbegun = true;
04872: break;
04873: }
04874: }
04875: if (isInfiniteLoop) {
04876: continue;
04877: }
04878: java.lang.String tempstr = "";
04879: if (info[currentForIndex - 1] != JvmOpCodes.DCMPG
04880: && info[currentForIndex - 1] != JvmOpCodes.DCMPL
04881: && info[currentForIndex - 1] != JvmOpCodes.FCMPG
04882: && info[currentForIndex - 1] != JvmOpCodes.FCMPL
04883: && info[currentForIndex - 1] != JvmOpCodes.LCMP) {
04884: tempString = "\nwhile("
04885: + op.getOperandValue()
04886: + "<0)\n{\n";
04887: tempstr = op.getOperandValue() + ">=0";
04888: } else {
04889: tempString = "\nwhile("
04890: + op.getOperandValue()
04891: + ")\n{\n";
04892: tempstr = op.getOperandValue();
04893: }
04894: boolean last = lastIFinShortCutChain(info,
04895: ifst, currentForIndex);
04896: boolean c = addCodeStatementWRTShortcutOR(
04897: ifst, tempstr, true, "while", last,
04898: op.getOperandValue() + "<0");
04899: if (c)
04900: //codeStatements +=Util.formatDecompiledStatement(tempString);
04901: isWhileInScope = true;
04902: whileIndex++;
04903:
04904: } else {
04905: /* ifLevel++;
04906: ifst = new IFBlock();
04907: ifst.setIfStart(currentForIndex);
04908: ifst.setHasIfBeenGenerated(true);*/
04909: // ifst.setIfCloseLineNumber(classIndex-3);
04910: ifst.setElseCloseLineNumber(gotoIndex);
04911: //ifHashTable.put(""+(ifLevel),ifst);
04912:
04913: isIfInScope = true;
04914: //addBranchLabel(classIndex,i,ifst,currentForIndex,info);
04915: boolean bb = isBeyondLoop(getJumpAddress(
04916: info, currentForIndex), behaviour
04917: .getBehaviourLoops(), info);
04918: boolean print = true;
04919: if (bb && this Loop != null
04920: && this Loop.isInfinite()
04921: && !encounteredOrComp) {
04922: if ((info[currentForIndex - 1] != JvmOpCodes.DCMPG)
04923: && (info[currentForIndex - 1] != JvmOpCodes.DCMPL)
04924: && info[currentForIndex - 1] != JvmOpCodes.FCMPG
04925: && info[currentForIndex - 1] != JvmOpCodes.FCMPL
04926: && info[currentForIndex - 1] != JvmOpCodes.LCMP)
04927: tempString = "\nif("
04928: + op.getOperandValue()
04929: + ">=0)\n{\nbreak;\n}\n";
04930: else
04931: tempString = "\nif("
04932: + op.getOperandValue()
04933: + ")\n{\nbreak;\n}\n";
04934: //codeStatements +=Util.formatDecompiledStatement(tempString);
04935: print = false;
04936: //ifst.setIfHasBeenClosed(true);
04937: }
04938: java.lang.String tempstr = "";
04939: boolean last = lastIFinShortCutChain(info,
04940: ifst, currentForIndex);
04941: if (info[currentForIndex - 1] != JvmOpCodes.DCMPG
04942: && info[currentForIndex - 1] != JvmOpCodes.DCMPL
04943: && info[currentForIndex - 1] != JvmOpCodes.FCMPG
04944: && info[currentForIndex - 1] != JvmOpCodes.FCMPL
04945: && info[currentForIndex - 1] != JvmOpCodes.LCMP) {
04946: tempString = "\nif("
04947: + op.getOperandValue()
04948: + "<0)\n{\n";
04949: tempstr = op.getOperandValue() + ">=0";
04950: } else {
04951: tempString = "\nif("
04952: + op.getOperandValue()
04953: + ")\n{\n";
04954: tempstr = op.getOperandValue();
04955: }
04956: boolean c = addCodeStatementWRTShortcutOR(
04957: ifst, tempstr, print, "if", last,
04958: op.getOperandValue() + "<0");
04959: if (c)
04960: //codeStatements +=Util.formatDecompiledStatement(tempString);
04961: ifhasbegun = true;
04962: }
04963: } else {
04964: /*ifLevel++;
04965: ifst = new IFBlock();
04966: ifst.setIfStart(currentForIndex);
04967: ifst.setHasIfBeenGenerated(true);
04968: ifHashTable.put(""+(ifLevel),ifst);*/
04969: isIfInScope = true;
04970: //addBranchLabel(classIndex,i,ifst,currentForIndex,info);
04971: boolean bb = isBeyondLoop(getJumpAddress(info,
04972: currentForIndex), behaviour
04973: .getBehaviourLoops(), info);
04974: boolean print = true;
04975: if (bb && this Loop != null
04976: && this Loop.isInfinite()
04977: && !encounteredOrComp) {
04978: if ((info[currentForIndex - 1] != JvmOpCodes.DCMPG)
04979: && (info[currentForIndex - 1] != JvmOpCodes.DCMPL)
04980: && info[currentForIndex - 1] != JvmOpCodes.FCMPG
04981: && info[currentForIndex - 1] != JvmOpCodes.FCMPL
04982: && info[currentForIndex - 1] != JvmOpCodes.LCMP)
04983: tempString = "\nif("
04984: + op.getOperandValue()
04985: + ">=0)\n{\nbreak;\n}\n";
04986: else
04987: tempString = "\nif("
04988: + op.getOperandValue()
04989: + ")\n{\nbreak;\n}\n";
04990: //codeStatements +=Util.formatDecompiledStatement(tempString);
04991: print = false;
04992: // ifst.setIfHasBeenClosed(true);
04993: }
04994: java.lang.String tempstr = "";
04995: if (info[currentForIndex - 1] != JvmOpCodes.DCMPG
04996: && info[currentForIndex - 1] != JvmOpCodes.DCMPL
04997: && info[currentForIndex - 1] != JvmOpCodes.FCMPG
04998: && info[currentForIndex - 1] != JvmOpCodes.FCMPL
04999: && info[currentForIndex - 1] != JvmOpCodes.LCMP) {
05000: tempString = "\nif(" + op.getOperandValue()
05001: + "<0)\n{\n";
05002: tempstr = op.getOperandValue() + ">=0";
05003: } else {
05004: tempString = "\nif(" + op.getOperandValue()
05005: + ")\n{\n";
05006: tempstr = op.getOperandValue();
05007: }
05008: boolean last = lastIFinShortCutChain(info,
05009: ifst, currentForIndex);
05010: boolean c = addCodeStatementWRTShortcutOR(ifst,
05011: tempstr, print, "if", last, op
05012: .getOperandValue()
05013: + "<0");
05014: if (c)
05015: //codeStatements +=Util.formatDecompiledStatement(tempString);
05016: ifhasbegun = true;
05017: }
05018:
05019: continue;
05020: case JvmOpCodes.IFGT:
05021: op = (Operand) opStack.pop();
05022: //op1 = (Operand)opStack.pop();
05023: classIndex = getJumpAddress(info, i);
05024: addParsedOutput("Instruction Pos "
05025: + currentForIndex + "\t:- " + " ifgt "
05026: + classIndex + "\n");
05027: i += 2;
05028: blockLevel++;
05029: list = behaviour.getBehaviourLoops();
05030: ifLevel++;
05031: ifst = new IFBlock();
05032: ifst.setIfStart(currentForIndex);
05033: ifst.setHasIfBeenGenerated(true);
05034: ifHashTable.put("" + (ifLevel), ifst);
05035: addBranchLabel(classIndex, i, ifst,
05036: currentForIndex, info);
05037:
05038: isEndOfLoop = isIndexEndOfLoop(list, ifst
05039: .getIfCloseLineNumber());
05040: beyondLoop = isBeyondLoop(ifst
05041: .getIfCloseLineNumber(), list, info);
05042: correctIf = false;
05043: if (isEndOfLoop) {
05044: loopstart = getLoopStartForEnd(ifst
05045: .getIfCloseLineNumber(), list);
05046: if (currentForIndex > loopstart) {
05047: boolean ifinstcodepresent = getIfinst(
05048: loopstart, info, currentForIndex);
05049: if (ifinstcodepresent) {
05050: correctIf = false;
05051: } else
05052: correctIf = true;
05053: }
05054: }
05055:
05056: if (info[ifst.getIfCloseLineNumber()] == JvmOpCodes.GOTO
05057: && isEndOfLoop && correctIf) {
05058: int t = ifst.getIfCloseLineNumber();
05059: int gotoIndex = getJumpAddress(info, t);// ((info[t+1] << 8) | info[t+2]) + (ifst.getIfCloseLineNumber());
05060: if (gotoIndex < (t + 3)) {
05061: boolean isInfiniteLoop = false;
05062: Iterator infLoop = behaviour
05063: .getBehaviourLoops().iterator();
05064: while (infLoop.hasNext()) {
05065: Loop iloop = (Loop) infLoop.next();
05066: if (iloop.getStartIndex() == gotoIndex
05067: && iloop.isInfinite()) {
05068: isInfiniteLoop = true;
05069: /*ifLevel++;
05070: ifst = new IFBlock();
05071: ifst.setIfStart(currentForIndex);
05072: ifst.setHasIfBeenGenerated(true);
05073: //ifst.setIfCloseLineNumber(classIndex-3);
05074: ifst.setElseCloseLineNumber(gotoIndex);
05075: ifHashTable.put(""+(ifLevel),ifst);*/
05076: ifst
05077: .setElseCloseLineNumber(gotoIndex);
05078: isIfInScope = true;
05079: //addBranchLabel(classIndex,i,ifst,currentForIndex,info);
05080: boolean bb = isBeyondLoop(
05081: getJumpAddress(info,
05082: currentForIndex),
05083: behaviour
05084: .getBehaviourLoops(),
05085: info);
05086: boolean print = true;
05087: if (bb && this Loop != null
05088: && this Loop.isInfinite()
05089: && !encounteredOrComp) {
05090: if ((info[currentForIndex - 1] != JvmOpCodes.DCMPG)
05091: && (info[currentForIndex - 1] != JvmOpCodes.DCMPL)
05092: && info[currentForIndex - 1] != JvmOpCodes.FCMPG
05093: && info[currentForIndex - 1] != JvmOpCodes.FCMPL
05094: && info[currentForIndex - 1] != JvmOpCodes.LCMP)
05095: tempString = "\nif("
05096: + op
05097: .getOperandValue()
05098: + ">0)\n{\nbreak;\n}\n";
05099: else
05100: tempString = "\nif("
05101: + op
05102: .getOperandValue()
05103: + ")\n{\nbreak;\n}\n";
05104: //codeStatements +=Util.formatDecompiledStatement(tempString);
05105: print = false;
05106: // ifst.setIfHasBeenClosed(true);
05107: }
05108: java.lang.String tempstr = "";
05109: if (info[currentForIndex - 1] != JvmOpCodes.DCMPG
05110: && info[currentForIndex - 1] != JvmOpCodes.DCMPL
05111: && info[currentForIndex - 1] != JvmOpCodes.FCMPG
05112: && info[currentForIndex - 1] != JvmOpCodes.FCMPL
05113: && info[currentForIndex - 1] != JvmOpCodes.LCMP) {
05114: tempString = "\nif("
05115: + op.getOperandValue()
05116: + "<=0)\n{\n";
05117: tempstr = op.getOperandValue()
05118: + ">0";
05119: } else {
05120: tempString = "\nif("
05121: + op.getOperandValue()
05122: + ")\n{\n";
05123: tempstr = op.getOperandValue();
05124: }
05125: boolean last = lastIFinShortCutChain(
05126: info, ifst, currentForIndex);
05127: boolean c = addCodeStatementWRTShortcutOR(
05128: ifst, tempstr, print, "if",
05129: last, op.getOperandValue()
05130: + "<=0");
05131: if (c)
05132: //codeStatements +=Util.formatDecompiledStatement(tempString);
05133: ifhasbegun = true;
05134: break;
05135: }
05136: }
05137: if (isInfiniteLoop) {
05138: continue;
05139: }
05140: java.lang.String tempstr = "";
05141: if (info[currentForIndex - 1] != JvmOpCodes.DCMPG
05142: && info[currentForIndex - 1] != JvmOpCodes.DCMPL
05143: && info[currentForIndex - 1] != JvmOpCodes.FCMPG
05144: && info[currentForIndex - 1] != JvmOpCodes.FCMPL
05145: && info[currentForIndex - 1] != JvmOpCodes.LCMP) {
05146: tempString = "\nwhile("
05147: + op.getOperandValue()
05148: + "<=0)\n{\n";
05149: tempstr = op.getOperandValue() + ">0";
05150: } else {
05151: tempString = "\nwhile("
05152: + op.getOperandValue()
05153: + ")\n{\n";
05154: tempstr = op.getOperandValue();
05155: }
05156: boolean last = lastIFinShortCutChain(info,
05157: ifst, currentForIndex);
05158: boolean c = addCodeStatementWRTShortcutOR(
05159: ifst, tempstr, true, "while", last,
05160: op.getOperandValue() + "<=0");
05161: if (c)
05162: //codeStatements +=Util.formatDecompiledStatement(tempString);
05163: isWhileInScope = true;
05164: whileIndex++;
05165:
05166: } else {
05167: /*ifLevel++;
05168: ifst = new IFBlock();
05169: ifst.setIfStart(currentForIndex);
05170: ifst.setHasIfBeenGenerated(true);
05171: //ifst.setIfCloseLineNumber(classIndex-3);*/
05172: ifst.setElseCloseLineNumber(gotoIndex);
05173: //ifHashTable.put(""+(ifLevel),ifst);
05174:
05175: isIfInScope = true;
05176: //addBranchLabel(classIndex,i,ifst,currentForIndex,info);
05177: boolean bb = isBeyondLoop(getJumpAddress(
05178: info, currentForIndex), behaviour
05179: .getBehaviourLoops(), info);
05180: boolean print = true;
05181: if (bb && this Loop != null
05182: && this Loop.isInfinite()
05183: && !encounteredOrComp) {
05184: if ((info[currentForIndex - 1] != JvmOpCodes.DCMPG)
05185: && (info[currentForIndex - 1] != JvmOpCodes.DCMPL)
05186: && info[currentForIndex - 1] != JvmOpCodes.FCMPG
05187: && info[currentForIndex - 1] != JvmOpCodes.FCMPL
05188: && info[currentForIndex - 1] != JvmOpCodes.LCMP)
05189: tempString = "\nif("
05190: + op.getOperandValue()
05191: + ">0)\n{\nbreak;\n}\n";
05192: else
05193: tempString = "\nif("
05194: + op.getOperandValue()
05195: + ")\n{\nbreak;\n}\n";
05196: //codeStatements +=Util.formatDecompiledStatement(tempString);
05197: print = false;
05198: // ifst.setIfHasBeenClosed(true);
05199: }
05200: java.lang.String tempstr = "";
05201: if (info[currentForIndex - 1] != JvmOpCodes.DCMPG
05202: && info[currentForIndex - 1] != JvmOpCodes.DCMPL
05203: && info[currentForIndex - 1] != JvmOpCodes.FCMPG
05204: && info[currentForIndex - 1] != JvmOpCodes.FCMPL
05205: && info[currentForIndex - 1] != JvmOpCodes.LCMP) {
05206: tempString = "\nif("
05207: + op.getOperandValue()
05208: + "<=0)\n{\n";
05209: tempstr = op.getOperandValue() + ">0";
05210: } else {
05211: tempString = "\nif("
05212: + op.getOperandValue()
05213: + ")\n{\n";
05214: tempstr = op.getOperandValue();
05215: }
05216: boolean last = lastIFinShortCutChain(info,
05217: ifst, currentForIndex);
05218: boolean c = addCodeStatementWRTShortcutOR(
05219: ifst, tempstr, print, "if", last,
05220: op.getOperandValue() + "<=0");
05221: if (c)
05222: //codeStatements +=Util.formatDecompiledStatement(tempString);
05223: ifhasbegun = true;
05224: }
05225:
05226: } else {
05227: /* ifLevel++;
05228: ifst = new IFBlock();
05229: ifst.setIfStart(currentForIndex);
05230: ifst.setHasIfBeenGenerated(true);
05231: ifHashTable.put(""+(ifLevel),ifst);*/
05232: isIfInScope = true;
05233: // addBranchLabel(classIndex,i,ifst,currentForIndex,info);
05234: boolean bb = isBeyondLoop(getJumpAddress(info,
05235: currentForIndex), behaviour
05236: .getBehaviourLoops(), info);
05237: boolean print = true;
05238: java.lang.String tempstr = "";
05239: if (bb && this Loop != null
05240: && this Loop.isInfinite()
05241: && !encounteredOrComp) {
05242: if ((info[currentForIndex - 1] != JvmOpCodes.DCMPG)
05243: && (info[currentForIndex - 1] != JvmOpCodes.DCMPL)
05244: && info[currentForIndex - 1] != JvmOpCodes.FCMPG
05245: && info[currentForIndex - 1] != JvmOpCodes.FCMPL
05246: && info[currentForIndex - 1] != JvmOpCodes.LCMP)
05247: tempString = "\nif("
05248: + op.getOperandValue()
05249: + ">0)\n{\nbreak;}\n";
05250: else
05251: tempString = "\nif("
05252: + op.getOperandValue()
05253: + ")\n{\nbreak;}\n";
05254: //codeStatements +=Util.formatDecompiledStatement(tempString);
05255: print = false;
05256: // ifst.setIfHasBeenClosed(true);
05257: }
05258: if (info[currentForIndex - 1] != JvmOpCodes.DCMPG
05259: && info[currentForIndex - 1] != JvmOpCodes.DCMPL
05260: && info[currentForIndex - 1] != JvmOpCodes.FCMPG
05261: && info[currentForIndex - 1] != JvmOpCodes.FCMPL
05262: && info[currentForIndex - 1] != JvmOpCodes.LCMP) {
05263: tempString = "\nif(" + op.getOperandValue()
05264: + "<=0)\n{\n";
05265: tempstr = op.getOperandValue() + "> 0";
05266: } else {
05267: tempString = "\nif(" + op.getOperandValue()
05268: + ")\n{\n";
05269: tempstr = op.getOperandValue();
05270: }
05271: boolean last = lastIFinShortCutChain(info,
05272: ifst, currentForIndex);
05273: boolean c = addCodeStatementWRTShortcutOR(ifst,
05274: tempstr, print, "if", last, op
05275: .getOperandValue()
05276: + "<=0");
05277: if (c)
05278: //codeStatements +=Util.formatDecompiledStatement(tempString);
05279: ifhasbegun = true;
05280:
05281: }
05282:
05283: continue;
05284: case JvmOpCodes.IFLE:
05285: op = (Operand) opStack.pop();
05286: //op1 = (Operand)opStack.pop();
05287: classIndex = getJumpAddress(info, i);
05288: i += 2;
05289: addParsedOutput("Instruction Pos "
05290: + currentForIndex + "\t:- " + " ifle "
05291: + classIndex + "\n");
05292: blockLevel++;
05293: //int s=info[classIndex-3];
05294: list = behaviour.getBehaviourLoops();
05295:
05296: ifLevel++;
05297: ifst = new IFBlock();
05298: ifst.setIfStart(currentForIndex);
05299: ifst.setHasIfBeenGenerated(true);
05300: ifHashTable.put("" + (ifLevel), ifst);
05301: addBranchLabel(classIndex, i, ifst,
05302: currentForIndex, info);
05303:
05304: isEndOfLoop = isIndexEndOfLoop(list, ifst
05305: .getIfCloseLineNumber());
05306: beyondLoop = isBeyondLoop(ifst
05307: .getIfCloseLineNumber(), list, info);
05308: correctIf = false;
05309: if (isEndOfLoop) {
05310: loopstart = getLoopStartForEnd(ifst
05311: .getIfCloseLineNumber(), list);
05312: if (currentForIndex > loopstart) {
05313: boolean ifinstcodepresent = getIfinst(
05314: loopstart, info, currentForIndex);
05315: if (ifinstcodepresent) {
05316: correctIf = false;
05317: } else
05318: correctIf = true;
05319: } else {
05320: correctIf = false;
05321: }
05322:
05323: }
05324:
05325: if (info[ifst.getIfCloseLineNumber()] == JvmOpCodes.GOTO
05326: && isEndOfLoop && correctIf) {
05327: int t = ifst.getIfCloseLineNumber();
05328: int gotoIndex = getJumpAddress(info, t);//((info[t+1] << 8) | info[t+2]) + (ifst.getIfCloseLineNumber());
05329: if (gotoIndex < (t + 3))
05330: if (gotoIndex < classIndex) {
05331: boolean isInfiniteLoop = false;
05332: Iterator infLoop = behaviour
05333: .getBehaviourLoops().iterator();
05334: while (infLoop.hasNext()) {
05335: Loop iloop = (Loop) infLoop.next();
05336: if (iloop.getStartIndex() == gotoIndex
05337: && iloop.isInfinite()) {
05338: isInfiniteLoop = true;
05339: /* ifLevel++;
05340: ifst = new IFBlock();
05341: ifst.setIfStart(currentForIndex);
05342: ifst.setHasIfBeenGenerated(true);*/
05343:
05344: ifst
05345: .setElseCloseLineNumber(gotoIndex);
05346:
05347: /*ifHashTable.put(""+(ifLevel),ifst);
05348: int resetVal=checkIfElseCloseNumber(classIndex-3,ifst);
05349: ifst.setIfCloseLineNumber(resetVal);*/
05350:
05351: isIfInScope = true;
05352:
05353: boolean bb = isBeyondLoop(
05354: getJumpAddress(info,
05355: currentForIndex),
05356: behaviour
05357: .getBehaviourLoops(),
05358: info);
05359: boolean print = true;
05360: if (bb
05361: && this Loop != null
05362: && this Loop
05363: .isInfinite()
05364: && !encounteredOrComp) {
05365: if (info[currentForIndex - 1] != JvmOpCodes.DCMPG
05366: && info[currentForIndex - 1] != JvmOpCodes.DCMPL
05367: && info[currentForIndex - 1] != JvmOpCodes.FCMPG
05368: && info[currentForIndex - 1] != JvmOpCodes.FCMPL
05369: && info[currentForIndex - 1] != JvmOpCodes.LCMP)
05370: tempString = "\nif("
05371: + op
05372: .getOperandValue()
05373: + "<=0)\n{\nbreak;\n}\n";
05374:
05375: else
05376: tempString = "\nif("
05377: + op
05378: .getOperandValue()
05379: + ")\n{\nbreak;\n}\n";
05380: //codeStatements +=Util.formatDecompiledStatement(tempString);
05381: print = false;
05382: // ifst.setIfHasBeenClosed(true);
05383: }
05384:
05385: java.lang.String tempstr = "";
05386: if (info[currentForIndex - 1] != JvmOpCodes.DCMPG
05387: && info[currentForIndex - 1] != JvmOpCodes.DCMPL
05388: && info[currentForIndex - 1] != JvmOpCodes.FCMPG
05389: && info[currentForIndex - 1] != JvmOpCodes.FCMPL
05390: && info[currentForIndex - 1] != JvmOpCodes.LCMP) {
05391: tempString = "\nif("
05392: + op
05393: .getOperandValue()
05394: + " > 0)\n{\n";
05395: tempstr = op
05396: .getOperandValue()
05397: + "<= 0";
05398: } else {
05399: tempString = "\nif("
05400: + op
05401: .getOperandValue()
05402: + " )\n{\n";
05403: tempstr = op
05404: .getOperandValue();
05405: }
05406:
05407: boolean last = lastIFinShortCutChain(
05408: info, ifst,
05409: currentForIndex);
05410: boolean c = addCodeStatementWRTShortcutOR(
05411: ifst, tempstr, print,
05412: "if", last,
05413: op.getOperandValue()
05414: + " > 0");
05415: if (c)
05416: //codeStatements +=Util.formatDecompiledStatement(tempString);
05417: ifhasbegun = true;
05418: break;
05419: }
05420: }
05421: if (isInfiniteLoop) {
05422: continue;
05423: }
05424: java.lang.String tempstr = "";
05425: if (info[currentForIndex - 1] != JvmOpCodes.DCMPG
05426: && info[currentForIndex - 1] != JvmOpCodes.DCMPL
05427: && info[currentForIndex - 1] != JvmOpCodes.FCMPG
05428: && info[currentForIndex - 1] != JvmOpCodes.FCMPL
05429: && info[currentForIndex - 1] != JvmOpCodes.LCMP) {
05430: tempString = "\nwhile("
05431: + op.getOperandValue()
05432: + " > 0)\n{\n";
05433: tempstr = op.getOperandValue()
05434: + " <= 0";
05435: } else {
05436: tempString = "\nwhile("
05437: + op.getOperandValue()
05438: + ")\n{\n";
05439: tempstr = op.getOperandValue();
05440: }
05441: boolean last = lastIFinShortCutChain(
05442: info, ifst, currentForIndex);
05443: boolean c = addCodeStatementWRTShortcutOR(
05444: ifst, tempstr, true, "while",
05445: last, op.getOperandValue()
05446: + " > 0");
05447: if (c)
05448: //codeStatements +=Util.formatDecompiledStatement(tempString);
05449: isWhileInScope = true;
05450: whileIndex++;
05451:
05452: } else {
05453: /*ifLevel++;
05454: ifst = new IFBlock();
05455: ifst.setIfStart(currentForIndex);
05456: ifst.setHasIfBeenGenerated(true);*/
05457: ifst.setElseCloseLineNumber(gotoIndex);
05458: /*ifHashTable.put(""+(ifLevel),ifst);
05459: int resetVal=checkIfElseCloseNumber(classIndex-3,ifst);
05460: ifst.setIfCloseLineNumber(resetVal);
05461: isIfInScope = true;*/
05462: isIfInScope = true;
05463: //addBranchLabel(classIndex,i,ifst,currentForIndex,info);
05464: boolean bb = isBeyondLoop(
05465: getJumpAddress(info,
05466: currentForIndex),
05467: behaviour.getBehaviourLoops(),
05468: info);
05469: boolean print = true;
05470: if (bb && this Loop != null
05471: && this Loop.isInfinite()
05472: && !encounteredOrComp) {
05473: if (info[currentForIndex - 1] != JvmOpCodes.DCMPG
05474: && info[currentForIndex - 1] != JvmOpCodes.DCMPL
05475: && info[currentForIndex - 1] != JvmOpCodes.FCMPG
05476: && info[currentForIndex - 1] != JvmOpCodes.FCMPL
05477: && info[currentForIndex - 1] != JvmOpCodes.LCMP)
05478: tempString = "\nif("
05479: + op.getOperandValue()
05480: + "<=0)\n{\nbreak;\n}\n";
05481:
05482: else
05483: tempString = "\nif("
05484: + op.getOperandValue()
05485: + ")\n{\nbreak;\n}\n";
05486: //codeStatements +=Util.formatDecompiledStatement(tempString);
05487: print = false;
05488: // ifst.setIfHasBeenClosed(true);
05489: }
05490:
05491: java.lang.String tempstr = "";
05492: if (info[currentForIndex - 1] != JvmOpCodes.DCMPG
05493: && info[currentForIndex - 1] != JvmOpCodes.DCMPL
05494: && info[currentForIndex - 1] != JvmOpCodes.FCMPG
05495: && info[currentForIndex - 1] != JvmOpCodes.FCMPL
05496: && info[currentForIndex - 1] != JvmOpCodes.LCMP) {
05497: tempString = "\nif("
05498: + op.getOperandValue()
05499: + " > 0)\n{\n";
05500: tempstr = op.getOperandValue()
05501: + " <= 0";
05502: } else {
05503: tempString = "\nif("
05504: + op.getOperandValue()
05505: + " )\n{\n";
05506: tempstr = op.getOperandValue();
05507: }
05508: boolean last = lastIFinShortCutChain(
05509: info, ifst, currentForIndex);
05510: boolean c = addCodeStatementWRTShortcutOR(
05511: ifst, tempstr, print, "if",
05512: last, op.getOperandValue()
05513: + " > 0");
05514: if (c)
05515: //codeStatements +=Util.formatDecompiledStatement(tempString);
05516:
05517: ifhasbegun = true;
05518: }
05519:
05520: } else {
05521: /*ifLevel++;
05522: ifst = new IFBlock();
05523: ifst.setIfStart(currentForIndex);
05524: ifst.setHasIfBeenGenerated(true);
05525: ifHashTable.put(""+(ifLevel),ifst);*/
05526: isIfInScope = true;
05527: //addBranchLabel(classIndex,i,ifst,currentForIndex,info);
05528: boolean bb = isBeyondLoop(getJumpAddress(info,
05529: currentForIndex), behaviour
05530: .getBehaviourLoops(), info);
05531: boolean print = true;
05532: if (bb && this Loop != null
05533: && this Loop.isInfinite()
05534: && !encounteredOrComp) {
05535: if (info[currentForIndex - 1] != JvmOpCodes.DCMPG
05536: && info[currentForIndex - 1] != JvmOpCodes.DCMPL
05537: && info[currentForIndex - 1] != JvmOpCodes.FCMPG
05538: && info[currentForIndex - 1] != JvmOpCodes.FCMPL
05539: && info[currentForIndex - 1] != JvmOpCodes.LCMP)
05540: tempString = "\nif("
05541: + op.getOperandValue()
05542: + "<=0)\n{\nbreak;\n}\n";
05543:
05544: else
05545: tempString = "\nif("
05546: + op.getOperandValue()
05547: + ")\n{\nbreak;\n}\n";
05548: //codeStatements +=Util.formatDecompiledStatement(tempString);
05549: print = false;
05550: }
05551: // ifst.setIfHasBeenClosed(true);
05552: java.lang.String tempstr = "";
05553: if (info[currentForIndex - 1] != JvmOpCodes.DCMPG
05554: && info[currentForIndex - 1] != JvmOpCodes.DCMPL
05555: && info[currentForIndex - 1] != JvmOpCodes.FCMPG
05556: && info[currentForIndex - 1] != JvmOpCodes.FCMPL
05557: && info[currentForIndex - 1] != JvmOpCodes.LCMP) {
05558: tempString = "\nif(" + op.getOperandValue()
05559: + " > 0)\n{\n";
05560: tempstr = op.getOperandValue() + " <= 0";
05561: } else {
05562: tempString = "\nif(" + op.getOperandValue()
05563: + " )\n{\n";
05564: tempstr = op.getOperandValue();
05565: }
05566: boolean last = lastIFinShortCutChain(info,
05567: ifst, currentForIndex);
05568: boolean c = addCodeStatementWRTShortcutOR(ifst,
05569: tempstr, print, "if", last, op
05570: .getOperandValue()
05571: + " > 0");
05572: if (c)
05573: //codeStatements +=Util.formatDecompiledStatement(tempString);
05574:
05575: ifhasbegun = true;
05576: }
05577:
05578: continue;
05579: case JvmOpCodes.IFNONNULL:
05580: op = (Operand) opStack.pop();
05581: classIndex = getJumpAddress(info, i);
05582: i += 2;
05583: addParsedOutput("Instruction Pos "
05584: + currentForIndex + "\t:- " + " ifnonnull "
05585: + classIndex + "\n");
05586: blockLevel++;
05587: list = behaviour.getBehaviourLoops();
05588: ifLevel++;
05589: ifst = new IFBlock();
05590: ifst.setIfStart(currentForIndex);
05591: ifst.setHasIfBeenGenerated(true);
05592: ifHashTable.put("" + (ifLevel), ifst);
05593:
05594: addBranchLabel(classIndex, i, ifst,
05595: currentForIndex, info);
05596: isEndOfLoop = isIndexEndOfLoop(list, ifst
05597: .getIfCloseLineNumber());
05598: beyondLoop = isBeyondLoop(ifst
05599: .getIfCloseLineNumber(), list, info);
05600: correctIf = false;
05601: if (isEndOfLoop) {
05602: loopstart = getLoopStartForEnd(ifst
05603: .getIfCloseLineNumber(), list);
05604: if (currentForIndex > loopstart) {
05605: boolean ifinstcodepresent = getIfinst(
05606: loopstart, info, currentForIndex);
05607: if (ifinstcodepresent) {
05608: correctIf = false;
05609: } else
05610: correctIf = true;
05611: }
05612: }
05613:
05614: if (info[ifst.getIfCloseLineNumber()] == JvmOpCodes.GOTO
05615: && isEndOfLoop && correctIf) {
05616: int t = ifst.getIfCloseLineNumber();
05617: int gotoIndex = getJumpAddress(info, t);//((info[t+1] << 8) | info[t+2]) + (ifst.getIfCloseLineNumber());
05618: if (gotoIndex < (t + 3))
05619: if (gotoIndex < classIndex) {
05620: boolean isInfiniteLoop = false;
05621: Iterator infLoop = behaviour
05622: .getBehaviourLoops().iterator();
05623: while (infLoop.hasNext()) {
05624: Loop iloop = (Loop) infLoop.next();
05625: if (iloop.getStartIndex() == gotoIndex
05626: && iloop.isInfinite()) {
05627: isInfiniteLoop = true;
05628: /* ifLevel++;
05629: ifst = new IFBlock();
05630: ifst.setIfStart(currentForIndex);
05631: ifst.setHasIfBeenGenerated(true);
05632: //ifst.setIfCloseLineNumber(classIndex-3);*/
05633: ifst
05634: .setElseCloseLineNumber(gotoIndex);
05635: /*ifHashTable.put(""+(ifLevel),ifst);
05636:
05637: int resetVal=checkIfElseCloseNumber(classIndex-3,ifst);
05638: ifst.setIfCloseLineNumber(resetVal);*/
05639: isIfInScope = true;
05640: boolean print = true;
05641: boolean bb = isBeyondLoop(
05642: getJumpAddress(info,
05643: currentForIndex),
05644: behaviour
05645: .getBehaviourLoops(),
05646: info);
05647: if (bb
05648: && this Loop != null
05649: && this Loop
05650: .isInfinite()
05651: && !encounteredOrComp) {
05652: tempString = "\nif("
05653: + op
05654: .getOperandValue()
05655: + "!= null)\n{\nbreak;\n}\n";
05656: // ifst.setIfHasBeenClosed(true);
05657: //codeStatements +=Util.formatDecompiledStatement(tempString);
05658: print = false;
05659: }
05660: boolean last = lastIFinShortCutChain(
05661: info, ifst,
05662: currentForIndex);
05663: boolean c = addCodeStatementWRTShortcutOR(
05664: ifst,
05665: op.getOperandValue()
05666: + "!=null",
05667: print, "if", last,
05668: op.getOperandValue()
05669: + "== null");
05670: if (c) {
05671: tempString = "\nif("
05672: + op
05673: .getOperandValue()
05674: + "== null)\n{\n";
05675: //codeStatements +=Util.formatDecompiledStatement(tempString);
05676: }
05677: ifhasbegun = true;
05678: break;
05679: }
05680: }
05681: if (isInfiniteLoop) {
05682: continue;
05683: }
05684: boolean last = lastIFinShortCutChain(
05685: info, ifst, currentForIndex);
05686: boolean c = addCodeStatementWRTShortcutOR(
05687: ifst, op.getOperandValue()
05688: + "!=null", true,
05689: "while", last, op
05690: .getOperandValue()
05691: + "==null");
05692: if (c) {
05693: tempString = "\nwhile("
05694: + op.getOperandValue()
05695: + " == null)\n{\n";
05696: //codeStatements +=Util.formatDecompiledStatement(tempString);
05697: }
05698: isWhileInScope = true;
05699: whileIndex++;
05700:
05701: } else {
05702: /* ifLevel++;
05703: ifst = new IFBlock();
05704: ifst.setIfStart(currentForIndex);
05705: ifst.setHasIfBeenGenerated(true);*/
05706: //ifst.setIfCloseLineNumber(classIndex-3);
05707: ifst.setElseCloseLineNumber(gotoIndex);
05708: //ifHashTable.put(""+(ifLevel),ifst);
05709:
05710: isIfInScope = true;
05711: boolean print = true;
05712: boolean bb = isBeyondLoop(
05713: getJumpAddress(info,
05714: currentForIndex),
05715: behaviour.getBehaviourLoops(),
05716: info);
05717: if (bb && this Loop != null
05718: && this Loop.isInfinite()
05719: && !encounteredOrComp) {
05720: tempString = "\nif("
05721: + op.getOperandValue()
05722: + "!= null)\n{\nbreak;\n}\n";
05723: // ifst.setIfHasBeenClosed(true);
05724: //codeStatements +=Util.formatDecompiledStatement(tempString);
05725: print = false;
05726: }
05727: boolean last = lastIFinShortCutChain(
05728: info, ifst, currentForIndex);
05729: boolean c = addCodeStatementWRTShortcutOR(
05730: ifst, op.getOperandValue()
05731: + "!=null", print,
05732: "if", last, op
05733: .getOperandValue()
05734: + "==null");
05735: if (c) {
05736: tempString = "\nif("
05737: + op.getOperandValue()
05738: + "== null)\n{\n";
05739: //codeStatements +=Util.formatDecompiledStatement(tempString);
05740: }
05741: ifhasbegun = true;
05742: }
05743:
05744: } else {
05745: /*ifLevel++;
05746: ifst = new IFBlock();
05747: ifst.setIfStart(currentForIndex);
05748: ifst.setHasIfBeenGenerated(true);
05749: ifst.setIfCloseLineNumber(classIndex);
05750: ifHashTable.put(""+(ifLevel),ifst);
05751: isIfInScope = true;*/
05752: isIfInScope = true;
05753: //addBranchLabel(classIndex,i,ifst,currentForIndex,info);
05754: boolean bb = isBeyondLoop(getJumpAddress(info,
05755: currentForIndex), behaviour
05756: .getBehaviourLoops(), info);
05757: boolean print = true;
05758: if (bb && this Loop != null
05759: && this Loop.isInfinite()
05760: && !encounteredOrComp) {
05761:
05762: tempString = "\nif(" + op.getOperandValue()
05763: + "!= null)\n{\nbreak;\n}\n";
05764: //ifst.setIfHasBeenClosed(true);
05765: //codeStatements +=Util.formatDecompiledStatement(tempString);
05766: print = false;
05767: }
05768:
05769: boolean last = lastIFinShortCutChain(info,
05770: ifst, currentForIndex);
05771: boolean c = addCodeStatementWRTShortcutOR(ifst,
05772: op.getOperandValue() + "!=null", print,
05773: "if", last, op.getOperandValue()
05774: + "==null");
05775:
05776: if (c) {
05777: tempString = "\nif(" + op.getOperandValue()
05778: + "== null)\n{\n";
05779: //codeStatements +=Util.formatDecompiledStatement(tempString);
05780: }
05781:
05782: ifhasbegun = true;
05783: }
05784:
05785: continue;
05786: case JvmOpCodes.IFNULL:
05787: op = (Operand) opStack.pop();
05788: classIndex = getJumpAddress(info, i);
05789: addParsedOutput("Instruction Pos "
05790: + currentForIndex + "\t:- " + " ifnull "
05791: + classIndex + "\n");
05792: i += 2;
05793: blockLevel++;
05794: list = behaviour.getBehaviourLoops();
05795: ifLevel++;
05796: ifst = new IFBlock();
05797: ifst.setIfStart(currentForIndex);
05798: ifst.setHasIfBeenGenerated(true);
05799: ifHashTable.put("" + (ifLevel), ifst);
05800: addBranchLabel(classIndex, i, ifst,
05801: currentForIndex, info);
05802:
05803: beyondLoop = isBeyondLoop(ifst
05804: .getIfCloseLineNumber(), list, info);
05805:
05806: isEndOfLoop = isIndexEndOfLoop(list, ifst
05807: .getIfCloseLineNumber());
05808: correctIf = false;
05809: if (isEndOfLoop) {
05810: loopstart = getLoopStartForEnd(ifst
05811: .getIfCloseLineNumber(), list);
05812: if (currentForIndex > loopstart) {
05813: boolean ifinstcodepresent = getIfinst(
05814: loopstart, info, currentForIndex);
05815: if (ifinstcodepresent) {
05816: correctIf = false;
05817: } else
05818: correctIf = true;
05819: }
05820: }
05821:
05822: if (info[ifst.getIfCloseLineNumber()] == JvmOpCodes.GOTO
05823: && isEndOfLoop && correctIf) {
05824: int t = ifst.getIfCloseLineNumber();
05825: int gotoIndex = getJumpAddress(info, t);//((info[t+1] << 8) | info[t+2]) + (ifst.getIfCloseLineNumber());
05826: if (gotoIndex < (t + 3)) {
05827: boolean isInfiniteLoop = false;
05828: Iterator infLoop = behaviour
05829: .getBehaviourLoops().iterator();
05830: while (infLoop.hasNext()) {
05831: Loop iloop = (Loop) infLoop.next();
05832: if (iloop.getStartIndex() == gotoIndex
05833: && iloop.isInfinite()) {
05834: isInfiniteLoop = true;
05835: /* ifLevel++;
05836: ifst = new IFBlock();
05837: ifst.setIfStart(currentForIndex);
05838: ifst.setHasIfBeenGenerated(true); */
05839: // ifst.setIfCloseLineNumber(classIndex-3);
05840: ifst
05841: .setElseCloseLineNumber(gotoIndex);
05842: // ifHashTable.put(""+(ifLevel),ifst);
05843: isIfInScope = true;
05844: boolean bb = isBeyondLoop(
05845: getJumpAddress(info,
05846: currentForIndex),
05847: behaviour
05848: .getBehaviourLoops(),
05849: info);
05850: boolean print = true;
05851: if (bb && this Loop != null
05852: && this Loop.isInfinite()
05853: && !encounteredOrComp) {
05854: //ifst.setIfHasBeenClosed(true);
05855: tempString = "\nif("
05856: + op.getOperandValue()
05857: + " == null)\n{\nbreak;\n}\n";
05858: //codeStatements +=Util.formatDecompiledStatement(tempString);
05859: print = false;
05860: }
05861: boolean last = lastIFinShortCutChain(
05862: info, ifst, currentForIndex);
05863: boolean c = addCodeStatementWRTShortcutOR(
05864: ifst, op.getOperandValue()
05865: + "==null", print,
05866: "if", last, op
05867: .getOperandValue()
05868: + "!=null");
05869: if (c) {
05870: tempString = "\nif("
05871: + op.getOperandValue()
05872: + " != null)\n{\n";
05873: //codeStatements +=Util.formatDecompiledStatement(tempString);
05874: }
05875: ifhasbegun = true;
05876: break;
05877: }
05878: }
05879: if (isInfiniteLoop) {
05880: continue;
05881: }
05882: boolean last = lastIFinShortCutChain(info,
05883: ifst, currentForIndex);
05884: boolean c = addCodeStatementWRTShortcutOR(
05885: ifst, op.getOperandValue()
05886: + "==null", true, "while",
05887: last, op.getOperandValue()
05888: + "!=null");
05889: if (c) {
05890: tempString = "\nwhile("
05891: + op.getOperandValue()
05892: + " != null )\n{\n";
05893: //codeStatements +=Util.formatDecompiledStatement(tempString);
05894: }
05895: isWhileInScope = true;
05896: whileIndex++;
05897:
05898: } else {
05899: /*ifLevel++;
05900: ifst = new IFBlock();
05901: ifst.setIfStart(currentForIndex);
05902: ifst.setHasIfBeenGenerated(true);
05903: //ifst.setIfCloseLineNumber(classIndex-3);*/
05904: ifst.setElseCloseLineNumber(gotoIndex);
05905: /*ifHashTable.put(""+(ifLevel),ifst);
05906: int resetVal=checkIfElseCloseNumber(classIndex-3,ifst);
05907: ifst.setIfCloseLineNumber(resetVal);*/
05908: isIfInScope = true;
05909: //addBranchLabel(classIndex,i,ifst,currentForIndex,info);
05910: boolean bb = isBeyondLoop(getJumpAddress(
05911: info, currentForIndex), behaviour
05912: .getBehaviourLoops(), info);
05913: boolean c = true;
05914: boolean print = true;
05915: if (bb && this Loop != null
05916: && this Loop.isInfinite()
05917: && !encounteredOrComp)
05918:
05919: {
05920: tempString = "\nif("
05921: + op.getOperandValue()
05922: + "==null)\n{\nbreak;\n}\n";
05923: //codeStatements +=Util.formatDecompiledStatement(tempString);
05924: print = false;
05925:
05926: }
05927: boolean last = lastIFinShortCutChain(info,
05928: ifst, currentForIndex);
05929: c = addCodeStatementWRTShortcutOR(ifst, op
05930: .getOperandValue()
05931: + "==null", print, "if", last, op
05932: .getOperandValue()
05933: + "!=null");
05934: if (c) {
05935: tempString = "\nif("
05936: + op.getOperandValue()
05937: + "!= \tnull)\n{\n";
05938:
05939: //codeStatements +=Util.formatDecompiledStatement(tempString);
05940: }
05941: ifhasbegun = true;
05942: }
05943:
05944: } else {
05945: /* ifLevel++;
05946: ifst = new IFBlock();
05947: ifst.setIfStart(currentForIndex);
05948: ifst.setHasIfBeenGenerated(true);
05949: ifHashTable.put(""+(ifLevel),ifst);*/
05950: isIfInScope = true;
05951: //addBranchLabel(classIndex,i,ifst,currentForIndex,info);
05952: boolean bb = isBeyondLoop(getJumpAddress(info,
05953: currentForIndex), behaviour
05954: .getBehaviourLoops(), info);
05955: boolean c = true;
05956: boolean print = true;
05957: if (bb && this Loop != null
05958: && this Loop.isInfinite()
05959: && !encounteredOrComp)
05960:
05961: {
05962:
05963: tempString = "\nif(" + op.getOperandValue()
05964: + "==null)\n{\nbreak;\n}\n";
05965: //codeStatements +=Util.formatDecompiledStatement(tempString);
05966: print = false;
05967:
05968: }
05969:
05970: boolean last = lastIFinShortCutChain(info,
05971: ifst, currentForIndex);
05972: c = addCodeStatementWRTShortcutOR(ifst, op
05973: .getOperandValue()
05974: + "==null", print, "if", last, op
05975: .getOperandValue()
05976: + "!=null");
05977: if (c) {
05978: tempString = "\nif(" + op.getOperandValue()
05979: + "!= \tnull)\n{\n";
05980: //codeStatements +=Util.formatDecompiledStatement(tempString);
05981: }
05982:
05983: ifhasbegun = true;
05984:
05985: }
05986:
05987: continue;
05988: case JvmOpCodes.IINC:
05989: classIndex = info[++i];
05990: java.lang.String constantStr = "";
05991: int constant = info[++i];
05992: java.lang.String varName = "";
05993: addParsedOutput("Instruction Pos "
05994: + currentForIndex + "\t:- " + " iinc "
05995: + classIndex + "\n");
05996: // NOTE: passing load is ok as the rangeindex used to query will be correct
05997: local = getLocalVariable(classIndex, "load", "int",
05998: true, currentForIndex);
05999:
06000: if (local != null) {
06001:
06002: boolean ad = checkForLoadAfterIINC(info,
06003: opStack, currentForIndex, local,
06004: classIndex, "" + constant);
06005: if (!ad) {
06006: prevLocalGenerated = local;
06007: varName = local.getVarName();
06008:
06009: if (local.isDeclarationGenerated() == false) {
06010: if (constant < 0)
06011: constantStr = "(" + constant + ")";
06012: else
06013: constantStr = "" + constant;
06014: tempString = local.getDataType() + " "
06015: + varName + " = " + varName
06016: + "+" + constantStr + ";\n";
06017: //codeStatements +=Util.formatDecompiledStatement(tempString);
06018: local.setDeclarationGenerated(true);
06019: } else {
06020: if (constant < 0)
06021: constantStr = "(" + constant + ")";
06022: else
06023: constantStr = "" + constant;
06024: tempString = varName + " = " + varName
06025: + "+" + constantStr + ";\n";
06026: //codeStatements +=Util.formatDecompiledStatement(tempString);
06027: }
06028: }
06029: }
06030: continue;
06031: case JvmOpCodes.ILOAD:
06032: opValueI = info[++i];
06033:
06034: local = getLocalVariable(opValueI, "load", "int",
06035: false, currentForIndex);
06036: if (cd.isClassCompiledWithMinusG() && local != null) {
06037: addParsedOutput("Instruction Pos "
06038: + currentForIndex + "\t:- " + " iload "
06039: + opValueI + " THIS LocalVariable:- "
06040: + local.getVarName());
06041: } else {
06042: addParsedOutput("Instruction Pos "
06043: + currentForIndex + "\t:- " + " iload "
06044: + opValueI + "\n");
06045: }
06046: if (local != null) {
06047: prevLocalGenerated = local;
06048: op = new Operand();
06049: boolean bo = isPrevInstIINC(info,
06050: currentForIndex, opValueI);
06051: java.lang.String ltmp = local.getTempVarName();
06052: if (bo && ltmp != null) {
06053: op.setOperandValue(ltmp);
06054: } else {
06055: op.setOperandValue(local.getVarName());
06056: }
06057:
06058: op.setLocalVarIndex(opValueI);
06059: op.setLocalVarType(local.getDataType());
06060: opStack.push(op);
06061: }
06062:
06063: continue;
06064: case JvmOpCodes.ILOAD_0:
06065:
06066: local = getLocalVariable(0, "load", "int", true,
06067: currentForIndex);
06068: if (cd.isClassCompiledWithMinusG() && local != null) {
06069: addParsedOutput("Instruction Pos "
06070: + currentForIndex + "\t:- "
06071: + " iload _0 THIS LocalVariable:- "
06072: + local.getVarName());
06073: } else {
06074: addParsedOutput("Instruction Pos "
06075: + currentForIndex + "\t:- "
06076: + " iload_0\n");
06077: }
06078: if (local != null) {
06079: prevLocalGenerated = local;
06080: op = new Operand();
06081: boolean bo = isPrevInstIINC(info,
06082: currentForIndex, 0);
06083: java.lang.String ltmp = local.getTempVarName();
06084: if (bo && ltmp != null) {
06085: op.setOperandValue(ltmp);
06086: } else {
06087: op.setOperandValue(local.getVarName());
06088: }
06089:
06090: op.setLocalVarIndex(0);
06091: op.setLocalVarType(local.getDataType());
06092: opStack.push(op);
06093: }
06094:
06095: continue;
06096: case JvmOpCodes.ILOAD_1:
06097: local = getLocalVariable(1, "load", "int", true,
06098: currentForIndex);
06099: if (cd.isClassCompiledWithMinusG() && local != null) {
06100: addParsedOutput("Instruction Pos "
06101: + currentForIndex + "\t:- "
06102: + " iload _1 THIS LocalVariable:- "
06103: + local.getVarName());
06104: } else {
06105: addParsedOutput("Instruction Pos "
06106: + currentForIndex + "\t:- "
06107: + " iload_1\n");
06108: }
06109: if (local != null) {
06110: prevLocalGenerated = local;
06111: op = new Operand();
06112: boolean bo = isPrevInstIINC(info,
06113: currentForIndex, 1);
06114: java.lang.String ltmp = local.getTempVarName();
06115: if (bo && ltmp != null) {
06116: op.setOperandValue(ltmp);
06117: } else {
06118: op.setOperandValue(local.getVarName());
06119: }
06120:
06121: op.setLocalVarIndex(1);
06122: op.setLocalVarType(local.getDataType());
06123: opStack.push(op);
06124: }
06125:
06126: continue;
06127: case JvmOpCodes.ILOAD_2:
06128:
06129: local = getLocalVariable(2, "load", "int", true,
06130: currentForIndex);
06131: if (cd.isClassCompiledWithMinusG() && local != null) {
06132: addParsedOutput("Instruction Pos "
06133: + currentForIndex + "\t:- "
06134: + " iload _2 THIS LocalVariable:- "
06135: + local.getVarName());
06136: } else {
06137: addParsedOutput("Instruction Pos "
06138: + currentForIndex + "\t:- "
06139: + " iload_2\n");
06140: }
06141: if (local != null) {
06142: prevLocalGenerated = local;
06143: op = new Operand();
06144: boolean bo = isPrevInstIINC(info,
06145: currentForIndex, 2);
06146: java.lang.String ltmp = local.getTempVarName();
06147: if (bo && ltmp != null) {
06148: op.setOperandValue(ltmp);
06149: } else {
06150: op.setOperandValue(local.getVarName());
06151: }
06152:
06153: op.setLocalVarIndex(2);
06154: op.setLocalVarType(local.getDataType());
06155: opStack.push(op);
06156: }
06157:
06158: continue;
06159: case JvmOpCodes.ILOAD_3:
06160: local = getLocalVariable(3, "load", "int", true,
06161: currentForIndex);
06162: if (cd.isClassCompiledWithMinusG() && local != null) {
06163: addParsedOutput("Instruction Pos "
06164: + currentForIndex + "\t:- "
06165: + " iload _3 THIS LocalVariable:- "
06166: + local.getVarName());
06167: } else {
06168: addParsedOutput("Instruction Pos "
06169: + currentForIndex + "\t:- "
06170: + " iload_3\n");
06171: }
06172: if (local != null) {
06173: prevLocalGenerated = local;
06174: op = new Operand();
06175: boolean bo = isPrevInstIINC(info,
06176: currentForIndex, 3);
06177: java.lang.String ltmp = local.getTempVarName();
06178: if (bo && ltmp != null) {
06179: op.setOperandValue(ltmp);
06180: } else {
06181: op.setOperandValue(local.getVarName());
06182: }
06183:
06184: op.setLocalVarIndex(3);
06185: op.setLocalVarType(local.getDataType());
06186: opStack.push(op);
06187: }
06188:
06189: continue;
06190: case JvmOpCodes.IMUL:
06191: addParsedOutput("Instruction Pos "
06192: + currentForIndex + "\t:- " + " imul\n");
06193: op = (Operand) opStack.pop();
06194: op1 = (Operand) opStack.pop();
06195:
06196: op2 = new Operand();
06197: op2.setOperandValue(op1.getOperandValue() + "*"
06198: + op.getOperandValue());
06199: op2.setOperandType(Constants.IS_CONSTANT_INT);
06200: op2.setCategory(Constants.CATEGORY1);
06201:
06202: opStack.push(op2);
06203:
06204: continue;
06205: case JvmOpCodes.INEG:
06206: addParsedOutput("Instruction Pos "
06207: + currentForIndex + "\t:- " + " ineg\n");
06208: op = (Operand) opStack.pop();
06209:
06210: op1 = new Operand();
06211: op1.setOperandValue("-" + "("
06212: + op.getOperandValue() + ")");
06213: op1.setOperandType(Constants.IS_CONSTANT_INT);
06214: op1.setCategory(Constants.CATEGORY1);
06215: opStack.push(op1);
06216: continue;
06217: case JvmOpCodes.INSTANCEOF:
06218:
06219: op = (Operand) opStack.pop();
06220: op1 = new Operand();
06221: op1.setCategory(Constants.CATEGORY1);
06222:
06223: classIndex = getOffset(info, i);
06224: i += 2;
06225:
06226: constCInfo = cd
06227: .getClassInfoAtCPoolPosition(classIndex);
06228: addParsedOutput("Instruction Pos "
06229: + currentForIndex
06230: + "\t:- "
06231: + " instanceof "
06232: + cd.getUTF8String(
06233: constCInfo.getUtf8pointer())
06234: .replace('/', '.'));
06235: ninfo = cd
06236: .getNameAndTypeAtCPoolPosition(classIndex);
06237: op1.setOperandValue(op.getOperandValue()
06238: + " instanceof "
06239: + cd.getUTF8String(
06240: constCInfo.getUtf8pointer())
06241: .replace('/', '.'));
06242:
06243: opStack.push(op1);
06244: instanceof found = true;
06245: continue;
06246: case JvmOpCodes.INVOKEINTERFACE:
06247:
06248: classIndex = getOffset(info, i);
06249:
06250: i += 2;
06251:
06252: InterfaceMethodRef iref = cd
06253: .getInterfaceMethodAtCPoolPosition(classIndex);
06254: java.lang.String classname = iref.getClassname();
06255: java.lang.String typeofmet = iref.getTypeofmethod();
06256: addParsedOutput("Instruction Pos "
06257: + currentForIndex + "\t:- "
06258: + "invokeinterface " + classIndex
06259: + " CLASSNAME:- " + classname
06260: + " TYPEOFMET :- " + typeofmet + "\n");
06261: Util.parseDescriptor(typeofmet);
06262: ArrayList paramlist = Util
06263: .getParsedSignatureAsList();
06264: boolean takeret = isNextInstAStore(info,
06265: currentForIndex + 5);
06266: int s1 = typeofmet.indexOf(")");
06267: returntype = null;
06268: java.lang.String rettp = "";
06269: if (s1 != -1 && s1 + 1 < typeofmet.length()) {
06270:
06271: rettp = typeofmet.substring(s1 + 1);
06272:
06273: Util.parseReturnType(rettp);
06274: returntype = Util.getreturnSignatureAsList();
06275: }
06276: java.lang.String pushStr = classname;
06277: if (takeret && returntype != null
06278: && returntype.size() > 0) {
06279: pushStr = (java.lang.String) returntype.get(0);
06280: }
06281:
06282: resetMethodParameters(opStack, paramlist,
06283: currentForIndex);
06284: java.lang.String argumentRetType = "";
06285: int br = typeofmet.indexOf(")");
06286: if (br != -1) {
06287: char c;
06288: if (typeofmet.length() >= (br + 1))
06289: c = typeofmet.charAt(br + 1);
06290: else
06291: c = '?';
06292: argumentRetType = "" + c;
06293:
06294: }
06295: int nargs = paramlist.size();
06296: ClassInfo clazz = cd
06297: .getClassInfoAtCPoolPosition(iref
06298: .getClassPointer());
06299: NameAndType nmtype = cd
06300: .getNameAndTypeAtCPoolPosition(iref
06301: .getDescriptionPointer());
06302: java.lang.String clazzName = cd.getUTF8String(clazz
06303: .getUtf8pointer());
06304: registerInnerClassIfAny(clazzName.replace('.', '/'));
06305: java.lang.String description = cd
06306: .getUTF8String(nmtype.getUtf8pointer());
06307: int j = i + 1;
06308: //int nargs=info[j]-1;
06309: Operand allargs[] = new Operand[nargs];
06310: int start = 0;
06311:
06312: int dex = 0;
06313: for (int counter = nargs - 1; counter >= 0; counter--) {
06314: //boolean boolparam=isParameterTypeBoolean(paramlist,counter);
06315: op2 = opStack.getTopOfStack();
06316: resetOperandValueIfNecessary(paramlist,
06317: counter, op2);
06318: allargs[dex++] = op2;
06319:
06320: }
06321: Operand interfaceRef = opStack.getTopOfStack();
06322: java.lang.String args = "";
06323: java.lang.String bracket = "(";
06324: for (int c = (allargs.length - 1); c >= 0; c--) {
06325: args += allargs[c].getOperandValue();
06326: if (c != 0)
06327: args += ",";
06328: }
06329: if (args.length() > 0) {
06330: bracket += args + ")";
06331: } else
06332: bracket += ")";
06333: i++;
06334: i++;
06335: op1 = new Operand();
06336: op1.setOperandValue(interfaceRef.getOperandValue()
06337: + "." + description + bracket);
06338:
06339: op1.setClassType(pushStr);
06340: java.lang.String opvalue = (java.lang.String) op1
06341: .getOperandValue();
06342: if (opvalue.startsWith("\n")) {
06343: opvalue = opvalue.trim() + "\n";
06344: op1.setOperandValue(opvalue);
06345: }
06346: if (isInstStore0(info, i + 1)) {
06347: opStack.push(op1);
06348: } else if (isNextInstructionInvokeStatic((info[i + 1]))
06349: || isNextInstructionInvokeVirtual(info[i + 1])
06350: || isNextInstructionInvokeInterface(info[i + 1])
06351: || isNextInstructionInvokeSpecial(info[i + 1])
06352: || isNextInstructionStore(info[i + 1])
06353: || isNextInstructionIf(info[i + 1])
06354: || (info[(i + 1)] == JvmOpCodes.PUTFIELD)
06355: || (info[(i + 1)] == JvmOpCodes.PUTSTATIC)) { //TODO need to check for other cases like switch
06356:
06357: if (argumentRetType.equalsIgnoreCase("V") == false
06358: || argumentRetType
06359: .equalsIgnoreCase("void") == false) {
06360: //op1=new Operand();
06361: //op1.setOperandValue(interfaceRef.getOperandValue()+"."+description+bracket+";\n");
06362: opStack.push(op1);
06363: //op1.setClassType(pushStr);
06364: } else {
06365: tempString = interfaceRef.getOperandValue()
06366: + "." + description + bracket
06367: + ";\n";
06368: //codeStatements+=Util.formatDecompiledStatement(tempString);
06369: }
06370: } else if (isNextInstructionLoad(info[i + 1])) {
06371: if (argumentRetType.equalsIgnoreCase("V") == true
06372: || argumentRetType
06373: .equalsIgnoreCase("void") == true) {
06374: tempString = interfaceRef.getOperandValue()
06375: + "." + description + bracket
06376: + ";\n";
06377: //codeStatements+=Util.formatDecompiledStatement(tempString);
06378: } else {
06379: // op1=new Operand();
06380: ///op1.setOperandValue(interfaceRef.getOperandValue()+"."+description+bracket+";\n");
06381: opStack.push(op1);
06382: // op1.setClassType(pushStr);
06383: }
06384:
06385: } else if (isNextInstructionPop(info[i + 1])
06386: || isNextInstructionReturn(info[i + 1])) {
06387:
06388: tempString = interfaceRef.getOperandValue()
06389: + "." + description + bracket + ";\n";
06390: //codeStatements+=Util.formatDecompiledStatement(tempString);
06391:
06392: } else if (isNextInstructionConversionInst(info[i + 1])) {
06393:
06394: opStack.push(op1);
06395:
06396: } else if (checkForValueReturn(info, (i + 1))) {
06397:
06398: opStack.push(op1);
06399:
06400: } else if (checkForSomeSpecificInstructions(info,
06401: (i + 1))) {
06402: opStack.push(op1);
06403: //op1.setClassType(classname);
06404: } else {
06405: /*op1=new Operand();
06406: op1.setOperandValue(interfaceRef.getOperandValue()+"."+description+bracket+";\n");
06407: opStack.push(op1);*/
06408: if (argumentRetType.equalsIgnoreCase("V") == false
06409: || argumentRetType
06410: .equalsIgnoreCase("void") == false) {
06411: opStack.push(op1);
06412: // op1.setClassType(classname);
06413: } else {
06414: tempString = interfaceRef.getOperandValue()
06415: + "." + description + bracket
06416: + ";\n";
06417: //codeStatements+=Util.formatDecompiledStatement(tempString);
06418: }
06419: }
06420:
06421: // TODO check this condition whether it will apply
06422: // in all cases . Why only if ot store....Check
06423: /*if(isNextInstructionStore(info[i+1]) || isNextInstructionIf(info[i+1])) {
06424: op1=new Operand();
06425: op1.setOperandValue(interfaceRef.getOperandValue()+"."+description+bracket+";\n");
06426: opStack.push(op1);
06427: }
06428: else if(info[i+1] == JvmOpCodes.POP) // TODO: Handle POP2
06429: {
06430: op1=new Operand();
06431: op1.setOperandValue(interfaceRef.getOperandValue()+"."+description+bracket+";\n");
06432: opStack.push(op1);
06433: tempString=interfaceRef.getOperandValue()+"."+description+bracket+";\n";
06434: //codeStatements+=Util.formatDecompiledStatement(tempString);
06435: }
06436: else if(info[i+1] == JvmOpCodes.CHECKCAST) // TODO: Handle POP2
06437: {
06438: op1=new Operand();
06439: op1.setOperandValue(interfaceRef.getOperandValue()+"."+description+bracket+";\n");
06440: opStack.push(op1);
06441: }
06442: else
06443: {
06444: tempString=interfaceRef.getOperandValue()+"."+description+bracket+";\n";
06445: //codeStatements+=Util.formatDecompiledStatement(tempString);
06446: }*/
06447:
06448: continue;
06449: case JvmOpCodes.INVOKESPECIAL:
06450:
06451: // TODO:
06452: /***
06453: * 1>check when result has to be pushed and when just printed and when both
06454: * 2>In case of method calls and b is not null check whether this has to be
06455: * added or super (no other case possible ? )
06456: * 3> Need to handle new instruction properly
06457: */
06458: boolean previnstwasinvoke = false;
06459: if (currentForIndex - 3 >= 0
06460: && isThisInstrStart(behaviour
06461: .getInstructionStartPositions(),
06462: currentForIndex - 3)) {
06463: if (info[(currentForIndex - 3)] == JvmOpCodes.INVOKESPECIAL)
06464: previnstwasinvoke = true;
06465: }
06466: java.lang.String RET = "";
06467: boolean appendToCodeStmt = false;
06468: Operand invokingObjectRef = null;
06469: prevInstInvokeVirtual = true;
06470: funcCall = "";
06471:
06472: /*temp1=info[++i];
06473: temp2=info[++i];
06474: classIndex=((temp1 << 8) | temp2);*/
06475: //if(classIndex < 0)classIndex=(temp1+1)*256-Math.abs(temp2);
06476: classIndex = getOffset(info, i);
06477: i += 2;
06478:
06479: mref = cd.getMethodRefAtCPoolPosition(classIndex);
06480: java.lang.String classtype = mref.getClassname();
06481: ninfo = cd.getNameAndTypeAtCPoolPosition(mref
06482: .getDescriptionPointer());
06483:
06484: b = (Behaviour) methodLookUp.get(mref.getKey());
06485:
06486: boolean argumentReturnTypeChecked = false;
06487: typeofmet = mref.getTypeofmethod();
06488: addParsedOutput("Instruction Pos "
06489: + currentForIndex + "\t:- "
06490: + "invokespecial " + classIndex
06491: + " CLASSNAME:- " + classtype
06492: + " TYPEOFMET :- " + typeofmet + "\n");
06493: Util.parseDescriptor(typeofmet);
06494: paramlist = Util.getParsedSignatureAsList();
06495:
06496: takeret = isNextInstAStore(info,
06497: currentForIndex + 3);
06498: s1 = typeofmet.indexOf(")");
06499: returntype = null;
06500: if (s1 != -1 && s1 + 1 < typeofmet.length()) {
06501:
06502: rettp = typeofmet.substring(s1 + 1);
06503:
06504: Util.parseReturnType(rettp);
06505: returntype = Util.getreturnSignatureAsList();
06506: }
06507: pushStr = classtype;
06508: if (returntype != null && returntype.size() > 0) {
06509: pushStr = (java.lang.String) returntype.get(0);
06510: }
06511: resetMethodParameters(opStack, paramlist,
06512: currentForIndex);
06513: br = typeofmet.indexOf(")");
06514: if (br != -1) {
06515: char c;
06516: if (typeofmet.length() >= (br + 1))
06517: c = typeofmet.charAt(br + 1);
06518: else
06519: c = '?';
06520: RET = "" + c;
06521:
06522: }
06523: argumentRetType = "";
06524: if (b != null) {
06525: argumentRetType = b.getReturnType();
06526: op1 = new Operand();
06527: //op1.setCategory(Constants.CATEGORY1);
06528: op1.setOperandType(Constants.IS_OBJECT_REF);
06529:
06530: int numParams = b.getMethodParams().length;
06531: if (!newfound)
06532: funcCall = b.getBehaviourName() + "(";
06533: if (numParams == 0) {
06534: funcCall += ")";
06535: op2 = (Operand) opStack.pop();
06536: invokingObjectRef = op2;
06537: } else {
06538: Operand[] oparr = new Operand[numParams];
06539: int opArrIndx = numParams - 1;
06540: dex = 0;
06541: for (int indx = numParams - 1; indx >= 0; indx--) {
06542:
06543: op2 = (Operand) opStack.pop();
06544: resetOperandValueIfNecessary(paramlist,
06545: indx, op2);
06546: oparr[dex++] = op2;
06547: opArrIndx--;
06548: /*if(indx == numParams - 1)
06549: {
06550: funcCall += op2.getOperandValue()+")";
06551: }
06552: else
06553: {
06554: funcCall += op2.getOperandValue()+",";
06555: }*/
06556: // b.getOpStack().push(op2);
06557: }
06558: Operand objRef = (Operand) opStack.pop();
06559: invokingObjectRef = objRef;
06560:
06561: for (int indx = numParams - 1; indx >= 0; indx--) {
06562: op2 = oparr[indx];
06563: if (indx > 0) {
06564: funcCall += op2.getOperandValue()
06565: + ",";
06566:
06567: } else {
06568: funcCall += op2.getOperandValue()
06569: + ")";
06570: }
06571: }
06572:
06573: }
06574: java.lang.String ThisClassName = this .behaviour
06575: .getDeclaringClass(); // Class getting decompiled
06576: java.lang.String methodName = mref
06577: .getMethodName(); // Method being invoked
06578: java.lang.String declaringClassname = mref
06579: .getClassname(); // Class declaring the method being invoked
06580: java.lang.String super ClassName = cd
06581: .getSuperClassName();
06582: if (methodName.equals(declaringClassname)
06583: && declaringClassname
06584: .equals(ThisClassName)) { // Constructor Call
06585: /*Operand objRef = (Operand)opStack.pop();
06586: invokingObjectRef=objRef;*/
06587: if (super ClassName
06588: .equals(declaringClassname)
06589: && !newfound) {
06590: invokingObjectRef
06591: .setOperandValue("super");
06592:
06593: op1.setOperandValue(invokingObjectRef
06594: .getOperandValue());
06595: }
06596: } else {
06597: /*Operand objRef = (Operand)opStack.pop();
06598: invokingObjectRef=objRef;*/
06599: if (super ClassName
06600: .equals(declaringClassname)
06601: && !newfound) {
06602: invokingObjectRef
06603: .setOperandValue("super");
06604: funcCall = invokingObjectRef
06605: .getOperandValue()
06606: + "." + funcCall;
06607: op1.setOperandValue(funcCall);
06608: } else {
06609: op1.setOperandValue(invokingObjectRef
06610: .getOperandValue()
06611: + "." + funcCall);
06612: }
06613: appendToCodeStmt = true;
06614: }
06615: if (newfound) {
06616: appendToCodeStmt = true;
06617:
06618: }
06619:
06620: } else {
06621:
06622: java.lang.String methodSignature = mref
06623: .getTypeofmethod();
06624: br = methodSignature.indexOf(")");
06625: if (br != -1) {
06626: char c;
06627: if (methodSignature.length() >= (br + 1))
06628: c = methodSignature.charAt(br + 1);
06629: else
06630: c = '?';
06631: argumentRetType = "" + c;
06632:
06633: }
06634: methodSignature = methodSignature.substring(1,
06635: methodSignature.indexOf(")"));
06636: int numberOfParameters = paramlist.size();
06637: java.lang.String[] funcArray = new java.lang.String[numberOfParameters];
06638: java.lang.String ThisClassName = this .behaviour
06639: .getDeclaringClass(); // Class getting decompiled
06640: java.lang.String declaringClassname = mref
06641: .getClassname(); // Class declaring the method being invoked
06642: java.lang.String methodName = mref
06643: .getMethodName(); // Method being invoked
06644:
06645: int index = 0;
06646: int funcArrayIndex = 0;
06647: dex = 0;
06648: for (int indx = numberOfParameters - 1; indx >= 0; indx--) {
06649: op2 = (Operand) opStack.pop();
06650: resetOperandValueIfNecessary(paramlist,
06651: indx, op2);
06652: funcArray[dex++] = (op2.getOperandValue())
06653: .toString();
06654: funcArrayIndex++;
06655: }
06656:
06657: // NOTE:
06658: // Case where it applies for the constructor of this class
06659: // we dont do anything here . This is because the new instruction
06660: // takes care of that
06661:
06662: //funcCall += (java.lang.String)op2.getOperandValue() + "." + mref.getMethodName() + "(";
06663: if (methodName.equals(declaringClassname)
06664: && declaringClassname.replace('/', '.')
06665: .equals(cd.getSuperClassName())
06666: && !newfound) {
06667: op2 = (Operand) opStack.pop();
06668: funcCall = "super(";
06669: appendToCodeStmt = true;
06670: }
06671: // Handle Case of super.<someMethod> Here
06672: else if (methodName.equals(declaringClassname) == false
06673: && declaringClassname.replace('/', '.')
06674: .equals(cd.getSuperClassName())
06675: && !newfound) {
06676:
06677: op2 = (Operand) opStack.pop();
06678: funcCall = "super." + mref.getMethodName()
06679: + "(";
06680: appendToCodeStmt = true;
06681:
06682: }
06683:
06684: //TODO : Why is this else block needed ?
06685: /* else if(methodN45ame.equals(declaringClassname)==false && declaringClassname.replace('/','.').equals(cd.getSuperClassName())==false)
06686: {
06687:
06688: int d=1;
06689: int d2=2;
06690: } */
06691: else if (newfound || previnstwasinvoke) {
06692: appendToCodeStmt = true;
06693: op2 = (Operand) opStack.pop();
06694:
06695: } else {
06696:
06697: appendToCodeStmt = true;
06698: op2 = (Operand) opStack.pop();
06699: }
06700:
06701: // TODO: check if anything else comes here
06702:
06703: for (int indx = funcArray.length - 1; indx >= 0; indx--) {
06704: if (indx != 0) {
06705: funcCall += funcArray[indx] + ",";
06706: } else {
06707: funcCall += funcArray[indx];
06708: }
06709:
06710: }
06711:
06712: funcCall += ")";
06713:
06714: op1 = new Operand();
06715: //op1.setCategory(Constants.CATEGORY1);
06716: op1.setOperandType(Constants.IS_OBJECT_REF);
06717: op1.setOperandValue(funcCall);
06718:
06719: }
06720: /*boolean invokedfound=false;
06721: boolean retonload=false;
06722: if(isNextInstructionAnyInvoke(info[(i+1)],new StringBuffer()))
06723: {
06724: invokedfound=true;
06725: } */
06726:
06727: if (newfound && !previnstwasinvoke) // removed appendToCodeStmt
06728: {
06729: //booleaisNewPresentBeforeThisNew(currentForIndex);
06730: tempString = "(" + funcCall + ";\n";
06731: ////codeStatements +=Util.formatDecompiledStatement(tempString);
06732: //codeStatements +=tempString;
06733:
06734: }
06735: if (previnstwasinvoke) // removed appendToCodeStmt
06736: {
06737:
06738: if (opStack.isEmpty() == false)
06739: op2 = opStack.getTopOfStack();
06740: funcCall = op2.getOperandValue() + funcCall;
06741: op1 = new Operand();
06742: //op1.setCategory(Constants.CATEGORY1);
06743: op1.setOperandType(Constants.IS_OBJECT_REF);
06744: op1.setOperandValue(funcCall);
06745: if (opStack.size() > 1) {
06746: Operand temp1 = opStack.peekTopOfStack();
06747: if (temp1.getOperandValue().equals(
06748: op2.getOperandValue())) {
06749: opStack.pop();
06750: }
06751:
06752: }
06753:
06754: }
06755: /*java.lang.String v=op1.getOperandValue();
06756: StringBuffer bb=new StringBuffer("");
06757: Util.checkForImport(v,bb);
06758: op1.setOperandValue(bb.toString());*/
06759: StringBuffer dummy = new StringBuffer("");
06760: //else
06761: //{
06762: if (isInstStore0(info, i + 1)) {
06763: /* if(opStack.size() > 0)
06764: {
06765: Operand top=opStack.peekTopOfStack();
06766: java.lang.String v=top.getOperandValue();
06767: /*try
06768: {
06769: if(v!=null)
06770: {
06771: Integer.parseInt(v.trim()) ;
06772: }
06773: }
06774: catch(NumberFormatException ne)
06775: {
06776: opStack.pop();
06777: }
06778:
06779: } */
06780:
06781: if (!newfound && !previnstwasinvoke) {
06782: opStack.push(op1);
06783: op1.setClassType(pushStr);
06784: }
06785: } else if (isNextInstructionInvokeStatic((info[i + 1]))
06786: || isNextInstructionInvokeVirtual(info[i + 1])
06787: || isNextInstructionInvokeInterface(info[i + 1])
06788: || isNextInstructionInvokeSpecial(info[i + 1])
06789: || isNextInstructionStore(info[i + 1])
06790: || isNextInstructionIf(info[i + 1])) {
06791: if (RET.equalsIgnoreCase("V") == false) {
06792: if (newfound)// || previnstwasinvoke)
06793: {
06794: op1 = opStack.peekTopOfStack();
06795: }
06796: // if(previnstwasinvoke || newfound)
06797: opStack.push(op1);
06798: op1.setClassType(pushStr);
06799: } else {
06800: boolean n = false;
06801: if (!newfound && !previnstwasinvoke) {
06802: tempString = Util
06803: .formatDecompiledStatement(funcCall
06804: + ";\n");
06805: //codeStatements += tempString;
06806: n = true;
06807: }
06808: if (previnstwasinvoke) {
06809: //op1=opStack.peekTopOfStack();
06810:
06811: n = true;
06812: opStack.push(op1);
06813: op1.setClassType(pushStr);
06814: }
06815: if (!n) {
06816: if (newfound)// || previnstwasinvoke)
06817: {
06818: op1 = opStack.peekTopOfStack();
06819: }
06820: opStack.push(op1);
06821: op1.setClassType(pushStr);
06822: }
06823: }
06824: } else if ((info[(i + 1)] == JvmOpCodes.PUTFIELD)
06825: || (info[(i + 1)] == JvmOpCodes.PUTSTATIC)) {
06826: if (newfound)// || previnstwasinvoke) // TODO: test invokespecial tho
06827: {
06828: op1 = opStack.peekTopOfStack();
06829: }
06830: opStack.push(op1);
06831: op1.setClassType(pushStr);
06832: } else if (isNextInstructionLoad(info[i + 1])) {
06833:
06834: if (RET.equalsIgnoreCase("V") == true) {
06835: boolean n = false;
06836: if (!newfound && !previnstwasinvoke) {
06837: tempString = Util
06838: .formatDecompiledStatement(funcCall
06839: + ";\n");
06840: //codeStatements += tempString;
06841: n = true;
06842: }
06843: if (previnstwasinvoke) {
06844: //op1=opStack.peekTopOfStack();
06845: n = true;
06846: opStack.push(op1);
06847: op1.setClassType(pushStr);
06848: }
06849:
06850: if (!n) {
06851: int removeme = 1;
06852: if (newfound)// || previnstwasinvoke)
06853: {
06854: op1 = opStack.peekTopOfStack();
06855: }
06856: // opStack.push(op1);
06857: op1.setClassType(pushStr);
06858:
06859: }
06860: } else
06861:
06862: {
06863: if (newfound)// || previnstwasinvoke)
06864: {
06865: op1 = opStack.peekTopOfStack();
06866: }
06867: //if(previnstwasinvoke || newfound)
06868: opStack.push(op1);
06869: op1.setClassType(pushStr);
06870: /* tempString=Util.formatDecompiledStatement(funcCall+";\n");
06871: //codeStatements += tempString;*/
06872: }
06873:
06874: } //?
06875: else if (isNextInstructionPop(info[i + 1])
06876: || isNextInstructionReturn(info[i + 1])) {
06877: boolean n = false;
06878: boolean skipr = false;
06879: if (isThisInstrStart(behaviour
06880: .getInstructionStartPositions(),
06881: (i + 2))) {
06882:
06883: if (info[(i + 2)] == JvmOpCodes.GETSTATIC) {
06884: opStack.push(op1);
06885: op1.setClassType(pushStr);
06886: skipr = true;
06887: }
06888:
06889: }
06890:
06891: if (!newfound && !previnstwasinvoke && !skipr) {
06892: tempString = Util
06893: .formatDecompiledStatement(funcCall
06894: + ";\n");
06895: //codeStatements += tempString;
06896: n = true;
06897: }
06898: if (previnstwasinvoke && !skipr) {
06899: //op1=opStack.peekTopOfStack();
06900: n = true;
06901: opStack.push(op1);
06902: op1.setClassType(pushStr);
06903: }
06904: if (!n && !skipr) {
06905: if (newfound)// || previnstwasinvoke)
06906: {
06907: op1 = opStack.peekTopOfStack();
06908: }
06909: opStack.push(op1);
06910: op1.setClassType(pushStr);
06911: }
06912:
06913: } else if (isNextInstructionConversionInst(info[i + 1])) {
06914: if (newfound)// || previnstwasinvoke)
06915: {
06916: op1 = opStack.peekTopOfStack();
06917: }
06918: //if(previnstwasinvoke || newfound)
06919: opStack.push(op1);
06920: op1.setClassType(pushStr);
06921: }
06922:
06923: else if (checkForValueReturn(info, (i + 1))) {
06924: if (newfound)// || previnstwasinvoke)
06925: {
06926: op1 = opStack.peekTopOfStack();
06927: }
06928: //if(previnstwasinvoke || newfound)
06929: opStack.push(op1);
06930: op1.setClassType(pushStr);
06931: } else if (checkForSomeSpecificInstructions(info,
06932: (i + 1))) {
06933: if (newfound)// || previnstwasinvoke)
06934: {
06935: op1 = opStack.peekTopOfStack();
06936: }
06937: //if(previnstwasinvoke || newfound) // because of checkcast addition
06938: opStack.push(op1);
06939: op1.setClassType(pushStr);
06940: //else
06941:
06942: }
06943:
06944: else if (isInstAnyBasicPrimitiveOperation(info,
06945: (i + 1), dummy)
06946: || (info[i + 1] == JvmOpCodes.GETFIELD || info[i + 1] == JvmOpCodes.GETSTATIC)) {
06947: if (newfound)// || previnstwasinvoke)
06948: {
06949: op1 = opStack.peekTopOfStack();
06950: }
06951: //if(previnstwasinvoke || newfound) // because of checkcast addition
06952: opStack.push(op1);
06953: op1.setClassType(pushStr);
06954: } else {
06955: if (!newfound && !previnstwasinvoke) {
06956: tempString = Util
06957: .formatDecompiledStatement(funcCall
06958: + ";\n");
06959: //codeStatements += tempString;
06960: } else {
06961: Operand opd = new Operand();
06962: //opd.setCategory(Constants.CATEGORY1);
06963: opd.setOperandType(Constants.IS_OBJECT_REF);
06964: opd.setOperandValue(funcCall);
06965: if (newfound) {
06966: Operand OP = opStack.peekTopOfStack();
06967: if (OP != null) {
06968: opd.setOperandValue(OP
06969: .getOperandValue());
06970: }
06971: }
06972: // opStack.push(opd);
06973:
06974: }
06975: }
06976: /*if(!newfound && (!invokedfound && !retonload ))
06977: {
06978: tempString=funcCall+";\n";
06979: // opStack.push(op1);
06980: //codeStatements +=Util.formatDecompiledStatement(tempString);
06981: }
06982: if(!newfound && (invokedfound || retonload))
06983: {
06984: if(invokedfound)
06985: {
06986: if(RET.equalsIgnoreCase("V")==false)
06987: {
06988: opStack.push(op1);
06989: }
06990: else
06991: {
06992: tempString=funcCall+";\n";
06993:
06994: //codeStatements +=Util.formatDecompiledStatement(tempString);
06995: }
06996: }
06997: else
06998: opStack.push(op1);
06999: // //codeStatements +=Util.formatDecompiledStatement(tempString);
07000: } */
07001: //}
07002: if (newfound)
07003: newfound = false;
07004: Operand p = opStack.peekTopOfStack();
07005: if (p != null)
07006: p.setClassType(classtype);
07007:
07008: continue;
07009:
07010: case JvmOpCodes.INVOKESTATIC:
07011: RET = "";
07012: boolean codeStmtFormed = false;
07013: funcCall = "";
07014: cd.printAllUtf8StringInNameAndTypeObjects();
07015:
07016: /*temp1=info[++i];
07017: temp2=info[++i];
07018: classIndex=((temp1 << 8) | temp2);
07019: if(classIndex < 0)classIndex=(temp1+1)*256-Math.abs(temp2);*/
07020: classIndex = getOffset(info, i);
07021: i += 2;
07022: mref = cd.getMethodRefAtCPoolPosition(classIndex);
07023: classname = mref.getClassname();
07024: typeofmet = mref.getTypeofmethod();
07025: addParsedOutput("Instruction Pos "
07026: + currentForIndex + "\t:- "
07027: + "invokestatic " + classIndex
07028: + " CLASSNAME:- " + classname
07029: + " TYPEOFMET :- " + typeofmet + "\n");
07030: Util.parseDescriptor(typeofmet);
07031: paramlist = Util.getParsedSignatureAsList();
07032: takeret = isNextInstAStore(info,
07033: currentForIndex + 3);
07034: s1 = typeofmet.indexOf(")");
07035: returntype = null;
07036: if (s1 != -1 && s1 + 1 < typeofmet.length()) {
07037:
07038: rettp = typeofmet.substring(s1 + 1);
07039:
07040: Util.parseReturnType(rettp);
07041: returntype = Util.getreturnSignatureAsList();
07042: }
07043: pushStr = classname;
07044:
07045: if (returntype != null && returntype.size() > 0) {
07046: pushStr = (java.lang.String) returntype.get(0);
07047: }
07048: resetMethodParameters(opStack, paramlist,
07049: currentForIndex);
07050: registerInnerClassIfAny(classname.replace('.', '/'));
07051: ninfo = cd.getNameAndTypeAtCPoolPosition(mref
07052: .getDescriptionPointer());
07053:
07054: b = (Behaviour) methodLookUp.get(mref.getKey());
07055:
07056: br = typeofmet.indexOf(")");
07057: if (br != -1) {
07058: char c;
07059: if (typeofmet.length() >= (br + 1))
07060: c = typeofmet.charAt(br + 1);
07061: else
07062: c = '?';
07063: RET = "" + c;
07064:
07065: }
07066: argumentReturnTypeChecked = false;
07067: argumentRetType = "";
07068: if (b != null) {
07069: argumentRetType = b.getReturnType();
07070: op1 = new Operand();
07071: //op1.setCategory(Constants.CATEGORY1);
07072: op1.setOperandType(Constants.IS_OBJECT_REF);
07073: // if(!b.isHasBeenDissassembled()) {
07074: int numParams = b.getMethodParams().length;
07075: funcCall = b.getBehaviourName() + "(";
07076: dex = 0;
07077: /* for(int indx=numParams-1;indx>=0;indx--) {
07078: op2 = (Operand)opStack.pop();
07079: resetOperandValueIfNecessary(paramlist,indx,op2);
07080: if(indx > 0) {
07081: funcCall += op2.getOperandValue()+",";
07082:
07083: } else {
07084: funcCall += op2.getOperandValue()+")";
07085: }
07086: b.getOpStack().push(op2);
07087: op2.setClassType(classname);
07088:
07089: } */
07090: java.lang.String[] funcArray = new java.lang.String[numParams];
07091: dex = 0;
07092: for (int indx = numParams - 1; indx >= 0; indx--) {
07093: op2 = (Operand) opStack.pop();
07094: resetOperandValueIfNecessary(paramlist,
07095: indx, op2);
07096: if (op2 != null
07097: && op2.getOperandValue() != null)
07098: funcArray[dex++] = (op2
07099: .getOperandValue()).toString();
07100: else
07101: funcArray[dex++] = ""
07102: + (op2.getOperandValue());
07103:
07104: }
07105: for (int indx = funcArray.length - 1; indx >= 0; indx--) {
07106: if (indx != 0) {
07107: funcCall += funcArray[indx] + ",";
07108: } else {
07109: funcCall += funcArray[indx];
07110: }
07111:
07112: }
07113:
07114: funcCall += ");\n";
07115:
07116: op1.setOperandValue(funcCall);
07117: //opStack.push(op1);
07118: /*b.setParentBehaviour(behaviour);
07119: Disassembler disassembler=new Disassembler(b,cd);
07120: disassembler.disassembleCode();
07121: disassembler=null;*/
07122:
07123: ////codeStatements += Util.formatDecompiledStatement(funcCall);
07124: ////codeStatements+=";\n";
07125: //codeStmtFormed=true;
07126:
07127: //}
07128: } else {
07129: java.lang.String methodSignature = mref
07130: .getTypeofmethod(); // Should Be Refactored...Or getting called wrongly
07131: br = methodSignature.indexOf(")");
07132: if (br != -1) {
07133: char c;
07134: if (methodSignature.length() >= (br + 1))
07135: c = methodSignature.charAt(br + 1);
07136: else
07137: c = '?';
07138: argumentRetType = "" + c;
07139:
07140: }
07141: methodSignature = methodSignature.substring(1,
07142: methodSignature.indexOf(")"));
07143: int numberOfParameters = paramlist.size();
07144: // int numberOfParameters =
07145: java.lang.String[] funcArray = new java.lang.String[numberOfParameters];
07146: int index = 0;
07147: int funcArrayIndex = 0;
07148: dex = 0;
07149: for (int indx = numberOfParameters - 1; indx >= 0; indx--) {
07150: op2 = (Operand) opStack.pop();
07151: resetOperandValueIfNecessary(paramlist,
07152: indx, op2);
07153: if (op2 != null
07154: && op2.getOperandValue() != null)
07155: funcArray[dex++] = (op2
07156: .getOperandValue()).toString();
07157: else
07158: funcArray[dex++] = ""
07159: + (op2.getOperandValue());
07160: funcArrayIndex++;
07161: }
07162:
07163: // op2 = (Operand)opStack.pop();
07164: //mref.getClassname()+"."+mref.getMethodName()
07165: boolean funcCallFormed = false;
07166: if (Configuration.getShowImport()
07167: .equalsIgnoreCase("false")) {
07168: funcCall += mref.getClassname().replace(
07169: '/', '.')
07170: + "." + mref.getMethodName() + "(";
07171: funcCallFormed = true;
07172: } else {
07173: java.lang.String simplename = "";
07174: java.lang.String fullName = mref
07175: .getClassname();
07176: int lastSlash = mref.getClassname()
07177: .lastIndexOf("/");
07178: if (lastSlash == -1) {
07179: lastSlash = mref.getClassname()
07180: .lastIndexOf(".");
07181: }
07182: if (lastSlash != -1) {
07183: simplename = fullName
07184: .substring(lastSlash + 1);
07185: } else
07186: simplename = fullName;
07187: funcCall += simplename + "."
07188: + mref.getMethodName() + "(";
07189: fullName = fullName.replace('/', '.');
07190: ConsoleLauncher.addImportClass(fullName);
07191: funcCallFormed = true;
07192:
07193: }
07194: for (int indx = funcArray.length - 1; indx >= 0; indx--) {
07195: if (indx != 0) {
07196: funcCall += funcArray[indx] + ",";
07197: } else {
07198: funcCall += funcArray[indx];
07199: }
07200:
07201: }
07202: if (funcCallFormed
07203: && funcCall.indexOf(";") == -1)
07204: funcCall += ")";
07205: op1 = new Operand();
07206: //op1.setCategory(Constants.CATEGORY1);
07207: op1.setOperandType(Constants.IS_OBJECT_REF);
07208: op1.setOperandValue(funcCall);
07209: //op3.setOperandValue(funcCall);
07210: //opStack.push(op3);
07211: }
07212: /* if(isNextInstructionInvokeVirtual(info[i+1]) || isNextInstructionInvokeSpecial(info[i+1]) || isNextInstructionStore(info[i+1]) || isNextInstructionIf(info[i+1])) { //TODO need to check for other cases like switch
07213: /*java.lang.String Temp=op1.getOperandValue().toString();
07214:
07215: Temp+=";\n";
07216: op1.setOperandValue(Temp);
07217: opStack.push(op1);
07218: }
07219: else {
07220: /*if(info[i+1] == JvmOpCodes.ATHROW && behaviour.getParentBehaviour() != null) { // Can this be removed
07221: //behaviour.getParentBehaviour().getOpStack().push(op1);
07222: ////codeStatements += funcCall+";\n";
07223: } else {
07224:
07225: opStack.push(op1);
07226: // Commented by belurs
07227: // if(!codeStmtFormed)
07228: // //codeStatements += Util.formatDecompiledStatement(funcCall);
07229: }*/
07230: opvalue = (java.lang.String) op1.getOperandValue();
07231: opvalue = opvalue.trim();
07232: if (opvalue.endsWith(";")) {
07233: opvalue = opvalue.substring(0, opvalue
07234: .lastIndexOf(";"));
07235: }
07236:
07237: op1.setOperandValue(opvalue);
07238: opvalue = (java.lang.String) op1.getOperandValue();
07239: if (opvalue.startsWith("\n")) {
07240: opvalue = opvalue.trim();
07241: op1.setOperandValue(opvalue);
07242: }
07243: /* v=op1.getOperandValue();
07244: bb=new StringBuffer("");
07245: Util.checkForImport(v,bb);
07246: // op1.setOperandValue(bb.toString());*/
07247: if (isInstStore0(info, i + 1)) {
07248: opStack.push(op1);
07249: op1.setClassType(pushStr);
07250: } else if (isNextInstructionInvokeStatic((info[i + 1]))
07251: || isNextInstructionInvokeVirtual(info[i + 1])
07252: || isNextInstructionInvokeInterface(info[i + 1])
07253: || isNextInstructionInvokeSpecial(info[i + 1])
07254: || isNextInstructionStore(info[i + 1])
07255: || isNextInstructionIf(info[i + 1])
07256: || (info[(i + 1)] == JvmOpCodes.PUTFIELD)
07257: || (info[(i + 1)] == JvmOpCodes.PUTSTATIC)) { //TODO need to check for other cases like switch
07258: if (RET.equalsIgnoreCase("V") == false) {
07259:
07260: opStack.push(op1);
07261: op1.setClassType(pushStr);
07262:
07263: } else {
07264: tempString = Util
07265: .formatDecompiledStatement("\n"
07266: + funcCall + ";\n");
07267: //codeStatements += tempString;
07268: }
07269: } else if (isNextInstructionLoad(info[i + 1])) {
07270: if (RET.equalsIgnoreCase("V") == true) {
07271: tempString = Util
07272: .formatDecompiledStatement("\n"
07273: + funcCall + "\n");
07274: //codeStatements += tempString;
07275: } else {
07276: opStack.push(op1);
07277: op1.setClassType(pushStr);
07278: /* tempString=Util.formatDecompiledStatement(funcCall+";\n");
07279: //codeStatements += tempString;*/
07280: }
07281:
07282: } //?
07283: else if (isNextInstructionPop(info[i + 1])
07284: || isNextInstructionReturn(info[i + 1])) {
07285:
07286: tempString = Util
07287: .formatDecompiledStatement("\n"
07288: + funcCall + "\n");
07289: //codeStatements += tempString;
07290:
07291: } else if (isNextInstructionConversionInst(info[i + 1])) {
07292:
07293: opStack.push(op1);
07294: op1.setClassType(pushStr);
07295: }
07296:
07297: else if (checkForValueReturn(info, (i + 1))) {
07298:
07299: opStack.push(op1);
07300: op1.setClassType(pushStr);
07301: } else if (checkForSomeSpecificInstructions(info,
07302: (i + 1))) {
07303: opStack.push(op1);
07304: op1.setClassType(pushStr);
07305: } else {
07306: // //opStack.push(op1);
07307: if (RET.equalsIgnoreCase("V") == false) {
07308: opStack.push(op1);
07309: op1.setClassType(pushStr);
07310: } else {
07311: tempString = Util
07312: .formatDecompiledStatement("\n"
07313: + funcCall + "\n");
07314: //codeStatements += tempString;
07315: }
07316: }
07317:
07318: continue;
07319: case JvmOpCodes.INVOKEVIRTUAL:
07320: prevInstInvokeVirtual = true;
07321: invokevirtualFound = true;
07322: funcCall = "";
07323:
07324: classIndex = getOffset(info, i);
07325: i += 2;
07326: mref = cd.getMethodRefAtCPoolPosition(classIndex);
07327: classname = mref.getClassname();
07328: registerInnerClassIfAny(classname.replace('.', '/'));
07329: ninfo = cd.getNameAndTypeAtCPoolPosition(mref
07330: .getDescriptionPointer());
07331: typeofmet = mref.getTypeofmethod();
07332: addParsedOutput("Instruction Pos "
07333: + currentForIndex + "\t:- "
07334: + "invokevirtual " + classIndex
07335: + " CLASSNAME:- " + classname
07336: + " TYPEOFMET :- " + typeofmet + "\n");
07337: s1 = typeofmet.indexOf(")");
07338: rettp = "";
07339: returntype = null;
07340: takeret = isNextInstAStore(info,
07341: currentForIndex + 3);
07342: if (s1 != -1 && s1 + 1 < typeofmet.length()) {
07343:
07344: rettp = typeofmet.substring(s1 + 1);
07345:
07346: Util.parseReturnType(rettp);
07347: returntype = Util.getreturnSignatureAsList();
07348: }
07349: pushStr = classname;
07350: // NOTE: removed takeret : sbelur
07351: if (returntype != null && returntype.size() > 0) {
07352: pushStr = (java.lang.String) returntype.get(0);
07353: }
07354: Util.parseDescriptor(typeofmet);
07355: paramlist = Util.getParsedSignatureAsList();
07356:
07357: resetMethodParameters(opStack, paramlist,
07358: currentForIndex);
07359: b = (Behaviour) methodLookUp.get(mref.getKey());
07360: argumentReturnTypeChecked = false;
07361: argumentRetType = "";
07362: br = typeofmet.indexOf(")");
07363: RET = "";
07364: if (br != -1) {
07365: char c;
07366: if (typeofmet.length() >= (br + 1))
07367: c = typeofmet.charAt(br + 1);
07368: else
07369: c = '?';
07370: RET = "" + c;
07371:
07372: }
07373: if (b != null) {
07374: argumentReturnTypeChecked = true;
07375: argumentRetType = b.getReturnType();
07376: op1 = new Operand();
07377: //op1.setCategory(Constants.CATEGORY1);
07378: op1.setOperandType(Constants.IS_OBJECT_REF);
07379: int numParams = b.getMethodParams().length;
07380: funcCall = b.getBehaviourName() + "(";
07381: if (numParams == 0) {
07382: funcCall += ")";
07383: Operand objRef = opStack.getTopOfStack();
07384: java.lang.String temp = funcCall;
07385: funcCall = "";
07386: funcCall = objRef.getOperandValue() + "."
07387: + temp;
07388: } else {
07389: Operand[] oparr = new Operand[numParams];
07390: int opArrIndx = numParams - 1;
07391: dex = 0;
07392: for (int indx = numParams - 1; indx >= 0; indx--) {
07393: op2 = (Operand) opStack.pop();
07394: resetOperandValueIfNecessary(paramlist,
07395: indx, op2);
07396: oparr[dex++] = op2;
07397: opArrIndx--;
07398: /*if(indx == numParams - 1)
07399: {
07400: funcCall += op2.getOperandValue()+")";
07401: }
07402: else
07403: {
07404: funcCall += op2.getOperandValue()+",";
07405: }*/
07406: //b.getOpStack().push(op2);
07407: }
07408:
07409: for (int indx = numParams - 1; indx >= 0; indx--) {
07410: op2 = oparr[indx];
07411: if (indx > 0) {
07412: funcCall += op2.getOperandValue()
07413: + ",";
07414:
07415: } else {
07416: funcCall += op2.getOperandValue()
07417: + ")";
07418: }
07419: }
07420: Operand objRef = opStack.getTopOfStack();
07421: java.lang.String temp = funcCall;
07422: funcCall = "";
07423: funcCall = objRef.getOperandValue() + "."
07424: + temp;
07425: }
07426:
07427: op1.setOperandValue(funcCall);
07428:
07429: // Commented by belurs
07430: // Do we have to do it ?
07431:
07432: //opStack.push(op1);
07433: /*b.setParentBehaviour(behaviour);
07434: Disassembler disassembler=new Disassembler(b,cd);
07435: disassembler.disassembleCode();
07436: disassembler=null;
07437: //TODO : Call the parseJVMCodes Function recrusively to parse the invokedfunction*/
07438: //b.setHasBeenDissassembled(true); // TODO: Commented by belurs
07439: // Need to check where all this method is used
07440: // and if and how it shud be is used
07441: ////codeStatements += funcCall+";\n";
07442: } else {
07443: argumentReturnTypeChecked = true;
07444: java.lang.String methodSignature = mref
07445: .getTypeofmethod(); // Should Be Refactored...Or getting called wrongly
07446: br = methodSignature.indexOf(")");
07447: if (br != -1) {
07448: char c;
07449: if (methodSignature.length() >= (br + 1))
07450: c = methodSignature.charAt(br + 1);
07451: else
07452: c = '?';
07453: argumentRetType = "" + c;
07454:
07455: }
07456: methodSignature = methodSignature.substring(1,
07457: methodSignature.indexOf(")"));
07458: int numberOfParameters = paramlist.size();
07459: // int numberOfParameters =
07460: java.lang.String[] funcArray = new java.lang.String[numberOfParameters];
07461: int index = 0;
07462: int funcArrayIndex = 0;
07463: for (int indx = numberOfParameters - 1; indx >= 0; indx--) {
07464: op2 = (Operand) opStack.pop();
07465: resetOperandValueIfNecessary(paramlist,
07466: indx, op2);
07467:
07468: if (op2.getOperandValue() != null)
07469: funcArray[indx] = (op2
07470: .getOperandValue()).toString();
07471: else
07472: funcArray[indx] = ""
07473: + (op2.getOperandValue());
07474: funcArrayIndex++;
07475: }
07476:
07477: op2 = (Operand) opStack.pop();
07478: // System.out.println(op2.getOperandValue().getClass()+" op2.getOperandValue().class");
07479: funcCall += (op2.getOperandValue() != null ? op2
07480: .getOperandValue().toString()
07481: : "")
07482: + "." + mref.getMethodName() + "(";
07483: for (int indx = 0; indx < funcArray.length; indx++) {
07484: if (indx < funcArray.length - 1) {
07485: funcCall += funcArray[indx] + ",";
07486: } else {
07487: funcCall += funcArray[indx];
07488: }
07489:
07490: }
07491: funcCall += ")";
07492: op1 = new Operand();
07493: //op1.setCategory(Constants.CATEGORY1);
07494: op1.setOperandType(Constants.IS_OBJECT_REF);
07495: op1.setOperandValue(funcCall);
07496: //op3.setOperandValue(funcCall);
07497: //opStack.push(op3);
07498: }
07499: /*v=op1.getOperandValue();
07500: bb=new StringBuffer("");
07501: Util.checkForImport(v,bb);
07502: op1.setOperandValue(bb.toString());*/
07503: if (isInstStore0(info, i + 1)) {
07504: opStack.push(op1);
07505: op1.setClassType(pushStr);
07506: } else if (isNextInstructionInvokeStatic((info[i + 1]))
07507: || isNextInstructionInvokeVirtual(info[i + 1])
07508: || isNextInstructionInvokeInterface(info[i + 1])
07509: || isNextInstructionInvokeSpecial(info[i + 1])
07510: || isNextInstructionStore(info[i + 1])
07511: || isNextInstructionIf(info[i + 1])
07512: || (info[(i + 1)] == JvmOpCodes.PUTFIELD)
07513: || (info[(i + 1)] == JvmOpCodes.PUTSTATIC)) { //TODO need to check for other cases like switch
07514: if (RET.equalsIgnoreCase("V") == false) {
07515: opStack.push(op1);
07516: op1.setClassType(pushStr);
07517: } else {
07518: tempString = Util
07519: .formatDecompiledStatement(funcCall
07520: + ";\n");
07521: //codeStatements += tempString;
07522: }
07523: } else if (isNextInstructionLoad(info[i + 1])) {
07524: if (RET.equalsIgnoreCase("V") == true) {
07525: tempString = Util
07526: .formatDecompiledStatement(funcCall
07527: + ";\n");
07528: //codeStatements += tempString;
07529: } else {
07530: opStack.push(op1);
07531: op1.setClassType(pushStr);
07532: }
07533:
07534: } else if (isNextInstructionPop(info[i + 1])
07535: || isNextInstructionReturn(info[i + 1])) {
07536:
07537: tempString = Util
07538: .formatDecompiledStatement(funcCall
07539: + ";\n");
07540: //codeStatements += tempString;
07541:
07542: } else if (isNextInstructionConversionInst(info[i + 1])) {
07543: opStack.push(op1);
07544: op1.setClassType(pushStr);
07545: } else if (checkForValueReturn(info, (i + 1))) {
07546: opStack.push(op1);
07547: op1.setClassType(pushStr);
07548: } else if (checkForSomeSpecificInstructions(info,
07549: (i + 1))) // BUG here w.r.t LDC
07550: {
07551: opStack.push(op1);
07552: op1.setClassType(pushStr);
07553: } else {
07554: //opStack.push(op1);
07555: if (RET.equalsIgnoreCase("V") == false) {
07556: opStack.push(op1);
07557: op1.setClassType(pushStr);
07558: }
07559:
07560: else {
07561: tempString = Util
07562: .formatDecompiledStatement(funcCall
07563: + ";\n");
07564: //codeStatements += tempString;
07565: }
07566: }
07567: continue;
07568: case JvmOpCodes.IOR:
07569: addParsedOutput("Instruction Pos "
07570: + currentForIndex + "\t:- " + "ior\n");
07571: op = (Operand) opStack.pop();
07572: op1 = (Operand) opStack.pop();
07573:
07574: op2 = new Operand();
07575: //op2.setCategory(Constants.CATEGORY1);
07576: //op2.setOperandType(Constants.IS_CONSTANT_INT);
07577:
07578: op2.setOperandValue("(" + op1.getOperandValue()
07579: + "|" + op.getOperandValue() + ")");
07580:
07581: opStack.push(op2);
07582:
07583: continue;
07584: case JvmOpCodes.IREM:
07585: addParsedOutput("Instruction Pos "
07586: + currentForIndex + "\t:- " + "irem\n");
07587: op = (Operand) opStack.pop();
07588: op1 = (Operand) opStack.pop();
07589:
07590: op2 = new Operand();
07591: //op2.setCategory(Constants.CATEGORY1);
07592: op2.setOperandType(Constants.IS_CONSTANT_INT);
07593:
07594: op2.setOperandValue("(" + op1.getOperandValue()
07595: + "%" + op.getOperandValue() + ")");
07596:
07597: opStack.push(op2);
07598:
07599: continue;
07600: case JvmOpCodes.IRETURN:
07601: addParsedOutput("Instruction Pos "
07602: + currentForIndex + "\t:- " + "ireturn\n");
07603: oktoadd = true;
07604: mapIT = returnsAtI.entrySet().iterator();
07605: while (mapIT.hasNext()) {
07606: Map.Entry entry = (Map.Entry) mapIT.next();
07607: Object key = entry.getKey();
07608: Object retStatus = entry.getValue().toString();
07609: if (key instanceof Integer) {
07610: Integer pos = (Integer) key;
07611: int temp = pos.intValue();
07612: if (temp == i) {
07613: if (retStatus.equals("true")) {
07614:
07615: oktoadd = false;
07616: break;
07617: }
07618: }
07619: }
07620:
07621: }
07622:
07623: if (!oktoadd) {
07624: returnsAtI.remove(new Integer(i));
07625: }
07626:
07627: if (oktoadd && opStack.size() > 0) {
07628: op = (Operand) opStack.pop();
07629: boolean bool = isMethodRetBoolean(this .behaviour);
07630: if (bool) {
07631: if (op.getOperandValue().equals("1")) {
07632: op.setOperandValue("true");
07633: } else if (op.getOperandValue().equals("0")) {
07634: op.setOperandValue("false");
07635: }
07636: }
07637: tempString = "return " + op.getOperandValue()
07638: + ";\n";
07639: //codeStatements +=Util.formatDecompiledStatement(tempString);
07640: }
07641: //behaviour.getParentBehaviour().getOpStack().push(op);
07642: continue;
07643: case JvmOpCodes.ISHL:
07644: addParsedOutput("Instruction Pos "
07645: + currentForIndex + "\t:- " + "ishl\n");
07646: op = (Operand) opStack.pop();
07647: op1 = (Operand) opStack.pop();
07648:
07649: op2 = new Operand();
07650: op2.setOperandType(Constants.IS_CONSTANT_INT);
07651: op2.setOperandValue("(" + op1.getOperandValue()
07652: + "<<" + op.getOperandValue() + ")");
07653:
07654: opStack.push(op2);
07655: continue;
07656: case JvmOpCodes.ISHR:
07657: addParsedOutput("Instruction Pos "
07658: + currentForIndex + "\t:- " + "ishr\n");
07659: op = (Operand) opStack.pop();
07660: op1 = (Operand) opStack.pop();
07661:
07662: op2 = new Operand();
07663: op2.setOperandType(Constants.IS_CONSTANT_INT);
07664: op2.setOperandValue("(" + op1.getOperandValue()
07665: + ">>" + op.getOperandValue() + ")");
07666: opStack.push(op2);
07667:
07668: continue;
07669: case JvmOpCodes.ISTORE:
07670: classIndex = info[++i];
07671:
07672: addParsedOutput("Instruction Pos "
07673: + currentForIndex + "\t:- " + "istore "
07674: + classIndex);
07675: handleISTORE(opStack, info, classIndex, false);
07676: continue;
07677: case JvmOpCodes.ISTORE_0:
07678: addParsedOutput("Instruction Pos "
07679: + currentForIndex + "\t:- " + "istore_0");
07680: handleISTORE(opStack, info, 0, true);
07681: // Store the op.getOperandValue() in the local Variable;
07682: continue;
07683: case JvmOpCodes.ISTORE_1:
07684: addParsedOutput("Instruction Pos "
07685: + currentForIndex + "\t:- " + "istore_1");
07686: handleISTORE(opStack, info, 1, true);
07687: continue;
07688: case JvmOpCodes.ISTORE_2:
07689: addParsedOutput("Instruction Pos "
07690: + currentForIndex + "\t:- " + "istore_2");
07691: handleISTORE(opStack, info, 2, true);
07692:
07693: continue;
07694: case JvmOpCodes.ISTORE_3:
07695: addParsedOutput("Instruction Pos "
07696: + currentForIndex + "\t:- " + "istore_3");
07697: handleISTORE(opStack, info, 3, true);
07698: continue;
07699: case JvmOpCodes.ISUB:
07700: addParsedOutput("Instruction Pos "
07701: + currentForIndex + "\t:- " + "isub\n");
07702: op = (Operand) opStack.pop();
07703: op1 = (Operand) opStack.pop();
07704:
07705: op2 = new Operand();
07706: op2.setCategory(Constants.CATEGORY1);
07707: op2.setOperandType(Constants.IS_CONSTANT_INT);
07708: op2.setOperandValue("(" + op1.getOperandValue()
07709: + "- " + op.getOperandValue() + ")");
07710:
07711: opStack.push(op2);
07712: continue;
07713: case JvmOpCodes.IUSHR:
07714: addParsedOutput("Instruction Pos "
07715: + currentForIndex + "\t:- " + "iushr\n");
07716: op = (Operand) opStack.pop();
07717: op1 = (Operand) opStack.pop();
07718:
07719: op.setOperandValue(op.getOperandValue() + " & 31");
07720:
07721: op2 = new Operand();
07722:
07723: op2.setOperandType(Constants.IS_CONSTANT_INT);
07724: op2.setOperandValue("(" + op1.getOperandValue()
07725: + ">>>" + op.getOperandValue() + ")");
07726: opStack.push(op2);
07727: continue;
07728: case JvmOpCodes.IXOR:
07729: addParsedOutput("Instruction Pos "
07730: + currentForIndex + "\t:- " + "ixor\n");
07731: op = (Operand) opStack.pop();
07732: op1 = (Operand) opStack.pop();
07733:
07734: op2 = new Operand();
07735:
07736: op2.setOperandType(Constants.IS_CONSTANT_INT);
07737:
07738: op2.setOperandValue("(" + op1.getOperandValue()
07739: + " ^ " + op.getOperandValue() + ")");
07740:
07741: opStack.push(op2);
07742:
07743: continue;
07744: //LETTER J
07745:
07746: case JvmOpCodes.JSR_W: // TODO: Generate a program with this inst
07747:
07748: addParsedOutput("Instruction Pos "
07749: + currentForIndex + "\t:- " + "jsr_w\n");
07750:
07751: // Push the Return Address on top of Stack
07752:
07753: i = i + 4;
07754:
07755: ////codeStatements+=""; // TODO To form the original stmt....HOW?
07756: continue;
07757:
07758: case JvmOpCodes.JSR: // Dummy code needed to increment i
07759: addParsedOutput("Instruction Pos "
07760: + currentForIndex + "\t:- " + "jsr\n");
07761: byte nextBytes[] = new byte[3];
07762: nextBytes[0] = info[++i];
07763: nextBytes[1] = info[++i];
07764: int offset = ((nextBytes[0] << 8) | nextBytes[1])
07765: + (i - 2);
07766:
07767: continue;
07768: ////codeStatements+=""; // TODO To form the original stmt....HOW? continue;
07769:
07770: // Letter L
07771: case JvmOpCodes.L2D:
07772: addParsedOutput("Instruction Pos "
07773: + currentForIndex + "\t:- " + "l2d\n");
07774: Operand operand = (Operand) opStack.pop();
07775: operand.setOperandValue(operand.getOperandValue());
07776: operand
07777: .setOperandType(Constants.IS_CONSTANT_DOUBLE);
07778:
07779: opStack.push(operand);
07780: continue;
07781: case JvmOpCodes.L2F:
07782: addParsedOutput("Instruction Pos "
07783: + currentForIndex + "\t:- " + "l2f\n");
07784: operand = opStack.getTopOfStack();
07785: op.setOperandValue(op.getOperandValue());
07786: operand.setOperandType(Constants.IS_CONSTANT_FLOAT);
07787:
07788: opStack.push(operand);
07789: continue;
07790: case JvmOpCodes.L2I:
07791: addParsedOutput("Instruction Pos "
07792: + currentForIndex + "\t:- " + "l2i\n");
07793: operand = opStack.getTopOfStack();
07794: op.setOperandValue("(int)" + "("
07795: + op.getOperandValue() + ")");
07796: operand.setOperandType(Constants.IS_CONSTANT_INT);
07797:
07798: opStack.push(operand);
07799: continue;
07800: case JvmOpCodes.LADD:
07801: addParsedOutput("Instruction Pos "
07802: + currentForIndex + "\t:- " + "ladd\n");
07803: Operand operand1 = opStack.getTopOfStack();
07804: Operand operand2 = opStack.getTopOfStack();
07805: Object result = "(" + operand1.getOperandValue()
07806: + "+" + operand2.getOperandValue() + ")";
07807: op = new Operand();
07808: op.setOperandType(Constants.IS_CONSTANT_LONG);
07809: op.setOperandValue(result);
07810: //(Constants.CATEGORY2);
07811: opStack.push(op);
07812: continue;
07813: case JvmOpCodes.LALOAD:
07814: addParsedOutput("Instruction Pos "
07815: + currentForIndex + "\t:- " + "laload\n");
07816: Operand index = opStack.getTopOfStack();
07817: Operand arRef = opStack.getTopOfStack();
07818: result = arRef.getOperandValue() + "["
07819: + index.getOperandValue() + "]";
07820: op = new Operand();
07821: op.setOperandType(Constants.IS_CONSTANT_LONG);
07822: op.setOperandValue(result);
07823: //(Constants.CATEGORY2);
07824: opStack.push(op);
07825: continue;
07826: case JvmOpCodes.LAND:
07827: addParsedOutput("Instruction Pos "
07828: + currentForIndex + "\t:- " + "land\n");
07829: operand1 = opStack.getTopOfStack();
07830: operand2 = opStack.getTopOfStack();
07831: result = "(" + operand1.getOperandValue() + " & "
07832: + operand2.getOperandValue() + ")";
07833: op = new Operand();
07834: op.setOperandType(Constants.IS_CONSTANT_LONG);
07835: //(Constants.CATEGORY2);
07836: op.setOperandValue(result);
07837: opStack.push(op);
07838: continue;
07839: case JvmOpCodes.LASTORE:
07840: addParsedOutput("Instruction Pos "
07841: + currentForIndex + "\t:- " + "lastore\n");
07842: Operand value = opStack.getTopOfStack();
07843: index = opStack.getTopOfStack();
07844: arRef = opStack.getTopOfStack();
07845: java.lang.String stmt = arRef.getOperandValue()
07846: + "[" + index.getOperandValue() + "]"
07847: + " = " + value.getOperandValue();
07848: if (stmt.indexOf(";") == -1)
07849: stmt += ";\n";
07850: //codeStatements+=Util.formatDecompiledStatement(stmt);continue;
07851: case JvmOpCodes.LCMP:
07852: addParsedOutput("Instruction Pos "
07853: + currentForIndex + "\t:- " + "lcmp\n");
07854: handleLCMP(opStack, info);
07855: continue;
07856:
07857: case JvmOpCodes.LCONST_0:
07858: addParsedOutput("Instruction Pos "
07859: + currentForIndex + "\t:- " + "lconst_0\n");
07860: handleLCONST(opStack, "0");
07861:
07862: continue;
07863: case JvmOpCodes.LCONST_1:
07864: addParsedOutput("Instruction Pos "
07865: + currentForIndex + "\t:- " + "lconst_1\n");
07866: handleLCONST(opStack, "1");
07867: continue;
07868: case JvmOpCodes.LDC:
07869:
07870: opValueI = info[++i];
07871:
07872: // Important Fix
07873: if (opValueI < 0)
07874: opValueI += 256;
07875:
07876: type = -1;
07877: constInt = cd
07878: .getINTPrimitiveAtCPoolPosition(opValueI);
07879: if (constInt == null) {
07880: constFloat = cd
07881: .getFloatPrimitiveAtCPoolPosition(opValueI);
07882: if (constFloat == null) {
07883: constString = cd
07884: .getStringsAtCPoolPosition(opValueI);
07885: stringLiteral = cd
07886: .getUTF8String(constString
07887: .getUtf8pointer());
07888: if (constString == null) {
07889: //ERROR CONDITION
07890: } else {
07891: type = Constants.IS_OBJECT_REF;
07892: }
07893: } else {
07894: type = Constants.IS_CONSTANT_FLOAT;
07895: }
07896: } else {
07897: type = Constants.IS_CONSTANT_INT;
07898: }
07899: op = new Operand();
07900: op.setOperandType(type);
07901: if (type == Constants.IS_CONSTANT_INT) {
07902: op.setOperandValue(new Integer(constInt
07903: .getValue()));
07904: op.setClassType("int");
07905: addParsedOutput("Instruction Pos "
07906: + currentForIndex + "\t:- " + "ldc "
07907: + opValueI + " (" + constInt.getValue()
07908: + ")\n");
07909: }
07910: if (type == Constants.IS_CONSTANT_FLOAT) {
07911: op.setOperandValue(new Float(constFloat
07912: .getValue()));
07913: op.setClassType("float");
07914: addParsedOutput("Instruction Pos "
07915: + currentForIndex + "\t:- " + "ldc "
07916: + opValueI + " ("
07917: + constFloat.getValue() + ")\n");
07918: }
07919: if (type == Constants.IS_OBJECT_REF) {
07920: op.setOperandValue("\"" + stringLiteral + "\"");
07921: op.setClassType("String");
07922: addParsedOutput("Instruction Pos "
07923: + currentForIndex + "\t:- " + "ldc "
07924: + opValueI + " (" + stringLiteral
07925: + ")\n");
07926: }
07927: //(Constants.CATEGORY1);
07928: opStack.push(op);
07929: continue;
07930: case JvmOpCodes.LDC_W:
07931:
07932: /* temp1=info[++i];
07933: temp2=info[++i];
07934: opValueI = ((temp1<<8)|temp2);
07935: if(opValueI < 0)opValueI=(temp1+1)*256-Math.abs(temp2);*/
07936: opValueI = getOffset(info, i);
07937: i += 2;
07938:
07939: constInt = null;
07940: constFloat = null;
07941: type = -1;
07942: constInt = cd
07943: .getINTPrimitiveAtCPoolPosition(opValueI);
07944: if (constInt == null) {
07945: constFloat = cd
07946: .getFloatPrimitiveAtCPoolPosition(opValueI);
07947: if (constFloat == null) {
07948: constString = cd
07949: .getStringsAtCPoolPosition(opValueI);
07950: stringLiteral = cd
07951: .getUTF8String(constString
07952: .getUtf8pointer());
07953: if (stringLiteral == null
07954: || stringLiteral.length() == 0) {
07955: //ERROR CONDITION
07956: } else {
07957: type = Constants.IS_OBJECT_REF;
07958: }
07959: } else {
07960: type = Constants.IS_CONSTANT_FLOAT;
07961: }
07962: } else {
07963: type = Constants.IS_CONSTANT_INT;
07964: }
07965: op = new Operand();
07966: op.setOperandType(type);
07967: if (type == Constants.IS_CONSTANT_INT) {
07968: op.setOperandValue(new Integer(constInt
07969: .getValue()));
07970: op.setClassType("int");
07971: addParsedOutput("Instruction Pos "
07972: + currentForIndex + "\t:- " + "ldc_w "
07973: + constInt.getValue() + "\n");
07974: }
07975: if (type == Constants.IS_CONSTANT_FLOAT) {
07976: op.setOperandValue(new Float(constFloat
07977: .getValue()));
07978: op.setClassType("float");
07979: addParsedOutput("Instruction Pos "
07980: + currentForIndex + "\t:- " + "ldc_w "
07981: + constFloat.getValue() + "\n");
07982: }
07983: if (type == Constants.IS_OBJECT_REF) {
07984: op.setOperandValue(stringLiteral);
07985: op.setClassType("String");
07986: addParsedOutput("Instruction Pos "
07987: + currentForIndex + "\t:- " + "ldc_w "
07988: + stringLiteral + "\n");
07989: }
07990: //(Constants.CATEGORY1);
07991: opStack.push(op);
07992: continue;
07993: case JvmOpCodes.LDC2_W:
07994: opValueI = getOffset(info, i);
07995:
07996: i += 2;
07997: constLong = null;
07998: constDouble = null;
07999: type = -1;
08000: constLong = cd
08001: .getLongPrimitiveAtCPoolPosition(opValueI);
08002: if (constLong == null) {
08003: constDouble = cd
08004: .getDoublePrimitiveAtCPoolPosition(opValueI);
08005: if (constDouble == null) {
08006: // ERROR CONDITION
08007: } else {
08008: type = Constants.IS_CONSTANT_DOUBLE;
08009: }
08010: } else {
08011: type = Constants.IS_CONSTANT_LONG;
08012: }
08013: op = new Operand();
08014: op.setOperandType(type);
08015: if (type == Constants.IS_CONSTANT_DOUBLE) {
08016: op.setOperandValue(new Double(constDouble
08017: .getValue()));
08018:
08019: }
08020: if (type == Constants.IS_CONSTANT_LONG) {
08021: op.setOperandValue(new Long(constLong
08022: .getValue())
08023: + "L");
08024: }
08025: //(Constants.CATEGORY2);
08026: opStack.push(op);
08027: java.lang.String Value = "";
08028: if (type == Constants.IS_CONSTANT_LONG) {
08029: Value = "[Long " + constLong.getValue() + "L]";
08030: addParsedOutput("Instruction Pos "
08031: + currentForIndex + "\t:- " + "ldc2_w "
08032: + opValueI + " " + Value + "\n");
08033: }
08034: if (type == Constants.IS_CONSTANT_DOUBLE) {
08035: Value = "[Double " + constDouble.getValue()
08036: + "]";
08037: addParsedOutput("Instruction Pos "
08038: + currentForIndex + "\t:- " + "ldc2_w "
08039: + opValueI + " " + Value + "\n");
08040: }
08041:
08042: continue;
08043:
08044: case JvmOpCodes.LDIV:
08045: addParsedOutput("Instruction Pos "
08046: + currentForIndex + "\t:- " + "ldiv\n");
08047: handleLDIV(opStack);
08048:
08049: continue;
08050: case JvmOpCodes.LLOAD:
08051: opValueI = info[++i];
08052: if (opValueI < 0)
08053: opValueI += 256;
08054: local = getLocalVariable(opValueI, "load", "long",
08055: false, currentForIndex);
08056: if (local != null && cd.isClassCompiledWithMinusG()) {
08057: addParsedOutput("Instruction Pos "
08058: + currentForIndex + "\t:- " + "lload"
08059: + opValueI + " THIS LocalVariable:- "
08060: + local.getVarName() + "\n");
08061: } else {
08062: addParsedOutput("Instruction Pos "
08063: + currentForIndex + "\t:- " + "lload"
08064: + opValueI + "\n");
08065: }
08066: if (local != null) {
08067: prevLocalGenerated = local;
08068:
08069: op = new Operand();
08070: op.setOperandType(Constants.IS_CONSTANT_LONG);
08071: //(Constants.CATEGORY2);
08072: op.setOperandValue(local.getVarName());
08073: opStack.push(op);
08074:
08075: }
08076:
08077: continue;
08078: case JvmOpCodes.LLOAD_0:
08079: //
08080: handleSIMPLELLOAD(opStack, 0);
08081:
08082: continue;
08083: case JvmOpCodes.LLOAD_1:
08084: handleSIMPLELLOAD(opStack, 1);
08085:
08086: continue;
08087: case JvmOpCodes.LLOAD_2:
08088: handleSIMPLELLOAD(opStack, 2);
08089:
08090: continue;
08091: case JvmOpCodes.LLOAD_3:
08092: handleSIMPLELLOAD(opStack, 3);
08093:
08094: continue;
08095: case JvmOpCodes.LMUL:
08096:
08097: addParsedOutput("Instruction Pos "
08098: + currentForIndex + "\t:- " + " lmul\n");
08099: operand1 = opStack.getTopOfStack();
08100: operand2 = opStack.getTopOfStack();
08101:
08102: op = new Operand();
08103: op.setOperandType(Constants.IS_CONSTANT_LONG);
08104: //(Constants.CATEGORY2);
08105: op.setOperandValue("(" + operand1.getOperandValue()
08106: + "*" + operand2.getOperandValue() + ")");
08107: opStack.push(op);
08108:
08109: continue;
08110: case JvmOpCodes.LNEG:
08111: addParsedOutput("Instruction Pos "
08112: + currentForIndex + "\t:- " + " lneg\n");
08113: operand1 = opStack.getTopOfStack();
08114:
08115: op = new Operand();
08116: op.setOperandType(Constants.IS_CONSTANT_LONG);
08117: //(Constants.CATEGORY2);
08118: op.setOperandValue("-" + "("
08119: + operand1.getOperandValue() + ")");
08120: opStack.push(op);
08121:
08122: continue;
08123: case JvmOpCodes.LOOKUPSWITCH:
08124:
08125: int lookupSwitchPos = i;
08126: int leave_bytes = (4 - (i % 4)) - 1;
08127: for (int indx = 0; indx < leave_bytes; indx++) {
08128: i++;
08129: }
08130: // Read Default
08131: int Default = getSwitchOffset(info, i, "");//(info[++i] << 24) | (info[++i] << 16) | (info[++i] << 8) |info[++i];
08132: i = i + 4;
08133: int numberOfLabels = getSwitchOffset(info, i, "");//(info[++i] << 24) | (info[++i] << 16) | (info[++i] << 8) |info[++i];
08134: i += 4;
08135: //int high=(info[++i] << 24) | (info[++i] << 16) | (info[++i] << 8) |info[++i];
08136: //int numberOfOffsets=(high-low)+1;
08137: int offsetValues[] = new int[numberOfLabels];
08138: int labels[] = new int[numberOfLabels];
08139: for (start = 0; start < numberOfLabels; start++) {
08140: int label = getSwitchOffset(info, i, "label");//(info[++i] << 24) | (info[++i] << 16) | (info[++i] << 8) |info[++i];
08141: i += 4;
08142: int offsetVal = getSwitchOffset(info, i, "");//(info[++i] << 24) | (info[++i] << 16) | (info[++i] << 8) |info[++i];
08143: i += 4;
08144: labels[start] = label;
08145: offsetValues[start] = offsetVal;
08146:
08147: }
08148:
08149: Object ob = opStack.getTopOfStack()
08150: .getOperandValue();
08151: // Add to each offset
08152: for (start = 0; start < numberOfLabels; start++) {
08153:
08154: offsetValues[start] = offsetValues[start]
08155: + lookupSwitchPos;
08156: }
08157: Default += lookupSwitchPos;
08158: java.lang.StringBuffer desc = new StringBuffer("");
08159: desc.append("[DEFAULT :- " + Default + "]\n");
08160: for (int c = 0; c < labels.length; c++) {
08161: desc.append("[LABEL " + (c + 1) + ":- "
08162: + labels[c] + " OFFSET :- "
08163: + offsetValues[c] + "]\n");
08164: }
08165:
08166: addParsedOutput("Instruction Pos "
08167: + currentForIndex + "\t:- "
08168: + " lookupswitch \n" + desc + "\n\n");
08169: //start=low;
08170: tempString = "switch(" + ob.toString() + ")\n{\n ";
08171: //codeStatements+=Util.formatDecompiledStatement(tempString);
08172:
08173: continue;
08174: case JvmOpCodes.LOR:
08175: addParsedOutput("Instruction Pos "
08176: + currentForIndex + "\t:- " + "lor\n");
08177: operand1 = opStack.getTopOfStack();
08178: operand2 = opStack.getTopOfStack();
08179:
08180: op = new Operand();
08181: op.setOperandType(Constants.IS_CONSTANT_LONG);
08182: op.setOperandValue("(" + operand1.getOperandValue()
08183: + "|" + operand2.getOperandValue() + ")");
08184: //(Constants.CATEGORY2);
08185: opStack.push(op);
08186:
08187: continue;
08188: case JvmOpCodes.LREM:
08189: addParsedOutput("Instruction Pos "
08190: + currentForIndex + "\t:- " + "lrem\n");
08191: operand1 = opStack.getTopOfStack();
08192: operand2 = opStack.getTopOfStack();
08193:
08194: op = new Operand();
08195: op.setOperandType(Constants.IS_CONSTANT_LONG);
08196: //(Constants.CATEGORY2);
08197: op.setOperandValue("(" + operand2.getOperandValue()
08198: + "%" + operand1.getOperandValue() + ")");
08199: opStack.push(op);
08200: continue;
08201: case JvmOpCodes.LRETURN:
08202: addParsedOutput("Instruction Pos "
08203: + currentForIndex + "\t:- " + "lreturn\n");
08204: oktoadd = true;
08205: mapIT = returnsAtI.entrySet().iterator();
08206: while (mapIT.hasNext()) {
08207: Map.Entry entry = (Map.Entry) mapIT.next();
08208: Object key = entry.getKey();
08209: Object retStatus = entry.getValue().toString();
08210: if (key instanceof Integer) {
08211: Integer pos = (Integer) key;
08212: int temp = pos.intValue();
08213: if (temp == i) {
08214: if (retStatus.equals("true")) {
08215:
08216: oktoadd = false;
08217: break;
08218: }
08219: }
08220: }
08221:
08222: }
08223:
08224: if (!oktoadd) {
08225: returnsAtI.remove(new Integer(i));
08226: }
08227:
08228: if (oktoadd && opStack.size() > 0) {
08229: op = opStack.getTopOfStack();
08230: tempString = "return "
08231: + op.getOperandValue().toString()
08232: + ";\n";
08233: //codeStatements+=Util.formatDecompiledStatement(tempString);
08234: }
08235:
08236: //behaviour.getParentBehaviour().getOpStack().push(op);
08237: continue;
08238: case JvmOpCodes.LSHL:
08239: addParsedOutput("Instruction Pos "
08240: + currentForIndex + "\t:- " + "lshl\n");
08241: operand1 = opStack.getTopOfStack();
08242: operand2 = opStack.getTopOfStack();
08243:
08244: op = new Operand();
08245: op.setOperandType(Constants.IS_CONSTANT_LONG);
08246: op.setCategory(Constants.CATEGORY2);
08247: op.setOperandValue("(" + operand2.getOperandValue()
08248: + "<<" + operand1.getOperandValue() + ")");
08249: opStack.push(op);
08250:
08251: continue;
08252: case JvmOpCodes.LSHR:
08253: addParsedOutput("Instruction Pos "
08254: + currentForIndex + "\t:- " + "lshr\n");
08255: operand1 = opStack.getTopOfStack();
08256: operand2 = opStack.getTopOfStack();
08257:
08258: op = new Operand();
08259: op.setOperandType(Constants.IS_CONSTANT_LONG);
08260: op.setOperandValue("(" + operand2.getOperandValue()
08261: + ">>" + operand1.getOperandValue() + ")");
08262: opStack.push(op);
08263:
08264: continue;
08265: case JvmOpCodes.LSTORE:
08266: int pos = info[++i];
08267: if (pos < 0)
08268: pos += 256;
08269:
08270: local = getLocalVariable(pos, "store", "long",
08271: false, currentForIndex);
08272: if (local != null && cd.isClassCompiledWithMinusG()) {
08273: addParsedOutput("Instruction Pos "
08274: + currentForIndex + "\t:- " + "lstore "
08275: + pos + " THIS LocalVariable:- "
08276: + local.getVarName() + "\n");
08277: } else
08278: addParsedOutput("Instruction Pos "
08279: + currentForIndex + "\t:- " + "lstore "
08280: + pos + "\n");
08281:
08282: if (local != null && !doNotPop) {
08283: operand1 = opStack.getTopOfStack();
08284: prevLocalGenerated = local;
08285: boolean push = isPrevInstDup(info,
08286: currentForIndex);
08287: if (!push) {
08288: if (!local.isDeclarationGenerated()) {
08289: local.setBlockIndex(blockLevel);
08290: tempString = local.getDataType() + " "
08291: + local.getVarName() + "="
08292: + operand1.getOperandValue()
08293: + ";\n";
08294: //codeStatements +=Util.formatDecompiledStatement(tempString);
08295: local.setDeclarationGenerated(true);
08296: } else {
08297: tempString = local.getVarName() + "="
08298: + operand1.getOperandValue()
08299: + ";\n";
08300: //codeStatements +=Util.formatDecompiledStatement(tempString);
08301: }
08302: } else {
08303: if (info[currentForIndex - 1] == JvmOpCodes.DUP)
08304: opStack.getTopOfStack();
08305: if (info[currentForIndex - 1] == JvmOpCodes.DUP2) {
08306: opStack.getTopOfStack();
08307: opStack.getTopOfStack();
08308: }
08309:
08310: //codeStatements +=Util.formatDecompiledStatement("("+local.getVarName()+"=("+operand1.getOperandValue()+"));\n");
08311: op = createOperand(local.getVarName());
08312: opStack.push(op);
08313: }
08314: }
08315: if (doNotPop == true)
08316: doNotPop = false;
08317: continue;
08318: case JvmOpCodes.LSTORE_0:
08319: codes = new StringBuffer("");
08320: handleSimpleLStoreCase(opStack, info, codes, 0);
08321: //codeStatements+=codes.toString();
08322:
08323: continue;
08324: case JvmOpCodes.LSTORE_1:
08325:
08326: codes = new StringBuffer("");
08327: handleSimpleLStoreCase(opStack, info, codes, 1);
08328: //codeStatements+=codes.toString();
08329: continue;
08330: case JvmOpCodes.LSTORE_2:
08331:
08332: codes = new StringBuffer("");
08333: handleSimpleLStoreCase(opStack, info, codes, 2);
08334: //codeStatements+=codes.toString();
08335:
08336: continue;
08337: case JvmOpCodes.LSTORE_3:
08338:
08339: codes = new StringBuffer("");
08340: handleSimpleLStoreCase(opStack, info, codes, 3);
08341: //codeStatements+=codes.toString();
08342: continue;
08343: case JvmOpCodes.LSUB:
08344: addParsedOutput("Instruction Pos "
08345: + currentForIndex + "\t:- " + " lsub\n");
08346: operand1 = opStack.getTopOfStack();
08347: operand2 = opStack.getTopOfStack();
08348:
08349: result = "(" + operand2.getOperandValue() + "-"
08350: + operand1.getOperandValue() + ")";
08351: op = new Operand();
08352: op.setOperandType(Constants.IS_CONSTANT_LONG);
08353:
08354: op.setOperandValue(result);
08355: opStack.push(op);
08356:
08357: continue;
08358: case JvmOpCodes.LUSHR:
08359: addParsedOutput("Instruction Pos "
08360: + currentForIndex + "\t:- " + " lushr\n");
08361: operand1 = opStack.getTopOfStack();
08362: operand2 = opStack.getTopOfStack();
08363: result = "(" + operand2.getOperandValue() + ">>>"
08364: + operand1.getOperandValue() + ")";
08365: op = new Operand();
08366: op.setOperandType(Constants.IS_CONSTANT_LONG);
08367: op.setCategory(Constants.CATEGORY2);
08368: op.setOperandValue(result);
08369: opStack.push(op);
08370:
08371: continue;
08372: case JvmOpCodes.LXOR:
08373: addParsedOutput("Instruction Pos "
08374: + currentForIndex + "\t:- " + " lxor\n");
08375: operand1 = opStack.getTopOfStack();
08376: operand2 = opStack.getTopOfStack();
08377:
08378: result = "(" + operand2.getOperandValue() + "^"
08379: + operand1.getOperandValue() + ")";
08380: op = new Operand();
08381: op.setOperandType(Constants.IS_CONSTANT_LONG);
08382: op.setOperandValue(result);
08383: op.setCategory(Constants.CATEGORY2);
08384: opStack.push(op);
08385:
08386: continue;
08387:
08388: // Letter M
08389: case JvmOpCodes.MONITORENTER:
08390: addParsedOutput("Instruction Pos "
08391: + currentForIndex + "\t:- "
08392: + " monitorenter\n");
08393: blockLevel++;
08394: op = opStack.getTopOfStack();
08395: tempString = "synchronized(" + op.getOperandValue()
08396: + ")\n{\n";
08397: //codeStatements+=Util.formatDecompiledStatement(tempString);
08398: currentMonitorEnterPos = currentForIndex;
08399:
08400: continue;
08401: case JvmOpCodes.MONITOREXIT:
08402: addParsedOutput("Instruction Pos "
08403: + currentForIndex + "\t:- "
08404: + " monitorexitr\n");
08405: if (info[i + 1] != JvmOpCodes.ATHROW)
08406: op = opStack.getTopOfStack();
08407: //Shutdown s;
08408: // Note: i is not icremented
08409: /*if(info[i+1]!=JvmOpCodes.ATHROW)
08410: {
08411: //codeStatements+="\n";
08412:
08413: //codeStatements+=Util.formatDecompiledStatement("}\n");
08414: } */
08415:
08416: continue;
08417: case JvmOpCodes.MULTIANEWARRAY:
08418: multinewound = true;
08419: classIndex = getOffset(info, i);//(info[++i] << 8) | info[++i]);
08420: i += 2;
08421: ClassInfo cinfo = cd
08422: .getClassInfoAtCPoolPosition(classIndex);
08423: java.lang.String temp = cd.getUTF8String(cinfo
08424: .getUtf8pointer());
08425: ;
08426:
08427: int lastBracket = temp.lastIndexOf("[");
08428: temp = temp.substring(lastBracket + 1);
08429: temp = getArrayType(temp);
08430:
08431: int dimensions = info[++i];
08432: int Temp = i + 1;
08433: int nextindex = -1;
08434: boolean ty = false;
08435: if (info[Temp] == JvmOpCodes.ASTORE) {
08436: nextindex = info[(Temp + 1)];
08437: ty = true;
08438: }
08439: if (info[Temp] == JvmOpCodes.ASTORE_0) {
08440:
08441: nextindex = 0;
08442: }
08443: if (info[Temp] == JvmOpCodes.ASTORE_1) {
08444:
08445: nextindex = 1;
08446: }
08447: if (info[Temp] == JvmOpCodes.ASTORE_2) {
08448:
08449: nextindex = 2;
08450: }
08451: if (info[Temp] == JvmOpCodes.ASTORE_3) {
08452:
08453: nextindex = 3;
08454: }
08455: int d = -1;
08456: int cnt = -1;
08457: if (variableDimAss != null) {
08458: Integer n = (Integer) variableDimAss
08459: .get(new Integer(nextindex));
08460: d = -1;
08461:
08462: if (n != null) {
08463: d = n.intValue();
08464: }
08465: } else {
08466: if (cd.isClassCompiledWithMinusG()) {
08467: LocalVariable lv;
08468: java.lang.String tpe = null;
08469:
08470: if (ty) {
08471: lv = structure.getVariabelAtIndex(
08472: nextindex, Temp + 2);
08473: if (lv != null)
08474: tpe = lv.getDataType();
08475:
08476: } else {
08477: lv = structure.getVariabelAtIndex(
08478: nextindex, Temp + 1);
08479: if (lv != null)
08480: tpe = lv.getDataType();
08481: }
08482: if (tpe != null) {
08483: int openb = tpe.indexOf("[");
08484:
08485: if (openb != -1) {
08486: cnt = 1;
08487:
08488: while ((openb + 1) < tpe.length()) {
08489:
08490: char ch = tpe
08491: .charAt((openb + 1));
08492: if (ch == '[') {
08493: cnt++;
08494:
08495: }
08496: openb++;
08497: }
08498:
08499: }
08500: }
08501: }
08502:
08503: }
08504:
08505: Operand ops[] = new Operand[dimensions];
08506: java.lang.String dimenPart = "[";
08507: for (int indx = 0; indx < dimensions; indx++) {
08508: ops[indx] = opStack.getTopOfStack();
08509:
08510: }
08511:
08512: // Reverse Array
08513: Operand opsTemp[] = new Operand[dimensions];
08514: int lastPos = dimensions - 1;
08515: for (int indx = 0; indx < dimensions; indx++) {
08516: opsTemp[indx] = ops[lastPos];
08517: lastPos--;
08518:
08519: }
08520: for (int indx = 0; indx < dimensions; indx++) {
08521: dimenPart += opsTemp[indx].getOperandValue()
08522: + "]";
08523: if (indx != dimensions - 1)
08524: dimenPart += "[";
08525: }
08526: if (d > dimensions) {
08527: int rem = d - dimensions;
08528: for (int zz = 0; zz < rem; zz++) {
08529: dimenPart += "[]";
08530: }
08531: }
08532:
08533: if (cnt > dimensions && d == -1) {
08534: int rem = cnt - dimensions;
08535: for (int zz = 0; zz < rem; zz++) {
08536: dimenPart += "[]";
08537: }
08538: }
08539: if (cd.isClassCompiledWithMinusG() == false) {
08540: variableDimAss.put(new Integer(nextindex),
08541: new Integer(dimensions));
08542: }
08543:
08544: op2 = new Operand();
08545: op2.setClassType(temp);
08546: temp = "new " + temp + dimenPart;
08547:
08548: addParsedOutput("Instruction Pos "
08549: + currentForIndex + "\t:- "
08550: + " MULTIANEWARRAY :- " + temp + dimenPart
08551: + "\n");
08552: op2.setCategory(Constants.CATEGORY1);
08553: op2.setOperandType(Constants.IS_ARRAY_REF);
08554: op2.setOperandValue(temp);
08555: op2.setMultiDimension(true);
08556: opStack.push(op2);
08557: continue;
08558: // letter N
08559: case JvmOpCodes.NEW:
08560: boolean nextisnew = true;
08561: nextisnew = isNewFollowedByNew(info,
08562: currentForIndex); // returns false for invoke
08563: newfound = true;
08564: int newpos = i;
08565:
08566: // classIndex=((info[++i] << 8)|info[++i]);
08567: /*temp1=info[++i];
08568: temp2=info[++i];
08569: classIndex=((temp1 << 8) | temp2);
08570: if(classIndex < 0)classIndex=(temp1+1)*256-Math.abs(temp2);*/
08571: classIndex = getOffset(info, i);
08572: i += 2;
08573:
08574: cinfo = cd.getClassInfoAtCPoolPosition(classIndex);
08575: op = new Operand();
08576: java.lang.String Type = cd.getUTF8String(
08577: cinfo.getUtf8pointer()).replace('/', '.');
08578: registerInnerClassIfAny(Type.replace('.', '/'));
08579: op.setOperandType(Constants.IS_OBJECT_REF);
08580: java.lang.String Reference = "JdecGenerated" + i;
08581: java.lang.String newTemp = "";
08582: //java.lang.String objParams=getObjectParameters(newpos,info,methodLookUp);
08583: if (Configuration.getShowImport().equals("false")
08584: && !nextisnew)
08585: newTemp = Type + " " + Reference + "=new "
08586: + Type.trim();
08587: if (Configuration.getShowImport().equals("true")
08588: && !nextisnew) {
08589: java.lang.String fullName = Type;
08590: java.lang.String simpleName = "";
08591: int lastdot = fullName.lastIndexOf(".");
08592: if (lastdot != -1) {
08593: simpleName = fullName
08594: .substring(lastdot + 1);
08595: Type = simpleName;
08596: ConsoleLauncher.addImportClass(fullName);
08597: }
08598: newTemp = Type + " " + Reference + "=new "
08599: + Type.trim();
08600: }
08601: if (Configuration.getShowImport().equals("false")
08602: && nextisnew)
08603: newTemp = "new " + Type.trim() + "(";
08604: if (Configuration.getShowImport().equals("true")
08605: && nextisnew) {
08606: java.lang.String fullName = Type;
08607: java.lang.String simpleName = "";
08608: int lastdot = fullName.lastIndexOf(".");
08609: if (lastdot != -1) {
08610: simpleName = fullName
08611: .substring(lastdot + 1);
08612: Type = simpleName;
08613: ConsoleLauncher.addImportClass(fullName);
08614: }
08615: newTemp = "new " + Type.trim() + "(";
08616: }
08617: newTemp = newTemp.trim();
08618: addParsedOutput("Instruction Pos "
08619: + currentForIndex + "\t:- " + " new :- "
08620: + Type);
08621: if (!nextisnew) {
08622: //codeStatements+="\n"+Util.formatDecompiledStatement(newTemp);
08623: op.setOperandValue(Reference);
08624: } else {
08625: op.setOperandValue(newTemp);
08626: }
08627: op.setClassType(Type);
08628: opStack.push(op);
08629: continue;
08630: case JvmOpCodes.NEWARRAY:
08631:
08632: handleNEWARRAYCase(info);
08633: i++;
08634:
08635: continue;
08636: case JvmOpCodes.NOP:
08637: addParsedOutput("Instruction Pos "
08638: + currentForIndex + "\t:- " + " nop \n");
08639: continue;
08640:
08641: // letter p
08642:
08643: case JvmOpCodes.POP:
08644: addParsedOutput("Instruction Pos "
08645: + currentForIndex + "\t:- " + " pop \n");
08646: instructionPos = i;
08647: //add=checkForStartOfCatch(instructionPos,methodTries);
08648: if (opStack.size() > 0) // removed add==true
08649: {
08650: if (info[i + 1] != JvmOpCodes.GETSTATIC)
08651: opStack.getTopOfStack();
08652: }
08653: continue;
08654: case JvmOpCodes.POP2: // TODO: check this out
08655: addParsedOutput("Instruction Pos "
08656: + currentForIndex + "\t:- " + " pop2 \n");
08657: if (opStack.size() >= 3) {
08658: operand = opStack.getTopOfStack();
08659: operand = opStack.getTopOfStack();
08660: operand = opStack.getTopOfStack();
08661: }
08662: // BigInteger n;
08663: continue;
08664: case JvmOpCodes.PUTFIELD: //put
08665:
08666: pos = getOffset(info, i);
08667: i += 2;
08668: fref = cd.getFieldRefAtCPoolPosition(pos);
08669: addParsedOutput("Instruction Pos "
08670: + currentForIndex + "\t:- " + " putfield "
08671: + fref.getFieldName() + "\n");
08672: if (doNotPop == false) {
08673: value = opStack.getTopOfStack();
08674: Operand objRef = opStack.getTopOfStack();
08675:
08676: java.lang.String freftype = fref
08677: .getTypeoffield();
08678: StringBuffer sb = new StringBuffer("");
08679: checkForImport(objRef.getOperandValue(), sb);
08680: temp = sb.toString() + "."
08681: + fref.getFieldName() + " = "
08682: + value.getOperandValue() + ";";
08683: //codeStatements+="\n"+Util.formatDecompiledStatement(temp)+"\n";
08684: }
08685: if (doNotPop)
08686: doNotPop = false;
08687: continue;
08688: case JvmOpCodes.PUTSTATIC:
08689:
08690: pos = getOffset(info, i);
08691: i += 2;
08692: handlePUTSTATIC(pos);
08693: continue;
08694:
08695: // Letter R
08696: case JvmOpCodes.RET:
08697: pos = info[++i];
08698: addParsedOutput("Instruction Pos "
08699: + currentForIndex + "\t:- " + " ret " + pos
08700: + "\n");
08701: /* parsedString+="RET";
08702: parsedString+="\t"+pos+"\n";
08703: parsedString+="\t";parsedString+="\t";*/
08704: if (structure != null) {
08705: local = structure
08706: .getVariabelAtIndex(pos, i - 1);
08707: //TODO Check comment For RET of wide instruction
08708: }
08709: continue;
08710: case JvmOpCodes.RETURN:
08711: addParsedOutput("Instruction Pos "
08712: + currentForIndex + "\t:- " + " return\n");
08713: // parsedString+="RETURN\n";
08714: // parsedString+="\t";parsedString+="\t";
08715: handleSimpleReturn();
08716:
08717: continue;
08718:
08719: // Letter S
08720: case JvmOpCodes.SALOAD:
08721: addParsedOutput("Instruction Pos "
08722: + currentForIndex + "\t:- " + " saload\n");
08723: handleSALOAD();
08724: continue;
08725: case JvmOpCodes.SASTORE:
08726: addParsedOutput("Instruction Pos "
08727: + currentForIndex + "\t:- " + " sastore\n");
08728: handleSASTORE();
08729: continue;
08730: case JvmOpCodes.SIPUSH:
08731:
08732: handleSIPUSH(info);
08733: i += 2;
08734:
08735: continue;
08736: case JvmOpCodes.SWAP:
08737: addParsedOutput("Instruction Pos "
08738: + currentForIndex + "\t:- " + " swap\n");
08739: handleSwapInst(opStack);
08740: continue;
08741:
08742: //Letter T
08743: case JvmOpCodes.TABLESWITCH: // TODO
08744: int tableSwitchPos = i;
08745: leave_bytes = (4 - (i % 4)) - 1;
08746: for (int indx = 0; indx < leave_bytes; indx++) {
08747: i++;
08748: }
08749: // Read Default
08750: Default = getSwitchOffset(info, i, "");//(info[++i] << 24) | (info[++i] << 16) | (info[++i] << 8) |info[++i];
08751: i += 4;
08752: int low = getSwitchOffset(info, i, "label");//(info[++i] << 24) | (info[++i] << 16) | (info[++i] << 8) |info[++i];
08753: i += 4;
08754: int high = getSwitchOffset(info, i, "label");//(info[++i] << 24) | (info[++i] << 16) | (info[++i] << 8) |info[++i];
08755: i += 4;
08756: int numberOfOffsets = (high - low) + 1;
08757:
08758: offsetValues = new int[numberOfOffsets];
08759: for (start = 0; start < numberOfOffsets; start++) {
08760: int offsetVal = getSwitchOffset(info, i, "");//(info[++i] << 24) | (info[++i] << 16) | (info[++i] << 8) |info[++i];
08761: i = i + 4;
08762: offsetValues[start] = offsetVal;
08763:
08764: }
08765:
08766: ob = opStack.getTopOfStack().getOperandValue();
08767: Integer Index = null;
08768: // Add to each offset
08769: for (start = 0; start < numberOfOffsets; start++) {
08770:
08771: offsetValues[start] = offsetValues[start]
08772: + tableSwitchPos;
08773: }
08774: Default += tableSwitchPos;
08775: //parsedString+="\ntableswitch\t"+low+" "+high+": default "+Default+"\n";
08776: start = low;
08777: tempString = "switch(" + ob.toString() + ")\n{\n";
08778: addTBSWITCHtoDISSTMT(Default, offsetValues, low,
08779: high);
08780: //codeStatements+=Util.formatDecompiledStatement(tempString);
08781: //System.out.println();
08782: continue;
08783:
08784: // Letter W
08785: case JvmOpCodes.WIDE:
08786:
08787: byte nextEntry = info[++i];
08788: addParsedOutput("Instruction Pos "
08789: + currentForIndex + "\t:- " + " wide"
08790: + nextEntry + "\n");
08791: if (nextEntry == JvmOpCodes.IINC) {
08792: int localVarPos = getOffset(info, i);
08793: i += 2;
08794: constant = getOffset(info, i);
08795: i += 2;
08796:
08797: local = getLocalVariable(localVarPos, "load",
08798: "int", false, currentForIndex);
08799:
08800: if (local != null) {
08801: temp = local.getVarName() + " += ("
08802: + constant + ");";
08803: //codeStatements+="\n"+Util.formatDecompiledStatement(temp)+"\n";
08804: }
08805:
08806: } else {
08807: // parsedString+="WIDE\n";
08808: switch (nextEntry) {
08809: case JvmOpCodes.ILOAD:
08810:
08811: pos = getOffset(info, i);
08812: i += 2;
08813:
08814: local = getLocalVariable(pos, "load",
08815: "int", false, currentForIndex);
08816: if (local != null) {
08817: prevLocalGenerated = local;
08818: op = new Operand();
08819: op
08820: .setOperandType(Constants.IS_CONSTANT_INT);
08821: op.setOperandValue(local.getVarName());
08822: opStack.push(op);
08823: }
08824:
08825: break;
08826: case JvmOpCodes.FLOAD:
08827: pos = getOffset(info, i);
08828: i += 2;
08829:
08830: local = getLocalVariable(pos, "load",
08831: "float", false, currentForIndex);
08832: if (local != null) {
08833: prevLocalGenerated = local;
08834: op = new Operand();
08835: op
08836: .setOperandType(Constants.IS_CONSTANT_FLOAT);
08837: op.setOperandValue(local.getVarName());
08838: opStack.push(op);
08839: }
08840:
08841: //parsedString+="FLOAD "+pos+"\n";
08842: break;
08843: case JvmOpCodes.ALOAD:
08844: pos = getOffset(info, i);
08845: i += 2;
08846:
08847: local = getLocalVariable(pos, "load",
08848: "java.lang.Object", false,
08849: currentForIndex);
08850: if (local != null) {
08851: prevLocalGenerated = local;
08852: op = new Operand();
08853: op
08854: .setOperandType(Constants.IS_OBJECT_REF);
08855: op.setOperandValue(local.getVarName());
08856: opStack.push(op);
08857: }
08858:
08859: //parsedString+="ALOAD"+"\n";
08860: break;
08861: case JvmOpCodes.LLOAD:
08862:
08863: pos = getOffset(info, i);
08864: i += 2;
08865:
08866: local = getLocalVariable(pos, "load",
08867: "long", false, currentForIndex);
08868: if (local != null) {
08869: prevLocalGenerated = local;
08870: op = new Operand();
08871: op
08872: .setOperandType(Constants.IS_CONSTANT_LONG);
08873: op.setOperandValue(local.getVarName());
08874: opStack.push(op);
08875: }
08876:
08877: break;
08878: case JvmOpCodes.DLOAD:
08879: pos = getOffset(info, i);
08880: i += 2;
08881:
08882: local = getLocalVariable(pos, "load",
08883: "double", false, currentForIndex);
08884: if (local != null) {
08885: prevLocalGenerated = local;
08886: op = new Operand();
08887: op
08888: .setOperandType(Constants.IS_CONSTANT_DOUBLE);
08889: op.setOperandValue(local.getVarName());
08890: opStack.push(op);
08891: }
08892:
08893: // parsedString+="DLOAD"+"\n";
08894: break;
08895: case JvmOpCodes.ISTORE:
08896:
08897: pos = getOffset(info, i);
08898: i += 2;
08899: operand = opStack.getTopOfStack();
08900:
08901: local = getLocalVariable(pos, "store",
08902: "int", false, currentForIndex);
08903: if (local != null) {
08904: if (local.isDeclarationGenerated() == false) {
08905: temp = local.getDataType() + " "
08906: + local.getVarName() + "= "
08907: + operand.getOperandValue()
08908: + ";";
08909: local.setDeclarationGenerated(true);
08910: } else {
08911: temp = local.getVarName() + "= "
08912: + operand.getOperandValue()
08913: + ";";
08914: }
08915: //codeStatements+=Util.formatDecompiledStatement(temp);
08916: }
08917: break;
08918: case JvmOpCodes.FSTORE:
08919: temp = "";
08920: pos = getOffset(info, i);
08921: i += 2;
08922: operand = opStack.getTopOfStack();
08923:
08924: local = getLocalVariable(pos, "store",
08925: "float", false, currentForIndex);
08926: if (local != null) {
08927: if (local.isDeclarationGenerated() == false) {
08928: temp = local.getDataType() + " "
08929: + local.getVarName() + "= "
08930: + operand.getOperandValue()
08931: + ";";
08932: local.setDeclarationGenerated(true);
08933: } else {
08934: temp = local.getVarName() + "= "
08935: + operand.getOperandValue()
08936: + ";";
08937: }
08938: }
08939:
08940: //codeStatements+=Util.formatDecompiledStatement(temp);
08941: break;
08942: case JvmOpCodes.ASTORE:
08943: pos = getOffset(info, i);
08944: i += 2;
08945: operand = opStack.getTopOfStack();
08946:
08947: temp = "";
08948: local = getLocalVariable(pos, "store",
08949: "java.lang.Object", false,
08950: currentForIndex);
08951: if (local != null) {
08952: if (local.isDeclarationGenerated() == false) {
08953: if (local.wasCreated()
08954: && operand != null
08955: && operand.getClassType()
08956: .trim().length() > 0)
08957: local.setDataType(operand
08958: .getClassType());
08959: temp = local.getDataType() + " "
08960: + local.getVarName() + "= "
08961: + operand.getOperandValue()
08962: + ";";
08963: local.setDeclarationGenerated(true);
08964: } else {
08965: temp = local.getVarName() + "= "
08966: + operand.getOperandValue()
08967: + ";";
08968: }
08969: }
08970:
08971: //codeStatements+=Util.formatDecompiledStatement(temp);
08972: // parsedString+="ASTORE"+"\n";
08973: break;
08974: case JvmOpCodes.LSTORE:
08975: pos = getOffset(info, i);
08976: i += 2;
08977: operand = opStack.getTopOfStack();
08978:
08979: temp = "";
08980: local = getLocalVariable(pos, "store",
08981: "long", false, currentForIndex);
08982: if (local != null) {
08983: if (local.isDeclarationGenerated() == false) {
08984: temp = local.getDataType() + " "
08985: + local.getVarName() + "= "
08986: + operand.getOperandValue()
08987: + ";";
08988: local.setDeclarationGenerated(true);
08989: } else {
08990: temp = local.getVarName() + "= "
08991: + operand.getOperandValue()
08992: + ";";
08993: }
08994: }
08995:
08996: //codeStatements+=Util.formatDecompiledStatement(temp)+"\n";
08997: // parsedString+="LSTORE"+"\n\t\t";
08998: break;
08999: case JvmOpCodes.DSTORE:
09000: pos = getOffset(info, i);
09001: i += 2;
09002: operand = opStack.getTopOfStack();
09003:
09004: temp = "";
09005: local = getLocalVariable(pos, "store",
09006: "double", false, currentForIndex);
09007: if (local != null) {
09008: if (local.isDeclarationGenerated() == false) {
09009: temp = local.getDataType() + " "
09010: + local.getVarName() + "= "
09011: + operand.getOperandValue()
09012: + ";";
09013: local.setDeclarationGenerated(true);
09014: } else {
09015: temp = local.getVarName() + "= "
09016: + operand.getOperandValue()
09017: + ";";
09018: }
09019: }
09020: //codeStatements+=Util.formatDecompiledStatement(temp);
09021: //parsedString+="DSTORE"+"\n";
09022: break;
09023: case JvmOpCodes.RET: // TODO: Not doing anything here ?
09024: pos = getOffset(info, i);
09025: i += 2;
09026: /*if(structure!=null) {
09027: local=structure.getVariabelAtIndex(pos,i-2);
09028: if(local!=null) {
09029: prevLocalGenerated = local;
09030: local.getDataType();
09031: //If Type is not ReturnAddress Throw an ApplicationException
09032: }
09033: } */
09034:
09035: // parsedString+="RET"+"\n";
09036: break;
09037: }
09038:
09039: // parsedString+=(info[++i] << 8) | info[++i];
09040: // parsedString+="\n";
09041:
09042: }
09043: }
09044:
09045: }
09046:
09047: catch (EmptyStackException ese) {
09048: // Skip
09049: }
09050:
09051: catch (Exception e) {
09052: // Skip
09053: }
09054:
09055: }
09056: /*
09057: Cases to be complete ALOAD_WIDE
09058: ASTORE_WIDE
09059: FSTORE_WIDE
09060: */
09061: behaviour.setLabels(this .LABELS);
09062: behaviour.setVMInstructions(disOutput);
09063:
09064: //return parsedString;
09065: }
09066:
09067: private static StringBuffer interpretByteCodes(StringBuffer input) {
09068: StringBuffer opcodes = new StringBuffer();
09069:
09070: return opcodes;
09071:
09072: }
09073:
09074: private java.lang.String getArrayType(java.lang.String temp) {
09075:
09076: if (temp.indexOf("L") != -1) {
09077: java.lang.String tmp = temp.substring(
09078: temp.indexOf("L") + 1, temp.indexOf(";"));
09079: tmp = tmp.replace('/', '.');
09080: return tmp;
09081:
09082: }
09083:
09084: if (temp.equals("Z")) {
09085: return "boolean";
09086: }
09087: if (temp.equals("D")) {
09088: return "double";
09089: }
09090: if (temp.equals("J")) {
09091: return "long";
09092: }
09093: if (temp.equals("F")) {
09094: return "float";
09095: }
09096: if (temp.equals("B")) {
09097: return "byte";
09098: }
09099: if (temp.equals("I")) {
09100: return "int";
09101: }
09102:
09103: if (temp.equals("C")) {
09104: return "char";
09105: }
09106: if (temp.equals("S")) {
09107: return "short";
09108: }
09109: return null;
09110: }
09111:
09112: private java.lang.String parseOperandType(int type) {
09113:
09114: switch (type) {
09115:
09116: case Constants.IS_ARRAY_REF:
09117: return "Array Reference";
09118: case Constants.IS_CONSTANT_BYTE:
09119: return "byte";
09120: case Constants.IS_CONSTANT_DOUBLE:
09121: return "double";
09122: case Constants.IS_CONSTANT_FLOAT:
09123: return "float";
09124: case Constants.IS_CONSTANT_INT:
09125: return "int";
09126: case Constants.IS_CONSTANT_LONG:
09127: return "long";
09128: case Constants.IS_CONSTANT_SHORT:
09129: return "short";
09130: case Constants.IS_CONSTANT_STRING:
09131: return "string";
09132: case Constants.IS_NULL:
09133: return "NULL";
09134: case Constants.IS_OBJECT_REF:
09135: return "Object Reference Type";
09136: case Constants.IS_RETURN_ADDRESS:
09137: return "Return Address Type";
09138:
09139: default:
09140: return "ERROR...Unknown TYPE";
09141:
09142: }
09143:
09144: }
09145:
09146: private boolean isNextInstructionAnyInvoke(int nextinst,
09147: StringBuffer sb) {
09148: boolean b = isNextInstructionInvokeInterface(nextinst);
09149: if (b) {
09150: sb.append("interface");
09151: return b;
09152: }
09153: b = isNextInstructionInvokeSpecial(nextinst);
09154: if (b) {
09155: sb.append("special");
09156: return b;
09157: }
09158: b = isNextInstructionInvokeStatic(nextinst);
09159: if (b)
09160: return b;
09161: b = isNextInstructionInvokeVirtual(nextinst);
09162: if (b)
09163: return b;
09164: return false;
09165: }
09166:
09167: private boolean isNextInstructionInvokeInterface(int nextInst) {
09168:
09169: if (nextInst == JvmOpCodes.INVOKEINTERFACE)
09170: return true;
09171: else
09172: return false;
09173: }
09174:
09175: private boolean isNextInstructionInvokeSpecial(int nextInst) {
09176:
09177: if (nextInst == JvmOpCodes.INVOKESPECIAL)
09178: return true;
09179: else
09180: return false;
09181: }
09182:
09183: private boolean isNextInstructionInvokeStatic(int nextInst) {
09184:
09185: if (nextInst == JvmOpCodes.INVOKESTATIC)
09186: return true;
09187: else
09188: return false;
09189: }
09190:
09191: private boolean isNextInstructionInvokeVirtual(int nextInst) {
09192:
09193: if (nextInst == JvmOpCodes.INVOKEVIRTUAL)
09194: return true;
09195: else
09196: return false;
09197: }
09198:
09199: private boolean isNextInstructionConversionInst(int next) {
09200: boolean flag = false;
09201: switch (next) {
09202:
09203: case JvmOpCodes.D2L:
09204: case JvmOpCodes.D2I:
09205: case JvmOpCodes.D2F:
09206: case JvmOpCodes.I2B:
09207: case JvmOpCodes.I2C:
09208: case JvmOpCodes.I2D:
09209: case JvmOpCodes.I2F:
09210: case JvmOpCodes.I2L:
09211: case JvmOpCodes.I2S:
09212: case JvmOpCodes.L2D:
09213: case JvmOpCodes.L2F:
09214: case JvmOpCodes.L2I:
09215: case JvmOpCodes.F2D:
09216:
09217: case JvmOpCodes.F2I:
09218: case JvmOpCodes.F2L:
09219: return true;
09220: default:
09221: return false;
09222:
09223: }
09224:
09225: }
09226:
09227: private int isNextInstructionConversionInst(int i, byte[] code) {
09228: if (isThisInstrStart(behaviour.getInstructionStartPositions(),
09229: i) == false)
09230: return -1;
09231: switch (code[i]) {
09232:
09233: case JvmOpCodes.D2L:
09234: case JvmOpCodes.D2I:
09235: case JvmOpCodes.D2F:
09236: case JvmOpCodes.I2B:
09237: case JvmOpCodes.I2C:
09238: case JvmOpCodes.I2D:
09239: case JvmOpCodes.I2F:
09240: case JvmOpCodes.I2L:
09241: case JvmOpCodes.I2S:
09242: case JvmOpCodes.L2D:
09243: case JvmOpCodes.L2F:
09244: case JvmOpCodes.L2I:
09245: case JvmOpCodes.F2D:
09246:
09247: case JvmOpCodes.F2I:
09248: case JvmOpCodes.F2L:
09249: return i;
09250: default:
09251: return -1;
09252:
09253: }
09254:
09255: }
09256:
09257: private java.lang.String getSourceTypeForConversionInst(int i,
09258: byte[] code) {
09259: if (isThisInstrStart(behaviour.getInstructionStartPositions(),
09260: i) == false)
09261: return "";
09262: switch (code[i]) {
09263:
09264: case JvmOpCodes.D2L:
09265: return "double";
09266: case JvmOpCodes.D2I:
09267: return "double";
09268: case JvmOpCodes.D2F:
09269: return "double";
09270: case JvmOpCodes.I2B:
09271: return "int";
09272: case JvmOpCodes.I2C:
09273: return "int";
09274:
09275: case JvmOpCodes.I2D:
09276: return "int";
09277:
09278: case JvmOpCodes.I2F:
09279: return "int";
09280:
09281: case JvmOpCodes.I2L:
09282: return "int";
09283:
09284: case JvmOpCodes.I2S:
09285: return "int";
09286:
09287: case JvmOpCodes.L2D:
09288: return "long";
09289:
09290: case JvmOpCodes.L2F:
09291: return "long";
09292:
09293: case JvmOpCodes.L2I:
09294: return "long";
09295:
09296: case JvmOpCodes.F2D:
09297: return "float";
09298:
09299: case JvmOpCodes.F2I:
09300: return "float";
09301:
09302: case JvmOpCodes.F2L:
09303: return "float";
09304: default:
09305: return "";
09306:
09307: }
09308:
09309: }
09310:
09311: private java.lang.String getResulatantTypeForConversionInst(int i,
09312: byte[] code) {
09313: if (isThisInstrStart(behaviour.getInstructionStartPositions(),
09314: i) == false)
09315: return "";
09316: switch (code[i]) {
09317:
09318: case JvmOpCodes.D2L:
09319: return "long";
09320: case JvmOpCodes.D2I:
09321: return "int";
09322: case JvmOpCodes.D2F:
09323: return "float";
09324: case JvmOpCodes.I2B:
09325: return "byte";
09326: case JvmOpCodes.I2C:
09327: return "char";
09328:
09329: case JvmOpCodes.I2D:
09330: return "double";
09331:
09332: case JvmOpCodes.I2F:
09333: return "float";
09334:
09335: case JvmOpCodes.I2L:
09336: return "long";
09337:
09338: case JvmOpCodes.I2S:
09339: return "short";
09340:
09341: case JvmOpCodes.L2D:
09342: return "double";
09343:
09344: case JvmOpCodes.L2F:
09345: return "float";
09346:
09347: case JvmOpCodes.L2I:
09348: return "int";
09349:
09350: case JvmOpCodes.F2D:
09351: return "double";
09352:
09353: case JvmOpCodes.F2I:
09354: return "int";
09355:
09356: case JvmOpCodes.F2L:
09357: return "long";
09358: default:
09359: return "";
09360:
09361: }
09362:
09363: }
09364:
09365: private boolean isNextInstructionLoad(int nextInstruction) {
09366: boolean flag = false;
09367: switch (nextInstruction) {
09368:
09369: case JvmOpCodes.BIPUSH:
09370: flag = true;
09371: break;
09372:
09373: case JvmOpCodes.SIPUSH:
09374: flag = true;
09375: break;
09376:
09377: case JvmOpCodes.AALOAD:
09378: flag = true;
09379: break;
09380:
09381: case JvmOpCodes.BALOAD:
09382: flag = true;
09383: break;
09384:
09385: case JvmOpCodes.DALOAD:
09386: flag = true;
09387: break;
09388:
09389: case JvmOpCodes.FALOAD:
09390: flag = true;
09391: break;
09392:
09393: case JvmOpCodes.LALOAD:
09394: flag = true;
09395: break;
09396:
09397: case JvmOpCodes.IALOAD:
09398: flag = true;
09399: break;
09400:
09401: case JvmOpCodes.SALOAD:
09402: flag = true;
09403: break;
09404:
09405: case JvmOpCodes.CALOAD:
09406: flag = true;
09407: break;
09408:
09409: case JvmOpCodes.ALOAD:
09410: flag = true;
09411: break;
09412: case JvmOpCodes.ALOAD_0:
09413: flag = true;
09414: break;
09415: case JvmOpCodes.ALOAD_1:
09416: flag = true;
09417: break;
09418: case JvmOpCodes.ALOAD_2:
09419: flag = true;
09420: break;
09421: case JvmOpCodes.ALOAD_3:
09422: flag = true;
09423: break;
09424: case JvmOpCodes.ILOAD:
09425: flag = true;
09426: break;
09427: case JvmOpCodes.ILOAD_0:
09428: flag = true;
09429: break;
09430: case JvmOpCodes.ILOAD_1:
09431: flag = true;
09432: break;
09433: case JvmOpCodes.ILOAD_2:
09434: flag = true;
09435: break;
09436: case JvmOpCodes.ILOAD_3:
09437: flag = true;
09438: break;
09439:
09440: case JvmOpCodes.LLOAD:
09441: flag = true;
09442: break;
09443: case JvmOpCodes.LLOAD_0:
09444: flag = true;
09445: break;
09446: case JvmOpCodes.LLOAD_1:
09447: flag = true;
09448: break;
09449: case JvmOpCodes.LLOAD_2:
09450: flag = true;
09451: break;
09452: case JvmOpCodes.LLOAD_3:
09453: flag = true;
09454: break;
09455:
09456: case JvmOpCodes.FLOAD:
09457: flag = true;
09458: break;
09459: case JvmOpCodes.FLOAD_0:
09460: flag = true;
09461: break;
09462: case JvmOpCodes.FLOAD_1:
09463: flag = true;
09464: break;
09465: case JvmOpCodes.FLOAD_2:
09466: flag = true;
09467: break;
09468: case JvmOpCodes.FLOAD_3:
09469: flag = true;
09470: break;
09471:
09472: case JvmOpCodes.DLOAD:
09473: flag = true;
09474: break;
09475: case JvmOpCodes.DLOAD_0:
09476: flag = true;
09477: break;
09478: case JvmOpCodes.DLOAD_1:
09479: flag = true;
09480: break;
09481: case JvmOpCodes.DLOAD_2:
09482: flag = true;
09483: break;
09484: case JvmOpCodes.DLOAD_3:
09485: flag = true;
09486: break;
09487: case JvmOpCodes.ICONST_0:
09488: case JvmOpCodes.ICONST_1:
09489: case JvmOpCodes.ICONST_2:
09490: case JvmOpCodes.ICONST_3:
09491: case JvmOpCodes.ICONST_M1:
09492: case JvmOpCodes.ICONST_4:
09493: case JvmOpCodes.ICONST_5:
09494: case JvmOpCodes.LCONST_0:
09495: case JvmOpCodes.LCONST_1:
09496: case JvmOpCodes.DCONST_0:
09497: case JvmOpCodes.DCONST_1:
09498: case JvmOpCodes.FCONST_0:
09499: case JvmOpCodes.FCONST_1:
09500: case JvmOpCodes.FCONST_2:
09501: flag = true;
09502: break;
09503:
09504: }
09505:
09506: return flag;
09507: }
09508:
09509: private boolean isNextInstructionStore(int nextInstruction) {
09510: boolean flag = false;
09511:
09512: switch (nextInstruction) {
09513: /* case JvmOpCodes.AASTORE :
09514: flag = true;
09515: break;*/
09516: case JvmOpCodes.ASTORE:
09517: flag = true;
09518: break;
09519: case JvmOpCodes.ASTORE_WIDE:
09520: flag = true;
09521: break;
09522: case JvmOpCodes.ASTORE_0:
09523: flag = true;
09524: break;
09525: case JvmOpCodes.ASTORE_1:
09526: flag = true;
09527: break;
09528: case JvmOpCodes.ASTORE_2:
09529: flag = true;
09530: break;
09531: case JvmOpCodes.ASTORE_3:
09532: flag = true;
09533: break;
09534:
09535: case JvmOpCodes.DSTORE:
09536: flag = true;
09537: break;
09538: case JvmOpCodes.DSTORE_0:
09539: flag = true;
09540: break;
09541: case JvmOpCodes.DSTORE_1:
09542: flag = true;
09543: break;
09544: case JvmOpCodes.DSTORE_2:
09545: flag = true;
09546: break;
09547: case JvmOpCodes.DSTORE_3:
09548: flag = true;
09549: break;
09550:
09551: case JvmOpCodes.FSTORE:
09552: flag = true;
09553: break;
09554: case JvmOpCodes.FSTORE_0:
09555: flag = true;
09556: break;
09557: case JvmOpCodes.FSTORE_1:
09558: flag = true;
09559: break;
09560: case JvmOpCodes.FSTORE_2:
09561: flag = true;
09562: break;
09563: case JvmOpCodes.FSTORE_3:
09564: flag = true;
09565: break;
09566:
09567: case JvmOpCodes.ISTORE:
09568: flag = true;
09569: break;
09570: case JvmOpCodes.ISTORE_0:
09571: flag = true;
09572: break;
09573: case JvmOpCodes.ISTORE_1:
09574: flag = true;
09575: break;
09576: case JvmOpCodes.ISTORE_2:
09577: flag = true;
09578: break;
09579: case JvmOpCodes.ISTORE_3:
09580: flag = true;
09581: break;
09582:
09583: case JvmOpCodes.LSTORE:
09584: flag = true;
09585: break;
09586:
09587: case JvmOpCodes.LSTORE_0:
09588: flag = true;
09589: break;
09590: case JvmOpCodes.LSTORE_1:
09591: flag = true;
09592: break;
09593: case JvmOpCodes.LSTORE_2:
09594: flag = true;
09595: break;
09596: case JvmOpCodes.LSTORE_3:
09597: flag = true;
09598: break;
09599:
09600: default:
09601: flag = false;
09602: }
09603: return flag;
09604: }
09605:
09606: public boolean isNextInstructionReturn(int nextInstruction) {
09607: boolean flag = false;
09608: switch (nextInstruction) {
09609: case JvmOpCodes.RETURN:
09610: return true;
09611: default:
09612: return false;
09613:
09614: }
09615: }
09616:
09617: public boolean isNextInstructionPop(int nextInstruction) {
09618: boolean flag = false;
09619: switch (nextInstruction) {
09620: case JvmOpCodes.POP:
09621: case JvmOpCodes.POP2:
09622: return true;
09623: default:
09624: return false;
09625:
09626: }
09627: }
09628:
09629: public boolean isNextInstructionIf(int nextInstruction) {
09630: boolean flag = false;
09631:
09632: switch (nextInstruction) {
09633: case JvmOpCodes.IF_ACMPEQ:
09634: flag = true;
09635: break;
09636: case JvmOpCodes.IF_ACMPNE:
09637: flag = true;
09638: break;
09639: case JvmOpCodes.IF_ICMPEQ:
09640: flag = true;
09641: break;
09642: case JvmOpCodes.IF_ICMPGE:
09643: flag = true;
09644: break;
09645: case JvmOpCodes.IF_ICMPGT:
09646: flag = true;
09647: break;
09648: case JvmOpCodes.IF_ICMPLE:
09649: flag = true;
09650: break;
09651: case JvmOpCodes.IF_ICMPLT:
09652: flag = true;
09653: break;
09654: case JvmOpCodes.IF_ICMPNE:
09655: flag = true;
09656: break;
09657: case JvmOpCodes.IFEQ:
09658: flag = true;
09659: break;
09660: case JvmOpCodes.IFGE:
09661: flag = true;
09662: break;
09663: case JvmOpCodes.IFGT:
09664: flag = true;
09665: break;
09666: case JvmOpCodes.IFLE:
09667: flag = true;
09668: break;
09669: case JvmOpCodes.IFLT:
09670: flag = true;
09671: break;
09672: case JvmOpCodes.IFNE:
09673: flag = true;
09674: break;
09675: case JvmOpCodes.IFNONNULL:
09676: flag = true;
09677: break;
09678: case JvmOpCodes.IFNULL:
09679: flag = true;
09680: break;
09681: default:
09682: flag = false;
09683: }
09684: return flag;
09685: }
09686:
09687: // TODO: Write logic to poll for the end of the last catch
09688: private java.lang.String pollExcepionTables(int i, int instruction) {
09689: java.lang.String temp = "";
09690: //Algo
09691: // For Each ExceptionTable Do
09692: // 1> check whether = to start of Guard
09693: // If so Check Whether guardtype is try or catch
09694: // 2> Else check whether = to end of Guard
09695: // If so Just return a "}"
09696: // 3> Else check whether = to start of Handler
09697: // If so check whether type is catch or finally
09698: // Return appropriately
09699: // 4> Else check whether = to end of Handler
09700: // just Return "}"
09701:
09702: // 5> Check for invalid Table values
09703: ArrayList alltables = this .behaviour.getExceptionTableList();
09704: if (alltables != null) {
09705: for (int c = 0; c < alltables.size(); c++) {
09706: ExceptionTable table = (ExceptionTable) alltables
09707: .get(c);
09708: // System.out.println(i+"table.getEndOfHandlerForGuardRegion()"+table.getEndOfHandlerForGuardRegion());
09709:
09710: // Check for Invalid condition
09711: byte code[] = behaviour.getCode();
09712: if (code != null
09713: && code[table.getStartOfGuardRegion() + 1] == JvmOpCodes.MONITOREXIT)
09714: continue;
09715:
09716: if (code != null
09717: && code[table.getEndOfGuardRegion() - 1] == JvmOpCodes.MONITOREXIT) {
09718:
09719: continue;
09720: }
09721:
09722: if (table.getStartOfGuardRegion() == table
09723: .getStartOfHandlerForGuardRegion())
09724: continue;
09725: // Another invalid to check
09726: if (table.getEndOfGuardRegion() > table
09727: .getStartOfHandlerForGuardRegion())
09728: continue;
09729:
09730: // Check 1
09731: if (table.getStartOfGuardRegion() == i) {
09732: if (table.getTypeOfGuardRegion().equals("try")) {
09733: ArrayList Al = new ArrayList();
09734: temp = "try\n{\n";
09735: Al.add(table);
09736: Iterator IT = behaviour.getExceptionTableList()
09737: .iterator();
09738: while (IT.hasNext()) {
09739: ExceptionTable etb = (ExceptionTable) IT
09740: .next();
09741: if (etb.getStartOfGuardRegion() == i
09742: && etb.getTypeOfGuardRegion()
09743: .equals("try")) {
09744: boolean Present = alreadyPresent(Al,
09745: etb);
09746: if (Present == false) {
09747: temp += "\ntry\n{\n";
09748: Al.add(etb);
09749: }
09750:
09751: }
09752: }
09753:
09754: // Check from created Exception Table List.
09755: ArrayList createdList = behaviour
09756: .getCreatedTableList();
09757: if (createdList != null) {
09758: IT = createdList.iterator();
09759: while (IT.hasNext()) {
09760: ExceptionTable etb = (ExceptionTable) IT
09761: .next();
09762: if (etb.getStartOfGuardRegion() == i
09763: && etb.getTypeOfGuardRegion()
09764: .equals("try")) {
09765: boolean Present = alreadyPresent(
09766: Al, etb);
09767: if (Present == false) {
09768: temp += "\ntry\n{\n";
09769: Al.add(etb);
09770: }
09771:
09772: }
09773: }
09774: }
09775:
09776: break;
09777: }
09778: if (table.getTypeOfGuardRegion().equals("catch")) {
09779: // Need to Get Exception Name
09780: java.lang.String expName = "";
09781: for (int c2 = 0; c2 < alltables.size(); c2++) {
09782: ExceptionTable temptable = (ExceptionTable) alltables
09783: .get(c2);
09784: if (temptable.getEndOfGuardRegion() == i) {
09785: expName = temptable.getExceptionName();
09786: expName.replace('/', '.');
09787: LocalVariableStructure structure = this .behaviour
09788: .getLocalVariables();
09789: int indexPos = -1;
09790: boolean simple = true;
09791: switch (instruction) {
09792: case JvmOpCodes.ASTORE:
09793: indexPos = this .behaviour.getCode()[i + 1];
09794: simple = false;
09795: break;
09796: case JvmOpCodes.ASTORE_0:
09797: indexPos = 0;
09798: break;
09799: case JvmOpCodes.ASTORE_1:
09800: indexPos = 1;
09801: break;
09802: case JvmOpCodes.ASTORE_2:
09803: indexPos = 2;
09804: break;
09805: case JvmOpCodes.ASTORE_3:
09806: indexPos = 3;
09807: break;
09808: // TODO: Later check for wide instruction with astore.
09809: // Need to Handle it.
09810:
09811: }
09812:
09813: LocalVariable expVar = getLocalVariable(
09814: indexPos, "store",
09815: "java.lang.Object", simple, i); //
09816: java.lang.String expVarName = "";
09817: if (expVar != null)
09818: expVarName = expVar.getVarName();
09819: if (expVar == null) {
09820: // TODO handle Later
09821: expVarName = "exception";
09822: }
09823: temp += "\ncatch("
09824: + expName.replace('/', '.')
09825: + " " + expVarName + ")\n{\n";
09826: break;
09827: }
09828: }
09829: temp += "";
09830: break;
09831:
09832: }
09833: }
09834: if (table.getEndOfGuardRegion() == i) {
09835: // Apply Rule For Try
09836: // Purpose of this rule is to check whether
09837: // i is actually the end for this try or not
09838: int startOfGuard = table.getStartOfGuardRegion();
09839: boolean alreadyEnded = false;
09840: if (table.getTypeOfGuardRegion().equals("try")) {
09841: ArrayList excepTables = this .behaviour
09842: .getExceptionTableList();
09843: ;
09844: for (int Start = 0; Start < excepTables.size(); Start++) {
09845: ExceptionTable tab = (ExceptionTable) excepTables
09846: .get(Start);
09847: if (tab.getStartOfGuardRegion() == startOfGuard) {
09848: int endOfGuard = tab
09849: .getEndOfGuardRegion();
09850: int beginofHandler = tab
09851: .getStartOfHandlerForGuardRegion();
09852: if (i > endOfGuard
09853: && i < beginofHandler) {
09854: alreadyEnded = true;
09855: break;
09856: }
09857: }
09858: }
09859: }
09860: boolean addGE = addGuardEnd(i);
09861: boolean b1 = isHandlerEndPresentAtGuardEnd(i);
09862: if (alreadyEnded == false
09863: && (table.getTypeOfGuardRegion().equals("") == false)
09864: && addGE && !b1) {
09865: temp += "}";// some try catch end
09866: guardEnds.put(new Integer(i), "true");
09867: } else
09868: temp += "";
09869: // Check for overlap
09870: ArrayList excepTables = this .behaviour
09871: .getExceptionTableList();
09872: ;
09873: for (int Start = 0; Start < excepTables.size(); Start++) {
09874: ExceptionTable tab = (ExceptionTable) excepTables
09875: .get(Start);
09876: if (tab.getStartOfHandlerForGuardRegion() == i
09877: && tab.getExceptionName().equals(
09878: "<any>") == false) {
09879: // Added code for generating excepion Name
09880: LocalVariableStructure structure = this .behaviour
09881: .getLocalVariables();
09882: int indexPos = -1;
09883: boolean simple = true;
09884: switch (instruction) {
09885: case JvmOpCodes.ASTORE:
09886: indexPos = this .behaviour.getCode()[i + 1];
09887: simple = false;
09888: break;
09889: case JvmOpCodes.ASTORE_0:
09890: indexPos = 0;
09891: break;
09892: case JvmOpCodes.ASTORE_1:
09893: indexPos = 1;
09894: break;
09895: case JvmOpCodes.ASTORE_2:
09896: indexPos = 2;
09897: break;
09898: case JvmOpCodes.ASTORE_3:
09899: indexPos = 3;
09900: break;
09901: // TODO: Later check for wide instruction with astore.
09902: // Need to Handle it.
09903:
09904: }
09905:
09906: LocalVariable expVar = getLocalVariable(
09907: indexPos, "store",
09908: "java.lang.Object", simple, i);
09909: java.lang.String expName = "";
09910: if (expVar != null)
09911: expName = expVar.getVarName();
09912: if (expVar == null) {
09913: // TODO
09914: expName = "exception";
09915: }
09916: temp += "\ncatch("
09917: + tab.getExceptionName().replace(
09918: '/', '.') + " " + expName
09919: + ")\n{\n";
09920: break;
09921: }
09922: if (tab.getStartOfHandlerForGuardRegion() == i
09923: && tab.getExceptionName().equals(
09924: "<any>") == true) {
09925: temp += "\nfinally\n{\n";
09926: break;
09927: }
09928: }
09929:
09930: // Check from newly created Table list
09931: ArrayList newexcepTables = this .behaviour
09932: .getCreatedTableList();
09933: if (newexcepTables != null) {
09934: for (int Start = 0; Start < newexcepTables
09935: .size(); Start++) {
09936: ExceptionTable tab = (ExceptionTable) newexcepTables
09937: .get(Start);
09938: boolean addG = addGuardEnd(i);
09939: boolean z = isHandlerEndPresentAtGuardEnd(i);
09940: if (tab.getEndOfGuardRegion() == i && addG
09941: && !z) {
09942: temp += "}\n";
09943: guardEnds.put(new Integer(i), "true");
09944: break;
09945: }
09946: }
09947: }
09948:
09949: // System.out.println();
09950: break;
09951: }
09952:
09953: if (table.getStartOfHandlerForGuardRegion() == i) {
09954:
09955: /* Iterator itz=behaviour.getExceptionTableList().iterator();
09956: while(itz.hasNext()) {
09957: ExceptionTable etb=(ExceptionTable)itz.next();
09958: if(etb.getEndOfHandlerForGuardRegion()==i) {
09959: // temp+="\n}// end of handler2\n";
09960:
09961: }
09962: } */
09963:
09964: if (table.getTypeOfHandlerForGuardRegion().equals(
09965: "FinallyBlock")) {
09966: temp += "finally\n{\n";
09967: break;
09968: }
09969: if (table.getTypeOfHandlerForGuardRegion().equals(
09970: "CatchBlock")) {
09971: LocalVariableStructure structure = this .behaviour
09972: .getLocalVariables();
09973: int indexPos = -1;
09974: int blockIndexValue = -1;
09975: boolean simple = true;
09976: switch (instruction) {
09977: case JvmOpCodes.ASTORE:
09978: indexPos = this .behaviour.getCode()[i + 1];
09979: blockIndexValue = i + 2;
09980: simple = false;
09981: break;
09982: case JvmOpCodes.ASTORE_0:
09983: indexPos = 0;
09984: blockIndexValue = i + 1;
09985: break;
09986: case JvmOpCodes.ASTORE_1:
09987: blockIndexValue = i + 1;
09988: indexPos = 1;
09989: break;
09990: case JvmOpCodes.ASTORE_2:
09991: blockIndexValue = i + 1;
09992: indexPos = 2;
09993: break;
09994: case JvmOpCodes.ASTORE_3:
09995: blockIndexValue = i + 1;
09996: indexPos = 3;
09997: break;
09998: // TODO: Later check for wide instruction with astore.
09999: // Need to Handle it.
10000:
10001: }
10002:
10003: LocalVariable expVar = getLocalVariable(
10004: indexPos, "store", "java.lang.Object",
10005: simple, i);
10006: java.lang.String expName = "";
10007: if (expVar != null)
10008: expName = expVar.getVarName();
10009: else
10010: expName = "exception";
10011: boolean add = addHandlerStart(i);
10012: if (add) {
10013: temp += "catch("
10014: + table.getExceptionName().replace(
10015: '/', '.') + " " + expName
10016: + ")\n{\n";
10017: handlerStarts.put(new Integer(i), "true");
10018: }
10019: break;
10020:
10021: }
10022: }
10023: if (table.getEndOfHandlerForGuardRegion() == i) {
10024:
10025: boolean b = addhandlerEnd(i, table);
10026: if (b) {
10027: addedHandlerEnds.add(new Integer(i));
10028: temp += "\n}\n";
10029: int s = table.getStartOfHandlerForGuardRegion();
10030: int e = table.getEndOfHandlerForGuardRegion();
10031: java.lang.String t = table
10032: .getTypeOfHandlerForGuardRegion();
10033: handlertracker.put(new Integer(i),
10034: new handlerEndTracker(s, e, t));
10035: // guardEnds.put(new Integer(i),"true");
10036: }
10037: Iterator tempIterator = null;
10038:
10039: // Check for End of Guard
10040: // TODO: Get the example for This...
10041: tempIterator = behaviour.getExceptionTableList()
10042: .iterator();
10043: while (tempIterator.hasNext()) {
10044: ExceptionTable etb = (ExceptionTable) tempIterator
10045: .next();
10046: boolean addG = addGuardEnd(i);
10047: boolean z = isHandlerEndPresentAtGuardEnd(i);
10048: if (etb.getEndOfGuardRegion() == i && addG
10049: && !z) {
10050: temp += "\n}";
10051: guardEnds.put(new Integer(i), "true");
10052: break;
10053: }
10054: }
10055:
10056: // Check for overlap with Created Table List
10057: ArrayList newList = behaviour.getCreatedTableList();
10058: if (newList != null) {
10059: tempIterator = newList.iterator();
10060: while (tempIterator.hasNext()) {
10061: ExceptionTable etb = (ExceptionTable) tempIterator
10062: .next();
10063: boolean addG = addGuardEnd(i);
10064: boolean z = isHandlerEndPresentAtGuardEnd(i);
10065: if (etb.getEndOfGuardRegion() == i && addG
10066: && !z) {
10067: temp += "}\n";
10068: guardEnds.put(new Integer(i), "true");
10069: break;
10070: }
10071: }
10072: }
10073:
10074: // Check here for overlap condition
10075: tempIterator = behaviour.getExceptionTableList()
10076: .iterator();
10077: while (tempIterator.hasNext()) {
10078: ExceptionTable etb = (ExceptionTable) tempIterator
10079: .next();
10080: if (etb.getStartOfHandlerForGuardRegion() == i
10081: && etb.getExceptionName().equals(
10082: "<any>") == false) {
10083: java.lang.String ename = etb
10084: .getExceptionName();
10085: ename = ename.replace('/', '.');
10086: LocalVariableStructure structure = this .behaviour
10087: .getLocalVariables();
10088: int indexPos = -1;
10089: int blockIndexValue = -1;
10090: boolean simple = true;
10091: switch (instruction) {
10092: case JvmOpCodes.ASTORE:
10093: indexPos = this .behaviour.getCode()[i + 1];
10094: blockIndexValue = i + 2;
10095: simple = false;
10096: break;
10097: case JvmOpCodes.ASTORE_0:
10098: blockIndexValue = i + 1;
10099: indexPos = 0;
10100: break;
10101: case JvmOpCodes.ASTORE_1:
10102: blockIndexValue = i + 1;
10103: indexPos = 1;
10104: break;
10105: case JvmOpCodes.ASTORE_2:
10106: blockIndexValue = i + 1;
10107: indexPos = 2;
10108: break;
10109: case JvmOpCodes.ASTORE_3:
10110: blockIndexValue = i + 1;
10111: indexPos = 3;
10112: break;
10113: // TODO: Later check for wide instruction with astore.
10114: // Need to Handle it.
10115:
10116: }
10117:
10118: LocalVariable expVar = getLocalVariable(
10119: indexPos, "store",
10120: "java.lang.Object", simple, i);
10121: java.lang.String expName = "";
10122: if (expVar != null)
10123: expName = expVar.getVarName();
10124: if (expVar == null) {
10125: // TODO handle Later
10126: expName = "exception";
10127: }
10128: boolean add = addHandlerStart(i);
10129: if (add) {
10130: temp += "catch("
10131: + ename.replace('/', '.') + " "
10132: + expName + ")\n{\n";
10133: handlerStarts.put(new Integer(i),
10134: "true");
10135: }
10136: break;
10137: }
10138: }
10139:
10140: // break;
10141: }
10142:
10143: }
10144:
10145: }
10146: // Check For End of Catch For Last Catch
10147: // Note Handled Here because This there is no entry in exception table list for The end of last catch
10148: // as there is no finally for try
10149:
10150: //if(temp.length()==0) // Removing if because this was preventing last catch's end of guard of to be printed
10151: // As that info was only held in a CatchBlock Object
10152: //{
10153: ArrayList allTryBlks = getAllTriesForBehaviour(); // All try blocks for method
10154: if (allTryBlks != null) {
10155: Iterator it = allTryBlks.iterator();
10156: while (it.hasNext()) {
10157: TryBlock tryblock = (TryBlock) it.next(); // Get Each Try
10158: if (tryblock.hasFinallyBlk() == false) // Go in only if there is no finally for this try
10159: {
10160: ArrayList allcatches = tryblock
10161: .getAllCatchesForThisTry(); // Get catches for this try
10162: if (allcatches.size() > 0) // Try may not have any catches
10163: {
10164: CatchBlock LastCatch = (CatchBlock) allcatches
10165: .get(allcatches.size() - 1);
10166: int endOfCatch = LastCatch.getEnd(); // Get end of last catch block for this try
10167: if (endOfCatch == i
10168: && LastCatch
10169: .isUsedForDeterminingTheEndOfLastCatch()) // compare with i
10170: {
10171: temp += "}\n"; // end Catch and break
10172: break;
10173: }
10174: }
10175: }
10176:
10177: }
10178:
10179: }
10180:
10181: return temp;
10182:
10183: }
10184:
10185: private ArrayList getAllTriesForBehaviour() {
10186: ArrayList alltries = behaviour.getAllTriesForMethod();
10187: int size = alltries.size();
10188: if (size == 0)
10189: return null;
10190: else
10191: return alltries;
10192: }
10193:
10194: private boolean skipCurrentIteraton(int i,
10195: boolean includeEndOfGuard, byte[] info) {
10196: boolean skip = false;
10197: boolean exit = false;
10198: ArrayList tries = this .behaviour.getAllTriesForMethod();
10199: Iterator triesIT = tries.iterator();
10200: while (triesIT.hasNext()) {
10201: TryBlock TRY = (TryBlock) triesIT.next();
10202: ArrayList catches = TRY.getAllCatchesForThisTry();
10203: Iterator catchesIT = catches.iterator();
10204: TryCatchFinally prevBlock = TRY;
10205: while (catchesIT.hasNext()) {
10206: CatchBlock Catch = (CatchBlock) catchesIT.next();
10207: TryCatchFinally curBlock = Catch;
10208: if (includeEndOfGuard) {
10209: if (i >= prevBlock.getEnd()
10210: && i < curBlock.getStart()) {
10211: skip = true;
10212: boolean retStmt = checkForReturn(info, i);
10213: if (retStmt == true)
10214: skip = false;
10215: exit = true;
10216: break;
10217: }
10218: }
10219: if (!includeEndOfGuard && i > prevBlock.getEnd()
10220: && i < curBlock.getStart()) {
10221: skip = true;
10222: boolean retStmt = checkForReturn(info, i);
10223: if (retStmt == true)
10224: skip = false;
10225: exit = true;
10226: break;
10227: }
10228: prevBlock = curBlock;
10229: }
10230: if (exit)
10231: break;
10232: // Check for Finally Block
10233: FinallyBlock Finally = TRY.getFinallyBlock();
10234: if (Finally != null) {
10235: CatchBlock catchblock = TRY.getLastCatchBlock();
10236: if (catchblock != null) {
10237: if (!includeEndOfGuard && i > catchblock.getEnd()
10238: && i < Finally.getStart()) {
10239: boolean retStmt = checkForReturn(info, i);
10240: if (retStmt == true) {
10241: skip = false;
10242: } else {
10243: skip = true;
10244: }
10245: }
10246: if (includeEndOfGuard && i >= catchblock.getEnd()
10247: && i < Finally.getStart()) {
10248: boolean retStmt = checkForReturn(info, i);
10249: if (retStmt == true) {
10250: skip = false;
10251: } else {
10252: skip = true;
10253: }
10254: }
10255: } else {
10256: if (!includeEndOfGuard && i > TRY.getEnd()
10257: && i < Finally.getStart()) {
10258:
10259: boolean retStmt = checkForReturn(info, i);
10260: if (retStmt == true) {
10261: skip = false;
10262: } else {
10263: skip = true;
10264: }
10265: }
10266: if (includeEndOfGuard && i >= TRY.getEnd()
10267: && i < Finally.getStart()) {
10268: boolean retStmt = checkForReturn(info, i);
10269: if (retStmt == true) {
10270: skip = false;
10271: } else {
10272: skip = true;
10273: }
10274: }
10275: }
10276:
10277: }
10278: }
10279:
10280: /* if(!skip && behaviour.getSynchronizedEntries()!=null && behaviour.getSynchronizedEntries().size() > 0)
10281: {
10282: ArrayList synchEntries=behaviour.getSynchronizedEntries();
10283: for(int s=0;s<synchEntries.size();s++)
10284: {
10285: ExceptionTable synchTab=(ExceptionTable)synchEntries.get(s);
10286: int endPC=synchTab.getEndPC();
10287: int athrowpos=getNextAthrowPos(endPC,info);
10288: if(athrowpos!=-1)
10289: {
10290: if(i >=endPC && i<= athrowpos)
10291: {
10292: skip=true;
10293: break;
10294: }
10295: }
10296: }
10297:
10298: }*/
10299:
10300: if (synchSkips != null && synchSkips.size() > 0) {
10301:
10302: Iterator it = synchSkips.entrySet().iterator();
10303: while (it.hasNext()) {
10304:
10305: Map.Entry e = (Map.Entry) it.next();
10306: Integer st = (Integer) e.getKey();
10307: Integer en = (Integer) e.getValue();
10308: if (i >= st.intValue() && i <= en.intValue()) {
10309: skip = true;
10310: break;
10311: }
10312:
10313: }
10314:
10315: }
10316:
10317: if (skip == false) {
10318:
10319: ArrayList tableList = Util
10320: .getAllTablesWithFinallyAsHandler(behaviour
10321: .getExceptionTableList());
10322: tableList = Util.getTablesSortedByGuardStart(tableList);
10323: if (tableList != null) {
10324: for (int z = 0; z < tableList.size(); z++) {
10325:
10326: ExceptionTable table1 = (ExceptionTable) tableList
10327: .get(z);
10328: int next = z + 1;
10329: if (next < tableList.size()) {
10330: ExceptionTable table2 = (ExceptionTable) tableList
10331: .get(next);
10332: int epc = table1.getEndPC();
10333: int spc = table2.getStartPC();
10334: if (i >= epc && i < spc) {
10335: boolean sometrystart = isThisTryStart(i);
10336: if (!sometrystart) {
10337: skip = true;
10338: break;
10339: }
10340: }
10341:
10342: } else
10343: break;
10344: }
10345: }
10346:
10347: }
10348:
10349: return skip;
10350:
10351: }
10352:
10353: private boolean alreadyPresent(ArrayList AL, ExceptionTable etb) {
10354: boolean present = false;
10355: for (int jj = 0; jj < AL.size(); jj++) {
10356: ExceptionTable t = (ExceptionTable) AL.get(jj);
10357: int start = t.getStartOfGuardRegion();
10358: int end = t.getEndOfGuardRegion();
10359: if (start == etb.getStartOfGuardRegion()
10360: && end == etb.getEndOfGuardRegion()) {
10361: present = true;
10362: break;
10363: } else
10364: present = false;
10365: }
10366: if (present == false) {
10367:
10368: for (int jj = 0; jj < AL.size(); jj++) {
10369: ExceptionTable t = (ExceptionTable) AL.get(jj);
10370: int start = t.getStartOfGuardRegion();
10371: int endPC = t.getEndPC();
10372: int handlerPC = t.getStartOfHandler();
10373: if (start == etb.getStartPC()) {
10374: int etbendPC = etb.getEndPC();
10375: if (etbendPC > endPC && etbendPC < handlerPC) {
10376: //present=true; // NOTE: commented on 16 oct by belurs
10377: // As it was preventing a try from appearing
10378:
10379: // TODO: Continuous thoruough testing of try/catch/finally
10380: break; // Necessary
10381: }
10382:
10383: }
10384: }
10385:
10386: }
10387: return present;
10388:
10389: }
10390:
10391: // Copied from LocalVariable Class
10392: private java.lang.String parse(java.lang.String input) {
10393: java.lang.String type = "";
10394: if (input.equals("I")) {
10395: type = "int";
10396: } else if (input.equals("B")) {
10397: type = "byte";
10398: } else if (input.equals("C")) {
10399: type = "char";
10400: } else if (input.equals("S")) {
10401: type = "short";
10402: } else if (input.equals("Z")) {
10403: type = "boolean";
10404: } else if (input.equals("F")) {
10405: type = "float";
10406: } else if (input.equals("D")) {
10407: type = "double";
10408: } else if (input.equals("J")) {
10409: type = "long";
10410: } else if (input.startsWith("L")) {
10411: type = input.substring(1);
10412: if (type.indexOf(";") != -1)
10413: type = type.substring(0, type.indexOf(";"));
10414: } else if (input.startsWith("[")) {
10415: int lastBracket = input.lastIndexOf("[");
10416: int objectType = input.indexOf("L");
10417: java.lang.String className = "";
10418: if (objectType != -1)
10419: className = input.substring(objectType + 1);
10420: else
10421: className = input.substring(lastBracket + 1);
10422: if (className.indexOf(";") != -1)
10423: className = className.substring(0, className
10424: .indexOf(";"));
10425: boolean b = AmIPrimitive(className);
10426: if (b == true)
10427: type = parse(className);
10428: else {
10429: java.lang.String temp = "";
10430: for (int c = 0; c < lastBracket + 1; c++)
10431: temp += "[]";
10432: type = className + " " + temp;
10433: }
10434:
10435: } else {
10436: type = input;
10437: }
10438:
10439: return type;
10440:
10441: }
10442:
10443: private boolean AmIPrimitive(java.lang.String className) {
10444: if (className.equals("I") || className.equals("B")
10445: || className.equals("C") || className.equals("S")
10446: || className.equals("F") || className.equals("D")
10447: || className.equals("J") || className.equals("Z")) {
10448: return true;
10449: } else
10450: return false;
10451:
10452: }
10453:
10454: private java.lang.String pollSwitchBlksForMethod(int i) {
10455:
10456: java.lang.String stmt = "";
10457: boolean processed = false;
10458: ArrayList allswitches = behaviour.getAllSwitchBlks();
10459: if (allswitches != null) {
10460:
10461: for (int start = 0; start < allswitches.size(); start++) {
10462: Switch switchblk = (Switch) allswitches.get(start);
10463: ArrayList allcases = switchblk.getAllCases();
10464: allcases = sortCasesByStart(allcases);
10465: if (allcases.size() > 0) {
10466: for (int c = 0; c < allcases.size(); c++) {
10467: Case caseblk = (Case) allcases.get(c);
10468: if (caseblk.getCaseStart() == i) {
10469: java.lang.String temp = "case "
10470: + caseblk.getCaseLabel() + ":\n{\n";
10471: processed = true;
10472: stmt = Util.formatDecompiledStatement(temp);
10473: return stmt;
10474:
10475: }
10476: if (caseblk.getCaseEnd() == i) {
10477:
10478: java.lang.String temp = "";
10479: if (caseblk.isFallsThru() == false
10480: && caseblk.isGotoAsEndForCase())
10481: temp += "break;\n";
10482: temp = Util.formatDecompiledStatement(temp);
10483: java.lang.String tempString = "\n}\n";
10484: temp += Util
10485: .formatDecompiledStatement(tempString);
10486: ArrayList allcasesDUP = switchblk
10487: .getAllCases();
10488: if (allcasesDUP.size() > 0) {
10489: for (int c2 = 0; c2 < allcasesDUP
10490: .size(); c2++) {
10491: Case caseblkDUP = (Case) allcasesDUP
10492: .get(c2);
10493: if (caseblkDUP.getCaseStart() == i) {
10494: tempString = "case "
10495: + caseblkDUP
10496: .getCaseLabel()
10497: + ": \n{\n";
10498: temp += Util
10499: .formatDecompiledStatement(tempString);
10500: stmt = temp;
10501: break;
10502: }
10503:
10504: }
10505: }
10506:
10507: // Now check with default:
10508: if (i == switchblk.getDefaultStart()
10509: && switchblk.defaultToBeDisplayed()) {
10510: tempString = "default:\n{\n";
10511: temp += Util
10512: .formatDecompiledStatement(tempString);
10513: }
10514: if (i == switchblk.getDefaultStart()
10515: && !switchblk
10516: .defaultToBeDisplayed()) {
10517: tempString = "\n}\n";
10518: temp += Util
10519: .formatDecompiledStatement(tempString);
10520: }
10521:
10522: return temp;
10523: }
10524: }
10525: // check default
10526:
10527: }
10528: int defStart = switchblk.getDefaultStart();
10529: if (defStart == i && switchblk.defaultToBeDisplayed()) {
10530: stmt = "default:\n{\n";
10531: stmt = Util.formatDecompiledStatement(stmt);
10532: return stmt;
10533: }
10534: int defEnd = switchblk.getDefaultEnd();
10535: if (defEnd == i) {
10536: if (switchblk.defaultToBeDisplayed()) {
10537: stmt = Util
10538: .formatDecompiledStatement("}// Some End");
10539: stmt += Util
10540: .formatDecompiledStatement("\n}// Some end\n");
10541: } else
10542: stmt = Util
10543: .formatDecompiledStatement("}// Some End\n");
10544: return stmt;
10545: }
10546:
10547: }
10548:
10549: }
10550: return stmt;
10551: }
10552:
10553: private boolean checkForStartOfCatch(int instructionPos,
10554: ArrayList methodTries) {
10555: boolean add = true;
10556: boolean returnFromMethod = false;
10557: // Figure is this is a start of catch here
10558: if (methodTries != null) {
10559: for (int st = 0; st < methodTries.size(); st++) {
10560: TryBlock tryblk = (TryBlock) methodTries.get(st);
10561: FinallyBlock finblk = tryblk.getFinallyBlock();
10562: if (tryblk != null) {
10563: ArrayList allCatches = tryblk
10564: .getAllCatchesForThisTry();
10565: if (allCatches != null && allCatches.size() > 0) {
10566:
10567: for (int s1 = 0; s1 < allCatches.size(); s1++) {
10568:
10569: CatchBlock catchBlk = (CatchBlock) allCatches
10570: .get(s1);
10571: if (catchBlk != null) {
10572: int catchStart = catchBlk.getStart();
10573: if (catchStart == instructionPos) {
10574: add = false;
10575: returnFromMethod = true;
10576: break;
10577: }
10578: }
10579: }
10580: if (returnFromMethod)
10581: return add;
10582: }
10583: if (finblk != null) {
10584: int finstart = finblk.getStart();
10585: if (finstart == instructionPos) {
10586: return false;
10587: }
10588: }
10589: }
10590:
10591: }
10592:
10593: }
10594:
10595: return add;
10596: }
10597:
10598: ArrayList list;
10599:
10600: private boolean isPrevInstructionAload(int pos, byte[] code) {
10601: boolean present = false;
10602: int pos1 = pos - 1;
10603: int pos2 = pos - 2;
10604: int jvmInst_1 = code[pos1];
10605: int jvmInst_2 = code[pos2];
10606: switch (jvmInst_1) {
10607: case JvmOpCodes.ALOAD_0:
10608: case JvmOpCodes.ALOAD_1:
10609: case JvmOpCodes.ALOAD_2:
10610: case JvmOpCodes.ALOAD_3:
10611: present = true;
10612: break;
10613: default:
10614: present = false;
10615: break;
10616:
10617: }
10618: if (present == false) {
10619: if (jvmInst_2 == JvmOpCodes.ALOAD)
10620: present = true;
10621: }
10622:
10623: return present;
10624: }
10625:
10626: private boolean isPrevInstructionAload(int pos, byte[] code,
10627: StringBuffer sb) {
10628: boolean present = false;
10629: int pos1 = pos - 1;
10630: int pos2 = pos - 2;
10631: int jvmInst_1 = -1;
10632: int jvmInst_2 = -1;
10633: if (pos1 >= 0)
10634: jvmInst_1 = code[pos1];
10635: if (pos2 >= 0)
10636: jvmInst_2 = code[pos2];
10637: if (pos1 != -1) {
10638: switch (jvmInst_1) {
10639:
10640: case JvmOpCodes.ALOAD_0:
10641: case JvmOpCodes.ALOAD_1:
10642: case JvmOpCodes.ALOAD_2:
10643: case JvmOpCodes.ALOAD_3:
10644: present = true;
10645: break;
10646: default:
10647: present = false;
10648: break;
10649:
10650: }
10651: }
10652: if (present)
10653: sb.append(pos1);
10654: if (present == false) {
10655:
10656: if (jvmInst_2 == JvmOpCodes.ALOAD) {
10657: present = true;
10658: sb.append(pos2);
10659: }
10660:
10661: }
10662:
10663: return present;
10664: }
10665:
10666: private boolean checkForReturn(byte[] code, int i) {
10667: boolean present = false;
10668: int jvmInst = code[i];
10669: boolean b = isThisInstrStart(behaviour
10670: .getInstructionStartPositions(), i);
10671: if (b == false)
10672: return false;
10673: switch (jvmInst) {
10674: case JvmOpCodes.ARETURN:
10675: case JvmOpCodes.IRETURN:
10676: case JvmOpCodes.FRETURN:
10677: case JvmOpCodes.DRETURN:
10678: case JvmOpCodes.LRETURN:
10679: case JvmOpCodes.RETURN:
10680: present = true;
10681: break;
10682: default:
10683: present = false;
10684: break;
10685: }
10686: return present;
10687: }
10688:
10689: private boolean checkForValueReturn(byte[] code, int i) {
10690: boolean present = false;
10691: int jvmInst = code[i];
10692: switch (jvmInst) {
10693: case JvmOpCodes.ARETURN:
10694: case JvmOpCodes.IRETURN:
10695: case JvmOpCodes.FRETURN:
10696: case JvmOpCodes.DRETURN:
10697: case JvmOpCodes.LRETURN:
10698: present = true;
10699: break;
10700: default:
10701: present = false;
10702: break;
10703: }
10704: return present;
10705: }
10706:
10707: private boolean isIEndOfGuard(int i, Behaviour behaviour) {
10708: boolean end = false;
10709:
10710: ArrayList alltries = behaviour.getAllTriesForMethod();
10711: Iterator it = alltries.iterator();
10712: while (it.hasNext()) {
10713:
10714: TryBlock Try = (TryBlock) it.next();
10715: if (Try != null) {
10716: int endoftry = Try.getEnd();
10717: if (endoftry == i) // check for try's end
10718: {
10719: end = true;
10720: break;
10721: } else // Check for catches
10722: {
10723: ArrayList catches = Try.getAllCatchesForThisTry();
10724: for (int s = 0; s < catches.size(); s++) {
10725:
10726: CatchBlock catchblk = (CatchBlock) catches
10727: .get(s);
10728: if (catchblk != null) {
10729: int catchend = catchblk.getEnd();
10730: if (catchend == i) {
10731: end = true;
10732: break;
10733: }
10734:
10735: }
10736:
10737: }
10738:
10739: }
10740:
10741: }
10742: }
10743:
10744: return end;
10745: }
10746:
10747: private java.lang.String isAnyReturnPresentInSkipRegion(
10748: byte[] info, int i, Behaviour behaviour, StringBuffer stb) {
10749: boolean exit = false;
10750: java.lang.String ret = "";
10751: ArrayList tries = this .behaviour.getAllTriesForMethod();
10752: Iterator triesIT = tries.iterator();
10753: while (triesIT.hasNext()) {
10754: TryBlock TRY = (TryBlock) triesIT.next();
10755: ArrayList catches = TRY.getAllCatchesForThisTry();
10756: Iterator catchesIT = catches.iterator();
10757: TryCatchFinally prevBlock = TRY;
10758: while (catchesIT.hasNext()) {
10759: CatchBlock Catch = (CatchBlock) catchesIT.next();
10760: TryCatchFinally curBlock = Catch;
10761:
10762: if (i >= prevBlock.getEnd() && i < curBlock.getStart()) {
10763:
10764: java.lang.String retStmt = getReturnInstinRange(
10765: info, i, curBlock.getStart(), stb);
10766: ret = retStmt;
10767: exit = true;
10768: break;
10769: }
10770: prevBlock = curBlock;
10771: }
10772: if (exit)
10773: break;
10774: // Check for Finally Block
10775: if (!exit) {
10776: FinallyBlock Finally = TRY.getFinallyBlock();
10777: if (Finally != null) {
10778: CatchBlock catchblock = TRY.getLastCatchBlock();
10779: if (catchblock != null) {
10780:
10781: if (i >= catchblock.getEnd()
10782: && i < Finally.getStart()) {
10783: java.lang.String retStmt = getReturnInstinRange(
10784: info, i, Finally.getStart(), stb);
10785: ret = retStmt;
10786: break;
10787: }
10788: } else {
10789: if (i >= TRY.getEnd() && i < Finally.getStart()) {
10790: java.lang.String retStmt = getReturnInstinRange(
10791: info, i, Finally.getStart(), stb);
10792: ret = retStmt;
10793: break;
10794: }
10795: }
10796:
10797: }
10798: }
10799:
10800: if (ret.length() == 0) {
10801:
10802: if (i == TRY.getEnd()) {
10803: java.lang.String retStmt = getReturnInstinRange(
10804: info, i, i + 1, stb);
10805: ret = retStmt;
10806: break;
10807: }
10808:
10809: }
10810: }
10811:
10812: return ret;
10813: }
10814:
10815: private java.lang.String getReturnInstinRange(byte[] info, int i,
10816: int blockstart, StringBuffer sb) {
10817:
10818: for (int s = i; s < blockstart; s++) {
10819: int jvmInst = info[s];
10820: switch (jvmInst) {
10821: case JvmOpCodes.IRETURN:
10822: sb.append(s);
10823: return "ireturn";
10824: case JvmOpCodes.LRETURN:
10825: sb.append(s);
10826: return "lreturn";
10827: case JvmOpCodes.FRETURN:
10828: sb.append(s);
10829: return "freturn";
10830: case JvmOpCodes.DRETURN:
10831: sb.append(s);
10832: return "dreturn";
10833: case JvmOpCodes.ARETURN:
10834: sb.append(s);
10835: return "areturn";
10836: case JvmOpCodes.RETURN:
10837: sb.append(s);
10838: return "return";
10839: default:
10840: continue;
10841:
10842: }
10843:
10844: }
10845: sb.append("-1");
10846: return null;
10847:
10848: }
10849:
10850: private int getReturnStringPosInCode(byte[] info, int i,
10851: Behaviour behaviour) {
10852: int pos = -1;
10853: boolean exit = false;
10854:
10855: ArrayList tries = this .behaviour.getAllTriesForMethod();
10856: Iterator triesIT = tries.iterator();
10857: while (triesIT.hasNext()) {
10858: TryBlock TRY = (TryBlock) triesIT.next();
10859: ArrayList catches = TRY.getAllCatchesForThisTry();
10860: Iterator catchesIT = catches.iterator();
10861: TryCatchFinally prevBlock = TRY;
10862: while (catchesIT.hasNext()) {
10863: CatchBlock Catch = (CatchBlock) catchesIT.next();
10864: TryCatchFinally curBlock = Catch;
10865:
10866: if (i >= prevBlock.getEnd() && i < curBlock.getStart()) {
10867:
10868: pos = getReturnInstPosInRange(info, i, curBlock
10869: .getStart());
10870: exit = true;
10871: break;
10872: }
10873: prevBlock = curBlock;
10874: }
10875: if (exit)
10876: break;
10877: // Check for Finally Block
10878: if (!exit) {
10879: FinallyBlock Finally = TRY.getFinallyBlock();
10880: if (Finally != null) {
10881: CatchBlock catchblock = TRY.getLastCatchBlock();
10882: if (catchblock != null) {
10883:
10884: if (i >= catchblock.getEnd()
10885: && i < Finally.getStart()) {
10886:
10887: pos = getReturnInstPosInRange(info, i,
10888: Finally.getStart());
10889: break;
10890: }
10891: } else {
10892: if (i >= TRY.getEnd() && i < Finally.getStart()) {
10893: pos = getReturnInstPosInRange(info, i,
10894: Finally.getStart());
10895:
10896: break;
10897: }
10898: }
10899:
10900: }
10901: }
10902: if (i == TRY.getEnd()) {
10903: pos = getReturnInstPosInRange(info, i, i + 1);
10904:
10905: break;
10906: }
10907: } //Shutdown d;
10908: return pos;
10909: }
10910:
10911: private int getReturnInstPosInRange(byte[] info, int i,
10912: int blockstart) {
10913:
10914: for (int s = i; s < blockstart; s++) {
10915: int jvmInst = info[s];
10916: switch (jvmInst) {
10917: case JvmOpCodes.IRETURN:
10918: case JvmOpCodes.LRETURN:
10919: case JvmOpCodes.FRETURN:
10920: case JvmOpCodes.DRETURN:
10921: case JvmOpCodes.ARETURN:
10922: case JvmOpCodes.RETURN:
10923: return s;
10924: default:
10925: continue;
10926:
10927: }
10928:
10929: }
10930:
10931: return -1;
10932:
10933: }
10934:
10935: private int getNextAthrowPos(int endPC, byte[] info) {
10936: int pos = -1;
10937: for (int s = endPC; s < info.length; s++) {
10938: if (info[s] == JvmOpCodes.ATHROW) {
10939: pos = s;
10940: break;
10941: }
10942: }
10943:
10944: return pos;
10945: }
10946:
10947: private int findElseCloseLineNumber(int codeIndex, int gotoIndex,
10948: byte[] srcArray) {
10949: int retCodeIndex = -1;
10950:
10951: for (int srcArrayIndex = codeIndex; srcArrayIndex < srcArray.length; srcArrayIndex++) {
10952: if (srcArray[srcArrayIndex] == JvmOpCodes.GOTO) {
10953: int nextGotoIndex = getJumpAddress(srcArray,
10954: (srcArrayIndex));//(srcArray[++srcArrayIndex] << 8) | srcArray[++srcArrayIndex]) + (srcArrayIndex - 2);
10955:
10956: if (nextGotoIndex == gotoIndex) {
10957: retCodeIndex = srcArrayIndex - 2;
10958: break;
10959: }
10960: }
10961: }
10962: return retCodeIndex;
10963: }
10964:
10965: private int findCodeIndexFromInfiniteLoop(IFBlock ifst,
10966: ArrayList LoopTable, int codeIndex) {
10967: Iterator iterInfLoop = LoopTable.iterator();
10968: int start = ifst.getIfStart();
10969: int loopstarts[] = new int[LoopTable.size()];
10970: int j = 0;
10971: boolean ok = false;
10972: while (iterInfLoop.hasNext()) {
10973: Loop iloop = (Loop) iterInfLoop.next();
10974: int lstart = iloop.getStartIndex();
10975: loopstarts[j] = lstart;
10976: j++;
10977: ok = true;
10978: /*if(iloop.getStartIndex() == codeIndex)
10979: {
10980: return iloop.getEndIndex();
10981: } */
10982: }
10983: if (ok) {
10984: for (int z = loopstarts.length - 1; z >= 0; z--) {
10985:
10986: if (loopstarts[z] < start) {
10987: int end = getloopEndForStart(LoopTable,
10988: loopstarts[z]);
10989: if (end < start)
10990: return -1;
10991: return end;
10992: }
10993:
10994: }
10995: }
10996:
10997: return -1;
10998: }
10999:
11000: private boolean isIndexEndOfLoop(ArrayList list, int s) {
11001: boolean ok = false;
11002: for (int st = 0; st < list.size(); st++) {
11003: if (((Loop) list.get(st)).getEndIndex() == s)
11004: return true;
11005: }
11006: return ok;
11007: }
11008:
11009: private int getLoopStartForEnd(int s, ArrayList list) {
11010: for (int k = 0; k < list.size(); k++) {
11011: Loop l = (Loop) list.get(k);
11012: if (l.getEndIndex() == s)
11013: return l.getStartIndex();
11014: }
11015: return -1;
11016: }
11017:
11018: private boolean getIfinst(int start, byte[] info, int tillWhere) {
11019: boolean ok = false;
11020: ArrayList list = behaviour.getInstructionStartPositions();
11021: for (int k = start; k < tillWhere; k++) {
11022: int current = info[k];
11023: ok = isNextInstructionIf(current);
11024: if (ok && isThisInstrStart(list, k))
11025: return ok;
11026: }
11027: return ok;
11028: }
11029:
11030: private Collection curentIFS;
11031:
11032: private Collection getCurrentIFStructues() {
11033: if (ifHashTable != null && ifHashTable.size() > 0) {
11034: curentIFS = ifHashTable.values();
11035: return curentIFS;
11036: } else
11037: return null;
11038: }
11039:
11040: private Object[] sortIFStructures() {
11041: if (curentIFS != null && curentIFS.size() > 0) {
11042: Object o[] = curentIFS.toArray();
11043: Arrays.sort(o);
11044: return o;
11045: } else
11046: return null;
11047: }
11048:
11049: private IFBlock getParentBlock(Object o[], int startOfIf) {
11050:
11051: IFBlock parent = null;
11052: int reqdPos = -1;
11053: for (int s = 0; s < o.length; s++) {
11054: if (o[s] instanceof IFBlock) {
11055: IFBlock IF = (IFBlock) o[s];
11056: if (IF.getIfStart() == startOfIf) {
11057: if (s > 0) {
11058: reqdPos = s - 1;
11059: return (IFBlock) o[reqdPos];
11060: }
11061: }
11062:
11063: } else {
11064: return null;
11065: }
11066: }
11067: return null;
11068: }
11069:
11070: /***
11071: *
11072: * @param parent Immediate above IF instruction in code...MAY OR MAY NOT BE PARENT
11073: * @param ifstart For the If Block for which we are checking end of else
11074: * @param elseClose The current end of else...for which we are checking
11075: * @return
11076: */
11077:
11078: private int checkElseCloseLineNumber(Object ifsorted[],
11079: IFBlock parent, IFBlock currentIF, int ifstart,
11080: int elseClose, java.lang.StringBuffer needToCheck) {
11081: int elseToReturn = -1;
11082: int parentIFStart = parent.getIfStart();
11083: int parentIFEnd = parent.getIfCloseLineNumber();
11084: boolean doesParentHaveElse = parent.isHasElse();
11085: boolean needToFindSuperParent = false;
11086: int curifend = currentIF.getIfCloseLineNumber();
11087:
11088: // Check 1: Check whether currentIF lies withing the if of parent
11089: if (ifstart < parentIFEnd) // Yes it lies
11090: {
11091: if (elseClose > parentIFEnd) {
11092: elseToReturn = parentIFEnd;
11093: return elseToReturn;
11094: } else if (elseClose < curifend) {
11095: elseToReturn = parentIFEnd;
11096: return elseToReturn;
11097: } else {
11098: elseToReturn = elseClose; // Passes else was correct
11099: return elseToReturn;
11100: }
11101:
11102: }
11103: if (ifstart > parentIFEnd) {
11104: if (doesParentHaveElse) {
11105: int parentElseEnd = parent.getElseCloseLineNumber();
11106: if (currentIF.getIfCloseLineNumber() < parentElseEnd) // Lies within the else of parent IF
11107: {
11108: if (elseClose > parentElseEnd) {
11109: elseToReturn = parentElseEnd;
11110: return elseToReturn;
11111: } else if (elseClose < curifend) {
11112: elseToReturn = parentElseEnd;
11113: return elseToReturn;
11114: } else {
11115: elseToReturn = elseClose; // Passes else was correct
11116: return elseToReturn;
11117: }
11118: } else {
11119: needToFindSuperParent = true;
11120: }
11121:
11122: } else {
11123: needToFindSuperParent = true;
11124: }
11125:
11126: }
11127: if (needToFindSuperParent) {
11128: IFBlock super Parent = getParentBlock(ifsorted,
11129: parentIFStart);
11130: int tmp;
11131: if (super Parent != null) {
11132: StringBuffer t = new StringBuffer("false");
11133: tmp = checkElseCloseLineNumber(ifsorted, super Parent,
11134: currentIF, ifstart, elseClose, t);
11135: } else {
11136: if (behaviour.getBehaviourLoops().size() == 0)
11137: tmp = elseClose;
11138: else {
11139: tmp = elseClose;
11140: needToCheck.append("true");
11141: }
11142:
11143: }
11144: return tmp;
11145: } else {
11146: return elseClose; // Should Never come here
11147: }
11148:
11149: }
11150:
11151: private Loop this Loop = null;
11152:
11153: private boolean isBeyondLoop(int ifjump, ArrayList list, byte[] info) {
11154: boolean b = false;
11155: int temp = ifjump - 3;
11156: Loop l;
11157:
11158: if (temp >= 0 && info[temp] == JvmOpCodes.GOTO) {
11159:
11160: int jmp = getJumpAddress(info, temp);
11161: boolean end;
11162: end = isIndexEndOfLoop(list, temp);
11163: if (end) {
11164: b = true;
11165: l = getThisLoop(list, temp);
11166: this Loop = l;
11167: }
11168: /*if(!b)
11169: {
11170: int tmp2=jmp-3;
11171: end=isIndexEndOfLoop(list,tmp2);
11172: if(end)
11173: {
11174: b=true;
11175:
11176: l=getThisLoop(list,tmp2);
11177: thisLoop=l;
11178: }
11179: } */
11180:
11181: }
11182: return b;
11183:
11184: }
11185:
11186: // Primarily use it for goto and some special cases where appplicable
11187: private int getJumpAddress(byte[] info, int counter) {
11188:
11189: int b1 = info[++counter];
11190: int b2 = info[++counter];
11191: int z;
11192: if (b1 < 0)
11193: b1 = (256 + b1);
11194: if (b2 < 0)
11195: b2 = (256 + b2);
11196:
11197: int indexInst = ((((b1 << 8) | b2)) + (counter - 2));
11198: if (indexInst > 65535)
11199: indexInst = indexInst - 65536;
11200: if (indexInst < 0)
11201: indexInst = 256 + indexInst;
11202: return indexInst;
11203: }
11204:
11205: private int getOffset(byte[] info, int counter) {
11206:
11207: int b1 = info[++counter];
11208: int b2 = info[++counter];
11209: int z;
11210: if (b1 < 0)
11211: b1 = (256 + b1);
11212: if (b2 < 0)
11213: b2 = (256 + b2);
11214:
11215: int indexInst = (((b1 << 8) | b2));
11216: if (indexInst > 65535)
11217: indexInst = indexInst - 65536;
11218: if (indexInst < 0)
11219: indexInst = 256 + indexInst;
11220: return indexInst;
11221: }
11222:
11223: private int checkIfElseCloseNumber(int end, IFBlock ifs) {
11224: int ifend = -1;
11225: this .getCurrentIFStructues();
11226: Object ifsSorted[] = sortIFStructures();
11227: IFBlock parent = getParentBlock(ifsSorted, ifs.getIfStart());
11228: if (parent == null) {
11229:
11230: int temp = checkLoopsAndSwitchForIfEnd(end, ifs, behaviour);
11231: if (temp != -1)
11232: ifend = temp;
11233: else
11234: ifend = end;
11235: } else {
11236: ifend = reEvaluateIFStart(ifs, ifsSorted, parent, end);
11237: }
11238: return ifend;
11239: }
11240:
11241: private int reEvaluateIFStart(IFBlock ifs, Object[] ifsSorted,
11242: IFBlock parent, int currentEnd) {
11243: int ifend = -1;
11244: int parentEnd = parent.getIfCloseLineNumber();
11245: int this Start = ifs.getIfStart();
11246: if (this Start < parentEnd) {
11247: if (currentEnd > parentEnd) {
11248: // belurs:
11249: // Test case BigInteger.class
11250: /***
11251: * BasicallY this part of the code is not bug free.
11252: * It assumes that if the parentIF is ending before
11253: * this if end is ending then this ifend is wrong.
11254: * Well, it worked for every case until BigInteger
11255: * ws decompiled. So basically resetting parent
11256: * if end to this if end if parent if end was not
11257: * a GOTO instruction.
11258: */
11259: // Test for The above case
11260: if ((behaviour.getCode()[parentEnd] != JvmOpCodes.GOTO)
11261: && (behaviour.getCode()[parentEnd] != JvmOpCodes.GOTO_W)) {
11262: ifend = currentEnd;
11263: parent.setIfCloseLineNumber(ifend);
11264: } else {
11265:
11266: ifend = parentEnd;
11267: }
11268: } else if (currentEnd < this Start) {
11269: ifend = parentEnd;
11270: } else
11271: ifend = currentEnd;
11272:
11273: } // Need to handle thisif end inside parent's else end
11274: /* else if(thisStart > parentEnd)
11275: {
11276: boolean doesParentHaveElse=parent.isHasElse();
11277: if(doesParentHaveElse)
11278: {
11279: int parentElseEnd=parent.getElseCloseLineNumber();
11280: if(thisStart < parentElseEnd)
11281: {
11282: // Within parent else block
11283: if(currentEnd > parentElseEnd)
11284: {
11285: ifend=parentElseEnd;
11286: }
11287: else if(currentEnd < thisStart)
11288: {
11289: ifend=parentElseEnd;
11290: }
11291: else
11292: {
11293: ifend=currentEnd;
11294: }
11295:
11296: BigInteger b;
11297: }
11298: }
11299: } */
11300: else {
11301:
11302: IFBlock super parent = getParentBlock(ifsSorted, parent
11303: .getIfStart());
11304: if (super parent == null) {
11305: int temp = checkLoopsAndSwitchForIfEnd(currentEnd, ifs,
11306: behaviour);
11307: if (temp != -1)
11308: ifend = temp;
11309: else
11310: ifend = currentEnd;
11311:
11312: } else {
11313: int tmp = reEvaluateIFStart(ifs, ifsSorted,
11314: super parent, currentEnd);
11315: ifend = tmp;
11316: }
11317:
11318: }
11319:
11320: return ifend;
11321:
11322: }
11323:
11324: private java.lang.String getBranchType(int if_else_begin,
11325: int GotoStart, byte[] info, ArrayList loops,
11326: StringBuffer sb, boolean b) {
11327: java.lang.String lbl = "";
11328: boolean done = false;
11329: int immGotoJmp = getJumpAddress(info, GotoStart);
11330: int i = immGotoJmp;
11331: boolean end = isIndexEndOfLoop(loops, GotoStart);
11332: int lend = -1;
11333: if (end)
11334: lend = GotoStart;
11335:
11336: if (!end) {
11337: StringBuffer S = new StringBuffer("");
11338: end = checkForMatchingLoopAgain(loops, immGotoJmp, S);
11339: if (end)
11340: lend = Integer.parseInt(S.toString());
11341: }
11342: if (end) {
11343: int start = getLoopStartForEnd(lend, loops);
11344: if (start > if_else_begin) {
11345: return lbl;
11346: }
11347: Object[] sortedLoops = sortLoops(loops);
11348: int parentLoopStart = getParentLoopStartForIf(sortedLoops,
11349: if_else_begin);
11350: if (parentLoopStart == start) {
11351: java.lang.String s = setJDecLabelForContinue(
11352: parentLoopStart, lend);
11353: sb.append(s);
11354: lbl = "continue";
11355: continue_JumpOffsets.add(new Integer(immGotoJmp));
11356:
11357: } else {
11358: int nextstart = getNextLoopStart(start);
11359: if (nextstart != -1) {
11360: int loopend = getloopEndForStart(loops, nextstart);
11361: if (loopend != -1) {
11362: if (if_else_begin > loopend
11363: && nextstart < GotoStart) {
11364: sb.append("jdecLABEL" + start);
11365: lbl = "continue";
11366: done = true;
11367: LABELS.put(new Integer(start), "jdecLABEL"
11368: + start);
11369: }
11370: }
11371: if (done == false && (nextstart < GotoStart)) {
11372: break_JumpOffsets.add(new Integer(nextstart));
11373: sb.append("jdecLABEL" + nextstart);
11374: LABELS.put(new Integer(nextstart), "jdecLABEL"
11375: + nextstart);
11376: lbl = "break";
11377: }
11378: }
11379:
11380: }
11381:
11382: } else {
11383: lbl = "";
11384:
11385: }
11386: return lbl;
11387: }
11388:
11389: private java.lang.String getBranchType(int if_else_begin,
11390: int GotoStart, byte[] info, ArrayList loops, StringBuffer sb) {
11391: boolean over = false;
11392: java.lang.String lbl = "";
11393: int immGotoJmp = getJumpAddress(info, GotoStart);
11394: int i = immGotoJmp;
11395: boolean cont = continueFindingBranchType(immGotoJmp, info);
11396:
11397: // check whether immGotoJmp is loop start
11398: int loop_end = getloopEndForStart(loops, immGotoJmp);
11399: boolean done = false;
11400: if (loop_end != -1) {
11401: // Some loop is present
11402:
11403: Object[] sortedLoops = sortLoops(loops);
11404: int parentLoopStart = getParentLoopStartForIf(sortedLoops,
11405: if_else_begin);
11406: if (parentLoopStart == immGotoJmp) {
11407: java.lang.String s = setJDecLabelForContinue(
11408: parentLoopStart, loop_end);
11409: sb.append(s);
11410: lbl = "continue";
11411: continue_JumpOffsets.add(new Integer(immGotoJmp));
11412: done = true;
11413: } else {
11414: int nextstart = getNextLoopStart(immGotoJmp);
11415: if (nextstart != -1) {
11416: int loopend = getloopEndForStart(loops, nextstart);
11417: if (loopend != -1) {
11418: if (if_else_begin > loopend
11419: && nextstart < GotoStart) {
11420: sb.append("jdecLABEL" + immGotoJmp);
11421: lbl = "continue";
11422: over = true;
11423: LABELS.put(new Integer(immGotoJmp),
11424: "jdecLABEL" + immGotoJmp);
11425: }
11426: }
11427: if (over == false && nextstart < GotoStart) {
11428: break_JumpOffsets.add(new Integer(nextstart));
11429: sb.append("jdecLABEL" + nextstart);
11430: LABELS.put(new Integer(nextstart), "jdecLABEL"
11431: + nextstart);
11432: lbl = "break";
11433: }
11434: }
11435:
11436: done = true;
11437: }
11438:
11439: }
11440:
11441: if (done == false) {
11442: while ((i < info.length))// && cont) // TODO: check why This was needed
11443: {
11444: int current = info[i];
11445: if (current == JvmOpCodes.GOTO) {
11446: BigInteger b;
11447:
11448: if (i > immGotoJmp
11449: && info[immGotoJmp] != JvmOpCodes.GOTO) {
11450: lbl = "";
11451: break;
11452: }
11453: boolean end = isIndexEndOfLoop(loops, i);
11454: if (end) {
11455: int start = getLoopStartForEnd(i, loops);
11456: if (start > if_else_begin) {
11457: return lbl;
11458: }
11459: Object[] sortedLoops = sortLoops(loops);
11460: int parentLoopStart = getParentLoopStartForIf(
11461: sortedLoops, if_else_begin);
11462: if (parentLoopStart == start) {
11463: java.lang.String s = setJDecLabelForContinue(
11464: parentLoopStart, i);
11465: sb.append(s);
11466: lbl = "continue";
11467: continue_JumpOffsets.add(new Integer(
11468: immGotoJmp));
11469: break;
11470: } else {
11471: int nextstart = getNextLoopStart(start);
11472: if (nextstart != -1
11473: && nextstart < GotoStart) {
11474: break_JumpOffsets.add(new Integer(
11475: nextstart));
11476: sb.append("jdecLABEL" + nextstart);
11477: LABELS.put(new Integer(nextstart),
11478: "jdecLABEL" + nextstart);
11479: }
11480: lbl = "break";
11481: break;
11482: }
11483:
11484: } else {
11485: lbl = "";
11486: break;
11487: }
11488:
11489: } else
11490: i++;
11491:
11492: }
11493: }
11494:
11495: return lbl;
11496: }
11497:
11498: private Object[] sortLoops(ArrayList list) {
11499: Object o[] = list.toArray();
11500: Arrays.sort(o);
11501: return o;
11502: }
11503:
11504: private int getParentLoopStartForIf(Object[] sortedloops,
11505: int ifbegin) {
11506: int reqdStart = -1;
11507: int max = -1;
11508: int pos = 0;
11509: int counter = sortedloops.length - 1;
11510: while (counter >= 0) {
11511: Object o = sortedloops[counter];
11512: if (o instanceof Loop) {
11513: Loop l = (Loop) o;
11514: int ls = l.getStartIndex();
11515: if (ls < ifbegin) {
11516: reqdStart = ls;
11517: break;
11518: }
11519:
11520: }
11521: counter--;
11522: }
11523: return reqdStart;
11524:
11525: }
11526:
11527: private int getReqdGoto(int start, byte[] info, int end) {
11528: int x = -1;
11529: for (int s = (start + 3); s <= end; s++) {
11530: int cur = info[s];
11531: if (cur == JvmOpCodes.GOTO) {
11532: x = s;
11533: }//break;}
11534: }
11535: boolean b = isThisInstrStart(behaviour
11536: .getInstructionStartPositions(), x);
11537: if (b)
11538: return x;
11539: else
11540: return -1;
11541: }
11542:
11543: private Hashtable branchLabels = new Hashtable();
11544:
11545: private class BranchLabel {
11546: IFBlock IF;
11547: java.lang.String l; // continue or break or empty
11548:
11549: public java.lang.String getBrlbl() {
11550: return brlbl;
11551: }
11552:
11553: java.lang.String brlbl; // jmpindexlabel
11554:
11555: BranchLabel(IFBlock ifst, java.lang.String label,
11556: java.lang.String brlbl) {
11557: IF = ifst;
11558: l = label;
11559: this .brlbl = brlbl;
11560: }
11561:
11562: public IFBlock getIF() {
11563: return IF;
11564: }
11565:
11566: public java.lang.String getLBL() {
11567: return l;
11568: }
11569: }
11570:
11571: private java.lang.String getBranchTypeAtI(int i, IFBlock ifst,
11572: StringBuffer sb) {
11573: boolean skip = skipBranchCheck(i);
11574: if (skip)
11575: return "";
11576: Iterator it = branchLabels.entrySet().iterator();
11577: while (it.hasNext()) {
11578: Map.Entry e = (Map.Entry) it.next();
11579: int end = ((Integer) (e.getValue())).intValue();
11580: if (end == i) {
11581: BranchLabel b = (BranchLabel) e.getKey();
11582: IFBlock IF = b.getIF();
11583: if (IF == ifst) {
11584: labelAssociated.put(new Integer(i), "true");
11585: sb.append(b.getBrlbl());
11586: return b.getLBL();
11587: }
11588: }
11589:
11590: }
11591:
11592: return "";
11593: }
11594:
11595: private boolean skipBranchCheck(int i) {
11596: boolean b = false;
11597: Iterator it = labelAssociated.entrySet().iterator();
11598: while (it.hasNext()) {
11599: Map.Entry e = (Map.Entry) it.next();
11600: java.lang.String skip = ((java.lang.String) (e.getValue()));
11601: int end = ((Integer) e.getKey()).intValue();
11602: if (i == end && skip.equals("true"))
11603: b = true;
11604: }
11605: return b;
11606: }
11607:
11608: private Hashtable labelAssociated = null;//new Hashtable();
11609:
11610: private ArrayList continue_JumpOffsets = null;//new ArrayList();
11611: private ArrayList break_JumpOffsets = null;
11612:
11613: private int resetElseCloseNumber(ArrayList loopList, IFBlock ifs,
11614: int gotoStart) {
11615:
11616: if (loopList.size() > 0) {
11617: Object[] sortedLoops = sortLoops(loopList);
11618: int parentLoopStart = getParentLoopStartForIf(sortedLoops,
11619: ifs.getIfStart());
11620: int end = getloopEndForStart(loopList, parentLoopStart);
11621: int elseEnd = ifs.getElseCloseLineNumber();
11622: if (elseEnd > end && end != -1 && parentLoopStart != -1)
11623: ifs.setElseCloseLineNumber(end);
11624: return ifs.getElseCloseLineNumber();
11625: } else
11626: return ifs.getElseCloseLineNumber();
11627:
11628: }
11629:
11630: private boolean isNewEndValid(int newend, IFBlock ifs,
11631: java.lang.String type, int curend) {
11632:
11633: int end;
11634: if (type.equals("else"))
11635: end = ifs.getElseCloseLineNumber();
11636: else
11637: end = curend;
11638: if (newend == -1)
11639: return false;
11640: if (newend > end) {
11641: return false;
11642: }
11643:
11644: else
11645: return true;
11646: }
11647:
11648: private int resetEndofIFElseWRTSwitch(ArrayList switches,
11649: IFBlock anIf, int curend, int curStart,
11650: java.lang.String type) {
11651: int k = -1;
11652: ArrayList possibleCaseEnds = new ArrayList();
11653: for (int s = 0; s < switches.size(); s++) {
11654:
11655: Switch swblk = (Switch) switches.get(s);
11656: ArrayList cases = swblk.getAllCases();
11657: for (int c = 0; c < cases.size(); c++) {
11658: Case caseblk = (Case) cases.get(c);
11659: int end = caseblk.getCaseEnd();
11660: int ifelseStart = curStart;
11661: int ifelseEnd;
11662: if (type.equals("else"))
11663: ifelseEnd = anIf.getElseCloseLineNumber();
11664: else
11665: ifelseEnd = curend;
11666: if (end > ifelseStart && end < ifelseEnd) {
11667: possibleCaseEnds.add(new Integer(end));
11668: }
11669:
11670: }
11671:
11672: }
11673:
11674: if (possibleCaseEnds.size() > 0) {
11675: Integer ints[] = (Integer[]) possibleCaseEnds
11676: .toArray(new Integer[possibleCaseEnds.size()]);
11677: Arrays.sort(ints);
11678: k = ints[0].intValue();
11679:
11680: }
11681:
11682: return k;
11683: }
11684:
11685: private int getloopEndForStart(ArrayList list, int start) {
11686: for (int i = 0; i < list.size(); i++) {
11687: Loop l = (Loop) list.get(i);
11688: if (l.getStartIndex() == start) {
11689: return l.getEndIndex();
11690: }
11691: }
11692: return -1;
11693:
11694: }
11695:
11696: private int resetElseCloseNumber(int start, int end) {
11697: int newend = end;
11698: int t1 = start + 2;
11699: int t2 = end;
11700: for (int s = 0; s < continue_JumpOffsets.size(); s++) {
11701: int i = ((Integer) continue_JumpOffsets.get(s)).intValue();
11702: if ((i > t1) && (i < t2)) {
11703: newend = i;
11704: break;
11705: }
11706: }
11707: return newend;
11708: }
11709:
11710: private Loop getThisLoop(ArrayList list, int s) {
11711: Loop l;
11712: for (int st = 0; st < list.size(); st++) {
11713: Loop tmp = (Loop) list.get(st);
11714: if (tmp.getEndIndex() == s)
11715: return tmp;
11716: }
11717: return null;
11718: }
11719:
11720: private void addBranchLabel(int classIndex, int i, IFBlock ifst,
11721: int currentForIndex, byte[] info) {
11722:
11723: boolean add = true;
11724: boolean continuetofind = false;
11725: /* if(classIndex < i)
11726: {
11727: ifst.setIfCloseLineNumber(findCodeIndexFromInfiniteLoop(ifst,behaviour.getBehaviourLoops(),classIndex));
11728: if(ifst.getIfCloseLineNumber()==-1)
11729: continuetofind=true;
11730: }
11731: if(classIndex > i || continuetofind)
11732: {*/
11733: if (isThisInstrStart(behaviour.getInstructionStartPositions(),
11734: classIndex - 3)
11735: && info[classIndex - 3] == JvmOpCodes.GOTO) // GOTO_W?
11736: {
11737:
11738: int resetVal = checkIfElseCloseNumber(classIndex - 3, ifst);
11739: ifst.setIfCloseLineNumber(resetVal);
11740: } else {
11741:
11742: int resetVal = checkIfElseCloseNumber(classIndex, ifst);
11743: ifst.setIfCloseLineNumber(resetVal);
11744: }
11745:
11746: // }
11747:
11748: int if_start = ifst.getIfStart();
11749: int if_end = ifst.getIfCloseLineNumber();
11750: if (if_end == -1 || if_end < if_start) {
11751: boolean b = false;
11752: int bytecodeend = ifst.getIfCloseFromByteCode();
11753: b = isByteCodeALoopStart(behaviour.getBehaviourLoops(),
11754: bytecodeend);
11755: if (b) {
11756: int loopend = getloopEndForStart(behaviour
11757: .getBehaviourLoops(), bytecodeend);
11758: if (loopend != -1) {
11759: ifst.setIfCloseLineNumber(loopend);
11760: }
11761: }
11762: }
11763:
11764: int k = ifst.getIfCloseFromByteCode();
11765: k = k - 3;
11766: if (isThisInstrStart(behaviour.getInstructionStartPositions(),
11767: k)
11768: && k > ifst.getIfStart()) {
11769: boolean IF = isInstructionIF(info[k]);
11770: if (IF && k != ifst.getIfStart()) {
11771: ifst.setDonotclose(true);
11772: }
11773: }
11774:
11775: k = ifst.getIfCloseLineNumber();
11776: k = k - 3;
11777: if (isThisInstrStart(behaviour.getInstructionStartPositions(),
11778: k)
11779: && ifst.getIfCloseFromByteCode() < ifst.getIfStart()) {
11780: boolean IF = isInstructionIF(info[k]);
11781: if (IF && k != ifst.getIfStart()) {
11782: ifst.setDonotclose(true);
11783: }
11784: }
11785: java.lang.String s = "";
11786: StringBuffer sb = new StringBuffer("");
11787: int gotos = -1;
11788: if (isThisInstrStart(behaviour.getInstructionStartPositions(),
11789: currentForIndex + 3)
11790: && info[currentForIndex + 3] == JvmOpCodes.GOTO) {
11791: s = getBranchType(currentForIndex, currentForIndex + 3,
11792: info, behaviour.getBehaviourLoops(), sb, true);
11793: if (s.trim().length() == 0) {
11794: int end = getClosestLoopEndForThisIf(currentForIndex,
11795: behaviour.getBehaviourLoops(), info);
11796: if (end != -1) {
11797: s = "break";
11798: }
11799:
11800: }
11801: // TODO
11802: gotos = currentForIndex + 3;
11803: } else {
11804: int x = getReqdGoto(currentForIndex, info, ifst
11805: .getIfCloseLineNumber());
11806: if (x != -1) {
11807: s = getBranchType(currentForIndex, x, info, behaviour
11808: .getBehaviourLoops(), sb);
11809: gotos = x;
11810: }
11811:
11812: }
11813: if (gotos != -1) {
11814: // TODO: Skip if IFSTRUCTURE is a loop
11815:
11816: int gotoj = getJumpAddress(info, gotos);
11817: if (isThisInstrStart(behaviour
11818: .getInstructionStartPositions(), gotoj)
11819: && info[gotoj] == JvmOpCodes.RETURN) {
11820: retAtIfElseEnd.put(new Integer(ifst
11821: .getIfCloseLineNumber()), "return");
11822: add = false;
11823: }
11824: }
11825:
11826: if (add)
11827: branchLabels.put(new BranchLabel(ifst, s, sb.toString()),
11828: new Integer(ifst.getIfCloseLineNumber()));
11829:
11830: }
11831:
11832: private ArrayList sortCasesByStart(ArrayList allcases) {
11833: ArrayList sorted = new ArrayList();
11834: int s[] = new int[allcases.size()];
11835: for (int i = 0; i < allcases.size(); i++) {
11836: s[i] = ((Case) allcases.get(i)).getCaseStart();
11837: }
11838: Arrays.sort(s);
11839: for (int j = 0; j < s.length; j++) {
11840: int c = s[j];
11841: for (int k = 0; k < allcases.size(); k++) {
11842: Case current = (Case) allcases.get(k);
11843: if (current.getCaseStart() == c) {
11844: sorted.add(current);
11845: break;
11846: }
11847: }
11848: }
11849: return sorted;
11850: }
11851:
11852: private int checkLoopsAndSwitchForIfEnd(int end, IFBlock ifs,
11853: Behaviour behaviour) {
11854: int reqdEnd = -1;
11855: ArrayList loops = behaviour.getBehaviourLoops();
11856: if (loops != null && loops.size() > 0) {
11857:
11858: Object[] sortedLoops = sortLoops(loops);
11859: int parentLoopStart = getParentLoopStartForIf(sortedLoops,
11860: ifs.getIfStart());
11861: int loopend = getloopEndForStart(loops, parentLoopStart);
11862: if (ifs.getIfStart() < loopend && end > loopend)
11863: ifs.setIfCloseLineNumber(loopend);
11864: reqdEnd = ifs.getIfCloseLineNumber();
11865:
11866: }
11867:
11868: ArrayList allswicthes = behaviour.getAllSwitchBlks();
11869: if (allswicthes != null && allswicthes.size() > 0) {
11870:
11871: int newifend = -1;
11872: newifend = resetEndofIFElseWRTSwitch(allswicthes, ifs,
11873: reqdEnd, currentForIndex, "if");
11874: boolean valid = isNewEndValid(newifend, ifs, "if", end);
11875: if (valid) {
11876: ifs.setIfCloseLineNumber(newifend);
11877: reqdEnd = ifs.getIfCloseLineNumber();
11878:
11879: }
11880:
11881: }
11882: return reqdEnd;
11883:
11884: }
11885:
11886: private void checkEndOfLoops(Hashtable IfS, Behaviour b) {
11887: this .getCurrentIFStructues();
11888: Object ifsSorted[] = sortIFStructures();
11889: ArrayList loops = b.getBehaviourLoops();
11890: Object sorted[] = sortLoops(loops);
11891: ArrayList allswitches = b.getAllSwitchBlks();
11892: if (loops.size() == 0)
11893: return;
11894: else {
11895: for (int s = 0; s < sorted.length; s++) {
11896: if (!(sorted[s] instanceof Loop))
11897: continue;
11898: Loop cur = (Loop) sorted[s];
11899: if (IfS.size() > 0)
11900: resetLoopEndWRTIFs(IfS, b, cur, ifsSorted);
11901: int newloopend = resetLoopEndWRTLoops(sorted, b, cur);
11902: cur.setEndIndex(newloopend);
11903: if (allswitches != null && allswitches.size() > 0) {
11904: newloopend = resetLoopEndWRTSwitch(allswitches, b,
11905: cur);
11906: cur.setEndIndex(newloopend);
11907: }
11908: }
11909:
11910: }
11911:
11912: }
11913:
11914: private void resetLoopEndWRTIFs(Hashtable IfS, Behaviour b,
11915: Loop cur, Object ifsorted[]) {
11916:
11917: IFBlock parentif = getParentIFforLoop(cur, ifsorted);
11918: if (parentif == null)
11919: return;
11920: else {
11921: int lend = checkEndofLoopWRTIF(parentif, ifsorted, cur);
11922: cur.setEndIndex(lend);
11923: }
11924:
11925: }
11926:
11927: private IFBlock getParentIFforLoop(Loop cur, Object ifsorted[]) {
11928: IFBlock par = null;
11929: for (int n = (ifsorted.length - 1); n >= 0; n--) {
11930: if (!(ifsorted[n] instanceof IFBlock))
11931: continue;
11932: IFBlock IF = (IFBlock) ifsorted[n];
11933: int s = IF.getIfStart();
11934: if (s < cur.getStartIndex()) {
11935: par = IF;
11936: break;
11937: }
11938: }
11939: return par;
11940: }
11941:
11942: private int checkEndofLoopWRTIF(IFBlock parentif,
11943: Object[] ifsorted, Loop cur) {
11944: int end = -1;
11945: int parentIFStart = parentif.getIfStart();
11946: int parentIFEnd = parentif.getIfCloseLineNumber();
11947: boolean doesParentHaveElse = parentif.isHasElse();
11948: boolean needToFindSuperParent = false;
11949:
11950: if (cur.getStartIndex() < parentIFEnd) // Yes it lies
11951: {
11952: if (cur.getEndIndex() > parentIFEnd) {
11953: end = parentIFEnd;
11954: return end;
11955: } else {
11956: end = cur.getEndIndex(); // Passes else was correct
11957: return end;
11958: }
11959:
11960: }
11961:
11962: if (cur.getStartIndex() > parentIFEnd) {
11963: if (doesParentHaveElse) {
11964: int parentElseEnd = parentif.getElseCloseLineNumber();
11965: if (cur.getStartIndex() < parentElseEnd) // Lies within the else of parent IF
11966: {
11967: if (cur.getEndIndex() > parentElseEnd) {
11968: end = parentElseEnd;
11969: return end;
11970: } else {
11971: end = cur.getEndIndex();
11972: return end;
11973: }
11974: } else {
11975: needToFindSuperParent = true;
11976: }
11977:
11978: } else {
11979: needToFindSuperParent = true;
11980: }
11981:
11982: }
11983: if (needToFindSuperParent) {
11984: IFBlock super Parent = getParentBlock(ifsorted,
11985: parentIFStart);
11986: int tmp;
11987: if (super Parent != null)
11988: tmp = checkEndofLoopWRTIF(super Parent, ifsorted, cur);
11989: else {
11990: tmp = cur.getEndIndex();
11991: }
11992: return tmp;
11993: } else {
11994: return cur.getEndIndex(); // Should Never come here
11995: }
11996:
11997: }
11998:
11999: private int resetLoopEndWRTLoops(Object[] loops, Behaviour b,
12000: Loop cur) {
12001: Loop temp = null;
12002: Loop parent = null;
12003: for (int s = 0; s < loops.length; s++) {
12004: temp = (Loop) loops[s];
12005: if (temp == cur) {
12006: if (s == 0)
12007: return cur.getEndIndex();
12008: if (s > 0) {
12009: int prev = s - 1;
12010: parent = (Loop) loops[prev];
12011: int parEnd = parent.getEndIndex();
12012: if (cur.getEndIndex() > parEnd) {
12013: return parEnd;
12014: } else {
12015: return cur.getEndIndex();
12016: }
12017: }
12018: }
12019:
12020: }
12021: return cur.getEndIndex();
12022:
12023: }
12024:
12025: private int resetLoopEndWRTSwitch(ArrayList allswitches,
12026: Behaviour b, Loop cur) {
12027: int k = -1;
12028: ArrayList possibleCaseEnds = new ArrayList();
12029: for (int s = 0; s < allswitches.size(); s++) {
12030:
12031: Switch swblk = (Switch) allswitches.get(s);
12032: ArrayList cases = swblk.getAllCases();
12033: for (int c = 0; c < cases.size(); c++) {
12034: Case caseblk = (Case) cases.get(c);
12035: int end = caseblk.getCaseEnd();
12036: if (end > cur.getStartIndex()
12037: && end < cur.getEndIndex()) {
12038: possibleCaseEnds.add(new Integer(end));
12039: }
12040:
12041: }
12042:
12043: }
12044:
12045: if (possibleCaseEnds.size() > 0) {
12046: Integer ints[] = (Integer[]) possibleCaseEnds
12047: .toArray(new Integer[possibleCaseEnds.size()]);
12048: Arrays.sort(ints);
12049: k = ints[0].intValue();
12050: return k;
12051: } else
12052: return cur.getEndIndex();
12053: }
12054:
12055: private boolean isThisLoopEndAlso(ArrayList loops, int i,
12056: int ifstart) {
12057: for (int s = 0; s < loops.size(); s++) {
12058: Loop l = (Loop) loops.get(s);
12059: int lend = (l).getEndIndex();
12060: if (lend == i && ifstart > l.getStartIndex())
12061: return true;
12062: }
12063: return false;
12064: }
12065:
12066: private boolean doesthis ClashWithCaseBegin(ArrayList switches, int i) {
12067: if (switches == null || switches.size() == 0)
12068: return false;
12069: boolean ret = false;
12070: for (int s = 0; s < switches.size(); s++) {
12071:
12072: Switch swblk = (Switch) switches.get(s);
12073: ArrayList cases = swblk.getAllCases();
12074: for (int k = 0; k < cases.size(); k++) {
12075: Case c = (Case) cases.get(k);
12076: if (c.getCaseStart() == i) {
12077: ret = true;
12078: break;
12079: }
12080: }
12081:
12082: }
12083: return ret;
12084: }
12085:
12086: private Case isIFInCase(Behaviour behaviour, int currentForIndex,
12087: IFBlock ifs) {
12088:
12089: Case caseblk = null;
12090: boolean present = false;
12091: int ifstart = ifs.getIfStart();
12092: int ifend = ifs.getIfCloseLineNumber();
12093: ArrayList allswitches = behaviour.getAllSwitchBlks();
12094: for (int s = 0; s < allswitches.size(); s++) {
12095:
12096: ArrayList allcases = ((Switch) allswitches.get(s))
12097: .getAllCases();
12098: for (int k = 0; k < allcases.size(); k++) {
12099: Case cblk = (Case) allcases.get(k);
12100: int casestart = cblk.getCaseStart();
12101: int caseend = cblk.getCaseEnd();
12102: if (ifstart >= casestart && ifend < caseend) {
12103:
12104: present = true;
12105: caseblk = cblk;
12106: break;
12107: }
12108:
12109: }
12110: //System.out.println(caseblk);
12111: if (present)
12112: break;
12113:
12114: }
12115:
12116: return caseblk;
12117:
12118: }
12119:
12120: private int getElseEndwrtcaseblk(Case caseblk, byte[] info,
12121: int start) {
12122:
12123: int end = -1;
12124: boolean found = false;
12125: int caseend = caseblk.getCaseEnd();
12126: for (int i = start; i <= caseend; i++) {
12127: int inst = info[i];
12128: if (isThisInstrStart(behaviour
12129: .getInstructionStartPositions(), i)
12130: && inst == JvmOpCodes.GOTO) {
12131: end = i;
12132: found = true;
12133: break;
12134: }
12135:
12136: }
12137: if (!found)
12138: end = caseend;
12139: return end;
12140: }
12141:
12142: private boolean checkForSomeSpecificInstructions(byte[] code, int i)
12143:
12144: {
12145: int inst = code[i];
12146: switch (inst) {
12147:
12148: //LDC // TODO: Need to Regressoion Testing Here // uncommented bcoz of trytrest_4
12149: case JvmOpCodes.LDC2_W:
12150: case JvmOpCodes.LDC_W:
12151:
12152: // case JvmOpCodes.ACONST_NULL:
12153: case JvmOpCodes.DUP:
12154: case JvmOpCodes.DUP2:
12155: // case JvmOpCodes.NEW:
12156: case JvmOpCodes.CHECKCAST:
12157: case JvmOpCodes.ATHROW:
12158:
12159: case JvmOpCodes.ANEWARRAY:
12160: case JvmOpCodes.NEWARRAY:
12161: case JvmOpCodes.MULTIANEWARRAY:
12162: return true;
12163:
12164: }
12165: if (inst == JvmOpCodes.LDC
12166: && (isThisInstrStart(behaviour
12167: .getInstructionStartPositions(), (i - 3)) && code[(i - 3)] != JvmOpCodes.INVOKESPECIAL)) {
12168: return true;
12169: }
12170: return false;
12171:
12172: }
12173:
12174: private Hashtable LABELS;
12175: private Hashtable retAtIfElseEnd;
12176:
12177: private java.lang.String setJDecLabelForContinue(int start, int end) {
12178:
12179: // Skip If IFBlock under examination is a Loop
12180: ArrayList loops = behaviour.getBehaviourLoops();
12181: for (int s1 = 0; s1 < loops.size(); s1++) {
12182: Loop l = (Loop) loops.get(s1);
12183: int st = l.getStartIndex();
12184: int ed = l.getEndIndex();
12185: if (st == start && ed == end) {
12186: return "";
12187: }
12188: }
12189:
12190: byte[] info;
12191: if (behaviour != null) {
12192: info = behaviour.getCode();
12193: int inst = info[start];
12194: int loadIndex = getLoadInstIndex(inst, info, start);
12195: if (loadIndex == -1)
12196: return "";
12197: else {
12198: int pos = getStoreInstPosInCode(info, end, loadIndex);
12199: if (pos != -1) {
12200: LABELS.put(new Integer(pos), "jdecLABEL" + pos);
12201: return "jdecLABEL" + pos;
12202: }
12203:
12204: }
12205: }
12206:
12207: return "";
12208: }
12209:
12210: private int getStoreInstPosInCode(byte[] info, int lend,
12211: int loadIndex)
12212:
12213: {
12214: for (int s = lend; s >= 0; s--) {
12215: if (isThisInstrStart(behaviour
12216: .getInstructionStartPositions(), s)) {
12217: int curinst = info[s];
12218: boolean b = isCurrentInstStore(curinst);
12219: if (b) {
12220: int temp = s + 1;
12221: int storeindex = info[temp];
12222: if (storeindex == loadIndex)
12223: return s;
12224: }
12225: }
12226:
12227: }
12228: return -1;
12229: }
12230:
12231: private boolean isCurrentInstStore(int inst) {
12232: boolean flag;
12233: switch (inst) {
12234:
12235: case JvmOpCodes.ASTORE:
12236: flag = true;
12237: break;
12238:
12239: case JvmOpCodes.ASTORE_0:
12240: flag = true;
12241: break;
12242: case JvmOpCodes.ASTORE_1:
12243: flag = true;
12244: break;
12245: case JvmOpCodes.ASTORE_2:
12246: flag = true;
12247: break;
12248: case JvmOpCodes.ASTORE_3:
12249: flag = true;
12250: break;
12251: case JvmOpCodes.DSTORE:
12252: flag = true;
12253: break;
12254: case JvmOpCodes.DSTORE_0:
12255: flag = true;
12256: break;
12257: case JvmOpCodes.DSTORE_1:
12258: flag = true;
12259: break;
12260: case JvmOpCodes.DSTORE_2:
12261: flag = true;
12262: break;
12263: case JvmOpCodes.DSTORE_3:
12264: flag = true;
12265: break;
12266:
12267: case JvmOpCodes.FSTORE:
12268: flag = true;
12269: break;
12270: case JvmOpCodes.FSTORE_0:
12271: flag = true;
12272: break;
12273: case JvmOpCodes.FSTORE_1:
12274: flag = true;
12275: break;
12276: case JvmOpCodes.FSTORE_2:
12277: flag = true;
12278: break;
12279: case JvmOpCodes.FSTORE_3:
12280: flag = true;
12281: break;
12282:
12283: case JvmOpCodes.ISTORE:
12284: flag = true;
12285: break;
12286: case JvmOpCodes.ISTORE_0:
12287: flag = true;
12288: break;
12289: case JvmOpCodes.ISTORE_1:
12290: flag = true;
12291: break;
12292: case JvmOpCodes.ISTORE_2:
12293: flag = true;
12294: break;
12295: case JvmOpCodes.ISTORE_3:
12296: flag = true;
12297: break;
12298: case JvmOpCodes.LSTORE:
12299: flag = true;
12300: break;
12301:
12302: case JvmOpCodes.LSTORE_0:
12303: flag = true;
12304: break;
12305: case JvmOpCodes.LSTORE_1:
12306: flag = true;
12307: break;
12308: case JvmOpCodes.LSTORE_2:
12309: flag = true;
12310: break;
12311: case JvmOpCodes.LSTORE_3:
12312: flag = true;
12313: break;
12314:
12315: default:
12316: flag = false;
12317: }
12318: return flag;
12319: }
12320:
12321: /****
12322: * NOTE: This is not general purpose method tofind load index inst...Skips ceratian loads
12323: * see usages
12324: * @param inst
12325: * @param info
12326: * @param s
12327: * @return
12328: */
12329: public int getLoadInstIndex(int inst, byte info[], int s) {
12330: // chkIndex is the index of the goto instruction.
12331:
12332: switch (inst) {
12333:
12334: case JvmOpCodes.ALOAD:
12335: return info[++s];
12336:
12337: case JvmOpCodes.ALOAD_0:
12338: return 0;
12339:
12340: case JvmOpCodes.ALOAD_1:
12341: return 1;
12342:
12343: case JvmOpCodes.ALOAD_2:
12344: return 2;
12345:
12346: case JvmOpCodes.ALOAD_3:
12347: return 3;
12348:
12349: case JvmOpCodes.DLOAD:
12350: return info[++s];
12351:
12352: case JvmOpCodes.DLOAD_0:
12353: return 0;
12354:
12355: case JvmOpCodes.DLOAD_1:
12356: return 1;
12357:
12358: case JvmOpCodes.DLOAD_2:
12359: return 2;
12360:
12361: case JvmOpCodes.DLOAD_3:
12362: return 3;
12363:
12364: case JvmOpCodes.FLOAD:
12365: return info[++s];
12366:
12367: case JvmOpCodes.FLOAD_0:
12368: return 0;
12369:
12370: case JvmOpCodes.FLOAD_1:
12371: return 1;
12372:
12373: case JvmOpCodes.FLOAD_2:
12374: return 2;
12375:
12376: case JvmOpCodes.FLOAD_3:
12377: return 3;
12378:
12379: case JvmOpCodes.ILOAD:
12380: return info[++s];
12381:
12382: case JvmOpCodes.ILOAD_0:
12383: return 0;
12384:
12385: case JvmOpCodes.ILOAD_1:
12386: return 1;
12387:
12388: case JvmOpCodes.ILOAD_2:
12389: return 2;
12390:
12391: case JvmOpCodes.ILOAD_3:
12392: return 3;
12393:
12394: case JvmOpCodes.LLOAD:
12395: return info[++s];
12396:
12397: case JvmOpCodes.LLOAD_0:
12398: return 0;
12399: case JvmOpCodes.LLOAD_1:
12400: return 1;
12401: case JvmOpCodes.LLOAD_2:
12402: return 2;
12403: case JvmOpCodes.LLOAD_3:
12404: return 3;
12405:
12406: }
12407:
12408: return -1;
12409: }
12410:
12411: private java.lang.String getAnyLabelAtI(Hashtable labels, int i) {
12412: java.lang.String lbl = (java.lang.String) labels
12413: .get(new Integer(i));
12414: return lbl;
12415: }
12416:
12417: /****
12418: * NOTE: This is not general purpose method tofind load inst...Skips ceratian loads
12419: * see usages
12420: */
12421: public boolean continueFindingBranchType(int i, byte info[]) {
12422: // chkIndex is the index of the goto instruction.
12423:
12424: switch (info[i]) {
12425:
12426: case JvmOpCodes.ALOAD:
12427:
12428: case JvmOpCodes.ALOAD_0:
12429:
12430: case JvmOpCodes.ALOAD_1:
12431:
12432: case JvmOpCodes.ALOAD_2:
12433:
12434: case JvmOpCodes.ALOAD_3:
12435:
12436: case JvmOpCodes.DLOAD:
12437:
12438: case JvmOpCodes.DLOAD_0:
12439:
12440: case JvmOpCodes.DLOAD_1:
12441:
12442: case JvmOpCodes.DLOAD_2:
12443:
12444: case JvmOpCodes.DLOAD_3:
12445:
12446: case JvmOpCodes.FLOAD:
12447:
12448: case JvmOpCodes.FLOAD_0:
12449:
12450: case JvmOpCodes.FLOAD_1:
12451:
12452: case JvmOpCodes.FLOAD_2:
12453:
12454: case JvmOpCodes.FLOAD_3:
12455:
12456: case JvmOpCodes.ILOAD:
12457:
12458: case JvmOpCodes.ILOAD_0:
12459:
12460: case JvmOpCodes.ILOAD_1:
12461:
12462: case JvmOpCodes.ILOAD_2:
12463:
12464: case JvmOpCodes.ILOAD_3:
12465:
12466: case JvmOpCodes.LLOAD:
12467:
12468: case JvmOpCodes.LLOAD_0:
12469:
12470: case JvmOpCodes.LLOAD_1:
12471:
12472: case JvmOpCodes.LLOAD_2:
12473:
12474: case JvmOpCodes.LLOAD_3:
12475: return true;
12476:
12477: }
12478:
12479: return false;
12480: }
12481:
12482: private boolean skipGeneratingElse(ArrayList gotos,
12483: ArrayList gotoj, int currentForIndex, IFBlock ifs) {
12484: boolean skip = false;
12485: int temp = currentForIndex + 3;
12486: for (int s = 0; s < gotoj.size(); s++) {
12487:
12488: int jump = ((Integer) gotoj.get(s)).intValue();
12489: if (jump == temp) {
12490: int corS = ((Integer) gotos.get(s)).intValue();
12491: if (corS > ifs.getIfStart()
12492: && corS < ifs.getIfCloseLineNumber())
12493: return true;
12494: }
12495:
12496: }
12497:
12498: return skip;
12499:
12500: }
12501:
12502: private boolean isThisIfALoopCondition(IFBlock IF, byte[] info,
12503: ArrayList loops) {
12504: boolean b = true;
12505: int ifend = IF.getIfCloseLineNumber();
12506: int ifs = IF.getIfStart();
12507: boolean b1 = isThisLoopEndAlso(loops, ifend, ifs);
12508: ArrayList list = behaviour.getInstructionStartPositions();
12509: if (!b1)
12510: return false;
12511: if (b1) {
12512: int jump = getJumpAddress(info, ifend);
12513: if (jump >= ifs)
12514: return false;
12515: for (int s = jump; s < ifs; s++) {
12516: int inst = info[s];
12517: boolean b2 = isNextInstructionIf(inst);
12518: if (b2 && isThisInstrStart(list, s)) {
12519: b = false;
12520: return b;
12521: }
12522: }
12523:
12524: }
12525:
12526: return b;
12527:
12528: }
12529:
12530: private java.lang.String getReturnTypeInst(byte[] info, int i) {
12531: switch (info[i]) {
12532: case JvmOpCodes.IRETURN:
12533: return "ireturn";
12534: case JvmOpCodes.LRETURN:
12535: return "lreturn";
12536: case JvmOpCodes.FRETURN:
12537: return "freturn";
12538: case JvmOpCodes.DRETURN:
12539: return "dreturn";
12540: case JvmOpCodes.ARETURN:
12541: return "areturn";
12542: case JvmOpCodes.RETURN:
12543: return "return";
12544: default:
12545: return "";
12546:
12547: }
12548:
12549: }
12550:
12551: private Hashtable handlertracker = new Hashtable();
12552:
12553: private class handlerEndTracker {
12554:
12555: private int start = -1;
12556: private int end = -1;
12557:
12558: public int getStart() {
12559: return start;
12560: }
12561:
12562: public int getEnd() {
12563: return end;
12564: }
12565:
12566: public java.lang.String getType() {
12567: return type;
12568: }
12569:
12570: private java.lang.String type = "";
12571:
12572: private boolean closed = false;
12573:
12574: handlerEndTracker(int s, int e, java.lang.String t) {
12575: start = s;
12576: end = e;
12577: type = t;
12578: }
12579:
12580: void setClose(boolean c) {
12581: closed = c;
12582: }
12583:
12584: boolean getClosed() {
12585: return closed;
12586: }
12587:
12588: }
12589:
12590: private boolean addhandlerEnd(int i, ExceptionTable table) {
12591: boolean add = true;
12592: Object o = handlertracker.get(new Integer(i));
12593: if (o == null)
12594: return add;
12595: else {
12596: handlerEndTracker h = (handlerEndTracker) o;
12597: if (h.getType().equals(
12598: table.getTypeOfHandlerForGuardRegion())) {
12599: if (h.getStart() == table
12600: .getStartOfHandlerForGuardRegion()
12601: && h.getEnd() == table
12602: .getEndOfHandlerForGuardRegion()) {
12603: return false;
12604: }
12605: }
12606:
12607: }
12608:
12609: return add;
12610: }
12611:
12612: private Hashtable handlerStarts = new Hashtable();
12613:
12614: private boolean addHandlerStart(int i) {
12615: boolean add = true;
12616: if (handlerStarts.size() > 0) {
12617: java.lang.String s = (java.lang.String) handlerStarts
12618: .get(new Integer(i));
12619: if (s == null)
12620: return add;
12621: else
12622: return false;
12623: }
12624: return add;
12625: }
12626:
12627: private Hashtable guardEnds = new Hashtable();
12628:
12629: private boolean addGuardEnd(int i) {
12630:
12631: if (guardEnds.size() == 0)
12632: return true;
12633: else {
12634: java.lang.String s = (java.lang.String) guardEnds
12635: .get(new Integer(i));
12636: if (s == null)
12637: return true;
12638: else
12639: return false;
12640: }
12641:
12642: }
12643:
12644: /***
12645: *
12646: * @param index localvarindex
12647: * @param insttype pass it as store or load
12648: * @return
12649: */
12650:
12651: // [NOTE:] THIS METHOD CAN RETURN NULL: SO HANDLE WITH CARE IN CALLING METHOD....[belurs]
12652: private LocalVariable getLocalVariable(int index,
12653: java.lang.String insttype, java.lang.String dataType,
12654: boolean simpleLoadStore, int instpos) {
12655: LocalVariable l = null;
12656: LocalVariableStructure structure = behaviour
12657: .getLocalVariables();
12658: if (cd.isClassCompiledWithMinusG()) {
12659: if (structure != null)// Just a double check.. Need not check actually
12660: {
12661: int rangeIndex = -1;
12662: if (insttype.equals("store")) {
12663:
12664: if (simpleLoadStore == true)
12665: rangeIndex = instpos + 1;
12666: else
12667: rangeIndex = instpos + 2;
12668: LocalVariable var = structure.getVariabelAtIndex(
12669: index, rangeIndex);
12670: if (var == null) {
12671: Object o = cd
12672: .getMethod_name_storeNLoad_Map()
12673: .get(
12674: this .behaviour
12675: .getBehaviourName()
12676: .concat(
12677: behaviour
12678: .getStringifiedParameters()));
12679: if (o instanceof Hashtable) {
12680: Hashtable h = (Hashtable) o;
12681: if (h != null && h.size() > 0) {
12682: Integer il = (Integer) h
12683: .get(new Integer(instpos));
12684: if (il != null) {
12685: int loadpos = il.intValue();
12686: var = structure.getVariabelAtIndex(
12687: index, loadpos);
12688: }
12689: }
12690: }
12691: }
12692: if (var == null) {
12693: // NOT Sure what to do here// SHOULD NEVER COME HERE.....//
12694: // Possible due to a finally block
12695: /* try
12696: {
12697: Writer wr=Writer.getWriter("log");
12698: wr.writeLog("Could not obtain local variable While decompiling "+behaviour.getBehaviourName().concat(behaviour.getStringifiedParameters()));
12699: wr.writeLog("\nDetails.......");
12700: wr.writeLog("\n[Index Pos "+index+",Instruction Pos "+instpos+" INSTRUCTION CODE: "+behaviour.getCode()[instpos]+"]");
12701: wr.flush();
12702: }
12703: catch(Exception ex){} */
12704:
12705: }
12706: return var;
12707:
12708: } else // This is for load
12709: {
12710: LocalVariable var = structure.getVariabelAtIndex(
12711: index, instpos);
12712: if (var == null) // GOD forbid it reaches here
12713: {
12714: // NOT Sure what to do here// SHOULD NEVER COME HERE.....
12715: // Possible due to a finally block
12716: try {
12717: Writer wr = Writer.getWriter("log");
12718: wr
12719: .writeLog("Could not obtain local variable While decompiling "
12720: + behaviour
12721: .getBehaviourName()
12722: .concat(
12723: behaviour
12724: .getStringifiedParameters()));
12725: wr.writeLog("\nDetails.......");
12726: wr.writeLog("\n[Index Pos " + index
12727: + ",Instruction Pos " + instpos
12728: + " INSTRUCTION CODE: "
12729: + behaviour.getCode()[instpos]
12730: + "]");
12731: wr.flush();
12732: } catch (Exception ex) {
12733: }
12734:
12735: }
12736: return var;
12737:
12738: }
12739:
12740: } else
12741: return null; // should never come here // Programming error
12742: } else {
12743: LocalVariable toreturn = null;
12744: if (behaviour.getLocalVariables() == null) // Again shud not happen...
12745: {
12746: java.lang.String methodName = behaviour
12747: .getBehaviourName();
12748: structure = new LocalVariableStructure();
12749: behaviour.setMethodLocalVariables(structure);
12750: structure.setMethodDescription(methodName
12751: .concat(behaviour.getStringifiedParameters()));
12752: LocalVariableTable localVarTable = LocalVariableTable
12753: .getInstance();
12754: localVarTable.addEntry(methodName.concat(behaviour
12755: .getStringifiedParameters().concat(
12756: "" + behaviour.isMethodConstructor())),
12757: structure);
12758: }
12759: l = structure.getVariabelAtIndex(index, dataType,
12760: datatypesForParams);
12761:
12762: LocalVariable tmp = null;
12763: if (l == null) // Create and Add
12764: {
12765: java.lang.String variableName = "Var" + "_" + instpos
12766: + "_" + index;
12767: if (this .behaviour.getUserFriendlyMethodAccessors()
12768: .indexOf("static") == -1
12769: && (index == 0))
12770: variableName = "this";
12771: l = new LocalVariable(behaviour.getBehaviourName()
12772: .concat(behaviour.getStringifiedParameters()),
12773: variableName, index);
12774: l.setDeclarationGenerated(false);
12775: l.setDataType(dataType);
12776: l.setWasCreated(true);
12777: structure.addLocalVariable(l);
12778: toreturn = l;
12779: l.setPassedDataTypeWhileCreatingWithOutMinusG(dataType);
12780:
12781: } else {
12782:
12783: if (structure.getNumberOfSimilarIndexVars(index) > 1) {
12784: Object o = cd
12785: .getMethod_name_storeNLoad_Map()
12786: .get(
12787: this .behaviour
12788: .getBehaviourName()
12789: .concat(
12790: behaviour
12791: .getStringifiedParameters()));
12792: if (o instanceof Hashtable) {
12793: Hashtable h = (Hashtable) o;
12794: if (h != null && h.size() > 0) {
12795: Integer il = (Integer) h.get(new Integer(
12796: instpos));
12797: if (il != null) {
12798: int loadpos = il.intValue();
12799: tmp = structure
12800: .getVariableForLoadOrStorePos(
12801: index, loadpos);
12802: }
12803: }
12804: }
12805:
12806: }
12807:
12808: if (tmp == null)
12809: toreturn = l;
12810: else
12811: toreturn = tmp;
12812:
12813: }
12814:
12815: java.lang.String dt = getStoredDataType(toreturn
12816: .getIndexPos());
12817: if (dt != null && dt.trim().length() != 0)
12818: toreturn.setDataType(dt.trim());
12819: if (this .behaviour.getUserFriendlyMethodAccessors()
12820: .indexOf("static") == -1
12821: && (toreturn.getIndexPos() == 0)) {
12822: if (toreturn.getVarName().equals("this") == false) {
12823: toreturn.setVarName("this");
12824: }
12825: }
12826: return toreturn;
12827:
12828: }
12829:
12830: }
12831:
12832: private int getLoadIndexForReturn(byte[] info, int i,
12833: StringBuffer sb) {
12834: int index = -1;
12835: switch (info[(i - 1)]) {
12836:
12837: case JvmOpCodes.ALOAD_0:
12838:
12839: index = 0;
12840: break;
12841: case JvmOpCodes.ALOAD_1:
12842: index = 1;
12843: break;
12844: case JvmOpCodes.ALOAD_2:
12845: index = 2;
12846: break;
12847: case JvmOpCodes.ALOAD_3:
12848: index = 3;
12849: break;
12850:
12851: case JvmOpCodes.ILOAD_0:
12852: index = 0;
12853: break;
12854: case JvmOpCodes.ILOAD_1:
12855: index = 1;
12856: break;
12857: case JvmOpCodes.ILOAD_2:
12858: index = 2;
12859: break;
12860: case JvmOpCodes.ILOAD_3:
12861: index = 3;
12862: break;
12863:
12864: case JvmOpCodes.LLOAD_0:
12865: index = 0;
12866: break;
12867: case JvmOpCodes.LLOAD_1:
12868: index = 1;
12869: break;
12870: case JvmOpCodes.LLOAD_2:
12871: index = 2;
12872: break;
12873: case JvmOpCodes.LLOAD_3:
12874: index = 3;
12875: break;
12876:
12877: case JvmOpCodes.FLOAD_0:
12878: index = 0;
12879: break;
12880: case JvmOpCodes.FLOAD_1:
12881: index = 1;
12882: break;
12883: case JvmOpCodes.FLOAD_2:
12884: index = 2;
12885: break;
12886: case JvmOpCodes.FLOAD_3:
12887: index = 3;
12888: break;
12889:
12890: case JvmOpCodes.DLOAD_0:
12891: index = 0;
12892: break;
12893: case JvmOpCodes.DLOAD_1:
12894: index = 1;
12895: break;
12896: case JvmOpCodes.DLOAD_2:
12897: index = 2;
12898: break;
12899: case JvmOpCodes.DLOAD_3:
12900: index = 3;
12901: break;
12902: default:
12903: index = -1;
12904:
12905: }
12906: if (index != -1)
12907: sb.append((i - 1));
12908:
12909: if (index == -1) {
12910:
12911: switch (info[(i - 2)]) {
12912: case JvmOpCodes.ALOAD:
12913: index = info[(i - 1)];
12914: break;
12915:
12916: case JvmOpCodes.DLOAD:
12917: index = info[(i - 1)];
12918: break;
12919:
12920: case JvmOpCodes.FLOAD:
12921: index = info[(i - 1)];
12922: break;
12923: case JvmOpCodes.LLOAD:
12924: index = info[(i - 1)];
12925: break;
12926: case JvmOpCodes.ILOAD:
12927: index = info[(i - 1)];
12928: break;
12929:
12930: default:
12931: index = -1;
12932: }
12933:
12934: if (index != -1)
12935: sb.append((i - 2));
12936: }
12937:
12938: return index;
12939: }
12940:
12941: private Hashtable datatypesForParams = null;
12942:
12943: private void storeDataTypesForMethodParams(Behaviour b,
12944: ClassDescription cd) {
12945: datatypesForParams = new Hashtable();
12946:
12947: int count = 1;
12948: java.lang.String str = b.getUserFriendlyMethodParams();
12949: int staticPresent = b.getUserFriendlyMethodAccessors().indexOf(
12950: "static");
12951: if (staticPresent != -1) {
12952: count = 0;
12953: }
12954: int total = b.getNumberofparamters();
12955: if (total == 0)
12956: return;
12957: int s = 0;
12958: int endindex = str.indexOf(")");
12959: int startindex = str.indexOf("(");
12960: startindex += 1;
12961: if (startindex < endindex) {
12962: if (endindex > startindex) {
12963: java.lang.String reqdStr = str.substring(startindex,
12964: endindex);
12965: StringTokenizer tokenizer = new StringTokenizer(
12966: reqdStr, ",");
12967: while (tokenizer.hasMoreElements()) {
12968: Object o = tokenizer.nextElement();
12969: java.lang.String t = (java.lang.String) o;
12970: datatypesForParams.put(new Integer(count), t);
12971: if (t.trim().equals("long")
12972: || t.trim().equals("double"))
12973: count++;
12974: count++;
12975: }
12976:
12977: } else
12978: return;
12979:
12980: }
12981:
12982: }
12983:
12984: private java.lang.String getStoredDataType(int index) {
12985: java.lang.String dt = "";
12986: if (this .datatypesForParams != null
12987: && datatypesForParams.size() > 0) {
12988: return (java.lang.String) datatypesForParams
12989: .get(new Integer(index));
12990: }
12991: return dt;
12992:
12993: }
12994:
12995: private void storeDataTypesWRTConversionInst(Behaviour b,
12996: ClassDescription cd) {
12997:
12998: byte c[] = b.getCode();
12999: StringBuffer sb;
13000: LocalVariableStructure struc = b.getLocalVariables();
13001: for (int i = 0; i < c.length; i++) {
13002: sb = new StringBuffer("");
13003: int pos = isNextInstructionConversionInst(i, c);
13004:
13005: if (pos != -1) {
13006: java.lang.String resType = getResulatantTypeForConversionInst(
13007: i, c);
13008: java.lang.String srcType = getSourceTypeForConversionInst(
13009: i, c);
13010: boolean store = isNextInstructionPrimitiveStoreInst(c,
13011: (pos + 1));
13012: if (store) {
13013: StringBuffer sb1 = new StringBuffer(""); // denotes type
13014: StringBuffer sb2 = new StringBuffer(""); // denotes index
13015: getIndexNTypeForNextInst(sb1, sb2, c, (pos + 1));
13016: int index = Integer.parseInt(sb2.toString());
13017: java.lang.String varName = "Var_" + (pos + 1) + "_"
13018: + index;
13019: LocalVariable local = new LocalVariable(b
13020: .getBehaviourName().concat(
13021: b.getStringifiedParameters()),
13022: varName, index);
13023: local.setDeclarationGenerated(false);
13024: if (resType == null || resType.trim().equals(""))
13025: local.setDataType(sb1.toString());
13026: else
13027: local.setDataType(resType);
13028: local.setWasCreated(true);
13029:
13030: LocalVariable l = struc.getVariabelAtIndex(index);
13031: if (l == null) {
13032: b.getLocalVariables().addLocalVariable(local);
13033: } else {
13034:
13035: LocalVariable l2 = struc
13036: .getVariableForLoadOrStorePos(index,
13037: (pos + 1));
13038: if (l2 != null) {
13039: if (resType == null
13040: || resType.trim().equals(""))
13041: local.setDataType(sb1.toString());
13042: else
13043: local.setDataType(resType);
13044: }
13045:
13046: }
13047: }
13048: StringBuffer sb3 = new StringBuffer("");
13049: boolean prev = isPrevInstPrimitiveLoad(c, (pos), sb3);
13050: if (prev) {
13051: StringBuffer sb1 = new StringBuffer(""); // denotes type
13052: StringBuffer sb2 = new StringBuffer(""); // denotes index
13053: getIndexNTypeForPrevInst(sb1, sb2, c, (Integer
13054: .parseInt(sb3.toString())));
13055: int index = Integer.parseInt(sb2.toString());
13056: java.lang.String varName = "Var_"
13057: + (Integer.parseInt(sb3.toString())) + "_"
13058: + index;
13059:
13060: LocalVariable local = new LocalVariable(b
13061: .getBehaviourName().concat(
13062: b.getStringifiedParameters()),
13063: varName, index);
13064: local.setDeclarationGenerated(false);
13065: if (srcType == null || srcType.trim().equals(""))
13066: local.setDataType(sb1.toString());
13067: else
13068: local.setDataType(srcType);
13069: local.setWasCreated(true);
13070:
13071: LocalVariable l = struc.getVariabelAtIndex(index);
13072: if (l == null) {
13073: b.getLocalVariables().addLocalVariable(local);
13074: } else {
13075:
13076: LocalVariable l2 = struc
13077: .getVariableForLoadOrStorePos(index,
13078: (Integer.parseInt(sb3
13079: .toString())));
13080: if (l2 != null) {
13081: if (srcType == null
13082: || srcType.trim().equals(""))
13083: local.setDataType(sb1.toString());
13084: else
13085: local.setDataType(srcType);
13086: }
13087:
13088: }
13089: }
13090: }
13091:
13092: }
13093:
13094: }
13095:
13096: private boolean isNextInstructionPrimitiveStoreInst(byte[] c,
13097: int pos) {
13098: boolean flag = false;
13099: if (isThisInstrStart(behaviour.getInstructionStartPositions(),
13100: pos) == false)
13101: return false;
13102: switch (c[(pos)]) {
13103: case JvmOpCodes.DSTORE:
13104: flag = true;
13105: break;
13106: case JvmOpCodes.DSTORE_0:
13107: flag = true;
13108: break;
13109: case JvmOpCodes.DSTORE_1:
13110: flag = true;
13111: break;
13112: case JvmOpCodes.DSTORE_2:
13113: flag = true;
13114: break;
13115: case JvmOpCodes.DSTORE_3:
13116: flag = true;
13117: break;
13118:
13119: case JvmOpCodes.FSTORE:
13120: flag = true;
13121: break;
13122: case JvmOpCodes.FSTORE_0:
13123: flag = true;
13124: break;
13125: case JvmOpCodes.FSTORE_1:
13126: flag = true;
13127: break;
13128: case JvmOpCodes.FSTORE_2:
13129: flag = true;
13130: break;
13131: case JvmOpCodes.FSTORE_3:
13132: flag = true;
13133: break;
13134:
13135: case JvmOpCodes.ISTORE:
13136: flag = true;
13137: break;
13138: case JvmOpCodes.ISTORE_0:
13139: flag = true;
13140: break;
13141: case JvmOpCodes.ISTORE_1:
13142: flag = true;
13143: break;
13144: case JvmOpCodes.ISTORE_2:
13145: flag = true;
13146: break;
13147: case JvmOpCodes.ISTORE_3:
13148: flag = true;
13149: break;
13150:
13151: case JvmOpCodes.LSTORE:
13152: flag = true;
13153: break;
13154:
13155: case JvmOpCodes.LSTORE_0:
13156: flag = true;
13157: break;
13158: case JvmOpCodes.LSTORE_1:
13159: flag = true;
13160: break;
13161: case JvmOpCodes.LSTORE_2:
13162: flag = true;
13163: break;
13164: case JvmOpCodes.LSTORE_3:
13165: flag = true;
13166: break;
13167:
13168: }
13169:
13170: return flag;
13171: }
13172:
13173: // sb1 type
13174: private void getIndexNTypeForNextInst(StringBuffer sb1,
13175: StringBuffer sb2, byte[] c, int pos) {
13176: switch (c[(pos)]) {
13177: case JvmOpCodes.DSTORE:
13178: sb1.append("double");
13179: sb2.append(c[(pos + 1)]);
13180: break;
13181: case JvmOpCodes.DSTORE_0:
13182: sb1.append("double");
13183: sb2.append(0);
13184: break;
13185: case JvmOpCodes.DSTORE_1:
13186: sb1.append("double");
13187: sb2.append(1);
13188: break;
13189: case JvmOpCodes.DSTORE_2:
13190: sb1.append("double");
13191: sb2.append(2);
13192: break;
13193: case JvmOpCodes.DSTORE_3:
13194: sb1.append("double");
13195: sb2.append(3);
13196: break;
13197:
13198: case JvmOpCodes.FSTORE:
13199: sb1.append("float");
13200: sb2.append(c[(pos + 1)]);
13201: break;
13202: case JvmOpCodes.FSTORE_0:
13203: sb1.append("float");
13204: sb2.append(0);
13205: break;
13206: case JvmOpCodes.FSTORE_1:
13207: sb1.append("float");
13208: sb2.append(1);
13209: break;
13210: case JvmOpCodes.FSTORE_2:
13211: sb1.append("float");
13212: sb2.append(2);
13213: break;
13214: case JvmOpCodes.FSTORE_3:
13215: sb1.append("float");
13216: sb2.append(3);
13217: break;
13218:
13219: case JvmOpCodes.ISTORE:
13220: sb1.append("int");
13221: sb2.append(c[(pos + 1)]);
13222: break;
13223: case JvmOpCodes.ISTORE_0:
13224: sb1.append("int");
13225: sb2.append(0);
13226: break;
13227: case JvmOpCodes.ISTORE_1:
13228: sb1.append("int");
13229: sb2.append(1);
13230: break;
13231: case JvmOpCodes.ISTORE_2:
13232: sb1.append("int");
13233: sb2.append(2);
13234: break;
13235: case JvmOpCodes.ISTORE_3:
13236: sb1.append("int");
13237: sb2.append(3);
13238: break;
13239:
13240: case JvmOpCodes.LSTORE:
13241: sb1.append("long");
13242: sb2.append(c[(pos + 1)]);
13243: break;
13244:
13245: case JvmOpCodes.LSTORE_0:
13246: sb1.append("long");
13247: sb2.append(0);
13248: break;
13249: case JvmOpCodes.LSTORE_1:
13250: sb1.append("long");
13251: sb2.append(1);
13252: break;
13253: case JvmOpCodes.LSTORE_2:
13254: sb1.append("long");
13255: sb2.append(2);
13256: break;
13257: case JvmOpCodes.LSTORE_3:
13258: sb1.append("long");
13259: sb2.append(3);
13260: break;
13261:
13262: }
13263:
13264: }
13265:
13266: // pos --> conversion inst
13267: private boolean isPrevInstPrimitiveLoad(byte c[], int pos,
13268: StringBuffer sb) {
13269: boolean flag = false;
13270:
13271: switch (c[(pos - 1)]) {
13272:
13273: case JvmOpCodes.ILOAD_0:
13274: flag = true;
13275: break;
13276: case JvmOpCodes.ILOAD_1:
13277: flag = true;
13278: break;
13279: case JvmOpCodes.ILOAD_2:
13280: flag = true;
13281: break;
13282: case JvmOpCodes.ILOAD_3:
13283: flag = true;
13284: break;
13285:
13286: case JvmOpCodes.LLOAD_0:
13287: flag = true;
13288: break;
13289: case JvmOpCodes.LLOAD_1:
13290: flag = true;
13291: break;
13292: case JvmOpCodes.LLOAD_2:
13293: flag = true;
13294: break;
13295: case JvmOpCodes.LLOAD_3:
13296: flag = true;
13297: break;
13298:
13299: case JvmOpCodes.FLOAD_0:
13300: flag = true;
13301: break;
13302: case JvmOpCodes.FLOAD_1:
13303: flag = true;
13304: break;
13305: case JvmOpCodes.FLOAD_2:
13306: flag = true;
13307: break;
13308: case JvmOpCodes.FLOAD_3:
13309: flag = true;
13310: break;
13311:
13312: case JvmOpCodes.DLOAD_0:
13313: flag = true;
13314: break;
13315: case JvmOpCodes.DLOAD_1:
13316: flag = true;
13317: break;
13318: case JvmOpCodes.DLOAD_2:
13319: flag = true;
13320: break;
13321: case JvmOpCodes.DLOAD_3:
13322: flag = true;
13323: break;
13324:
13325: default:
13326: flag = false;
13327: break;
13328:
13329: }
13330: if (flag)
13331: sb.append((pos - 1));
13332: if (!flag) {
13333: switch (c[(pos - 2)]) {
13334: case JvmOpCodes.ILOAD:
13335: flag = true;
13336: break;
13337: case JvmOpCodes.LLOAD:
13338: flag = true;
13339: break;
13340:
13341: case JvmOpCodes.FLOAD:
13342: flag = true;
13343: break;
13344:
13345: case JvmOpCodes.DLOAD:
13346: flag = true;
13347: break;
13348: default:
13349: flag = false;
13350: break;
13351: }
13352: if (flag)
13353: sb.append((pos - 2));
13354: }
13355:
13356: return flag;
13357: }
13358:
13359: private void getIndexNTypeForPrevInst(StringBuffer sb1,
13360: StringBuffer sb2, byte c[], int pos) {
13361:
13362: boolean flag = false;
13363: switch (c[(pos)]) {
13364:
13365: case JvmOpCodes.ILOAD_0:
13366: flag = true;
13367: sb1.append("int");
13368: sb2.append(0);
13369: break;
13370: case JvmOpCodes.ILOAD_1:
13371: flag = true;
13372: sb1.append("int");
13373: sb2.append(1);
13374: break;
13375: case JvmOpCodes.ILOAD_2:
13376: flag = true;
13377: sb1.append("int");
13378: sb2.append(2);
13379: break;
13380: case JvmOpCodes.ILOAD_3:
13381: flag = true;
13382: sb1.append("int");
13383: sb2.append(3);
13384: break;
13385:
13386: case JvmOpCodes.LLOAD_0:
13387: flag = true;
13388: sb1.append("long");
13389: sb2.append(0);
13390: break;
13391: case JvmOpCodes.LLOAD_1:
13392: flag = true;
13393: sb1.append("long");
13394: sb2.append(1);
13395: break;
13396: case JvmOpCodes.LLOAD_2:
13397: flag = true;
13398: sb1.append("long");
13399: sb2.append(2);
13400:
13401: break;
13402: case JvmOpCodes.LLOAD_3:
13403: flag = true;
13404: sb1.append("long");
13405: sb2.append(3);
13406: break;
13407:
13408: case JvmOpCodes.FLOAD_0:
13409: flag = true;
13410: sb1.append("float");
13411: sb2.append(0);
13412: break;
13413: case JvmOpCodes.FLOAD_1:
13414: flag = true;
13415: sb1.append("float");
13416: sb2.append(1);
13417: break;
13418: case JvmOpCodes.FLOAD_2:
13419: flag = true;
13420: sb1.append("float");
13421: sb2.append(2);
13422: break;
13423: case JvmOpCodes.FLOAD_3:
13424: flag = true;
13425: sb1.append("float");
13426: sb2.append(3);
13427: break;
13428:
13429: case JvmOpCodes.DLOAD_0:
13430: flag = true;
13431: sb1.append("double");
13432: sb2.append(0);
13433: break;
13434: case JvmOpCodes.DLOAD_1:
13435: flag = true;
13436: sb1.append("double");
13437: sb2.append(1);
13438: break;
13439: case JvmOpCodes.DLOAD_2:
13440: flag = true;
13441: sb1.append("double");
13442: sb2.append(2);
13443: break;
13444: case JvmOpCodes.DLOAD_3:
13445: flag = true;
13446: sb1.append("double");
13447: sb2.append(3);
13448: break;
13449:
13450: default:
13451: flag = false;
13452: break;
13453:
13454: }
13455:
13456: if (!flag) {
13457: switch (c[(pos)]) {
13458: case JvmOpCodes.ILOAD:
13459: flag = true;
13460: sb1.append("int");
13461: sb2.append(c[(pos + 1)]);
13462: break;
13463: case JvmOpCodes.LLOAD:
13464: flag = true;
13465: sb1.append("long");
13466: sb2.append(c[(pos + 1)]);
13467: break;
13468:
13469: case JvmOpCodes.FLOAD:
13470: flag = true;
13471: sb1.append("float");
13472: sb2.append(c[(pos + 1)]);
13473: break;
13474:
13475: case JvmOpCodes.DLOAD:
13476: flag = true;
13477: sb1.append("double");
13478: sb2.append(c[(pos + 1)]);
13479: break;
13480: default:
13481: flag = false;
13482: break;
13483: }
13484: if (!flag) {
13485: sb1.append("");
13486: sb2.append(-1);
13487: }
13488: }
13489:
13490: }
13491:
13492: private void storeDataTypesWRTMethodParams(Behaviour b,
13493: ClassDescription cd) {
13494: LocalVariableStructure struc = b.getLocalVariables();
13495: if (datatypesForParams != null && datatypesForParams.size() > 0) {
13496: byte[] code = b.getCode();
13497: for (int s = 0; s < code.length; s++) {
13498: StringBuffer sb = new StringBuffer("");
13499: boolean bo = isThisInstructionIStoreInst(code, s, sb);
13500: if (bo) {
13501: StringBuffer sb2 = new StringBuffer("");
13502: boolean bo2 = isPrevInstIloadInst(code, s, sb2);
13503: if (bo2) {
13504: int loadindex = Integer
13505: .parseInt(sb2.toString());
13506: java.lang.String type = (java.lang.String) datatypesForParams
13507: .get(new Integer(loadindex));
13508: LocalVariable var = struc
13509: .getVariabelAtIndex(Integer.parseInt(sb
13510: .toString()));
13511: if (var == null && type != null) {
13512: int this Index = Integer.parseInt(sb
13513: .toString());
13514: java.lang.String varName = "Var_" + s + "_"
13515: + this Index;
13516: LocalVariable local = new LocalVariable(
13517: b
13518: .getBehaviourName()
13519: .concat(
13520: b
13521: .getStringifiedParameters()),
13522: varName, this Index);
13523: local.setDeclarationGenerated(false);
13524: local.setWasCreated(true);
13525: local.setDataType(type);
13526: struc.addLocalVariable(local);
13527: }
13528: }
13529: }
13530:
13531: // TODO: Handle astore and aload combinatiobn
13532: sb = new StringBuffer("");
13533: bo = isThisInstASTOREInst(code, s, sb);
13534: if (bo) {
13535: StringBuffer sb2 = new StringBuffer("");
13536: boolean bo2 = isPrevInstALOADInst(code, s, sb2);
13537: if (bo2) {
13538: int loadindex = Integer
13539: .parseInt(sb2.toString());
13540: java.lang.String type = (java.lang.String) datatypesForParams
13541: .get(new Integer(loadindex));
13542: LocalVariable var = struc
13543: .getVariabelAtIndex(Integer.parseInt(sb
13544: .toString()));
13545: if (var == null && type != null) {
13546: int this Index = Integer.parseInt(sb
13547: .toString());
13548: java.lang.String varName = "Var_" + s + "_"
13549: + this Index;
13550: LocalVariable local = new LocalVariable(
13551: b
13552: .getBehaviourName()
13553: .concat(
13554: b
13555: .getStringifiedParameters()),
13556: varName, this Index);
13557: local.setDeclarationGenerated(false);
13558: local.setWasCreated(true);
13559: local.setDataType(type);
13560: struc.addLocalVariable(local);
13561: }
13562:
13563: }
13564: }
13565: }
13566: }
13567: }
13568:
13569: private boolean isThisInstructionIStoreInst(byte[] code, int s,
13570: StringBuffer sb) {
13571: boolean b = false;
13572: if (isThisInstrStart(behaviour.getInstructionStartPositions(),
13573: s) == false)
13574: return false;
13575: switch (code[s]) {
13576: case JvmOpCodes.ISTORE_0:
13577: b = true;
13578: sb.append(0);
13579: break;
13580: case JvmOpCodes.ISTORE_1:
13581: b = true;
13582: sb.append(1);
13583: break;
13584: case JvmOpCodes.ISTORE_2:
13585: b = true;
13586: sb.append(2);
13587: break;
13588: case JvmOpCodes.ISTORE_3:
13589: b = true;
13590: sb.append(3);
13591: break;
13592: case JvmOpCodes.ISTORE:
13593: b = true;
13594: sb.append(code[(s + 1)]);
13595: break;
13596: }
13597:
13598: return b;
13599: }
13600:
13601: private boolean isPrevInstIloadInst(byte[] code, int s,
13602: StringBuffer sb2) {
13603: ArrayList starts = behaviour.getInstructionStartPositions();
13604: boolean b = false;
13605: if (isThisInstrStart(starts, (s - 1))) {
13606: switch (code[(s - 1)]) {
13607: case JvmOpCodes.ILOAD_0:
13608: b = true;
13609: sb2.append(0);
13610: break;
13611: case JvmOpCodes.ILOAD_1:
13612: b = true;
13613: sb2.append(1);
13614: break;
13615: case JvmOpCodes.ILOAD_2:
13616: b = true;
13617: sb2.append(2);
13618: break;
13619:
13620: case JvmOpCodes.ILOAD_3:
13621: b = true;
13622: sb2.append(3);
13623: break;
13624:
13625: }
13626: }
13627:
13628: if (!b && (s - 2) >= 0 && isThisInstrStart(starts, (s - 2))) {
13629:
13630: switch (code[s - 2]) {
13631:
13632: case JvmOpCodes.ILOAD:
13633: b = true;
13634: sb2.append(code[s - 1]);
13635: break;
13636: default:
13637: b = false;
13638: break;
13639:
13640: }
13641: }
13642:
13643: return b;
13644: }
13645:
13646: private void storeDataTypesWRTLoadNStoreCombinations(Behaviour b,
13647: ClassDescription cd) {
13648: byte code[] = b.getCode();
13649: LocalVariableStructure struc = b.getLocalVariables();
13650: for (int s = 0; s < code.length; s++) {
13651: StringBuffer sb = new StringBuffer("");
13652: boolean bo = isThisInstructionIStoreInst(code, s, sb);
13653: if (bo) {
13654: StringBuffer sb2 = new StringBuffer("");
13655: boolean bo2 = isPrevInstIloadInst(code, s, sb2);
13656: if (bo2) {
13657: int loadindex = Integer.parseInt(sb2.toString());
13658: LocalVariable var = struc
13659: .getVariabelAtIndex(Integer.parseInt(sb
13660: .toString()));
13661: LocalVariable loadvar = struc
13662: .getVariabelAtIndex(Integer.parseInt(sb2
13663: .toString()));
13664: if (loadvar != null) {
13665:
13666: // author :belurs:
13667: // NOTE:
13668: // Possible source of error here.
13669: // There may be more than one localvariable with the same index
13670: // And since this code is reachable from the option -g:none
13671: // It is not really possible to determine the exact variable
13672: // The below code is expected to give out the correct data type
13673: // in most cases.
13674: // END OF NOTE:
13675:
13676: // TODO: FIX ME later
13677: // FIX THE ambiguity in local variable at this point
13678: // [Possible correction : If localvar is null for this load
13679: // Index...Keep going back till a store occurs with same
13680: // index....Possibly recursive here..may have to serach for
13681: // prev local/store till local is not null...Will have to do
13682: // This carefully
13683:
13684: if (var == null) {
13685: int this Index = Integer.parseInt(sb
13686: .toString());
13687: java.lang.String varName = "Var_" + s + "_"
13688: + this Index;
13689: LocalVariable local = new LocalVariable(
13690: b
13691: .getBehaviourName()
13692: .concat(
13693: b
13694: .getStringifiedParameters()),
13695: varName, this Index);
13696: local.setDeclarationGenerated(false);
13697: local.setWasCreated(true);
13698: local.setDataType(loadvar.getDataType());
13699: struc.addLocalVariable(local);
13700: }
13701: }
13702: }
13703: }
13704:
13705: // TODO: aload and astore
13706: sb = new StringBuffer("");
13707: boolean astore = isThisInstASTOREInst(code, s, sb);
13708: if (astore) {
13709: StringBuffer sb2 = new StringBuffer("");
13710: boolean aload = isPrevInstALOADInst(code, s, sb2);
13711: if (aload) {
13712:
13713: int loadindex = Integer.parseInt(sb2.toString());
13714: LocalVariable var = struc
13715: .getVariabelAtIndex(Integer.parseInt(sb
13716: .toString()));
13717: LocalVariable loadvar = struc
13718: .getVariabelAtIndex(Integer.parseInt(sb2
13719: .toString()));
13720: if (loadvar != null) {
13721: if (var == null) {
13722: int this Index = Integer.parseInt(sb
13723: .toString());
13724: java.lang.String varName = "Var_" + s + "_"
13725: + this Index; //
13726: LocalVariable local = new LocalVariable(
13727: b
13728: .getBehaviourName()
13729: .concat(
13730: b
13731: .getStringifiedParameters()),
13732: varName, this Index);
13733: local.setDeclarationGenerated(false);
13734: local.setWasCreated(true);
13735: local.setDataType(loadvar.getDataType());
13736: struc.addLocalVariable(local);
13737: }
13738: }
13739: }
13740:
13741: }
13742:
13743: }
13744: }
13745:
13746: private void createLocalVariablesForMethodParams(Behaviour b,
13747: ClassDescription cd) {
13748: byte[] code = b.getCode();
13749: ArrayList loadStoreIndexes = new ArrayList();
13750:
13751: if (datatypesForParams != null && datatypesForParams.size() > 0) {
13752: Set set = datatypesForParams.keySet();
13753: /* for(int s=0;s<code.length;s++)
13754: {
13755:
13756: StringBuffer sb=new StringBuffer("");
13757: boolean anyIndex=getAnyLoadStoreIndex(code,s,sb);
13758: if(anyIndex)
13759: {
13760: Integer i=new Integer(sb.toString());
13761: loadStoreIndexes.add(i);
13762: }
13763:
13764: }*/
13765: Iterator it = set.iterator();
13766: LocalVariableStructure struc = b.getLocalVariables();
13767: while (it.hasNext()) {
13768: Integer pos = (Integer) it.next();
13769: if (pos != null) // Just a check ...
13770: {
13771: int ipos = pos.intValue();
13772:
13773: LocalVariable var = struc.getVariabelAtIndex(ipos);
13774: if (var == null) // Create dummy variable
13775: {
13776: java.lang.String vname = "param_" + ipos;
13777: LocalVariable lv = new LocalVariable(b
13778: .getBehaviourName().concat(
13779: b.getStringifiedParameters()),
13780: vname, ipos);
13781: lv.setDeclarationGenerated(false);
13782: lv.setWasCreated(true);
13783: lv
13784: .setDataType((java.lang.String) datatypesForParams
13785: .get(pos));
13786: struc.addLocalVariable(lv);
13787:
13788: } else {
13789: java.lang.String vname = "param_" + ipos;
13790: var.setVarName(vname);
13791: var
13792: .setDataType((java.lang.String) datatypesForParams
13793: .get(pos));
13794: }
13795:
13796: }
13797:
13798: }
13799:
13800: }
13801:
13802: }
13803:
13804: private boolean getAnyLoadStoreIndex(byte[] code, int s,
13805: StringBuffer sb) {
13806: boolean flag = false;
13807: switch (code[s]) {
13808:
13809: case JvmOpCodes.ALOAD:
13810: flag = true;
13811: sb.append(code[(s + 1)]);
13812: break;
13813: case JvmOpCodes.ALOAD_0:
13814: flag = true;
13815: sb.append(0);
13816: break;
13817: case JvmOpCodes.ALOAD_1:
13818: flag = true;
13819: sb.append(1);
13820: break;
13821: case JvmOpCodes.ALOAD_2:
13822: flag = true;
13823: sb.append(2);
13824: break;
13825: case JvmOpCodes.ALOAD_3:
13826: flag = true;
13827: sb.append(3);
13828: break;
13829: case JvmOpCodes.ILOAD:
13830: flag = true;
13831: sb.append(code[(s + 1)]);
13832: break;
13833: case JvmOpCodes.ILOAD_0:
13834: flag = true;
13835: sb.append(0);
13836: break;
13837: case JvmOpCodes.ILOAD_1:
13838: flag = true;
13839: sb.append(1);
13840: break;
13841: case JvmOpCodes.ILOAD_2:
13842: flag = true;
13843: sb.append(2);
13844: break;
13845: case JvmOpCodes.ILOAD_3:
13846: flag = true;
13847: sb.append(3);
13848: break;
13849:
13850: case JvmOpCodes.LLOAD:
13851: flag = true;
13852: sb.append(code[(s + 1)]);
13853: break;
13854: case JvmOpCodes.LLOAD_0:
13855: flag = true;
13856: sb.append(0);
13857: break;
13858: case JvmOpCodes.LLOAD_1:
13859: flag = true;
13860: sb.append(1);
13861: break;
13862: case JvmOpCodes.LLOAD_2:
13863: flag = true;
13864: sb.append(2);
13865: break;
13866: case JvmOpCodes.LLOAD_3:
13867: flag = true;
13868: sb.append(3);
13869: break;
13870:
13871: case JvmOpCodes.FLOAD:
13872: flag = true;
13873: sb.append(code[(s + 1)]);
13874: break;
13875: case JvmOpCodes.FLOAD_0:
13876: sb.append(0);
13877: flag = true;
13878: break;
13879: case JvmOpCodes.FLOAD_1:
13880: flag = true;
13881: sb.append(1);
13882:
13883: break;
13884: case JvmOpCodes.FLOAD_2:
13885: flag = true;
13886: sb.append(2);
13887:
13888: break;
13889: case JvmOpCodes.FLOAD_3:
13890: flag = true;
13891: sb.append(3);
13892:
13893: break;
13894:
13895: case JvmOpCodes.DLOAD:
13896: flag = true;
13897: sb.append(code[(s + 1)]);
13898:
13899: break;
13900: case JvmOpCodes.DLOAD_0:
13901: sb.append(0);
13902:
13903: flag = true;
13904: break;
13905: case JvmOpCodes.DLOAD_1:
13906: flag = true;
13907: sb.append(1);
13908:
13909: break;
13910: case JvmOpCodes.DLOAD_2:
13911: flag = true;
13912: sb.append(2);
13913:
13914: break;
13915: case JvmOpCodes.DLOAD_3:
13916: flag = true;
13917: sb.append(3);
13918:
13919: break;
13920:
13921: case JvmOpCodes.ASTORE:
13922: flag = true;
13923: sb.append(code[(s + 1)]);
13924: break;
13925:
13926: case JvmOpCodes.ASTORE_0:
13927: sb.append(0);
13928: flag = true;
13929: break;
13930: case JvmOpCodes.ASTORE_1:
13931: sb.append(1);
13932: flag = true;
13933: break;
13934: case JvmOpCodes.ASTORE_2:
13935: sb.append(2);
13936: flag = true;
13937: break;
13938: case JvmOpCodes.ASTORE_3:
13939: sb.append(3);
13940: flag = true;
13941: break;
13942:
13943: case JvmOpCodes.DSTORE:
13944: flag = true;
13945: sb.append(code[(s + 1)]);
13946: break;
13947: case JvmOpCodes.DSTORE_0:
13948: flag = true;
13949: sb.append(0);
13950: break;
13951: case JvmOpCodes.DSTORE_1:
13952: flag = true;
13953: sb.append(1);
13954: break;
13955: case JvmOpCodes.DSTORE_2:
13956: flag = true;
13957: sb.append(2);
13958: break;
13959: case JvmOpCodes.DSTORE_3:
13960: flag = true;
13961: sb.append(3);
13962: break;
13963:
13964: case JvmOpCodes.FSTORE:
13965: flag = true;
13966: sb.append(code[(s + 1)]);
13967: break;
13968: case JvmOpCodes.FSTORE_0:
13969: sb.append(0);
13970: flag = true;
13971: break;
13972: case JvmOpCodes.FSTORE_1:
13973: sb.append(1);
13974: flag = true;
13975: break;
13976: case JvmOpCodes.FSTORE_2:
13977: sb.append(2);
13978: flag = true;
13979: break;
13980: case JvmOpCodes.FSTORE_3:
13981: sb.append(3);
13982: flag = true;
13983: break;
13984:
13985: case JvmOpCodes.ISTORE:
13986: sb.append(code[(s + 1)]);
13987: flag = true;
13988: break;
13989: case JvmOpCodes.ISTORE_0:
13990: sb.append(0);
13991: flag = true;
13992: break;
13993: case JvmOpCodes.ISTORE_1:
13994: sb.append(1);
13995: flag = true;
13996: break;
13997: case JvmOpCodes.ISTORE_2:
13998: sb.append(2);
13999: flag = true;
14000: break;
14001: case JvmOpCodes.ISTORE_3:
14002: sb.append(3);
14003: flag = true;
14004: break;
14005:
14006: case JvmOpCodes.LSTORE:
14007: sb.append(code[(s + 1)]);
14008: flag = true;
14009: break;
14010:
14011: case JvmOpCodes.LSTORE_0:
14012: sb.append(0);
14013: flag = true;
14014: break;
14015: case JvmOpCodes.LSTORE_1:
14016: sb.append(1);
14017: flag = true;
14018: break;
14019: case JvmOpCodes.LSTORE_2:
14020: sb.append(2);
14021: flag = true;
14022: break;
14023: case JvmOpCodes.LSTORE_3:
14024: sb.append(3);
14025: flag = true;
14026: break;
14027:
14028: default:
14029: flag = false;
14030:
14031: }
14032: return flag;
14033: }
14034:
14035: public Hashtable getVariableDimAss() {
14036: return variableDimAss;
14037: }
14038:
14039: private Hashtable invokeStart_StackStart = null;
14040: private Hashtable invokeStartEnd = null;
14041: private Hashtable invokespecialpos = null;
14042: private ArrayList getField = null;
14043: private ArrayList getStatic = null;
14044: private Hashtable invokeinstrefpos = null;
14045: private Hashtable invokeinstrefretTypes = null;
14046:
14047: private void storeDataTypesWRTInvokeInst(Behaviour b,
14048: ClassDescription cd) {
14049: //if(cd.isClassCompiledWithMinusG()==false)
14050: //{
14051: variableDimAss = new Hashtable();
14052: invokeStart_StackStart = new Hashtable();
14053: invokeStartEnd = new Hashtable();
14054: invokespecialpos = new Hashtable();
14055: getField = new ArrayList();
14056: getStatic = new ArrayList();
14057: invokeinstrefpos = new Hashtable();
14058: invokeinstrefretTypes = new Hashtable();
14059:
14060: //}
14061: pushTypes = new Hashtable();
14062: byte code[] = b.getCode();
14063: LocalVariableStructure struc = b.getLocalVariables();
14064: label: for (int s = 0; s < code.length; s++) {
14065: //System.out.println(s+" In method "+b.getBehaviourName());
14066: StringBuffer sb = new StringBuffer("");
14067: boolean invoke = isNextInstructionAnyInvoke(code[s], sb);
14068: Integer skip = (Integer) ConsoleLauncher
14069: .getInstructionMap().get(new Integer(code[s]));
14070: boolean skipthis invoke = false;
14071: if (skip == null)
14072: continue;
14073: else {
14074: if (invoke) {
14075:
14076: int newpresent = s - 3;
14077: if (code[s] == JvmOpCodes.INVOKESPECIAL) {
14078: if (newpresent >= 0
14079: && code[newpresent] == JvmOpCodes.INVOKESPECIAL) {
14080: // int prevpos=
14081: ArrayList statpos = behaviour
14082: .getInstructionStartPositions();
14083: Integer z = (Integer) invokeinstrefpos
14084: .get(new Integer(newpresent));
14085: if (z != null) {
14086: int prevpos = z.intValue() - 1;
14087: ArrayList startpos = behaviour
14088: .getInstructionStartPositions();
14089: for (int k = prevpos; k >= 0; k--) {
14090: boolean st = isThisInstrStart(
14091: startpos, k);
14092: while (st == false && k >= 0) {
14093: k--;
14094: st = isThisInstrStart(startpos,
14095: k);
14096: }
14097:
14098: // some start pos found
14099: if (k >= 0) {
14100: if (code[k] == JvmOpCodes.NEW) {
14101: invokespecialpos.put(
14102: new Integer(s),
14103: new Integer(k));
14104: invokeinstrefpos.put(
14105: new Integer(s),
14106: new Integer(k));
14107: break;
14108: }
14109: }
14110:
14111: }
14112: }
14113:
14114: } else {
14115: int prevpos = s - 1;
14116: ArrayList startpos = behaviour
14117: .getInstructionStartPositions();
14118: for (int k = prevpos; k >= 0; k--) {
14119: boolean st = isThisInstrStart(startpos,
14120: k);
14121: while (st == false && k >= 0) {
14122: k--;
14123: st = isThisInstrStart(startpos, k);
14124: }
14125:
14126: // some start pos found
14127: boolean needtocontinue = false;
14128: if (k >= 0
14129: && code[k] == JvmOpCodes.GETFIELD) {
14130: Iterator it = invokeinstrefpos
14131: .entrySet().iterator();
14132: while (it.hasNext()) {
14133: Map.Entry en = (Map.Entry) it
14134: .next();
14135: Integer i1 = (Integer) en
14136: .getKey();
14137: Integer i2 = (Integer) en
14138: .getValue();
14139:
14140: if (i2.intValue() == (k - 1)
14141: && i1.intValue() != s) {
14142: needtocontinue = true;
14143: break;
14144: }
14145: if (i2.intValue() == (k - 2)
14146: && i1.intValue() != s) {
14147: needtocontinue = true;
14148: break;
14149: }
14150:
14151: }
14152:
14153: if (!needtocontinue)
14154: break;
14155:
14156: }
14157: if (k >= 0
14158: && (code[k] == JvmOpCodes.NEW)) {
14159: invokespecialpos.put(
14160: new Integer(s),
14161: new Integer(k));
14162: invokeinstrefpos.put(
14163: new Integer(s),
14164: new Integer(k));
14165: break;
14166: }
14167:
14168: }
14169:
14170: }
14171:
14172: }
14173:
14174: }
14175:
14176: //?
14177: if (!invoke) {
14178:
14179: /*if(code[s]==JvmOpCodes.ANEWARRAY)
14180: {
14181:
14182: StringBuffer invokepos=new StringBuffer("");
14183: boolean process=processANEWARRAYb4Invoke(code,s,invokepos);
14184: if(process)
14185: {
14186: stackHandler=new Stack();
14187: InstParam first=new InstParam();
14188: first.setNumberOfParamsLeft(1);
14189: first.setCurrentParamOffsetInCode(-1);
14190: stackHandler.push(first);
14191: handleBasicPrimitiveLoadOp(code,s-1);
14192: InstParam obj=(InstParam)stackHandler.pop();
14193: int offset=obj.getCurrentParamOffsetInCode();
14194: anewarrayrefpos.put(new Integer(Integer.parseInt(invokepos.toString())),new Integer(offset));
14195:
14196: }
14197:
14198:
14199: } */
14200:
14201: if (code[s] == JvmOpCodes.GETSTATIC) {
14202: getStatic.add(new Integer(s));
14203: }
14204: if (code[s] == JvmOpCodes.GETFIELD) {
14205: getField.add(new Integer(s));
14206: }
14207: int toskip = skip.intValue();
14208: boolean xx = false;
14209: if (toskip == -1) // lookup // TODO: verify increment
14210: {
14211: xx = true;
14212: int lookupSwitchPos = s;
14213: int leave_bytes = (4 - (s % 4)) - 1;
14214: for (int indx = 0; indx < leave_bytes; indx++) {
14215: s++;
14216: }
14217: // Read Default
14218: int Default = getSwitchOffset(code, s, "");//info[++i] << 24) | (info[++i] << 16) | (info[++i] << 8) |info[++i];
14219: s += 4;
14220: int numberOfLabels = (getSwitchOffset(code, s,
14221: "")); //info[++i] << 24) | (info[++i] << 16) | (info[++i] << 8) |info[++i];
14222: //int high=(info[++i] << 24) | (info[++i] << 16) | (info[++i] << 8) |info[++i];
14223: //int numberOfOffsets=(high-low)+1;
14224: int offsetValues[] = new int[numberOfLabels];
14225: int labels[] = new int[numberOfLabels];
14226: s += 4;
14227: for (int start = 0; start < numberOfLabels; start++) {
14228: int label = getSwitchOffset(code, s,
14229: "label");
14230: s += 4;
14231: int offsetVal = getSwitchOffset(code, s, "");//(info[++i] << 24) | (info[++i] << 16) | (info[++i] << 8) |info[++i];
14232: s += 4;
14233: labels[start] = label;
14234: offsetValues[start] = offsetVal;
14235:
14236: }
14237:
14238: }
14239: if (toskip == -2) // table
14240: {
14241: xx = true;
14242: int tableSwitchPos = s;
14243: int leave_bytes = (4 - (s % 4)) - 1;
14244: for (int indx = 0; indx < leave_bytes; indx++) {
14245: s++;
14246: }
14247: // Read Default
14248: int Default = getSwitchOffset(code, s, "");//(info[++i] << 24) | (info[++i] << 16) | (info[++i] << 8) |info[++i];
14249: s += 4;
14250: int low = getSwitchOffset(code, s, "label");//(info[++i] << 24) | (info[++i] << 16) | (info[++i] << 8) |info[++i];
14251: s += 4;
14252: int high = getSwitchOffset(code, s, "label");//(info[++i] << 24) | (info[++i] << 16) | (info[++i] << 8) |info[++i];
14253: s += 4;
14254: int numberOfOffsets = (high - low) + 1;
14255: int[] offsetValues = new int[numberOfOffsets];
14256: for (int start = 0; start < numberOfOffsets; start++) {
14257: int offsetVal = getSwitchOffset(code, s, "");
14258: s += 4;
14259: offsetValues[start] = offsetVal;
14260:
14261: }
14262:
14263: }
14264: if (toskip == -3) // wide // TODO ?
14265: {
14266:
14267: }
14268: if (!xx)
14269: s = s + toskip;
14270: else
14271: s = s + 1;
14272:
14273: continue;
14274: }
14275:
14276: }
14277:
14278: java.lang.String belongingClassName = "";
14279: java.lang.String returnTypeName = "";
14280: if (invoke) // && !(sb.toString().equalsIgnoreCase("special")))
14281: {
14282: int classIndex = getOffset(code, s);
14283: java.lang.String methodSignature = "";
14284: if (sb.toString().indexOf("interface") == -1) {
14285: MethodRef mref = cd
14286: .getMethodRefAtCPoolPosition(classIndex);
14287: methodSignature = mref.getTypeofmethod();
14288: belongingClassName = mref.getClassname();
14289: returnTypeName = mref.getTypeofmethod();
14290: int brk = returnTypeName.indexOf(")");
14291: if (brk != -1) {
14292: returnTypeName = returnTypeName
14293: .substring((brk + 1));
14294: brk = returnTypeName.indexOf("L");
14295: if (brk != -1) {
14296: returnTypeName = returnTypeName.substring(
14297: brk + 1, returnTypeName
14298: .indexOf(";"));
14299:
14300: }
14301: }
14302: invokeinstrefretTypes.put(new Integer(s),
14303: belongingClassName + "::" + returnTypeName);
14304: } else {
14305: InterfaceMethodRef mref = cd
14306: .getInterfaceMethodAtCPoolPosition(classIndex);
14307: methodSignature = mref.getTypeofmethod();
14308: belongingClassName = mref.getClassname();
14309: returnTypeName = mref.getTypeofmethod();
14310: int brk = returnTypeName.indexOf(")");
14311: if (brk != -1) {
14312: returnTypeName = returnTypeName
14313: .substring((brk + 1));
14314: brk = returnTypeName.indexOf("L");
14315: if (brk != -1) {
14316: returnTypeName = returnTypeName.substring(
14317: brk + 1, returnTypeName
14318: .indexOf(";"));
14319:
14320: }
14321: }
14322: invokeinstrefretTypes.put(new Integer(s),
14323: belongingClassName + "::" + returnTypeName);
14324: }
14325:
14326: Util.parseDescriptor(methodSignature);
14327: ArrayList list = Util.getParsedSignatureAsList();
14328:
14329: int num = list.size();
14330: int z = (num - 1);
14331: StringBuffer pos = null;
14332: int start = s - 1;
14333: int ipos = -1; // where local var occurs
14334: boolean skiploop = false;
14335: while (z >= 0) {
14336: StringBuffer index = new StringBuffer("");
14337: StringBuffer dim = new StringBuffer("");
14338:
14339: pos = new StringBuffer(""); // where local var occurs
14340: java.lang.String type = (java.lang.String) list
14341: .get(z);
14342:
14343: //
14344: Integer isinvokestart = (Integer) invokeStartEnd
14345: .get(new Integer(start));
14346: while (isinvokestart != null) {
14347: int invokestart = isinvokestart.intValue();
14348: Integer stackstart = (Integer) invokeStart_StackStart
14349: .get(new Integer(invokestart));
14350: Integer refstart = (Integer) invokeinstrefpos
14351: .get(new Integer(invokestart));
14352: int istart = -1;
14353: if (refstart == null) {
14354: problematicInvokes.add(new Integer(s));
14355: skipthis invoke = true;
14356: skiploop = true;
14357: break;
14358: }
14359: if (refstart != null) {
14360:
14361: istart = refstart.intValue();
14362: StringBuffer buffer = new StringBuffer("");
14363: if (isNextInstructionAnyInvoke(
14364: code[istart], buffer)) {
14365: java.lang.String sTR = (java.lang.String) invokeinstrefretTypes
14366: .get(new Integer(istart));
14367: if (sTR != null) {
14368: int sep = sTR.indexOf("::");
14369: java.lang.String rEF = sTR
14370: .substring(0, sep);
14371: java.lang.String rET = sTR
14372: .substring(sep + 2);
14373: if (rEF.trim().equalsIgnoreCase(
14374: rET.trim())) {
14375: ipos = istart;
14376: } else {
14377: refstart = (Integer) invokeinstrefpos
14378: .get(new Integer(istart));
14379: if (refstart != null)
14380: ipos = refstart.intValue();
14381: }
14382: }
14383:
14384: }
14385: start = refstart.intValue() - 1;
14386: }
14387:
14388: z--;
14389: int h = -1;
14390: if (ipos == -1)
14391: h = istart - 1;
14392: else
14393: h = ipos - 1;
14394: isinvokestart = (Integer) invokeStartEnd
14395: .get(new Integer(h));
14396:
14397: if (z == -1) {
14398: skiploop = true;
14399: break;
14400: }
14401: }
14402:
14403: if (skiploop)
14404: break;
14405: //
14406: type = (java.lang.String) list.get(z);
14407: try {
14408: getCorrespondingLoadInst(index, dim, start,
14409: pos, this .behaviour, this .cd, type, s);
14410: } catch (Exception e) {
14411: problematicInvokes.add(new Integer(s));
14412: skipthis invoke = true;
14413: break;
14414: }
14415: // Should the code stop this method and take next invoke into account
14416: try {
14417: int dummy = Integer.parseInt(pos.toString());
14418: } catch (NumberFormatException ne) {
14419: // Skip This invoke
14420: // Because the current rules are not sufficient to track the beginning
14421: // of a prameter load for a method
14422: problematicInvokes.add(new Integer(s));
14423: skipthis invoke = true;
14424: break;
14425:
14426: }
14427:
14428: ipos = Integer.parseInt(pos.toString());
14429: start = (ipos - 1);
14430: int in = Integer.parseInt(index.toString());
14431: int dimensions = Integer.parseInt(dim.toString());
14432: LocalVariable l = struc.getVariabelAtIndex(in);
14433:
14434: if (cd.isClassCompiledWithMinusG() == false) {
14435: if (l != null) {
14436:
14437: int bracket = type.indexOf("[");
14438: if (bracket != -1) {
14439: int brackets = 0;
14440: for (int d = bracket; d < type.length(); d++) {
14441: if (type.charAt(d) == '[')
14442: brackets++;
14443: else
14444: break;
14445: }
14446:
14447: int totalDimenForVar = dimensions
14448: + brackets;
14449: //Assocaite here
14450: if (variableDimAss != null)
14451: variableDimAss.put(new Integer(in),
14452: new Integer(
14453: totalDimenForVar));
14454: } else {
14455: int L = type.indexOf("L");
14456: if (L != -1) {
14457: type = type.substring((L + 1));
14458: }
14459: int semi = type.indexOf(";");
14460: if (semi != -1) {
14461: type = type.substring(0, (semi));
14462: }
14463: // l.setDataType(type); // NOTE: commented this line as it was resetting already set correct datatype
14464: }
14465: }
14466: if (l == null && in != -100 && in != -200) {
14467: int bracket = type.indexOf("[");
14468: if (bracket == -1) {
14469: int L = type.indexOf("L");
14470: if (L != -1) {
14471: type = type.substring((L + 1));
14472: }
14473: int semi = type.indexOf(";");
14474: if (semi != -1) {
14475: type = type.substring(0, (semi));
14476: }
14477:
14478: java.lang.String varName = "Var_"
14479: + ipos + "_" + in;
14480: if (this .behaviour
14481: .getUserFriendlyMethodAccessors()
14482: .indexOf("static") == -1
14483: && (in == 0))
14484: varName = "this";
14485: LocalVariable newl = new LocalVariable(
14486: b
14487: .getBehaviourName()
14488: .concat(
14489: b
14490: .getStringifiedParameters()),
14491: varName, in);
14492: newl.setDeclarationGenerated(false);
14493: newl.setWasCreated(true);
14494: newl.setDataType(type);
14495: struc.addLocalVariable(newl);
14496:
14497: }
14498: if (bracket != -1) {
14499: int brackets = 0;
14500: for (int d = bracket; d < type.length(); d++) {
14501: if (type.charAt(d) == '[')
14502: brackets++;
14503: else
14504: break;
14505: }
14506:
14507: int totalDimenForVar = dimensions
14508: + brackets;
14509: //Assocaite here
14510: if (variableDimAss != null)
14511: variableDimAss.put(new Integer(in),
14512: new Integer(
14513: totalDimenForVar));
14514: }
14515: }
14516: }
14517: if (in == -200) {
14518: pushTypes.put(new Integer(ipos), type);
14519: }
14520:
14521: z--;
14522:
14523: }
14524: boolean ok = false;
14525: if (invoke && !skipthis invoke) {
14526: StringBuffer S = new StringBuffer("");
14527: ok = checkForAssociatedGetField(getField, s, S,
14528: code);
14529: if (ok) {
14530: int iS = Integer.parseInt(S.toString());
14531: int refpos = getObjectRefForGetField(iS, code);
14532: if (refpos != -1) {
14533: if (invokeinstrefpos.get(new Integer(s)) == null) {
14534: invokeinstrefpos.put(new Integer(s),
14535: new Integer(refpos));
14536: }
14537:
14538: }
14539: }
14540: if (!ok) {
14541: S = new StringBuffer("");
14542: ok = checkForAssociatedGetStatic(getStatic, s,
14543: S, code); // TODO: possible bug : check for pop and aload then
14544: if (ok) {
14545: int iS = Integer.parseInt(S.toString());
14546: if ((iS - 1) >= 0
14547: && code[iS - 1] == JvmOpCodes.POP) {
14548: StringBuffer s2 = new StringBuffer("");
14549: boolean bb = isPrevInstructionAload(
14550: iS - 1, code, s2);
14551: if (bb) {
14552: iS = Integer
14553: .parseInt(s2.toString());
14554: }
14555: }
14556: if (invokeinstrefpos.get(new Integer(s)) == null) {
14557: invokeinstrefpos.put(new Integer(s),
14558: new Integer(iS));
14559: }
14560: }
14561: }
14562: if (!ok) {
14563: S = new StringBuffer("");
14564: ok = checkForAssociatedInvokeSpecial(
14565: invokespecialpos, s, S, code);
14566: if (ok) {
14567: int iS = Integer.parseInt(S.toString());
14568: if (invokeinstrefpos.get(new Integer(s)) == null) {
14569: invokeinstrefpos.put(new Integer(s),
14570: new Integer(iS));
14571: }
14572: }
14573:
14574: }
14575:
14576: }
14577: boolean skip2 = false;
14578: if (!ok && code[s] == JvmOpCodes.INVOKESTATIC
14579: && ipos == -1 && !skipthis invoke) {
14580: ipos = s;
14581: if (invokeinstrefpos.get(new Integer(s)) == null) {
14582: invokeinstrefpos.put(new Integer(s),
14583: new Integer(ipos));
14584: }
14585: skip2 = true;
14586:
14587: }
14588: if (!ok && code[s] == JvmOpCodes.INVOKESTATIC
14589: && ipos != -1 && !skipthis invoke) {
14590: if (invokeinstrefpos.get(new Integer(s)) == null) {
14591: invokeinstrefpos.put(new Integer(s),
14592: new Integer(ipos));
14593: }
14594: skip2 = true;
14595:
14596: }
14597:
14598: int prev = s - 1;
14599: if (ipos != -1)
14600: prev = ipos - 1;
14601: if (!ok && prev >= 0 && !skip2 && !skipthis invoke) {
14602: Integer pr = new Integer(prev);
14603: Integer be = (Integer) invokeStartEnd.get(pr);
14604: if (be != null) {
14605: int Ibe = be.intValue();
14606: if (code[Ibe] == JvmOpCodes.INVOKEVIRTUAL
14607: || code[Ibe] == JvmOpCodes.INVOKEINTERFACE) {
14608: java.lang.String sTR = (java.lang.String) invokeinstrefretTypes
14609: .get(new Integer(Ibe));
14610: if (sTR != null) {
14611: int sep = sTR.indexOf("::");
14612: java.lang.String rEF = sTR.substring(0,
14613: sep);
14614: java.lang.String rET = sTR
14615: .substring(sep + 2);
14616: if (rEF.trim().equalsIgnoreCase(
14617: rET.trim())) {
14618: Integer refpos = (Integer) invokeinstrefpos
14619: .get(new Integer(Ibe));
14620: if (refpos != null) {
14621: int irefpos = refpos.intValue();
14622: Integer reftemp = (Integer) invokeinstrefpos
14623: .get(new Integer(s));
14624: if (reftemp == null) {
14625: invokeinstrefpos
14626: .put(
14627: new Integer(
14628: s),
14629: new Integer(
14630: irefpos));
14631: }
14632: }
14633: } else {
14634: Integer refpos = (Integer) invokeinstrefpos
14635: .get(new Integer(s));
14636: if (refpos == null) {
14637: invokeinstrefpos.put(
14638: new Integer(s),
14639: new Integer(Ibe));
14640: }
14641: }
14642: }
14643: }
14644: if (code[Ibe] == JvmOpCodes.INVOKESTATIC
14645: || code[Ibe] == JvmOpCodes.INVOKESPECIAL) {
14646: Integer refpos = (Integer) invokeinstrefpos
14647: .get(new Integer(Ibe));
14648: if (invokeinstrefpos.get(new Integer(s)) == null) {
14649: invokeinstrefpos.put(new Integer(s),
14650: new Integer(refpos.intValue()));
14651: }
14652:
14653: }
14654: } else {
14655: StringBuffer sfb = new StringBuffer("");
14656: boolean bol = isPrevInstructionAload(prev + 1,
14657: code, sfb);
14658: if (bol) {
14659: int aloadpos = Integer.parseInt(sfb
14660: .toString());
14661: if (invokeinstrefpos.get(new Integer(s)) == null) {
14662: invokeinstrefpos.put(new Integer(s),
14663: new Integer(aloadpos));
14664:
14665: }
14666: } else {
14667: if (code[prev] == JvmOpCodes.AALOAD) {
14668: int x = prev;
14669: do {
14670: sfb = new StringBuffer("");
14671: x--;
14672: bol = isPrevInstructionAload(x,
14673: code, sfb);
14674: } while (!bol);
14675: int aloadpos = Integer.parseInt(sfb
14676: .toString());
14677: if (invokeinstrefpos
14678: .get(new Integer(s)) == null) {
14679: invokeinstrefpos.put(
14680: new Integer(s),
14681: new Integer(aloadpos));
14682: }
14683:
14684: }
14685: }
14686: }
14687:
14688: }
14689:
14690: if (invokeStart_StackStart != null)
14691: invokeStart_StackStart.put(new Integer(s),
14692: new Integer(ipos)); // modify for special/static
14693:
14694: int end = -1;
14695: if (invokeStartEnd != null) {
14696: end = findWhereThisInvokeEnds(s, code);
14697: invokeStartEnd
14698: .put(new Integer(end), new Integer(s));
14699: }
14700: if (end != -1) {
14701: int next = end + 1;
14702: s = end; // changed from next to end
14703: }
14704:
14705: }
14706: }
14707:
14708: }
14709:
14710: public Hashtable getPushTypes() {
14711: return pushTypes;
14712: }
14713:
14714: private Hashtable pushTypes = null;
14715:
14716: private java.lang.String[] convertTokenizerToArray(
14717: StringTokenizer tokens) {
14718:
14719: if (tokens != null) {
14720: int total = tokens.countTokens();
14721: java.lang.String array[] = new java.lang.String[total];
14722: int s = 0;
14723: while (tokens.hasMoreTokens()) {
14724: java.lang.String cur = (java.lang.String) tokens
14725: .nextToken();
14726: array[s++] = cur;
14727: }
14728: return array;
14729: } else
14730: return null;
14731:
14732: }
14733:
14734: private Hashtable variableDimAss = null;
14735:
14736: private boolean isInstAAload(int inst) {
14737: return inst == JvmOpCodes.AALOAD;
14738: }
14739:
14740: private int isInstAload(int i, byte[] code, StringBuffer bf) {
14741: if (isThisInstrStart(behaviour.getInstructionStartPositions(),
14742: i)) {
14743: switch (code[i]) {
14744:
14745: case JvmOpCodes.ALOAD_0:
14746: bf.append(0);
14747: return i;
14748: case JvmOpCodes.ALOAD_1:
14749: bf.append(1);
14750: return i;
14751: case JvmOpCodes.ALOAD_2:
14752: bf.append(2);
14753: return i;
14754: case JvmOpCodes.ALOAD_3:
14755: bf.append(3);
14756: return i;
14757: case JvmOpCodes.ALOAD:
14758: bf.append(code[(i + 1)]);
14759: return i;
14760:
14761: }
14762: }
14763:
14764: int temp = i - 1;
14765: if (isThisInstrStart(behaviour.getInstructionStartPositions(),
14766: temp)) {
14767: if (code[temp] == JvmOpCodes.ALOAD) {
14768: bf.append(code[i]);
14769: return temp;
14770: }
14771: }
14772: return -1;
14773:
14774: }
14775:
14776: // todo: // Search For StringBuffer from here
14777:
14778: private void getCorrespondingLoadInst(StringBuffer index,
14779: StringBuffer dim, int start, StringBuffer pos, Behaviour b,
14780: ClassDescription cd, java.lang.String type,
14781: int this invokestart) throws Exception {
14782: ArrayList starts = b.getInstructionStartPositions();
14783: boolean primitive = isPrimitive(type);
14784:
14785: byte[] code = b.getCode();
14786: int number = 0;
14787: boolean aaloadFound = false;
14788: int k = start;
14789: int orig = k;
14790: // Find out the instuction start here
14791: boolean istart = isThisInstrStart(starts, k);
14792: while (istart == false && k >= 0) {
14793: k = k - 1;
14794: istart = isThisInstrStart(starts, k);
14795: }
14796:
14797: // Now k must be inst start
14798:
14799: if (primitive) {
14800:
14801: if (code[k] == JvmOpCodes.ARRAYLENGTH) // TODO: TEST IT THOROUhLY
14802: {
14803:
14804: StringBuffer s6 = new StringBuffer("");
14805: boolean aloadp = isPrevInstructionAload(k, code, s6);
14806: if (aloadp) {
14807: index.append(-200);
14808: dim.append(0);
14809: pos.append(Integer.parseInt(s6.toString()));
14810: return;
14811: }
14812: if ((k - 1) >= 0) {
14813: boolean aaloadp = isInstAAload(code[k - 1]); // BUG check for getstatic alos.:TODO
14814: if (aaloadp) {
14815: s6 = new StringBuffer("");
14816: int in = k - 1;
14817: int posFound = isInstAload(in, code, s6);
14818: while (posFound == -1) {
14819: in = in - 1;
14820: posFound = isInstAload(in, code, s6);
14821: if (posFound == -1) {
14822: if (code[in] == JvmOpCodes.GETSTATIC) // TODO: Need to check at all such places whether the index is start of instruction
14823: {
14824:
14825: if (code[in - 1] == JvmOpCodes.POP) // TODO: Possible bug with pop2
14826: {
14827: StringBuffer s3 = new StringBuffer(
14828: "");
14829: boolean bb = isPrevInstructionAload(
14830: in - 1, code, s3);
14831: if (bb) {
14832: index.append(-200);
14833: dim.append(0);
14834: pos
14835: .append(Integer
14836: .parseInt(s3
14837: .toString()));
14838: return;
14839: }
14840: } else {
14841: index.append(-200);
14842: dim.append(0);
14843: pos.append(in);
14844: return;
14845: }
14846:
14847: }
14848: if (code[in] == JvmOpCodes.GETFIELD) {
14849: s6 = new StringBuffer("");
14850: aloadp = isPrevInstructionAload(in,
14851: code, s6);
14852: index.append(-200);
14853: dim.append(0);
14854: pos.append(Integer.parseInt(s6
14855: .toString()));
14856: return;
14857: }
14858:
14859: }
14860:
14861: }
14862: index.append(-200);
14863: dim.append(0);
14864: pos.append(posFound);
14865: return;
14866:
14867: }
14868: }
14869: if ((k - 3) >= 0) {
14870: boolean getfield = (code[k - 3] == JvmOpCodes.GETFIELD);
14871: if (getfield) {
14872: s6 = new StringBuffer("");
14873: aloadp = isPrevInstructionAload(k - 3, code, s6);
14874: index.append(-200);
14875: dim.append(0);
14876: pos.append(Integer.parseInt(s6.toString()));
14877: return;
14878: }
14879: }
14880: if ((k - 3) >= 0) {
14881: boolean getS = (code[k - 3] == JvmOpCodes.GETSTATIC);
14882: if (getS) {
14883: if (code[k - 4] == JvmOpCodes.POP) // TODO: Possible bug with pop2
14884: {
14885: StringBuffer s3 = new StringBuffer("");
14886: boolean bb = isPrevInstructionAload(k - 4,
14887: code, s3);
14888: if (bb) {
14889: index.append(-200);
14890: dim.append(0);
14891: pos.append(Integer.parseInt(s3
14892: .toString()));
14893: return;
14894: }
14895: }
14896: index.append(-200);
14897: dim.append(0);
14898: pos.append(k - 3);
14899: return;
14900:
14901: }
14902: }
14903:
14904: // TODO:newarray ?
14905:
14906: if ((k - 4) >= 0) {
14907: boolean multi = (code[k - 4] == JvmOpCodes.MULTIANEWARRAY);
14908: if (multi) {
14909: stackHandler = new Stack();
14910: InstParam first = new InstParam();
14911: first.setNumberOfParamsLeft(code[k - 4 + 3]);
14912: first.setCurrentParamOffsetInCode(-1);
14913: stackHandler.push(first);
14914: handleBasicPrimitiveLoadOp(code, k - 5);
14915: index.append(-100);
14916: dim.append(0);
14917: InstParam obj = (InstParam) stackHandler.pop(); // should be first
14918: pos.append(obj.getCurrentParamOffsetInCode()); // TODO: check whether this is correct
14919: return;
14920:
14921: }
14922: }
14923: if ((k - 3) >= 0) {
14924:
14925: boolean multi = (code[k - 3] == JvmOpCodes.ANEWARRAY);
14926: if (multi) {
14927:
14928: stackHandler = new Stack();
14929: InstParam first = new InstParam();
14930: first.setNumberOfParamsLeft(1);
14931: first.setCurrentParamOffsetInCode(-1);
14932: stackHandler.push(first);
14933: handleBasicPrimitiveLoadOp(code, k - 3 - 1);
14934: index.append(-100);
14935: dim.append(0);
14936: InstParam obj = (InstParam) stackHandler.pop(); // should be first
14937: pos.append(obj.getCurrentParamOffsetInCode()); // TODO: check whether this is correct
14938: return;
14939:
14940: }
14941: }
14942:
14943: if ((k - 2) >= 0) {
14944:
14945: boolean multi = (code[k - 2] == JvmOpCodes.NEWARRAY);
14946: if (multi) {
14947:
14948: stackHandler = new Stack();
14949: InstParam first = new InstParam();
14950: first.setNumberOfParamsLeft(1);
14951: first.setCurrentParamOffsetInCode(-1);
14952: stackHandler.push(first);
14953: handleBasicPrimitiveLoadOp(code, k - 3);
14954: index.append(-100);
14955: dim.append(0);
14956: InstParam obj = (InstParam) stackHandler.pop(); // should be first
14957: pos.append(obj.getCurrentParamOffsetInCode()); // TODO: check whether this is correct
14958: return;
14959:
14960: }
14961: }
14962:
14963: }
14964:
14965: }
14966:
14967: if (!primitive) // TODO: Need to check for getstatic and getfield also
14968: {
14969: boolean prevAAload = isInstAAload(code[k]); // TODO !!! Can there be any other option???
14970: boolean prevaload = false;
14971: if (prevAAload) {
14972: number++;
14973: k = k - 1;
14974: prevAAload = isInstAAload(code[k]);
14975: StringBuffer sb = new StringBuffer("");
14976: int posFound = isInstAload(k, code, sb);
14977: while (posFound == -1) {
14978: if (prevAAload)
14979: number++;
14980: k = k - 1;
14981: prevAAload = isInstAAload(code[k]);
14982: sb = new StringBuffer("");
14983: posFound = isInstAload(k, code, sb);
14984: /////////////////////
14985: if (posFound == -1) {
14986: if (code[k] == JvmOpCodes.GETSTATIC) // TODO: Need to check at all such places whether the index is start of instruction
14987: {
14988:
14989: if (isThisInstrStart(behaviour
14990: .getInstructionStartPositions(),
14991: (k - 1))
14992: && code[k - 1] == JvmOpCodes.POP) // TODO: Possible bug with pop2
14993: {
14994: StringBuffer s3 = new StringBuffer("");
14995: boolean bb = isPrevInstructionAload(
14996: k - 1, code, s3);
14997: if (bb) {
14998: index.append(-200);
14999: dim.append(0);
15000: pos.append(Integer.parseInt(s3
15001: .toString()));
15002: return;
15003: }
15004: } else {
15005: index.append(-200);
15006: dim.append(0);
15007: pos.append(k);
15008: return;
15009: }
15010:
15011: }
15012: if (code[k] == JvmOpCodes.GETFIELD) {
15013: StringBuffer s6 = new StringBuffer("");
15014: boolean aloadp = isPrevInstructionAload(k,
15015: code, s6);
15016: if (aloadp) {
15017: index.append(-200);
15018: dim.append(0);
15019: pos.append(Integer.parseInt(s6
15020: .toString()));
15021: return;
15022: }
15023: }
15024:
15025: }
15026: /////////
15027:
15028: }
15029:
15030: index.append(Integer.parseInt(sb.toString()));
15031: dim.append(number);
15032: pos.append(posFound);
15033: return;
15034:
15035: }
15036: }
15037: if (primitive) {
15038: if (code[k] == JvmOpCodes.BALOAD
15039: || code[k] == JvmOpCodes.CALOAD
15040: || code[k] == JvmOpCodes.DALOAD
15041: || code[k] == JvmOpCodes.FALOAD
15042: || code[k] == JvmOpCodes.LALOAD
15043: || code[k] == JvmOpCodes.IALOAD
15044: || code[k] == JvmOpCodes.SALOAD) {
15045: StringBuffer sb = new StringBuffer("");
15046: int posFound = isInstAload(k, code, sb);
15047: while (posFound == -1) {
15048:
15049: k = k - 1;
15050: sb = new StringBuffer("");
15051: posFound = isInstAload(k, code, sb);
15052:
15053: }
15054: index.append(Integer.parseInt(sb.toString()));
15055: dim.append(0);
15056: pos.append(posFound);
15057: return;
15058:
15059: }
15060: }
15061: if (primitive) {
15062: if (code[k] == JvmOpCodes.BIPUSH) {
15063: index.append(-200);
15064: dim.append(0);
15065: pos.append(k);
15066: return;
15067: }
15068: }
15069:
15070: if (primitive) {
15071: if (code[k] == JvmOpCodes.SIPUSH) {
15072: index.append(-200);
15073: dim.append(0);
15074: pos.append(k);
15075: return;
15076: }
15077: }
15078: StringBuffer sfb;
15079: if (!primitive) {
15080: sfb = new StringBuffer("");
15081: int y = isInstAload(k, code, sfb);
15082: if (y != -1) {
15083: index.append(Integer.parseInt(sfb.toString()));
15084: dim.append(0);
15085: pos.append(y);
15086: return;
15087: }
15088: }
15089:
15090: if (primitive) {
15091: sfb = new StringBuffer("");
15092: int y = isInstIloadInst(code, k, sfb);
15093: if (y != -1) {
15094: index.append(Integer.parseInt(sfb.toString()));
15095: dim.append(0);
15096: pos.append(y);
15097: return;
15098: }
15099: }
15100:
15101: if (type.equals("float") || type.equals("double")) {
15102: sfb = new StringBuffer("");
15103: int y = isInstFloadInst(code, k, sfb);
15104: if (y != -1) {
15105: index.append(Integer.parseInt(sfb.toString()));
15106: dim.append(0);
15107: pos.append(y);
15108: return;
15109: }
15110: }
15111:
15112: if (type.equals("double")) {
15113: sfb = new StringBuffer("");
15114: int y = isInstDloadInst(code, k, sfb);
15115: if (y != -1) {
15116: index.append(Integer.parseInt(sfb.toString()));
15117: dim.append(0);
15118: pos.append(y);
15119: return;
15120: }
15121: }
15122:
15123: if (type.equals("float") || type.equals("double")) {
15124: if (code[k] == JvmOpCodes.D2F)// || code[k]==JvmOpCodes.D2I || code[k]==JvmOpCodes.D2L)
15125: {
15126:
15127: int t = k - 1;
15128: StringBuffer strb = new StringBuffer("");
15129: int dload = isInstDloadInst(code, t, strb);
15130: if (dload != -1) {
15131: index.append(-100);
15132: dim.append(0);
15133: pos.append(dload);
15134: return;
15135: } else {
15136: strb = new StringBuffer("");
15137: int loadin = traceLoadInst(t, code, strb);
15138: if (loadin != -1) {
15139: index.append(-100);
15140: dim.append(0);
15141: pos.append(loadin);
15142: return;
15143: }
15144:
15145: }
15146: stackHandler = new Stack();
15147: InstParam first = new InstParam();
15148: first.setNumberOfParamsLeft(1);
15149: first.setCurrentParamOffsetInCode(-1);
15150: stackHandler.push(first);
15151: handleBasicPrimitiveLoadOp(code, k - 1);
15152: index.append(-100);
15153: dim.append(0);
15154: InstParam obj = (InstParam) stackHandler.pop(); // should be first
15155: pos.append(obj.getCurrentParamOffsetInCode());
15156: return;
15157:
15158: }
15159: }
15160: if (primitive) {
15161: if (code[k] == JvmOpCodes.D2I)//|| code[k]==JvmOpCodes.D2L)
15162: {
15163:
15164: int t = k - 1;
15165: StringBuffer strb = new StringBuffer("");
15166: int dload = isInstDloadInst(code, t, strb);
15167: if (dload != -1) {
15168: index.append(-100);
15169: dim.append(0);
15170: pos.append(dload);
15171: return;
15172: } else {
15173: strb = new StringBuffer("");
15174: int loadin = traceLoadInst(t, code, strb);
15175: if (loadin != -1) {
15176: index.append(-100);
15177: dim.append(0);
15178: pos.append(loadin);
15179: return;
15180: }
15181:
15182: }
15183: stackHandler = new Stack();
15184: InstParam first = new InstParam();
15185: first.setNumberOfParamsLeft(1);
15186: first.setCurrentParamOffsetInCode(-1);
15187: stackHandler.push(first);
15188: handleBasicPrimitiveLoadOp(code, k - 1);
15189: index.append(-100);
15190: dim.append(0);
15191: InstParam obj = (InstParam) stackHandler.pop(); // should be first
15192: pos.append(obj.getCurrentParamOffsetInCode());
15193: return;
15194: }
15195: }
15196: if (type.equals("long") || type.equals("float")
15197: || type.equals("double")) {
15198: if (code[k] == JvmOpCodes.D2L) {
15199:
15200: int t = k - 1;
15201: StringBuffer strb = new StringBuffer("");
15202: int dload = isInstDloadInst(code, t, strb);
15203: if (dload != -1) {
15204: index.append(-100);
15205: dim.append(0);
15206: pos.append(dload);
15207: return;
15208: } else {
15209: strb = new StringBuffer("");
15210: int loadin = traceLoadInst(t, code, strb);
15211: if (loadin != -1) {
15212: index.append(-100);
15213: dim.append(0);
15214: pos.append(loadin);
15215: return;
15216: }
15217:
15218: }
15219: stackHandler = new Stack();
15220: InstParam first = new InstParam();
15221: first.setNumberOfParamsLeft(1);
15222: first.setCurrentParamOffsetInCode(-1);
15223: stackHandler.push(first);
15224: handleBasicPrimitiveLoadOp(code, k - 1);
15225: index.append(-100);
15226: dim.append(0);
15227: InstParam obj = (InstParam) stackHandler.pop(); // should be first
15228: pos.append(obj.getCurrentParamOffsetInCode());
15229: return;
15230:
15231: }
15232: }
15233:
15234: if (primitive) {
15235: if (code[k] == JvmOpCodes.I2B || code[k] == JvmOpCodes.I2C
15236: || code[k] == JvmOpCodes.I2S)// || code[k]==JvmOpCodes.I2D || code[k]==JvmOpCodes.I2F || code[k]==JvmOpCodes.I2L || code[k]==JvmOpCodes.I2S )
15237: {
15238:
15239: int t = k - 1;
15240: StringBuffer strb = new StringBuffer("");
15241: int Iload = isInstIloadInst(code, t, strb);
15242: if (Iload != -1) {
15243: index.append(-100);
15244: dim.append(0);
15245: pos.append(Iload);
15246: return;
15247: } else {
15248: strb = new StringBuffer("");
15249: int loadin = traceLoadInst(t, code, strb);
15250: if (loadin != -1) {
15251: index.append(-100);
15252: dim.append(0);
15253: pos.append(loadin);
15254: return;
15255: }
15256:
15257: }
15258: stackHandler = new Stack();
15259: InstParam first = new InstParam();
15260: first.setNumberOfParamsLeft(1);
15261: first.setCurrentParamOffsetInCode(-1);
15262: stackHandler.push(first);
15263: handleBasicPrimitiveLoadOp(code, k - 1);
15264: index.append(-100);
15265: dim.append(0);
15266: InstParam obj = (InstParam) stackHandler.pop(); // should be first
15267: pos.append(obj.getCurrentParamOffsetInCode());
15268: return;
15269:
15270: }
15271: }
15272:
15273: if (type.equals("double")) {
15274: if (code[k] == JvmOpCodes.I2D)// || code[k]==JvmOpCodes.I2F || code[k]==JvmOpCodes.I2L || code[k]==JvmOpCodes.I2S )
15275: {
15276:
15277: int t = k - 1;
15278: StringBuffer strb = new StringBuffer("");
15279: int Iload = isInstIloadInst(code, t, strb);
15280: if (Iload != -1) {
15281: index.append(-100);
15282: dim.append(0);
15283: pos.append(Iload);
15284: return;
15285: } else {
15286: strb = new StringBuffer("");
15287: int loadin = traceLoadInst(t, code, strb);
15288: if (loadin != -1) {
15289: index.append(-100);
15290: dim.append(0);
15291: pos.append(loadin);
15292: return;
15293: }
15294:
15295: }
15296: stackHandler = new Stack();
15297: InstParam first = new InstParam();
15298: first.setNumberOfParamsLeft(1);
15299: first.setCurrentParamOffsetInCode(-1);
15300: stackHandler.push(first);
15301: handleBasicPrimitiveLoadOp(code, k - 1);
15302: index.append(-100);
15303: dim.append(0);
15304: InstParam obj = (InstParam) stackHandler.pop(); // should be first
15305: pos.append(obj.getCurrentParamOffsetInCode());
15306: return;
15307:
15308: }
15309:
15310: }
15311:
15312: if (type.equals("double") || type.equals("float")) {
15313: if (code[k] == JvmOpCodes.I2F)// || code[k]==JvmOpCodes.I2L || code[k]==JvmOpCodes.I2S )
15314: {
15315:
15316: int t = k - 1;
15317: StringBuffer strb = new StringBuffer("");
15318: int Iload = isInstIloadInst(code, t, strb);
15319: if (Iload != -1) {
15320: index.append(-100);
15321: dim.append(0);
15322: pos.append(Iload);
15323: return;
15324: } else {
15325: strb = new StringBuffer("");
15326: int loadin = traceLoadInst(t, code, strb);
15327: if (loadin != -1) {
15328: index.append(-100);
15329: dim.append(0);
15330: pos.append(loadin);
15331: return;
15332: }
15333:
15334: }
15335: stackHandler = new Stack();
15336: InstParam first = new InstParam();
15337: first.setNumberOfParamsLeft(1);
15338: first.setCurrentParamOffsetInCode(-1);
15339: stackHandler.push(first);
15340: handleBasicPrimitiveLoadOp(code, k - 1);
15341: index.append(-100);
15342: dim.append(0);
15343: InstParam obj = (InstParam) stackHandler.pop(); // should be first
15344: pos.append(obj.getCurrentParamOffsetInCode());
15345: return;
15346: }
15347: }
15348:
15349: if (type.equals("double") || type.equals("float")
15350: || type.equals("long")) {
15351: if (code[k] == JvmOpCodes.I2L) {
15352:
15353: int t = k - 1;
15354: StringBuffer strb = new StringBuffer("");
15355: int Iload = isInstIloadInst(code, t, strb);
15356: if (Iload != -1) {
15357: index.append(-100);
15358: dim.append(0);
15359: pos.append(Iload);
15360: return;
15361: } else {
15362: strb = new StringBuffer("");
15363: int loadin = traceLoadInst(t, code, strb);
15364: if (loadin != -1) {
15365: index.append(-100);
15366: dim.append(0);
15367: pos.append(loadin);
15368: return;
15369: }
15370:
15371: }
15372: stackHandler = new Stack();
15373: InstParam first = new InstParam();
15374: first.setNumberOfParamsLeft(1);
15375: first.setCurrentParamOffsetInCode(-1);
15376: stackHandler.push(first);
15377: handleBasicPrimitiveLoadOp(code, k - 1);
15378: index.append(-100);
15379: dim.append(0);
15380: InstParam obj = (InstParam) stackHandler.pop(); // should be first
15381: pos.append(obj.getCurrentParamOffsetInCode());
15382: return;
15383: }
15384: }
15385:
15386: if (type.equals("double")) {
15387: if (code[k] == JvmOpCodes.F2D)//|| code[k]==JvmOpCodes.F2I || code[k]==JvmOpCodes.F2L)
15388: {
15389:
15390: int t = k - 1;
15391: StringBuffer strb = new StringBuffer("");
15392: int Fload = isInstFloadInst(code, t, strb);
15393: if (Fload != -1) {
15394: index.append(-100);
15395: dim.append(0);
15396: pos.append(Fload);
15397: return;
15398: } else {
15399: strb = new StringBuffer("");
15400: int loadin = traceLoadInst(t, code, strb);
15401: if (loadin != -1) {
15402: index.append(-100);
15403: dim.append(0);
15404: pos.append(loadin);
15405: return;
15406: }
15407:
15408: }
15409: stackHandler = new Stack();
15410: InstParam first = new InstParam();
15411: first.setNumberOfParamsLeft(1);
15412: first.setCurrentParamOffsetInCode(-1);
15413: stackHandler.push(first);
15414: handleBasicPrimitiveLoadOp(code, k - 1);
15415: index.append(-100);
15416: dim.append(0);
15417: InstParam obj = (InstParam) stackHandler.pop(); // should be first
15418: pos.append(obj.getCurrentParamOffsetInCode());
15419: return;
15420: }
15421: }
15422:
15423: if (type.equals("double") || type.equals("float")
15424: || type.equals("long")) {
15425: if (code[k] == JvmOpCodes.F2L)//|| code[k]==JvmOpCodes.F2I || code[k]==JvmOpCodes.F2L)
15426: {
15427:
15428: int t = k - 1;
15429: StringBuffer strb = new StringBuffer("");
15430: int Fload = isInstFloadInst(code, t, strb);
15431: if (Fload != -1) {
15432: index.append(-100);
15433: dim.append(0);
15434: pos.append(Fload);
15435: return;
15436: } else {
15437: strb = new StringBuffer("");
15438: int loadin = traceLoadInst(t, code, strb);
15439: if (loadin != -1) {
15440: index.append(-100);
15441: dim.append(0);
15442: pos.append(loadin);
15443: return;
15444: }
15445:
15446: }
15447: stackHandler = new Stack();
15448: InstParam first = new InstParam();
15449: first.setNumberOfParamsLeft(1);
15450: first.setCurrentParamOffsetInCode(-1);
15451: stackHandler.push(first);
15452: handleBasicPrimitiveLoadOp(code, k - 1);
15453: index.append(-100);
15454: dim.append(0);
15455: InstParam obj = (InstParam) stackHandler.pop(); // should be first
15456: pos.append(obj.getCurrentParamOffsetInCode());
15457: return;
15458: }
15459: }
15460: if (primitive) {
15461: if (code[k] == JvmOpCodes.F2I) {
15462:
15463: int t = k - 1;
15464: StringBuffer strb = new StringBuffer("");
15465: int Fload = isInstFloadInst(code, t, strb);
15466: if (Fload != -1) {
15467: index.append(-100);
15468: dim.append(0);
15469: pos.append(Fload);
15470: return;
15471: } else {
15472: strb = new StringBuffer("");
15473: int loadin = traceLoadInst(t, code, strb);
15474: if (loadin != -1) {
15475: index.append(-100);
15476: dim.append(0);
15477: pos.append(loadin);
15478: return;
15479: }
15480:
15481: }
15482: stackHandler = new Stack();
15483: InstParam first = new InstParam();
15484: first.setNumberOfParamsLeft(1);
15485: first.setCurrentParamOffsetInCode(-1);
15486: stackHandler.push(first);
15487: handleBasicPrimitiveLoadOp(code, k - 1);
15488: index.append(-100);
15489: dim.append(0);
15490: InstParam obj = (InstParam) stackHandler.pop(); // should be first
15491: pos.append(obj.getCurrentParamOffsetInCode());
15492: return;
15493: }
15494: }
15495:
15496: if (type.equals("double")) {
15497: if (code[k] == JvmOpCodes.L2D)// || code[k]==JvmOpCodes.L2F || code[k]==JvmOpCodes.L2I)
15498: {
15499:
15500: int t = k - 1;
15501: StringBuffer strb = new StringBuffer("");
15502: int Fload = isInstLloadInst(code, t, strb);
15503: if (Fload != -1) {
15504: index.append(-100);
15505: dim.append(0);
15506: pos.append(Fload);
15507: return;
15508: } else {
15509: strb = new StringBuffer("");
15510: int loadin = traceLoadInst(t, code, strb);
15511: if (loadin != -1) {
15512: index.append(-100);
15513: dim.append(0);
15514: pos.append(loadin);
15515: return;
15516: }
15517:
15518: }
15519: stackHandler = new Stack();
15520: InstParam first = new InstParam();
15521: first.setNumberOfParamsLeft(1);
15522: first.setCurrentParamOffsetInCode(-1);
15523: stackHandler.push(first);
15524: handleBasicPrimitiveLoadOp(code, k - 1);
15525: index.append(-100);
15526: dim.append(0);
15527: InstParam obj = (InstParam) stackHandler.pop(); // should be first
15528: pos.append(obj.getCurrentParamOffsetInCode());
15529: return;
15530:
15531: }
15532: }
15533:
15534: if (type.equals("double") || type.equals("float")) {
15535: if (code[k] == JvmOpCodes.L2F)// || code[k]==JvmOpCodes.L2I)
15536: {
15537:
15538: int t = k - 1;
15539: StringBuffer strb = new StringBuffer("");
15540: int Fload = isInstLloadInst(code, t, strb);
15541: if (Fload != -1) {
15542: index.append(-100);
15543: dim.append(0);
15544: pos.append(Fload);
15545: return;
15546: } else {
15547: strb = new StringBuffer("");
15548: int loadin = traceLoadInst(t, code, strb);
15549: if (loadin != -1) {
15550: index.append(-100);
15551: dim.append(0);
15552: pos.append(loadin);
15553: return;
15554: }
15555:
15556: }
15557: stackHandler = new Stack();
15558: InstParam first = new InstParam();
15559: first.setNumberOfParamsLeft(1);
15560: first.setCurrentParamOffsetInCode(-1);
15561: stackHandler.push(first);
15562: handleBasicPrimitiveLoadOp(code, k - 1);
15563: index.append(-100);
15564: dim.append(0);
15565: InstParam obj = (InstParam) stackHandler.pop(); // should be first
15566: pos.append(obj.getCurrentParamOffsetInCode());
15567: return;
15568:
15569: }
15570: }
15571:
15572: if (primitive) {
15573: if (code[k] == JvmOpCodes.L2I) {
15574:
15575: int t = k - 1;
15576: StringBuffer strb = new StringBuffer("");
15577: int Fload = isInstLloadInst(code, t, strb);
15578: if (Fload != -1) {
15579: index.append(-100);
15580: dim.append(0);
15581: pos.append(Fload);
15582: return;
15583: } else {
15584: strb = new StringBuffer("");
15585: int loadin = traceLoadInst(t, code, strb);
15586: if (loadin != -1) {
15587: index.append(-100);
15588: dim.append(0);
15589: pos.append(loadin);
15590: return;
15591: }
15592:
15593: }
15594: stackHandler = new Stack();
15595: InstParam first = new InstParam();
15596: first.setNumberOfParamsLeft(1);
15597: first.setCurrentParamOffsetInCode(-1);
15598: stackHandler.push(first);
15599: handleBasicPrimitiveLoadOp(code, k - 1);
15600: index.append(-100);
15601: dim.append(0);
15602: InstParam obj = (InstParam) stackHandler.pop(); // should be first
15603: pos.append(obj.getCurrentParamOffsetInCode());
15604: return;
15605:
15606: }
15607: }
15608: int tmp = k;
15609: if (code[tmp] == JvmOpCodes.LDC) {
15610: index.append(-100);
15611: dim.append(0);
15612: pos.append(tmp);
15613: return;
15614: }
15615:
15616: if (code[tmp] == JvmOpCodes.LDC_W)// || code[tmp]==JvmOpCodes.LDC2_W)
15617: {
15618: index.append(-100);
15619: dim.append(0);
15620: pos.append(tmp);
15621: return;
15622: }
15623: if (type.equals("long") || type.equals("float")
15624: || type.equals("double")) {
15625: tmp = k;
15626: if (code[tmp] == JvmOpCodes.LDC2_W) {
15627: index.append(-100);
15628: dim.append(0);
15629: pos.append(tmp);
15630: return;
15631: }
15632: }
15633:
15634: if (!primitive) {
15635: if (code[k] == JvmOpCodes.ACONST_NULL) {
15636: index.append(-100);
15637: dim.append(0);
15638: pos.append(k);
15639: return;
15640: }
15641: }
15642: if (primitive) {
15643: if (isInstIConstInst(code, k) != -1) //
15644: {
15645: index.append(-100);
15646: dim.append(0);
15647: pos.append(k);
15648: return;
15649: }
15650: }
15651: if (type.equals("float") || type.equals("double")) {
15652: if (isInstFConstInst(code, k) != -1) {
15653: index.append(-100);
15654: dim.append(0);
15655: pos.append(k);
15656: return;
15657: }
15658: }
15659:
15660: if (type.equals("double")) {
15661: if (isInstdConstInst(code, k) != -1) {
15662: index.append(-100);
15663: dim.append(0);
15664: pos.append(k);
15665: return;
15666: }
15667: }
15668: if (type.equals("float") || type.equals("double")
15669: || type.equals("long")) {
15670: if (isInstLConstInst(code, k) != -1) {
15671: index.append(-100);
15672: dim.append(0);
15673: pos.append(k);
15674: return;
15675: }
15676: }
15677:
15678: if (!primitive) {
15679:
15680: if (code[k] == JvmOpCodes.MULTIANEWARRAY) {
15681: stackHandler = new Stack();
15682: InstParam first = new InstParam();
15683: first.setNumberOfParamsLeft(code[k + 3]);
15684: first.setCurrentParamOffsetInCode(-1);
15685: stackHandler.push(first);
15686: handleBasicPrimitiveLoadOp(code, k - 1);
15687: index.append(-100);
15688: dim.append(0);
15689: InstParam obj = (InstParam) stackHandler.pop(); // should be first
15690: pos.append(obj.getCurrentParamOffsetInCode()); // TODO: check whether this is correct
15691: return;
15692: }
15693: if (code[k] == JvmOpCodes.ANEWARRAY
15694: || code[k] == JvmOpCodes.NEWARRAY) {
15695:
15696: stackHandler = new Stack();
15697: InstParam first = new InstParam();
15698: first.setNumberOfParamsLeft(1);
15699: first.setCurrentParamOffsetInCode(-1);
15700: stackHandler.push(first);
15701: handleBasicPrimitiveLoadOp(code, k - 1);
15702: index.append(-100);
15703: dim.append(0);
15704: InstParam obj = (InstParam) stackHandler.pop(); // should be first
15705: pos.append(obj.getCurrentParamOffsetInCode()); // TODO: check whether this is correct
15706: return;
15707:
15708: }
15709:
15710: }
15711:
15712: if (primitive) {
15713:
15714: if (code[k] == JvmOpCodes.INSTANCEOF) {
15715: if (isThisInstrStart(behaviour
15716: .getInstructionStartPositions(), (k - 2))
15717: && code[k - 2] == JvmOpCodes.NEWARRAY) {
15718:
15719: stackHandler = new Stack();
15720: InstParam first = new InstParam();
15721: first.setNumberOfParamsLeft(1);
15722: first.setCurrentParamOffsetInCode(-1);
15723: stackHandler.push(first);
15724: handleBasicPrimitiveLoadOp(code, k - 3);
15725: index.append(-100);
15726: dim.append(0);
15727: InstParam obj = (InstParam) stackHandler.pop(); // should be first
15728: pos.append(obj.getCurrentParamOffsetInCode()); // TODO: check whether this is correct
15729: return;
15730:
15731: }
15732: StringBuffer s8 = new StringBuffer("");
15733: boolean aloadp = isPrevInstructionAload(k, code, s8);
15734: if (aloadp) {
15735:
15736: index.append(-100);
15737: dim.append(0);
15738: pos.append(Integer.parseInt(s8.toString()));
15739: return;
15740: }
15741: if (isThisInstrStart(behaviour
15742: .getInstructionStartPositions(), (k - 3))
15743: && code[k - 3] == JvmOpCodes.ANEWARRAY) {
15744:
15745: stackHandler = new Stack();
15746: InstParam first = new InstParam();
15747: first.setNumberOfParamsLeft(1);
15748: first.setCurrentParamOffsetInCode(-1);
15749: stackHandler.push(first);
15750: handleBasicPrimitiveLoadOp(code, k - 4);
15751: index.append(-100);
15752: dim.append(0);
15753: InstParam obj = (InstParam) stackHandler.pop(); // should be first
15754: pos.append(obj.getCurrentParamOffsetInCode()); // TODO: check whether this is correct
15755: return;
15756: }
15757: if (isThisInstrStart(behaviour
15758: .getInstructionStartPositions(), (k - 4))
15759: && code[k - 4] == JvmOpCodes.MULTIANEWARRAY) {
15760: stackHandler = new Stack();
15761: InstParam first = new InstParam();
15762: first.setNumberOfParamsLeft(code[k - 4 + 3]);
15763: first.setCurrentParamOffsetInCode(-1);
15764: stackHandler.push(first);
15765: handleBasicPrimitiveLoadOp(code, k - 5);
15766: index.append(-100);
15767: dim.append(0);
15768: InstParam obj = (InstParam) stackHandler.pop(); // should be first
15769: pos.append(obj.getCurrentParamOffsetInCode()); // TODO: check whether this is correct
15770: return;
15771: }
15772:
15773: }
15774:
15775: }
15776:
15777: if (!primitive) {
15778: if (code[k] == JvmOpCodes.CHECKCAST) {
15779: if (isThisInstrStart(behaviour
15780: .getInstructionStartPositions(), (k - 4))
15781: && code[k - 4] == JvmOpCodes.MULTIANEWARRAY) {
15782: stackHandler = new Stack();
15783: InstParam first = new InstParam();
15784: first.setNumberOfParamsLeft(code[k - 4 + 3]);
15785: first.setCurrentParamOffsetInCode(-1);
15786: stackHandler.push(first);
15787: handleBasicPrimitiveLoadOp(code, k - 5);
15788: index.append(-100);
15789: dim.append(0);
15790: InstParam obj = (InstParam) stackHandler.pop(); // should be first
15791: pos.append(obj.getCurrentParamOffsetInCode()); // TODO: check whether this is correct
15792: return;
15793: } else if (isThisInstrStart(behaviour
15794: .getInstructionStartPositions(), (k - 3))
15795: && code[k - 3] == JvmOpCodes.ANEWARRAY) {
15796:
15797: stackHandler = new Stack();
15798: InstParam first = new InstParam();
15799: first.setNumberOfParamsLeft(1);
15800: first.setCurrentParamOffsetInCode(-1);
15801: stackHandler.push(first);
15802: handleBasicPrimitiveLoadOp(code, k - 4);
15803: index.append(-100);
15804: dim.append(0);
15805: InstParam obj = (InstParam) stackHandler.pop(); // should be first
15806: pos.append(obj.getCurrentParamOffsetInCode()); // TODO: check whether this is correct
15807: return;
15808:
15809: } else if (isThisInstrStart(behaviour
15810: .getInstructionStartPositions(), (k - 2))
15811: && code[k - 2] == JvmOpCodes.NEWARRAY) {
15812:
15813: stackHandler = new Stack();
15814: InstParam first = new InstParam();
15815: first.setNumberOfParamsLeft(1);
15816: first.setCurrentParamOffsetInCode(-1);
15817: stackHandler.push(first);
15818: handleBasicPrimitiveLoadOp(code, k - 3);
15819: index.append(-100);
15820: dim.append(0);
15821: InstParam obj = (InstParam) stackHandler.pop(); // should be first
15822: pos.append(obj.getCurrentParamOffsetInCode()); // TODO: check whether this is correct
15823: return;
15824:
15825: } else {
15826: StringBuffer s5 = new StringBuffer("");
15827: boolean aload = isPrevInstructionAload(k, code, s5);
15828: if (aload) {
15829: index.append(-100);
15830: dim.append(0);
15831: pos.append(Integer.parseInt(s5.toString()));
15832: return;
15833: }
15834:
15835: }
15836:
15837: // Check for other object refs....
15838: if ((k - 1) >= 0) {
15839: boolean aaloadp = isInstAAload(code[k - 1]); // BUG check for getstatic alos.:TODO
15840: if (aaloadp) {
15841: StringBuffer s6 = new StringBuffer("");
15842: int in = k - 1;
15843: int posFound = isInstAload(in, code, s6);
15844: while (posFound == -1) {
15845: in = in - 1;
15846: posFound = isInstAload(in, code, s6);
15847: if (posFound == -1) {
15848: if (code[in] == JvmOpCodes.GETSTATIC) // TODO: Need to check at all such places whether the index is start of instruction
15849: {
15850:
15851: if (isThisInstrStart(
15852: behaviour
15853: .getInstructionStartPositions(),
15854: (in - 1))
15855: && code[in - 1] == JvmOpCodes.POP) // TODO: Possible bug with pop2
15856: {
15857: StringBuffer s3 = new StringBuffer(
15858: "");
15859: boolean bb = isPrevInstructionAload(
15860: in - 1, code, s3);
15861: if (bb) {
15862: index.append(-200);
15863: dim.append(0);
15864: pos
15865: .append(Integer
15866: .parseInt(s3
15867: .toString()));
15868: return;
15869: }
15870: } else {
15871: index.append(-200);
15872: dim.append(0);
15873: pos.append(in);
15874: return;
15875: }
15876:
15877: }
15878: if (code[in] == JvmOpCodes.GETFIELD) {
15879: s6 = new StringBuffer("");
15880: boolean aloadp = isPrevInstructionAload(
15881: in, code, s6);
15882: if (aloadp) {
15883: index.append(-200);
15884: dim.append(0);
15885: pos.append(Integer.parseInt(s6
15886: .toString()));
15887: return;
15888: }
15889: }
15890:
15891: }
15892:
15893: }
15894: index.append(-200);
15895: dim.append(0);
15896: pos.append(posFound);
15897: return;
15898:
15899: }
15900: } // here
15901: if ((k - 3) >= 0) {
15902: boolean getfield = (code[k - 3] == JvmOpCodes.GETFIELD);
15903: if (getfield) {
15904: StringBuffer s6 = new StringBuffer("");
15905: boolean aloadp = isPrevInstructionAload(k - 3,
15906: code, s6);
15907: if (aloadp) {
15908: index.append(-200);
15909: dim.append(0);
15910: pos.append(Integer.parseInt(s6.toString()));
15911: return;
15912: }
15913: }
15914: }
15915: if ((k - 3) >= 0) {
15916: boolean getS = (code[k - 3] == JvmOpCodes.GETSTATIC);
15917: if (getS) {
15918: if (code[k - 4] == JvmOpCodes.POP) // TODO: Possible bug with pop2
15919: {
15920: StringBuffer s3 = new StringBuffer("");
15921: boolean bb = isPrevInstructionAload(k - 4,
15922: code, s3);
15923: if (bb) {
15924: index.append(-200);
15925: dim.append(0);
15926: pos.append(Integer.parseInt(s3
15927: .toString()));
15928: return;
15929: }
15930: }
15931: index.append(-200);
15932: dim.append(0);
15933: pos.append(k - 3);
15934: return;
15935:
15936: }
15937: }
15938:
15939: //if(isNextInstructionAnyInvoke(code))
15940: Integer isinvokestart = (Integer) invokeStartEnd
15941: .get(new Integer(k - 1));
15942: if (isinvokestart != null) {
15943:
15944: Integer refpos = (Integer) invokeinstrefpos
15945: .get(new Integer(isinvokestart.intValue()));
15946: if (refpos != null) {
15947: index.append(-200);
15948: dim.append(0);
15949: pos.append(refpos.intValue());
15950: return;
15951: }
15952:
15953: }
15954:
15955: }
15956:
15957: }
15958:
15959: if (primitive) {
15960: StringBuffer sb = new StringBuffer("");
15961: boolean p = isInstAnyBasicPrimitiveOperation(code, k, sb);
15962:
15963: if (p) {
15964: // belurs:
15965:
15966: // Here need to call a function whill will handle tyes like imul,lmul,ldic etc
15967: // This function needs to be recursive. Handle this function with care
15968: // In this case the code will not set the index position because
15969: // any complex sequence of jvm blocks can be present for this
15970: // instruction itself. so for time being , what is important is that
15971: // this function should return load position for this jvm instr so that
15972: // for the next parameter the code will know from where to continue.
15973:
15974: stackHandler = new Stack();
15975: InstParam first = new InstParam();
15976: first.setNumberOfParamsLeft(Integer.parseInt(sb
15977: .toString()));
15978: first.setCurrentParamOffsetInCode(-1);
15979: stackHandler.push(first);
15980: handleBasicPrimitiveLoadOp(code, k - 1);
15981: index.append(-100);
15982: dim.append(0);
15983: InstParam obj = (InstParam) stackHandler.pop(); // should be first
15984: pos.append(obj.getCurrentParamOffsetInCode()); // TODO: check whether this is correct
15985: return;
15986:
15987: }
15988:
15989: }
15990:
15991: // This 2 should be last.
15992: // Any new thing should come before this 2
15993: if (code[k] == JvmOpCodes.GETFIELD) {
15994: StringBuffer sb1 = new StringBuffer("");
15995:
15996: int pos2 = isInstAload(k - 1, code, sb1);
15997: if (pos2 != -1) {
15998: index.append(Integer.parseInt(sb1.toString()));
15999: dim.append(0);
16000: pos.append(pos2);
16001: return;
16002: }
16003: }
16004: if (code[k] == JvmOpCodes.GETSTATIC) // POSSIBLE BUG: todo
16005: {
16006:
16007: index.append(-100);
16008: dim.append(0);
16009: pos.append(k);
16010: return;
16011:
16012: }
16013:
16014: //}
16015:
16016: }
16017:
16018: private int isInstIloadInst(byte[] code, int s, StringBuffer sb2) {
16019: if (isThisInstrStart(behaviour.getInstructionStartPositions(),
16020: s)) {
16021: switch (code[(s)]) {
16022: case JvmOpCodes.ILOAD_0:
16023: sb2.append(0);
16024: return s;
16025:
16026: case JvmOpCodes.ILOAD_1:
16027:
16028: sb2.append(1);
16029: return s;
16030:
16031: case JvmOpCodes.ILOAD_2:
16032:
16033: sb2.append(2);
16034: return s;
16035:
16036: case JvmOpCodes.ILOAD_3:
16037:
16038: sb2.append(3);
16039: return s;
16040:
16041: case JvmOpCodes.ILOAD:
16042: sb2.append(code[s + 1]);
16043: return s;
16044:
16045: }
16046: }
16047: int temp = s - 1;
16048: if (temp >= 0
16049: && isThisInstrStart(behaviour
16050: .getInstructionStartPositions(), temp)
16051: && code[temp] == JvmOpCodes.ILOAD) {
16052: sb2.append(code[s]);
16053: return temp;
16054:
16055: }
16056:
16057: return -1;
16058:
16059: }
16060:
16061: private int isInstFloadInst(byte[] code, int s, StringBuffer sb2) {
16062: if (isThisInstrStart(behaviour.getInstructionStartPositions(),
16063: s)) {
16064: switch (code[(s)]) {
16065: case JvmOpCodes.FLOAD_0:
16066: sb2.append(0);
16067: return s;
16068:
16069: case JvmOpCodes.FLOAD_1:
16070:
16071: sb2.append(1);
16072: return s;
16073:
16074: case JvmOpCodes.FLOAD_2:
16075:
16076: sb2.append(2);
16077: return s;
16078:
16079: case JvmOpCodes.FLOAD_3:
16080:
16081: sb2.append(3);
16082: return s;
16083:
16084: case JvmOpCodes.FLOAD:
16085:
16086: sb2.append(code[(s + 1)]);
16087: return s;
16088:
16089: }
16090: }
16091:
16092: int temp = s - 1;
16093: if (isThisInstrStart(behaviour.getInstructionStartPositions(),
16094: temp)
16095: && code[temp] == JvmOpCodes.FLOAD) {
16096: sb2.append(code[s]);
16097: return temp;
16098:
16099: }
16100:
16101: return -1;
16102:
16103: }
16104:
16105: private int isInstDloadInst(byte[] code, int s, StringBuffer sb2) {
16106: if (isThisInstrStart(behaviour.getInstructionStartPositions(),
16107: s)) {
16108:
16109: switch (code[(s)]) {
16110: case JvmOpCodes.DLOAD_0:
16111: sb2.append(0);
16112: return s;
16113:
16114: case JvmOpCodes.DLOAD_1:
16115:
16116: sb2.append(1);
16117: return s;
16118:
16119: case JvmOpCodes.DLOAD_2:
16120:
16121: sb2.append(2);
16122: return s;
16123:
16124: case JvmOpCodes.DLOAD_3:
16125:
16126: sb2.append(3);
16127: return s;
16128:
16129: case JvmOpCodes.DLOAD:
16130: sb2.append(code[s + 1]);
16131: return s;
16132:
16133: }
16134: }
16135: int temp = s - 1;
16136: if (isThisInstrStart(behaviour.getInstructionStartPositions(),
16137: temp)
16138: && code[temp] == JvmOpCodes.DLOAD) {
16139: sb2.append(code[s]);
16140: return temp;
16141:
16142: }
16143:
16144: return -1;
16145:
16146: }
16147:
16148: private int isInstLloadInst(byte[] code, int s, StringBuffer sb2) {
16149: if (isThisInstrStart(behaviour.getInstructionStartPositions(),
16150: s)) {
16151: switch (code[(s)]) {
16152: case JvmOpCodes.LLOAD_0:
16153: sb2.append(0);
16154: return s;
16155:
16156: case JvmOpCodes.LLOAD_1:
16157:
16158: sb2.append(1);
16159: return s;
16160:
16161: case JvmOpCodes.LLOAD_2:
16162:
16163: sb2.append(2);
16164: return s;
16165:
16166: case JvmOpCodes.LLOAD_3:
16167:
16168: sb2.append(3);
16169: return s;
16170:
16171: /*case JvmOpCodes.ILOAD:
16172: sb2.append(code[s+1]);
16173: return s;*/
16174:
16175: }
16176: }
16177: int temp = s - 1;
16178: if (isThisInstrStart(behaviour.getInstructionStartPositions(),
16179: temp)) {
16180: if (code[temp] == JvmOpCodes.LLOAD) {
16181: sb2.append(code[s]);
16182: return temp;
16183:
16184: }
16185: }
16186:
16187: return -1;
16188:
16189: }
16190:
16191: private int isInstIConstInst(byte[] code, int k) {
16192: if (isThisInstrStart(behaviour.getInstructionStartPositions(),
16193: k)) {
16194: switch (code[k]) {
16195: case JvmOpCodes.ICONST_0:
16196: case JvmOpCodes.ICONST_1:
16197: case JvmOpCodes.ICONST_2:
16198: case JvmOpCodes.ICONST_3:
16199: case JvmOpCodes.ICONST_M1:
16200: case JvmOpCodes.ICONST_4:
16201: case JvmOpCodes.ICONST_5:
16202: return k;
16203:
16204: }
16205: }
16206: return -1;
16207: }
16208:
16209: private int isInstLConstInst(byte[] code, int k) {
16210: if (isThisInstrStart(behaviour.getInstructionStartPositions(),
16211: k)) {
16212: switch (code[k]) {
16213: case JvmOpCodes.LCONST_0:
16214: case JvmOpCodes.LCONST_1:
16215: return k;
16216: }
16217: }
16218: return -1;
16219:
16220: }
16221:
16222: private int isInstFConstInst(byte[] code, int k) {
16223: if (isThisInstrStart(behaviour.getInstructionStartPositions(),
16224: k)) {
16225: switch (code[k]) {
16226: case JvmOpCodes.FCONST_0:
16227: case JvmOpCodes.FCONST_1:
16228: case JvmOpCodes.FCONST_2:
16229: return k;
16230: }
16231: }
16232: return -1;
16233: }
16234:
16235: private int isInstdConstInst(byte[] code, int k) {
16236: if (isThisInstrStart(behaviour.getInstructionStartPositions(),
16237: k)) {
16238: switch (code[k]) {
16239: case JvmOpCodes.DCONST_0:
16240: case JvmOpCodes.DCONST_1:
16241: return k;
16242: }
16243: }
16244: return -1;
16245: }
16246:
16247: private int isInstAnyConstInst(byte[] code, int k) {
16248: if (isThisInstrStart(behaviour.getInstructionStartPositions(),
16249: k)) {
16250: switch (code[k]) {
16251: case JvmOpCodes.ICONST_0:
16252: case JvmOpCodes.ICONST_1:
16253: case JvmOpCodes.ICONST_2:
16254: case JvmOpCodes.ICONST_3:
16255: case JvmOpCodes.ICONST_M1:
16256: case JvmOpCodes.ICONST_4:
16257: case JvmOpCodes.ICONST_5:
16258: case JvmOpCodes.LCONST_0:
16259: case JvmOpCodes.LCONST_1:
16260: case JvmOpCodes.DCONST_0:
16261: case JvmOpCodes.DCONST_1:
16262: case JvmOpCodes.FCONST_0:
16263: case JvmOpCodes.FCONST_1:
16264: case JvmOpCodes.FCONST_2:
16265: return k;
16266: default:
16267: return -1;
16268: }
16269: }
16270:
16271: return -1;
16272:
16273: }
16274:
16275: private boolean isPrimitive(java.lang.String type) {
16276: if (type.equals("int") || type.equals("short")
16277: || type.equals("char") || type.equals("byte")
16278: || type.equals("long") || type.equals("float")
16279: || type.equals("long") || type.equals("double")
16280: || type.equals("boolean"))
16281: return true;
16282: else
16283: return false;
16284: }
16285:
16286: private int traceLoadInst(int t, byte[] code, StringBuffer strb) {
16287: int pos = -1;
16288: int k = t;
16289:
16290: int getFieldPos = k - 2;
16291:
16292: int invokebegin = -1;
16293: if (invokeStartEnd != null) {
16294: Integer in = new Integer(k);
16295: Integer invs = (Integer) invokeStartEnd.get(in);
16296: if (invs != null) {
16297: invokebegin = invs.intValue();
16298: }
16299: }
16300:
16301: if (isThisInstrStart(behaviour.getInstructionStartPositions(),
16302: k)
16303: && code[k] == JvmOpCodes.BALOAD
16304: || code[k] == JvmOpCodes.CALOAD
16305: || code[k] == JvmOpCodes.DALOAD
16306: || code[k] == JvmOpCodes.FALOAD
16307: || code[k] == JvmOpCodes.LALOAD
16308: || code[k] == JvmOpCodes.IALOAD
16309: || code[k] == JvmOpCodes.SALOAD) {
16310:
16311: int posFound = isInstAload(k, code, strb);
16312: while (posFound == -1) {
16313:
16314: k = k - 1;
16315: strb = new StringBuffer("");
16316: posFound = isInstAload(k, code, strb);
16317:
16318: }
16319: return posFound;
16320:
16321: } else if (invokebegin != -1
16322: && isThisInstrStart(behaviour
16323: .getInstructionStartPositions(), invokebegin)) {
16324: if (isNextInstructionAnyInvoke(code[invokebegin],
16325: new StringBuffer(""))) {
16326: if (invokeinstrefpos != null) {
16327: Integer in = (Integer) invokeinstrefpos
16328: .get(new Integer(invokebegin));
16329: if (in != null) {
16330: int start = (in).intValue();
16331: return start;
16332: }
16333:
16334: }
16335: }
16336: }
16337:
16338: else if (code[getFieldPos] == JvmOpCodes.GETFIELD
16339: && isThisInstrStart(behaviour
16340: .getInstructionStartPositions(), getFieldPos)) {
16341: StringBuffer sb = new StringBuffer("");
16342: boolean ok = isPrevInstructionAload(getFieldPos, code, sb);
16343: if (ok) {
16344: int ref = Integer.parseInt(sb.toString());
16345: return ref;
16346: }
16347:
16348: } else if (isThisInstrStart(behaviour
16349: .getInstructionStartPositions(), getFieldPos)
16350: && code[getFieldPos] == JvmOpCodes.GETSTATIC) {
16351:
16352: if (code[getFieldPos - 1] == JvmOpCodes.POP) // TODO: Possible bug with pop2
16353: {
16354: StringBuffer s3 = new StringBuffer("");
16355: boolean bb = isPrevInstructionAload(getFieldPos - 1,
16356: code, s3);
16357: if (bb) {
16358: return Integer.parseInt(s3.toString());
16359: }
16360: }
16361:
16362: return getFieldPos;
16363: } else {
16364:
16365: // NOTE: The name is slightly misleading....what we want here is actually the previous inst...
16366: // Using this as it serves the pupose
16367: if (isNextInstructionConversionInst(code[k])) {
16368:
16369: int g = k - 1;
16370: int invokened = -1;
16371: while (isNextInstructionConversionInst(code[g])) {
16372: g = g - 1;
16373: }
16374: invokebegin = -1;
16375: if (invokeStartEnd != null) {
16376: Integer in = new Integer(g);
16377: Integer invs = (Integer) invokeStartEnd.get(in);
16378: if (invs != null) {
16379: invokebegin = invs.intValue();
16380: }
16381: }
16382: StringBuffer sbf = new StringBuffer("");
16383: if (isPrevInstPrimitiveLoad(code, (g + 1), sbf)) {
16384: pos = Integer.parseInt(sbf.toString());
16385: return pos;
16386: } else if (invokebegin != -1) {
16387: if (isNextInstructionAnyInvoke(code[invokebegin],
16388: new StringBuffer(""))) {
16389: if (invokeinstrefpos != null) {
16390: Integer in = (Integer) invokeinstrefpos
16391: .get(new Integer(invokebegin));
16392: if (in != null) {
16393: int start = (in).intValue();
16394: return start;
16395: }
16396:
16397: }
16398: }
16399: } else {
16400: k = g;
16401: if (isThisInstrStart(behaviour
16402: .getInstructionStartPositions(), k)
16403: && (code[k] == JvmOpCodes.BALOAD
16404: || code[k] == JvmOpCodes.CALOAD
16405: || code[k] == JvmOpCodes.DALOAD
16406: || code[k] == JvmOpCodes.FALOAD
16407: || code[k] == JvmOpCodes.LALOAD
16408: || code[k] == JvmOpCodes.IALOAD || code[k] == JvmOpCodes.SALOAD)) {
16409:
16410: int posFound = isInstAload(k, code, strb);
16411: while (posFound == -1) {
16412:
16413: k = k - 1;
16414: strb = new StringBuffer("");
16415: posFound = isInstAload(k, code, strb);
16416:
16417: }
16418: return posFound;
16419:
16420: }
16421: }
16422:
16423: }
16424:
16425: }
16426:
16427: return pos;
16428: }
16429:
16430: private int findWhereThisInvokeEnds(int s, byte[] code) {
16431: int temp = s;
16432: if (code[s] == JvmOpCodes.INVOKEINTERFACE) {
16433: temp = temp + 4;
16434: } else {
16435: temp += 2;
16436: }
16437: return temp;
16438:
16439: }
16440:
16441: private boolean checkForAssociatedGetField(ArrayList getField,
16442: int s, StringBuffer str, byte[] code) {
16443: boolean ret = false;
16444:
16445: HashMap map = ConsoleLauncher.getInstructionMap();
16446: if (getField == null || getField.size() == 0)
16447: return ret;
16448: else {
16449: for (int z = getField.size() - 1; z >= 0; z--) {
16450: Integer in = (Integer) getField.get(z);
16451: int Iin = in.intValue();
16452: if (s > Iin) // REQD getField
16453: {
16454: int temp1 = Iin;
16455: int temp2 = s;
16456: if (map != null) {
16457: Integer skip = (Integer) map.get(new Integer(
16458: temp1));
16459: if (skip != null) {
16460:
16461: int iskip = skip.intValue();
16462: int next = temp1 + iskip + 1;
16463: if (next < code.length)
16464: temp1 = next;
16465: }
16466:
16467: }
16468:
16469: for (int x = temp1; x < temp2; x++) {
16470: int inst = code[x];
16471: switch (inst) {
16472: case JvmOpCodes.INVOKEVIRTUAL:
16473: case JvmOpCodes.INVOKESTATIC:
16474: case JvmOpCodes.INVOKESPECIAL:
16475: case JvmOpCodes.INVOKEINTERFACE:
16476: return false;
16477:
16478: default:
16479: ret = true;
16480: }
16481: }
16482:
16483: if (ret) {
16484: str.append(Iin);
16485: return ret;
16486:
16487: }
16488: }
16489:
16490: }
16491:
16492: }
16493: return ret;
16494: }
16495:
16496: private boolean checkForAssociatedGetStatic(ArrayList getStatic,
16497: int s, StringBuffer str, byte[] code) {
16498:
16499: boolean ret = false;
16500: HashMap map = ConsoleLauncher.getInstructionMap();
16501: if (getStatic == null || getStatic.size() == 0)
16502: return ret;
16503: else {
16504: for (int z = 0; z < getStatic.size(); z++) {
16505: Integer in = (Integer) getStatic.get(z);
16506: int Iin = in.intValue();
16507: if (s > Iin) // REQD getStatic
16508: {
16509: int temp1 = Iin;
16510: int temp2 = s;
16511: if (map != null) {
16512: Integer skip = (Integer) map.get(new Integer(
16513: temp1));
16514: if (skip != null) {
16515:
16516: int iskip = skip.intValue();
16517: int next = temp1 + iskip + 1;
16518: if (next < code.length)
16519: temp1 = next;
16520: }
16521:
16522: }
16523:
16524: for (int x = temp1; x < temp2; x++) {
16525: if (isThisInstrStart(behaviour
16526: .getInstructionStartPositions(), x)) {
16527: int inst = code[x];
16528: switch (inst) {
16529: case JvmOpCodes.INVOKEVIRTUAL:
16530: case JvmOpCodes.INVOKESTATIC:
16531: case JvmOpCodes.INVOKESPECIAL:
16532: case JvmOpCodes.INVOKEINTERFACE:
16533: return false;
16534:
16535: default:
16536: ret = true;
16537: }
16538: }
16539: }
16540:
16541: if (ret) {
16542: str.append(Iin);
16543: return ret;
16544: }
16545: }
16546:
16547: }
16548:
16549: }
16550: return ret;
16551:
16552: }
16553:
16554: private boolean checkForAssociatedInvokeSpecial(
16555: Hashtable invokespecialpos, int s, StringBuffer str,
16556: byte[] code) {
16557:
16558: boolean ret = false;
16559: HashMap map = ConsoleLauncher.getInstructionMap();
16560: if (invokespecialpos != null && invokespecialpos.size() > 0) {
16561: Set set = invokespecialpos.keySet();
16562: Integer[] karr = (Integer[]) set.toArray(new Integer[set
16563: .size()]);
16564: Arrays.sort(karr);
16565: for (int z = 0; z < karr.length; z++) {
16566: Integer in = (Integer) karr[z];
16567: int Iin = in.intValue();
16568: if (s > Iin) // REQD invokespec
16569: {
16570: int temp1 = Iin;
16571: int temp2 = s;
16572: if (map != null) {
16573: Integer skip = (Integer) map.get(new Integer(
16574: temp1));
16575: if (skip != null) {
16576:
16577: int iskip = skip.intValue();
16578: int next = temp1 + iskip + 1;
16579: if (next < code.length)
16580: temp1 = next;
16581: }
16582:
16583: }
16584:
16585: for (int x = temp1; x < temp2; x++) {
16586: if (isThisInstrStart(behaviour
16587: .getInstructionStartPositions(), x)) {
16588: int inst = code[x];
16589: switch (inst) {
16590: case JvmOpCodes.INVOKEVIRTUAL:
16591: case JvmOpCodes.INVOKESTATIC:
16592: case JvmOpCodes.INVOKESPECIAL:
16593: case JvmOpCodes.INVOKEINTERFACE:
16594: return false;
16595:
16596: default:
16597: ret = true;
16598: }
16599: }
16600: }
16601:
16602: if (ret) {
16603: str.append(invokespecialpos
16604: .get(new Integer(Iin)));
16605: return ret;
16606: }
16607: }
16608:
16609: }
16610:
16611: }
16612: return false;
16613:
16614: }
16615:
16616: private int getObjectRefForGetField(int iS, byte[] code) {
16617: StringBuffer sb = new StringBuffer("");
16618: boolean ok = isPrevInstructionAload(iS, code, sb);
16619: if (ok) {
16620: int ref = Integer.parseInt(sb.toString());
16621: return ref;
16622: }
16623: //System.out.println("ERROR in getObjectRefForGetField "+iS);
16624: return iS;
16625:
16626: }
16627:
16628: private boolean isThisInstrStart(ArrayList list, int pos) {
16629: boolean ok = false;
16630: if (list == null)
16631: throw new NullPointerException(
16632: "Starts pos is null in disassembler");
16633: if (list != null) {
16634: for (int k = 0; k < list.size(); k++) {
16635: Integer in = (Integer) list.get(k);
16636: if (in != null) {
16637: int i = in.intValue();
16638: if (i == pos)
16639: return !ok;
16640: }
16641: }
16642: }
16643: return ok;
16644:
16645: }
16646:
16647: private boolean isThisLoopStart(IFBlock IF, ArrayList list,
16648: byte[] code) {
16649: boolean ok = false;
16650: ok = isThisIfALoopCondition(IF, code, list);
16651: return ok;
16652: }
16653:
16654: // currentForIndex --> goto start
16655: private int getElseCloseFromInRangeIfStructures(IFBlock ifs,
16656: int currentForIndex) {
16657: int i = -1;
16658: ArrayList ifbytecodestarts = new ArrayList();
16659: IFBlock inrangeifs[] = getInRangeIFS(ifs.getIfStart(),
16660: currentForIndex);
16661: if (inrangeifs != null) {
16662: for (int s = 0; s < inrangeifs.length; s++) {
16663: int j = inrangeifs[s].getIfCloseFromByteCode();
16664: if (j > ifs.getIfCloseFromByteCode()) {
16665: ifbytecodestarts.add(new Integer(j));
16666: }
16667:
16668: }
16669: if (ifbytecodestarts.size() > 0) {
16670: Integer ins[] = (Integer[]) ifbytecodestarts
16671: .toArray(new Integer[ifbytecodestarts.size()]);
16672: Arrays.sort(ins);
16673: return ins[0].intValue();
16674: } else
16675: return i;
16676: }
16677: return i;
16678:
16679: }
16680:
16681: // s --> Some if start
16682: // e--> goto start
16683:
16684: private IFBlock[] getInRangeIFS(int s, int e) {
16685: Collection ifs = getCurrentIFStructues();
16686: if (ifs == null || ifs.size() == 0)
16687: return null;
16688: ArrayList list = new ArrayList();
16689: int start = s + 2 + 1; // ifstart+skipbytes+1 --> start of next inst
16690: Iterator it = ifs.iterator();
16691: while (it.hasNext()) {
16692: IFBlock cur = (IFBlock) it.next();
16693: int ifstart = cur.getIfStart();
16694: if (ifstart >= start && ifstart < e) {
16695: list.add(cur);
16696: }
16697: }
16698:
16699: if (list.size() > 0)
16700: return (IFBlock[]) list.toArray(new IFBlock[list.size()]);
16701: else
16702: return null;
16703: }
16704:
16705: private java.lang.String anyWhileBodyHere(int e, Loop iloop,
16706: OperandStack opStack) {
16707: java.lang.String str = "";
16708: byte[] code = behaviour.getCode();
16709: Operand ops[] = new Operand[2];
16710: if (isThisInstrStart(behaviour.getInstructionStartPositions(),
16711: e)) {
16712: switch (code[e]) {
16713:
16714: case JvmOpCodes.IF_ACMPEQ:
16715: ops = getIFArgs(opStack, 2);
16716: if (ops != null) {
16717: str = "\nif(" + ops[1].getOperandValue() + "=="
16718: + ops[0].getOperandValue()
16719: + "))\n{\n}\nelse\n{\nbreak\n}\n;";
16720: } else {
16721: str = "";
16722: }
16723: break;
16724: case JvmOpCodes.IF_ACMPNE:
16725: ops = getIFArgs(opStack, 2);
16726: if (ops != null) {
16727: str = "\nif(!" + ops[1].getOperandValue() + "=="
16728: + ops[0].getOperandValue()
16729: + "))\n{\n}\nelse\n{\nbreak\n}\n;";
16730: } else {
16731: str = "";
16732: }
16733: break;
16734: case JvmOpCodes.IF_ICMPEQ:
16735:
16736: ops = getIFArgs(opStack, 2);
16737: if (ops != null) {
16738: str = "\nif(" + ops[1].getOperandValue() + " == "
16739: + ops[0].getOperandValue()
16740: + ")\n{\n}\nelse\n{\nbreak;\n}\n";
16741: } else {
16742: str = "";
16743: }
16744: break;
16745: case JvmOpCodes.IF_ICMPGE:
16746: ops = getIFArgs(opStack, 2);
16747: if (ops != null) {
16748: str = "\nif(" + ops[1].getOperandValue() + " >= "
16749: + ops[0].getOperandValue()
16750: + ")\n{\n}\nelse\n{\nbreak;\n}\n";
16751: } else {
16752: str = "";
16753: }
16754: break;
16755:
16756: case JvmOpCodes.IF_ICMPGT:
16757: ops = getIFArgs(opStack, 2);
16758: if (ops != null) {
16759: str = "\nif(" + ops[1].getOperandValue() + " > "
16760: + ops[0].getOperandValue()
16761: + ")\n{\n}\nelse\n{\nbreak;\n}\n";
16762: } else {
16763: str = "";
16764: }
16765: break;
16766:
16767: case JvmOpCodes.IF_ICMPLE:
16768: ops = getIFArgs(opStack, 2);
16769: if (ops != null) {
16770: str = "\nif(" + ops[1].getOperandValue() + " <= "
16771: + ops[0].getOperandValue()
16772: + ")\n{\n}\nelse\n{\nbreak;\n}\n";
16773: } else {
16774: str = "";
16775: }
16776: break;
16777:
16778: case JvmOpCodes.IF_ICMPLT:
16779: ops = getIFArgs(opStack, 2);
16780: if (ops != null) {
16781: str = "\nif(" + ops[1].getOperandValue() + "<"
16782: + ops[0].getOperandValue()
16783: + ")\n{\n}\nelse\n{\nbreak;\n}\n";
16784: } else {
16785: str = "";
16786: }
16787: break;
16788:
16789: case JvmOpCodes.IF_ICMPNE:
16790: ops = getIFArgs(opStack, 2);
16791: if (ops != null) {
16792: str = "\nif(" + ops[1].getOperandValue() + "!= "
16793: + ops[0].getOperandValue()
16794: + ")\n{\n}\nelse\n{\nbreak;\n}\n";
16795: } else {
16796: str = "";
16797: }
16798: break;
16799:
16800: case JvmOpCodes.IFEQ:
16801: ops = getIFArgs(opStack, 1);
16802: if (ops != null) {
16803: if ((code[currentForIndex - 1] != JvmOpCodes.DCMPG)
16804: && (code[currentForIndex - 1] != JvmOpCodes.DCMPL)
16805: && code[currentForIndex - 1] != JvmOpCodes.FCMPG
16806: && code[currentForIndex - 1] != JvmOpCodes.FCMPL
16807: && code[currentForIndex - 1] != JvmOpCodes.LCMP)
16808: str = "\nif(" + ops[0].getOperandValue()
16809: + "==0)\n{\n}\nelse\n{\nbreak;\n}\n";
16810: else
16811: str = "\nif(" + ops[0].getOperandValue()
16812: + ")\n{\nbreak;\n}\n" + "else\n"
16813: + "{\n" + "}\n";
16814: } else {
16815: str = "";
16816: }
16817: break;
16818: case JvmOpCodes.IFGE:
16819: ops = getIFArgs(opStack, 1);
16820: if (ops != null) {
16821: if ((code[currentForIndex - 1] != JvmOpCodes.DCMPG)
16822: && (code[currentForIndex - 1] != JvmOpCodes.DCMPL)
16823: && code[currentForIndex - 1] != JvmOpCodes.FCMPG
16824: && code[currentForIndex - 1] != JvmOpCodes.FCMPL
16825: && code[currentForIndex - 1] != JvmOpCodes.LCMP)
16826: str = "\nif(" + ops[0].getOperandValue()
16827: + ">=0)\n{\n}\nelse\n{\nbreak;\n}\n";
16828: else
16829: str = "\nif(" + ops[0].getOperandValue()
16830: + ")\n{\nbreak;\n}\n" + "else\n"
16831: + "{\n" + "}\n";
16832: } else {
16833: str = "";
16834: }
16835: break;
16836:
16837: case JvmOpCodes.IFGT:
16838: ops = getIFArgs(opStack, 1);
16839: if (ops != null) {
16840: if ((code[currentForIndex - 1] != JvmOpCodes.DCMPG)
16841: && (code[currentForIndex - 1] != JvmOpCodes.DCMPL)
16842: && code[currentForIndex - 1] != JvmOpCodes.FCMPG
16843: && code[currentForIndex - 1] != JvmOpCodes.FCMPL
16844: && code[currentForIndex - 1] != JvmOpCodes.LCMP)
16845: str = "\nif(" + ops[0].getOperandValue()
16846: + ">0)\n{\n}\nelse\n{\nbreak;\n}\n";
16847: else
16848: str = "\nif(" + ops[0].getOperandValue()
16849: + ")\n{\nbreak;\n}\n" + "else\n"
16850: + "{\n" + "}\n";
16851: } else {
16852: str = "";
16853: }
16854: break;
16855: case JvmOpCodes.IFLE:
16856: ops = getIFArgs(opStack, 1);
16857: if (ops != null) {
16858: if ((code[currentForIndex - 1] != JvmOpCodes.DCMPG)
16859: && (code[currentForIndex - 1] != JvmOpCodes.DCMPL)
16860: && code[currentForIndex - 1] != JvmOpCodes.FCMPG
16861: && code[currentForIndex - 1] != JvmOpCodes.FCMPL
16862: && code[currentForIndex - 1] != JvmOpCodes.LCMP)
16863: str = "\nif(" + ops[0].getOperandValue()
16864: + "<=0)\n{\n}\nelse\n{\nbreak;\n}\n";
16865: else
16866: str = "\nif(" + ops[0].getOperandValue()
16867: + ")\n{\nbreak;\n}\n" + "else\n"
16868: + "{\n" + "}\n";
16869: } else {
16870: str = "";
16871: }
16872: break;
16873: case JvmOpCodes.IFLT:
16874: ops = getIFArgs(opStack, 1);
16875: if (ops != null) {
16876: if ((code[currentForIndex - 1] != JvmOpCodes.DCMPG)
16877: && (code[currentForIndex - 1] != JvmOpCodes.DCMPL)
16878: && code[currentForIndex - 1] != JvmOpCodes.FCMPG
16879: && code[currentForIndex - 1] != JvmOpCodes.FCMPL
16880: && code[currentForIndex - 1] != JvmOpCodes.LCMP)
16881: str = "\nif(" + ops[0].getOperandValue()
16882: + "<0)\n{\n}\nelse\n{\nbreak;\n}\n";
16883: else
16884: str = "\nif(" + ops[0].getOperandValue()
16885: + ")\n{\nbreak;\n}\n" + "else\n"
16886: + "{\n" + "}\n";
16887: } else {
16888: str = "";
16889: }
16890: break;
16891: case JvmOpCodes.IFNE:
16892: ops = getIFArgs(opStack, 1);
16893: if (ops != null) {
16894: if ((code[currentForIndex - 1] != JvmOpCodes.DCMPG)
16895: && (code[currentForIndex - 1] != JvmOpCodes.DCMPL)
16896: && code[currentForIndex - 1] != JvmOpCodes.FCMPG
16897: && code[currentForIndex - 1] != JvmOpCodes.FCMPL
16898: && code[currentForIndex - 1] != JvmOpCodes.LCMP)
16899: str = "\nif(" + ops[0].getOperandValue()
16900: + "!=0)\n{\n}\nelse\n{\nbreak;\n}\n";
16901: else
16902: str = "\nif(" + ops[0].getOperandValue()
16903: + ")\n{\nbreak;\n}\n" + "else\n"
16904: + "{\n" + "}\n";
16905: } else {
16906: str = "";
16907: }
16908: break;
16909: case JvmOpCodes.IFNONNULL:
16910:
16911: ops = getIFArgs(opStack, 1);
16912: if (ops != null) {
16913: str = "\nif(" + ops[0].getOperandValue()
16914: + "!= null)\n{\n}\nelse\n{break;\n}\n";
16915: } else {
16916: str = "";
16917: }
16918: break;
16919: case JvmOpCodes.IFNULL:
16920: ops = getIFArgs(opStack, 1);
16921: if (ops != null) {
16922: str = "\nif(" + ops[0].getOperandValue()
16923: + "== null)\n{\n}\nelse\n{break;\n}\n";
16924: } else {
16925: str = "";
16926: }
16927: break;
16928: default:
16929: str = "";
16930: break;
16931:
16932: }
16933: }
16934: return str;
16935:
16936: }
16937:
16938: private Operand[] getIFArgs(OperandStack opStack, int number) {
16939: Operand ops[] = new Operand[number];
16940: if (opStack.size() >= number) {
16941:
16942: for (int z = 0; z < number; z++) // ops[0] --> Original TOS
16943: {
16944: ops[z] = opStack.getTopOfStack();
16945:
16946: }
16947:
16948: return ops;
16949: }
16950:
16951: return null;
16952: }
16953:
16954: private java.lang.String getIfElseReturnAtI(int i) {
16955: if (this .retAtIfElseEnd == null
16956: || this .retAtIfElseEnd.size() == 0) {
16957: return null;
16958: } else {
16959: boolean ret = addReturnAtIFElseEnd(i);
16960: if (ret) {
16961: returnsaddedAtIfElse.add(new Integer(i));
16962: return (java.lang.String) ((this .retAtIfElseEnd)
16963: .get(new Integer(i)));
16964: } else
16965: return null;
16966: }
16967: }
16968:
16969: private int getNextLoopStart(int start) {
16970: int i = -1;
16971: ArrayList loops = behaviour.getBehaviourLoops();
16972: for (int s = 0; s < loops.size(); s++) {
16973: Loop l = (Loop) loops.get(s);
16974: int next = s + 1;
16975: if (next < loops.size()) {
16976: Loop n = (Loop) loops.get(next);
16977: if (start == l.getStartIndex()) {
16978: return n.getStartIndex();
16979: }
16980:
16981: } else
16982: return i;
16983: }
16984:
16985: return i;
16986: }
16987:
16988: private boolean isNewFollowedByNew(byte[] info, int i) {
16989: int pos = i + 2 + 1 + 1;
16990: if (isThisInstrStart(behaviour.getInstructionStartPositions(),
16991: pos)) {
16992: if (info[pos] == JvmOpCodes.NEW)
16993: return true;
16994: else
16995: return false;
16996: } else
16997: return false;
16998: }
16999:
17000: private void registerInnerClassIfAny(java.lang.String Type) {
17001: java.lang.String type = Type.trim();
17002: if (type.indexOf("$") > 0) {
17003:
17004: java.lang.String path = Configuration
17005: .getPathForCurrentClassFile();
17006: java.lang.String name = ConsoleLauncher.getClassName(path);
17007: int numberof$inmain = 0;
17008: for (int j = 0; j < name.length(); j++) {
17009: char c = name.charAt(j);
17010: if (c == '$')
17011: numberof$inmain++;
17012: }
17013: int numberof$intype = 0;
17014: for (int j = 0; j < Type.length(); j++) {
17015: char c = Type.charAt(j);
17016: if (c == '$')
17017: numberof$intype++;
17018: }
17019: /// if(numberof$inmain+1==numberof$intype) // Need to register inner class
17020: // {
17021: InnerClassTracker tracker = ConsoleLauncher.getTracker();
17022: if (tracker != null) {
17023: InnerClassTracker.Node currentRoot = ConsoleLauncher
17024: .getCurrentRootAdded(); // Parent
17025: java.lang.String dir = ConsoleLauncher.getClassDir();
17026: if (type.endsWith(".class") == false)
17027: type += ".class";
17028: type = ConsoleLauncher.getClassName(type);
17029: InnerClassTracker.Node child = tracker.createNode(dir
17030: + File.separator + type, type);
17031: tracker.registerChildNode(currentRoot, child);
17032: }
17033: //}
17034:
17035: } else
17036: return;
17037:
17038: }
17039:
17040: private boolean isParameterTypeBoolean(List paramlist, int indx) {
17041: java.lang.String type = (java.lang.String) paramlist.get(indx);
17042: if (type.equalsIgnoreCase("boolean")) {
17043: return true;
17044: } else {
17045: return false;
17046: }
17047: }
17048:
17049: private void resetOperandValueIfNecessary(ArrayList paramlist,
17050: int indx, Operand op2) {
17051:
17052: boolean boolparam = isParameterTypeBoolean(paramlist, indx);
17053: if (boolparam) {
17054: if (op2 != null
17055: && op2.getOperandValue() != null
17056: && op2.getOperandValue().toString().trim().equals(
17057: "1"))
17058: op2.setOperandValue("true");
17059: if (op2 != null
17060: && op2.getOperandValue() != null
17061: && op2.getOperandValue().toString().trim().equals(
17062: "0"))
17063: op2.setOperandValue("false");
17064:
17065: }
17066: }
17067:
17068: public static java.lang.String getClassName(java.lang.String path) {
17069: java.lang.String slash = "";
17070: if (path.indexOf("\\") != -1) {
17071: slash = "\\";
17072: } else {
17073: slash = "/";
17074: }
17075: int lastSlash = path.lastIndexOf(slash);
17076: return path.substring(lastSlash + 1);
17077:
17078: }
17079:
17080: private boolean isInstAnyBasicPrimitiveOperation(byte code[],
17081: int pos, StringBuffer sb) {
17082: boolean b = false;
17083: switch (code[pos]) {
17084:
17085: case JvmOpCodes.DADD:
17086: sb.append(2);
17087: b = true;
17088: break;
17089: case JvmOpCodes.DDIV:
17090: b = true;
17091: sb.append(2);
17092: break;
17093: case JvmOpCodes.DMUL:
17094: b = true;
17095: sb.append(2);
17096: break;
17097: case JvmOpCodes.DNEG:
17098: b = true;
17099: sb.append(1);
17100: break;
17101: case JvmOpCodes.DREM:
17102: b = true;
17103: sb.append(2);
17104: break;
17105: case JvmOpCodes.DSUB:
17106: b = true;
17107: sb.append(2);
17108: break;
17109:
17110: case JvmOpCodes.FADD:
17111: b = true;
17112: sb.append(2);
17113: break;
17114: case JvmOpCodes.FDIV:
17115: b = true;
17116: sb.append(2);
17117: break;
17118: case JvmOpCodes.FMUL:
17119: b = true;
17120: sb.append(2);
17121: break;
17122: case JvmOpCodes.FNEG:
17123: b = true;
17124: sb.append(1);
17125: break;
17126: case JvmOpCodes.FREM:
17127: b = true;
17128: sb.append(2);
17129: break;
17130: case JvmOpCodes.IADD:
17131: b = true;
17132: sb.append(2);
17133: break;
17134: case JvmOpCodes.IAND:
17135: b = true;
17136: break;
17137: case JvmOpCodes.IDIV:
17138: b = true;
17139: sb.append(2);
17140: break;
17141: case JvmOpCodes.IMUL:
17142: b = true;
17143: sb.append(2);
17144: break;
17145: case JvmOpCodes.INEG:
17146: b = true;
17147: sb.append(1);
17148: break;
17149: case JvmOpCodes.IOR:
17150: b = true;
17151: sb.append(2);
17152: break;
17153: case JvmOpCodes.IREM:
17154: b = true;
17155: sb.append(2);
17156: break;
17157: case JvmOpCodes.ISHL:
17158: b = true;
17159: sb.append(2);
17160: break;
17161: case JvmOpCodes.ISHR:
17162: b = true;
17163: sb.append(2);
17164: break;
17165: case JvmOpCodes.ISUB:
17166: b = true;
17167: sb.append(2);
17168: break;
17169: case JvmOpCodes.IUSHR:
17170: b = true;
17171: sb.append(2);
17172: break;
17173: case JvmOpCodes.IXOR:
17174: b = true;
17175: sb.append(2);
17176: break;
17177: case JvmOpCodes.LADD:
17178: b = true;
17179: sb.append(2);
17180: break;
17181:
17182: case JvmOpCodes.LAND:
17183: b = true;
17184: sb.append(2);
17185: break;
17186: case JvmOpCodes.LDIV:
17187: b = true;
17188: sb.append(2);
17189: break;
17190: case JvmOpCodes.LMUL:
17191: b = true;
17192: sb.append(2);
17193: break;
17194: case JvmOpCodes.LNEG:
17195: b = true;
17196: sb.append(1);
17197: break;
17198: case JvmOpCodes.LOR:
17199: b = true;
17200: sb.append(2);
17201: break;
17202: case JvmOpCodes.LREM:
17203: b = true;
17204: sb.append(2);
17205: break;
17206: case JvmOpCodes.LSHL:
17207: b = true;
17208: sb.append(2);
17209: break;
17210: case JvmOpCodes.LSHR:
17211: b = true;
17212: sb.append(2);
17213: break;
17214: case JvmOpCodes.LSUB:
17215: b = true;
17216: sb.append(2);
17217: break;
17218: case JvmOpCodes.LUSHR:
17219: b = true;
17220: sb.append(2);
17221: break;
17222: case JvmOpCodes.LXOR:
17223: b = true;
17224: sb.append(2);
17225: break;
17226:
17227: }
17228:
17229: return b;
17230: }
17231:
17232: private void handleBasicPrimitiveLoadOp(byte[] code, int k)
17233: throws Exception {
17234: if (k < 0)
17235: throw new Exception();
17236: ArrayList list = behaviour.getInstructionStartPositions();
17237: boolean b = isThisInstrStart(list, k);
17238: while (!b) {
17239: k = k - 1;
17240: b = isThisInstrStart(list, k);
17241: }
17242: switch (code[k]) {
17243: /***
17244: * First List all recursive calls
17245: */
17246: case JvmOpCodes.DADD:
17247: InstParam newentry = new InstParam();
17248: newentry.setNumberOfParamsLeft(2);
17249: newentry.setCurrentParamOffsetInCode(-1);
17250: stackHandler.push(newentry);
17251: handleBasicPrimitiveLoadOp(code, (k - 1));
17252: InstParam tos = (InstParam) stackHandler.pop();
17253: int mybegin = tos.getCurrentParamOffsetInCode();
17254: tos = (InstParam) stackHandler.pop();
17255: int rem = tos.getNumberOfParamsLeft();
17256: rem = rem - 1;
17257: tos.setNumberOfParamsLeft(rem);
17258: tos.setCurrentParamOffsetInCode(mybegin);
17259: stackHandler.push(tos);
17260: if (rem == 0) {
17261: return;
17262: } else {
17263: handleBasicPrimitiveLoadOp(code, (mybegin - 1));
17264: return;
17265: }
17266:
17267: case JvmOpCodes.DDIV:
17268: newentry = new InstParam();
17269: newentry.setNumberOfParamsLeft(2);
17270: newentry.setCurrentParamOffsetInCode(-1);
17271: stackHandler.push(newentry);
17272: handleBasicPrimitiveLoadOp(code, (k - 1));
17273: tos = (InstParam) stackHandler.pop();
17274: mybegin = tos.getCurrentParamOffsetInCode();
17275: tos = (InstParam) stackHandler.pop();
17276: rem = tos.getNumberOfParamsLeft();
17277: rem = rem - 1;
17278: tos.setNumberOfParamsLeft(rem);
17279: tos.setCurrentParamOffsetInCode(mybegin);
17280: stackHandler.push(tos);
17281: if (rem == 0) {
17282: return;
17283: } else {
17284: handleBasicPrimitiveLoadOp(code, (mybegin - 1));
17285: return;
17286: }
17287:
17288: case JvmOpCodes.DMUL:
17289: newentry = new InstParam();
17290: newentry.setNumberOfParamsLeft(2);
17291: newentry.setCurrentParamOffsetInCode(-1);
17292: stackHandler.push(newentry);
17293: handleBasicPrimitiveLoadOp(code, (k - 1));
17294: tos = (InstParam) stackHandler.pop();
17295: mybegin = tos.getCurrentParamOffsetInCode();
17296: tos = (InstParam) stackHandler.pop();
17297: rem = tos.getNumberOfParamsLeft();
17298: rem = rem - 1;
17299: tos.setNumberOfParamsLeft(rem);
17300: tos.setCurrentParamOffsetInCode(mybegin);
17301: stackHandler.push(tos);
17302: if (rem == 0) {
17303: return;
17304: } else {
17305: handleBasicPrimitiveLoadOp(code, (mybegin - 1));
17306: return;
17307: }
17308:
17309: case JvmOpCodes.DNEG:
17310: newentry = new InstParam();
17311: newentry.setNumberOfParamsLeft(1);
17312: newentry.setCurrentParamOffsetInCode(-1);
17313: stackHandler.push(newentry);
17314: handleBasicPrimitiveLoadOp(code, (k - 1));
17315: tos = (InstParam) stackHandler.pop();
17316: mybegin = tos.getCurrentParamOffsetInCode();
17317: tos = (InstParam) stackHandler.pop();
17318: rem = tos.getNumberOfParamsLeft();
17319: rem = rem - 1;
17320: tos.setNumberOfParamsLeft(rem);
17321: tos.setCurrentParamOffsetInCode(mybegin);
17322: stackHandler.push(tos);
17323: if (rem == 0) {
17324: return;
17325: } else {
17326: handleBasicPrimitiveLoadOp(code, (mybegin - 1));
17327: return;
17328: }
17329:
17330: case JvmOpCodes.DREM:
17331: newentry = new InstParam();
17332: newentry.setNumberOfParamsLeft(2);
17333: newentry.setCurrentParamOffsetInCode(-1);
17334: stackHandler.push(newentry);
17335: handleBasicPrimitiveLoadOp(code, (k - 1));
17336: tos = (InstParam) stackHandler.pop();
17337: mybegin = tos.getCurrentParamOffsetInCode();
17338: tos = (InstParam) stackHandler.pop();
17339: rem = tos.getNumberOfParamsLeft();
17340: rem = rem - 1;
17341: tos.setNumberOfParamsLeft(rem);
17342: tos.setCurrentParamOffsetInCode(mybegin);
17343: stackHandler.push(tos);
17344: if (rem == 0) {
17345: return;
17346: } else {
17347: handleBasicPrimitiveLoadOp(code, (mybegin - 1));
17348: return;
17349: }
17350:
17351: case JvmOpCodes.DSUB:
17352: newentry = new InstParam();
17353: newentry.setNumberOfParamsLeft(2);
17354: newentry.setCurrentParamOffsetInCode(-1);
17355: stackHandler.push(newentry);
17356: handleBasicPrimitiveLoadOp(code, (k - 1));
17357: tos = (InstParam) stackHandler.pop();
17358: mybegin = tos.getCurrentParamOffsetInCode();
17359: tos = (InstParam) stackHandler.pop();
17360: rem = tos.getNumberOfParamsLeft();
17361: rem = rem - 1;
17362: tos.setNumberOfParamsLeft(rem);
17363: tos.setCurrentParamOffsetInCode(mybegin);
17364: stackHandler.push(tos);
17365: if (rem == 0) {
17366: return;
17367: } else {
17368: handleBasicPrimitiveLoadOp(code, (mybegin - 1));
17369: return;
17370: }
17371:
17372: case JvmOpCodes.FADD:
17373: newentry = new InstParam();
17374: newentry.setNumberOfParamsLeft(2);
17375: newentry.setCurrentParamOffsetInCode(-1);
17376: stackHandler.push(newentry);
17377: handleBasicPrimitiveLoadOp(code, (k - 1));
17378: tos = (InstParam) stackHandler.pop();
17379: mybegin = tos.getCurrentParamOffsetInCode();
17380: tos = (InstParam) stackHandler.pop();
17381: rem = tos.getNumberOfParamsLeft();
17382: rem = rem - 1;
17383: tos.setNumberOfParamsLeft(rem);
17384: tos.setCurrentParamOffsetInCode(mybegin);
17385: stackHandler.push(tos);
17386: if (rem == 0) {
17387: return;
17388: } else {
17389: handleBasicPrimitiveLoadOp(code, (mybegin - 1));
17390: return;
17391: }
17392:
17393: case JvmOpCodes.FDIV:
17394: newentry = new InstParam();
17395: newentry.setNumberOfParamsLeft(2);
17396: newentry.setCurrentParamOffsetInCode(-1);
17397: stackHandler.push(newentry);
17398: handleBasicPrimitiveLoadOp(code, (k - 1));
17399: tos = (InstParam) stackHandler.pop();
17400: mybegin = tos.getCurrentParamOffsetInCode();
17401: tos = (InstParam) stackHandler.pop();
17402: rem = tos.getNumberOfParamsLeft();
17403: rem = rem - 1;
17404: tos.setNumberOfParamsLeft(rem);
17405: tos.setCurrentParamOffsetInCode(mybegin);
17406: stackHandler.push(tos);
17407: if (rem == 0) {
17408: return;
17409: } else {
17410: handleBasicPrimitiveLoadOp(code, (mybegin - 1));
17411: return;
17412: }
17413:
17414: case JvmOpCodes.FMUL:
17415: newentry = new InstParam();
17416: newentry.setNumberOfParamsLeft(2);
17417: newentry.setCurrentParamOffsetInCode(-1);
17418: stackHandler.push(newentry);
17419: handleBasicPrimitiveLoadOp(code, (k - 1));
17420: tos = (InstParam) stackHandler.pop();
17421: mybegin = tos.getCurrentParamOffsetInCode();
17422: tos = (InstParam) stackHandler.pop();
17423: rem = tos.getNumberOfParamsLeft();
17424: rem = rem - 1;
17425: tos.setNumberOfParamsLeft(rem);
17426: tos.setCurrentParamOffsetInCode(mybegin);
17427: stackHandler.push(tos);
17428: if (rem == 0) {
17429: return;
17430: } else {
17431: handleBasicPrimitiveLoadOp(code, (mybegin - 1));
17432: return;
17433: }
17434:
17435: case JvmOpCodes.FNEG:
17436: newentry = new InstParam();
17437: newentry.setNumberOfParamsLeft(1);
17438: newentry.setCurrentParamOffsetInCode(-1);
17439: stackHandler.push(newentry);
17440: handleBasicPrimitiveLoadOp(code, (k - 1));
17441: tos = (InstParam) stackHandler.pop();
17442: mybegin = tos.getCurrentParamOffsetInCode();
17443: tos = (InstParam) stackHandler.pop();
17444: rem = tos.getNumberOfParamsLeft();
17445: rem = rem - 1;
17446: tos.setNumberOfParamsLeft(rem);
17447: tos.setCurrentParamOffsetInCode(mybegin);
17448: stackHandler.push(tos);
17449: if (rem == 0) {
17450: return;
17451: } else {
17452: handleBasicPrimitiveLoadOp(code, (mybegin - 1));
17453: return;
17454: }
17455:
17456: case JvmOpCodes.FREM:
17457: newentry = new InstParam();
17458: newentry.setNumberOfParamsLeft(2);
17459: newentry.setCurrentParamOffsetInCode(-1);
17460: stackHandler.push(newentry);
17461: handleBasicPrimitiveLoadOp(code, (k - 1));
17462: tos = (InstParam) stackHandler.pop();
17463: mybegin = tos.getCurrentParamOffsetInCode();
17464: tos = (InstParam) stackHandler.pop();
17465: rem = tos.getNumberOfParamsLeft();
17466: rem = rem - 1;
17467: tos.setNumberOfParamsLeft(rem);
17468: tos.setCurrentParamOffsetInCode(mybegin);
17469: stackHandler.push(tos);
17470: if (rem == 0) {
17471: return;
17472: } else {
17473: handleBasicPrimitiveLoadOp(code, (mybegin - 1));
17474: return;
17475: }
17476:
17477: case JvmOpCodes.IADD:
17478: newentry = new InstParam();
17479: newentry.setNumberOfParamsLeft(2);
17480: newentry.setCurrentParamOffsetInCode(-1);
17481: stackHandler.push(newentry);
17482: handleBasicPrimitiveLoadOp(code, (k - 1));
17483: tos = (InstParam) stackHandler.pop();
17484: mybegin = tos.getCurrentParamOffsetInCode();
17485: tos = (InstParam) stackHandler.pop();
17486: rem = tos.getNumberOfParamsLeft();
17487: rem = rem - 1;
17488: tos.setNumberOfParamsLeft(rem);
17489: tos.setCurrentParamOffsetInCode(mybegin);
17490: stackHandler.push(tos);
17491: if (rem == 0) {
17492: return;
17493: } else {
17494: handleBasicPrimitiveLoadOp(code, (mybegin - 1));
17495: return;
17496: }
17497:
17498: case JvmOpCodes.IAND:
17499: newentry = new InstParam();
17500: newentry.setNumberOfParamsLeft(2);
17501: newentry.setCurrentParamOffsetInCode(-1);
17502: stackHandler.push(newentry);
17503: handleBasicPrimitiveLoadOp(code, (k - 1));
17504: tos = (InstParam) stackHandler.pop();
17505: mybegin = tos.getCurrentParamOffsetInCode();
17506: tos = (InstParam) stackHandler.pop();
17507: rem = tos.getNumberOfParamsLeft();
17508: rem = rem - 1;
17509: tos.setNumberOfParamsLeft(rem);
17510: tos.setCurrentParamOffsetInCode(mybegin);
17511: stackHandler.push(tos);
17512: if (rem == 0) {
17513: return;
17514: } else {
17515: handleBasicPrimitiveLoadOp(code, (mybegin - 1));
17516: return;
17517: }
17518:
17519: case JvmOpCodes.IDIV:
17520: newentry = new InstParam();
17521: newentry.setNumberOfParamsLeft(2);
17522: newentry.setCurrentParamOffsetInCode(-1);
17523: stackHandler.push(newentry);
17524: handleBasicPrimitiveLoadOp(code, (k - 1));
17525: tos = (InstParam) stackHandler.pop();
17526: mybegin = tos.getCurrentParamOffsetInCode();
17527: tos = (InstParam) stackHandler.pop();
17528: rem = tos.getNumberOfParamsLeft();
17529: rem = rem - 1;
17530: tos.setNumberOfParamsLeft(rem);
17531: tos.setCurrentParamOffsetInCode(mybegin);
17532: stackHandler.push(tos);
17533: if (rem == 0) {
17534: return;
17535: } else {
17536: handleBasicPrimitiveLoadOp(code, (mybegin - 1));
17537: return;
17538: }
17539:
17540: case JvmOpCodes.IMUL:
17541: newentry = new InstParam();
17542: newentry.setNumberOfParamsLeft(2);
17543: newentry.setCurrentParamOffsetInCode(-1);
17544: stackHandler.push(newentry);
17545: handleBasicPrimitiveLoadOp(code, (k - 1));
17546: tos = (InstParam) stackHandler.pop();
17547: mybegin = tos.getCurrentParamOffsetInCode();
17548: tos = (InstParam) stackHandler.pop();
17549: rem = tos.getNumberOfParamsLeft();
17550: rem = rem - 1;
17551: tos.setNumberOfParamsLeft(rem);
17552: tos.setCurrentParamOffsetInCode(mybegin);
17553: stackHandler.push(tos);
17554: if (rem == 0) {
17555: return;
17556: } else {
17557: handleBasicPrimitiveLoadOp(code, (mybegin - 1));
17558: return;
17559:
17560: }
17561:
17562: case JvmOpCodes.INEG:
17563: newentry = new InstParam();
17564: newentry.setNumberOfParamsLeft(1);
17565: newentry.setCurrentParamOffsetInCode(-1);
17566: stackHandler.push(newentry);
17567: handleBasicPrimitiveLoadOp(code, (k - 1));
17568: tos = (InstParam) stackHandler.pop();
17569: mybegin = tos.getCurrentParamOffsetInCode();
17570: tos = (InstParam) stackHandler.pop();
17571: rem = tos.getNumberOfParamsLeft();
17572: rem = rem - 1;
17573: tos.setNumberOfParamsLeft(rem);
17574: tos.setCurrentParamOffsetInCode(mybegin);
17575: stackHandler.push(tos);
17576: if (rem == 0) {
17577: return;
17578: } else {
17579: handleBasicPrimitiveLoadOp(code, (mybegin - 1));
17580: return;
17581: }
17582:
17583: case JvmOpCodes.IOR:
17584: newentry = new InstParam();
17585: newentry.setNumberOfParamsLeft(2);
17586: newentry.setCurrentParamOffsetInCode(-1);
17587: stackHandler.push(newentry);
17588: handleBasicPrimitiveLoadOp(code, (k - 1));
17589: tos = (InstParam) stackHandler.pop();
17590: mybegin = tos.getCurrentParamOffsetInCode();
17591: tos = (InstParam) stackHandler.pop();
17592: rem = tos.getNumberOfParamsLeft();
17593: rem = rem - 1;
17594: tos.setNumberOfParamsLeft(rem);
17595: tos.setCurrentParamOffsetInCode(mybegin);
17596: stackHandler.push(tos);
17597: if (rem == 0) {
17598: return;
17599: } else {
17600: handleBasicPrimitiveLoadOp(code, (mybegin - 1));
17601: return;
17602: }
17603:
17604: case JvmOpCodes.IREM:
17605: newentry = new InstParam();
17606: newentry.setNumberOfParamsLeft(2);
17607: newentry.setCurrentParamOffsetInCode(-1);
17608: stackHandler.push(newentry);
17609: handleBasicPrimitiveLoadOp(code, (k - 1));
17610: tos = (InstParam) stackHandler.pop();
17611: mybegin = tos.getCurrentParamOffsetInCode();
17612: tos = (InstParam) stackHandler.pop();
17613: rem = tos.getNumberOfParamsLeft();
17614: rem = rem - 1;
17615: tos.setNumberOfParamsLeft(rem);
17616: tos.setCurrentParamOffsetInCode(mybegin);
17617: stackHandler.push(tos);
17618: if (rem == 0) {
17619: return;
17620: } else {
17621: handleBasicPrimitiveLoadOp(code, (mybegin - 1));
17622: return;
17623: }
17624:
17625: case JvmOpCodes.ISHL:
17626: newentry = new InstParam();
17627: newentry.setNumberOfParamsLeft(2);
17628: newentry.setCurrentParamOffsetInCode(-1);
17629: stackHandler.push(newentry);
17630: handleBasicPrimitiveLoadOp(code, (k - 1));
17631: tos = (InstParam) stackHandler.pop();
17632: mybegin = tos.getCurrentParamOffsetInCode();
17633: tos = (InstParam) stackHandler.pop();
17634: rem = tos.getNumberOfParamsLeft();
17635: rem = rem - 1;
17636: tos.setNumberOfParamsLeft(rem);
17637: tos.setCurrentParamOffsetInCode(mybegin);
17638: stackHandler.push(tos);
17639: if (rem == 0) {
17640: return;
17641: } else {
17642: handleBasicPrimitiveLoadOp(code, (mybegin - 1));
17643: return;
17644: }
17645:
17646: case JvmOpCodes.ISHR:
17647: newentry = new InstParam();
17648: newentry.setNumberOfParamsLeft(2);
17649: newentry.setCurrentParamOffsetInCode(-1);
17650: stackHandler.push(newentry);
17651: handleBasicPrimitiveLoadOp(code, (k - 1));
17652: tos = (InstParam) stackHandler.pop();
17653: mybegin = tos.getCurrentParamOffsetInCode();
17654: tos = (InstParam) stackHandler.pop();
17655: rem = tos.getNumberOfParamsLeft();
17656: rem = rem - 1;
17657: tos.setNumberOfParamsLeft(rem);
17658: tos.setCurrentParamOffsetInCode(mybegin);
17659: stackHandler.push(tos);
17660: if (rem == 0) {
17661: return;
17662: } else {
17663: handleBasicPrimitiveLoadOp(code, (mybegin - 1));
17664: return;
17665: }
17666:
17667: case JvmOpCodes.ISUB:
17668: newentry = new InstParam();
17669: newentry.setNumberOfParamsLeft(2);
17670: newentry.setCurrentParamOffsetInCode(-1);
17671: stackHandler.push(newentry);
17672: handleBasicPrimitiveLoadOp(code, (k - 1));
17673: tos = (InstParam) stackHandler.pop();
17674: mybegin = tos.getCurrentParamOffsetInCode();
17675: tos = (InstParam) stackHandler.pop();
17676: rem = tos.getNumberOfParamsLeft();
17677: rem = rem - 1;
17678: tos.setNumberOfParamsLeft(rem);
17679: tos.setCurrentParamOffsetInCode(mybegin);
17680: stackHandler.push(tos);
17681: if (rem == 0) {
17682: return;
17683: } else {
17684: handleBasicPrimitiveLoadOp(code, (mybegin - 1));
17685: return;
17686: }
17687:
17688: case JvmOpCodes.IUSHR:
17689: newentry = new InstParam();
17690: newentry.setNumberOfParamsLeft(2);
17691: newentry.setCurrentParamOffsetInCode(-1);
17692: stackHandler.push(newentry);
17693: handleBasicPrimitiveLoadOp(code, (k - 1));
17694: tos = (InstParam) stackHandler.pop();
17695: mybegin = tos.getCurrentParamOffsetInCode();
17696: tos = (InstParam) stackHandler.pop();
17697: rem = tos.getNumberOfParamsLeft();
17698: rem = rem - 1;
17699: tos.setNumberOfParamsLeft(rem);
17700: tos.setCurrentParamOffsetInCode(mybegin);
17701: stackHandler.push(tos);
17702: if (rem == 0) {
17703: return;
17704: } else {
17705: handleBasicPrimitiveLoadOp(code, (mybegin - 1));
17706: return;
17707: }
17708:
17709: case JvmOpCodes.IXOR:
17710: newentry = new InstParam();
17711: newentry.setNumberOfParamsLeft(2);
17712: newentry.setCurrentParamOffsetInCode(-1);
17713: stackHandler.push(newentry);
17714: handleBasicPrimitiveLoadOp(code, (k - 1));
17715: tos = (InstParam) stackHandler.pop();
17716: mybegin = tos.getCurrentParamOffsetInCode();
17717: tos = (InstParam) stackHandler.pop();
17718: rem = tos.getNumberOfParamsLeft();
17719: rem = rem - 1;
17720: tos.setNumberOfParamsLeft(rem);
17721: tos.setCurrentParamOffsetInCode(mybegin);
17722: stackHandler.push(tos);
17723: if (rem == 0) {
17724: return;
17725: } else {
17726: handleBasicPrimitiveLoadOp(code, (mybegin - 1));
17727: return;
17728: }
17729:
17730: case JvmOpCodes.LADD:
17731: newentry = new InstParam();
17732: newentry.setNumberOfParamsLeft(2);
17733: newentry.setCurrentParamOffsetInCode(-1);
17734: stackHandler.push(newentry);
17735: handleBasicPrimitiveLoadOp(code, (k - 1));
17736: tos = (InstParam) stackHandler.pop();
17737: mybegin = tos.getCurrentParamOffsetInCode();
17738: tos = (InstParam) stackHandler.pop();
17739: rem = tos.getNumberOfParamsLeft();
17740: rem = rem - 1;
17741: tos.setNumberOfParamsLeft(rem);
17742: tos.setCurrentParamOffsetInCode(mybegin);
17743: stackHandler.push(tos);
17744: if (rem == 0) {
17745: return;
17746: } else {
17747: handleBasicPrimitiveLoadOp(code, (mybegin - 1));
17748: return;
17749: }
17750:
17751: case JvmOpCodes.LAND:
17752: newentry = new InstParam();
17753: newentry.setNumberOfParamsLeft(2);
17754: newentry.setCurrentParamOffsetInCode(-1);
17755: stackHandler.push(newentry);
17756: handleBasicPrimitiveLoadOp(code, (k - 1));
17757: tos = (InstParam) stackHandler.pop();
17758: mybegin = tos.getCurrentParamOffsetInCode();
17759: tos = (InstParam) stackHandler.pop();
17760: rem = tos.getNumberOfParamsLeft();
17761: rem = rem - 1;
17762: tos.setNumberOfParamsLeft(rem);
17763: tos.setCurrentParamOffsetInCode(mybegin);
17764: stackHandler.push(tos);
17765: if (rem == 0) {
17766: return;
17767: } else {
17768: handleBasicPrimitiveLoadOp(code, (mybegin - 1));
17769: return;
17770: }
17771:
17772: case JvmOpCodes.LDIV:
17773: newentry = new InstParam();
17774: newentry.setNumberOfParamsLeft(2);
17775: newentry.setCurrentParamOffsetInCode(-1);
17776: stackHandler.push(newentry);
17777: handleBasicPrimitiveLoadOp(code, (k - 1));
17778: tos = (InstParam) stackHandler.pop();
17779: mybegin = tos.getCurrentParamOffsetInCode();
17780: tos = (InstParam) stackHandler.pop();
17781: rem = tos.getNumberOfParamsLeft();
17782: rem = rem - 1;
17783: tos.setNumberOfParamsLeft(rem);
17784: tos.setCurrentParamOffsetInCode(mybegin);
17785: stackHandler.push(tos);
17786: if (rem == 0) {
17787: return;
17788: } else {
17789: handleBasicPrimitiveLoadOp(code, (mybegin - 1));
17790: return;
17791: }
17792:
17793: case JvmOpCodes.LMUL:
17794: newentry = new InstParam();
17795: newentry.setNumberOfParamsLeft(2);
17796: newentry.setCurrentParamOffsetInCode(-1);
17797: stackHandler.push(newentry);
17798: handleBasicPrimitiveLoadOp(code, (k - 1));
17799: tos = (InstParam) stackHandler.pop();
17800: mybegin = tos.getCurrentParamOffsetInCode();
17801: tos = (InstParam) stackHandler.pop();
17802: rem = tos.getNumberOfParamsLeft();
17803: rem = rem - 1;
17804: tos.setNumberOfParamsLeft(rem);
17805: tos.setCurrentParamOffsetInCode(mybegin);
17806: stackHandler.push(tos);
17807: if (rem == 0) {
17808: return;
17809: } else {
17810: handleBasicPrimitiveLoadOp(code, (mybegin - 1));
17811: return;
17812: }
17813:
17814: case JvmOpCodes.LNEG:
17815: newentry = new InstParam();
17816: newentry.setNumberOfParamsLeft(1);
17817: newentry.setCurrentParamOffsetInCode(-1);
17818: stackHandler.push(newentry);
17819: handleBasicPrimitiveLoadOp(code, (k - 1));
17820: tos = (InstParam) stackHandler.pop();
17821: mybegin = tos.getCurrentParamOffsetInCode();
17822: tos = (InstParam) stackHandler.pop();
17823: rem = tos.getNumberOfParamsLeft();
17824: rem = rem - 1;
17825: tos.setNumberOfParamsLeft(rem);
17826: tos.setCurrentParamOffsetInCode(mybegin);
17827: stackHandler.push(tos);
17828: if (rem == 0) {
17829: return;
17830: } else {
17831: handleBasicPrimitiveLoadOp(code, (mybegin - 1));
17832: return;
17833: }
17834:
17835: case JvmOpCodes.LOR:
17836: newentry = new InstParam();
17837: newentry.setNumberOfParamsLeft(2);
17838: newentry.setCurrentParamOffsetInCode(-1);
17839: stackHandler.push(newentry);
17840: handleBasicPrimitiveLoadOp(code, (k - 1));
17841: tos = (InstParam) stackHandler.pop();
17842: mybegin = tos.getCurrentParamOffsetInCode();
17843: tos = (InstParam) stackHandler.pop();
17844: rem = tos.getNumberOfParamsLeft();
17845: rem = rem - 1;
17846: tos.setNumberOfParamsLeft(rem);
17847: tos.setCurrentParamOffsetInCode(mybegin);
17848: stackHandler.push(tos);
17849: if (rem == 0) {
17850: return;
17851: } else {
17852: handleBasicPrimitiveLoadOp(code, (mybegin - 1));
17853: return;
17854: }
17855:
17856: case JvmOpCodes.LREM:
17857: newentry = new InstParam();
17858: newentry.setNumberOfParamsLeft(2);
17859: newentry.setCurrentParamOffsetInCode(-1);
17860: stackHandler.push(newentry);
17861: handleBasicPrimitiveLoadOp(code, (k - 1));
17862: tos = (InstParam) stackHandler.pop();
17863: mybegin = tos.getCurrentParamOffsetInCode();
17864: tos = (InstParam) stackHandler.pop();
17865: rem = tos.getNumberOfParamsLeft();
17866: rem = rem - 1;
17867: tos.setNumberOfParamsLeft(rem);
17868: tos.setCurrentParamOffsetInCode(mybegin);
17869: stackHandler.push(tos);
17870: if (rem == 0) {
17871: return;
17872: } else {
17873: handleBasicPrimitiveLoadOp(code, (mybegin - 1));
17874: return;
17875: }
17876:
17877: case JvmOpCodes.LSHL:
17878: newentry = new InstParam();
17879: newentry.setNumberOfParamsLeft(2);
17880: newentry.setCurrentParamOffsetInCode(-1);
17881: stackHandler.push(newentry);
17882: handleBasicPrimitiveLoadOp(code, (k - 1));
17883: tos = (InstParam) stackHandler.pop();
17884: mybegin = tos.getCurrentParamOffsetInCode();
17885: tos = (InstParam) stackHandler.pop();
17886: rem = tos.getNumberOfParamsLeft();
17887: rem = rem - 1;
17888: tos.setNumberOfParamsLeft(rem);
17889: tos.setCurrentParamOffsetInCode(mybegin);
17890: stackHandler.push(tos);
17891: if (rem == 0) {
17892: return;
17893: } else {
17894: handleBasicPrimitiveLoadOp(code, (mybegin - 1));
17895: return;
17896: }
17897:
17898: case JvmOpCodes.LSHR:
17899: newentry = new InstParam();
17900: newentry.setNumberOfParamsLeft(2);
17901: newentry.setCurrentParamOffsetInCode(-1);
17902: stackHandler.push(newentry);
17903: handleBasicPrimitiveLoadOp(code, (k - 1));
17904: tos = (InstParam) stackHandler.pop();
17905: mybegin = tos.getCurrentParamOffsetInCode();
17906: tos = (InstParam) stackHandler.pop();
17907: rem = tos.getNumberOfParamsLeft();
17908: rem = rem - 1;
17909: tos.setNumberOfParamsLeft(rem);
17910: tos.setCurrentParamOffsetInCode(mybegin);
17911: stackHandler.push(tos);
17912: if (rem == 0) {
17913: return;
17914: } else {
17915: handleBasicPrimitiveLoadOp(code, (mybegin - 1));
17916: return;
17917: }
17918:
17919: case JvmOpCodes.LSUB:
17920: newentry = new InstParam();
17921: newentry.setNumberOfParamsLeft(2);
17922: newentry.setCurrentParamOffsetInCode(-1);
17923: stackHandler.push(newentry);
17924: handleBasicPrimitiveLoadOp(code, (k - 1));
17925: tos = (InstParam) stackHandler.pop();
17926: mybegin = tos.getCurrentParamOffsetInCode();
17927: tos = (InstParam) stackHandler.pop();
17928: rem = tos.getNumberOfParamsLeft();
17929: rem = rem - 1;
17930: tos.setNumberOfParamsLeft(rem);
17931: tos.setCurrentParamOffsetInCode(mybegin);
17932: stackHandler.push(tos);
17933: if (rem == 0) {
17934: return;
17935: } else {
17936: handleBasicPrimitiveLoadOp(code, (mybegin - 1));
17937: return;
17938: }
17939:
17940: case JvmOpCodes.LUSHR:
17941: newentry = new InstParam();
17942: newentry.setNumberOfParamsLeft(2);
17943: newentry.setCurrentParamOffsetInCode(-1);
17944: stackHandler.push(newentry);
17945: handleBasicPrimitiveLoadOp(code, (k - 1));
17946: tos = (InstParam) stackHandler.pop();
17947: mybegin = tos.getCurrentParamOffsetInCode();
17948: tos = (InstParam) stackHandler.pop();
17949: rem = tos.getNumberOfParamsLeft();
17950: rem = rem - 1;
17951: tos.setNumberOfParamsLeft(rem);
17952: tos.setCurrentParamOffsetInCode(mybegin);
17953: stackHandler.push(tos);
17954: if (rem == 0) {
17955: return;
17956: } else {
17957: handleBasicPrimitiveLoadOp(code, (mybegin - 1));
17958: return;
17959: }
17960:
17961: case JvmOpCodes.LXOR:
17962: newentry = new InstParam();
17963: newentry.setNumberOfParamsLeft(2);
17964: newentry.setCurrentParamOffsetInCode(-1);
17965: stackHandler.push(newentry);
17966: handleBasicPrimitiveLoadOp(code, (k - 1));
17967: tos = (InstParam) stackHandler.pop();
17968: mybegin = tos.getCurrentParamOffsetInCode();
17969: tos = (InstParam) stackHandler.pop();
17970: rem = tos.getNumberOfParamsLeft();
17971: rem = rem - 1;
17972: tos.setNumberOfParamsLeft(rem);
17973: tos.setCurrentParamOffsetInCode(mybegin);
17974: stackHandler.push(tos);
17975: if (rem == 0) {
17976: return;
17977: } else {
17978: handleBasicPrimitiveLoadOp(code, (mybegin - 1));
17979: return;
17980: }
17981:
17982: }
17983:
17984: if (code[k] == JvmOpCodes.BALOAD
17985: || code[k] == JvmOpCodes.CALOAD
17986: || code[k] == JvmOpCodes.DALOAD
17987: || code[k] == JvmOpCodes.FALOAD
17988: || code[k] == JvmOpCodes.LALOAD
17989: || code[k] == JvmOpCodes.IALOAD
17990: || code[k] == JvmOpCodes.SALOAD) {
17991: StringBuffer sb = new StringBuffer("");
17992: int posFound = isInstAload(k, code, sb);
17993: while (posFound == -1) {
17994:
17995: k = k - 1;
17996: sb = new StringBuffer("");
17997: posFound = isInstAload(k, code, sb);
17998:
17999: }
18000: InstParam tos = (InstParam) stackHandler.pop();
18001: int rem = tos.getNumberOfParamsLeft();
18002: rem = rem - 1;
18003: tos.setNumberOfParamsLeft(rem);
18004: tos.setCurrentParamOffsetInCode(posFound);
18005: stackHandler.push(tos);
18006: if (rem == 0)
18007: return;
18008: else {
18009: handleBasicPrimitiveLoadOp(code, posFound - 1);
18010: return;
18011: }
18012:
18013: }
18014:
18015: if (code[k] == JvmOpCodes.BIPUSH
18016: || code[k] == JvmOpCodes.SIPUSH) {
18017: InstParam tos = (InstParam) stackHandler.pop();
18018: int rem = tos.getNumberOfParamsLeft();
18019: rem = rem - 1;
18020: tos.setNumberOfParamsLeft(rem);
18021: tos.setCurrentParamOffsetInCode(k);
18022: stackHandler.push(tos);
18023: if (rem == 0)
18024: return;
18025: else {
18026: handleBasicPrimitiveLoadOp(code, k - 1);
18027: return;
18028: }
18029:
18030: }
18031: int y = isInstIloadInst(code, k, new StringBuffer(""));
18032: if (y != -1) {
18033: InstParam tos = (InstParam) stackHandler.pop();
18034: int rem = tos.getNumberOfParamsLeft();
18035: rem = rem - 1;
18036: tos.setNumberOfParamsLeft(rem);
18037: tos.setCurrentParamOffsetInCode(y);
18038: stackHandler.push(tos);
18039: if (rem == 0) {
18040: return;
18041: } else {
18042: handleBasicPrimitiveLoadOp(code, y - 1);
18043: tos = (InstParam) stackHandler.pop();
18044: rem = tos.getNumberOfParamsLeft();
18045: if (rem == 0) {
18046: stackHandler.push(tos);
18047: return;
18048: }
18049:
18050: }
18051:
18052: }
18053: y = isInstFloadInst(code, k, new StringBuffer(""));
18054: if (y != -1) {
18055: InstParam tos = (InstParam) stackHandler.pop();
18056: int rem = tos.getNumberOfParamsLeft();
18057: rem = rem - 1;
18058: tos.setNumberOfParamsLeft(rem);
18059: tos.setCurrentParamOffsetInCode(y);
18060: stackHandler.push(tos);
18061: if (rem == 0)
18062: return;
18063: else {
18064: handleBasicPrimitiveLoadOp(code, y - 1);
18065: return;
18066: }
18067:
18068: }
18069: y = isInstDloadInst(code, k, new StringBuffer(""));
18070: if (y != -1) {
18071: InstParam tos = (InstParam) stackHandler.pop();
18072: int rem = tos.getNumberOfParamsLeft();
18073: rem = rem - 1;
18074: tos.setNumberOfParamsLeft(rem);
18075: tos.setCurrentParamOffsetInCode(y);
18076: stackHandler.push(tos);
18077: if (rem == 0)
18078: return;
18079: else {
18080: handleBasicPrimitiveLoadOp(code, y - 1);
18081: return;
18082: }
18083:
18084: }
18085: if (code[k] == JvmOpCodes.LDC || code[k] == JvmOpCodes.LDC2_W
18086: || code[k] == JvmOpCodes.LDC_W) {
18087: InstParam tos = (InstParam) stackHandler.pop();
18088: int rem = tos.getNumberOfParamsLeft();
18089: rem = rem - 1;
18090: tos.setNumberOfParamsLeft(rem);
18091: tos.setCurrentParamOffsetInCode(k);
18092: stackHandler.push(tos);
18093: if (rem == 0)
18094: return;
18095: else {
18096: handleBasicPrimitiveLoadOp(code, k - 1);
18097: return;
18098: }
18099:
18100: }
18101: y = isInstIConstInst(code, k);
18102: if (y != -1) {
18103: InstParam tos = (InstParam) stackHandler.pop();
18104: int rem = tos.getNumberOfParamsLeft();
18105: rem = rem - 1;
18106: tos.setNumberOfParamsLeft(rem);
18107: tos.setCurrentParamOffsetInCode(y);
18108: stackHandler.push(tos);
18109: if (rem == 0)
18110: return;
18111: else {
18112: handleBasicPrimitiveLoadOp(code, y - 1);
18113: return;
18114: }
18115:
18116: }
18117: y = isInstFConstInst(code, k);
18118: if (y != -1) {
18119: InstParam tos = (InstParam) stackHandler.pop();
18120: int rem = tos.getNumberOfParamsLeft();
18121: rem = rem - 1;
18122: tos.setNumberOfParamsLeft(rem);
18123: tos.setCurrentParamOffsetInCode(y);
18124: stackHandler.push(tos);
18125: if (rem == 0)
18126: return;
18127: else {
18128: handleBasicPrimitiveLoadOp(code, y - 1);
18129: return;
18130: }
18131:
18132: }
18133: y = isInstdConstInst(code, k);
18134: if (y != -1) {
18135: InstParam tos = (InstParam) stackHandler.pop();
18136: int rem = tos.getNumberOfParamsLeft();
18137: rem = rem - 1;
18138: tos.setNumberOfParamsLeft(rem);
18139: tos.setCurrentParamOffsetInCode(y);
18140: stackHandler.push(tos);
18141: if (rem == 0)
18142: return;
18143: else {
18144: handleBasicPrimitiveLoadOp(code, y - 1);
18145: return;
18146: }
18147:
18148: }
18149: y = isInstLConstInst(code, k);
18150: if (y != -1) {
18151: InstParam tos = (InstParam) stackHandler.pop();
18152: int rem = tos.getNumberOfParamsLeft();
18153: rem = rem - 1;
18154: tos.setNumberOfParamsLeft(rem);
18155: tos.setCurrentParamOffsetInCode(y);
18156: stackHandler.push(tos);
18157: if (rem == 0)
18158: return;
18159: else {
18160: handleBasicPrimitiveLoadOp(code, y - 1);
18161: return;
18162: }
18163:
18164: }
18165: if (code[k] == JvmOpCodes.GETFIELD) {
18166: StringBuffer sb1 = new StringBuffer("");
18167: int pos2 = isInstAload(k - 1, code, sb1);
18168: if (pos2 != -1) {
18169: InstParam tos = (InstParam) stackHandler.pop();
18170: int rem = tos.getNumberOfParamsLeft();
18171: rem = rem - 1;
18172: tos.setNumberOfParamsLeft(rem);
18173: tos.setCurrentParamOffsetInCode(pos2);
18174: stackHandler.push(tos);
18175: if (rem == 0)
18176: return;
18177: else {
18178: handleBasicPrimitiveLoadOp(code, pos2 - 1);
18179: return;
18180: }
18181: }
18182: }
18183: if (code[k] == JvmOpCodes.GETSTATIC) {
18184:
18185: InstParam tos = (InstParam) stackHandler.pop();
18186: int rem = tos.getNumberOfParamsLeft();
18187: rem = rem - 1;
18188: tos.setNumberOfParamsLeft(rem);
18189: tos.setCurrentParamOffsetInCode(k); // todo: TAKE POP INTO ACCOUNT
18190: stackHandler.push(tos);
18191: if (rem == 0)
18192: return;
18193: else {
18194: handleBasicPrimitiveLoadOp(code, k - 1);
18195: return;
18196: }
18197:
18198: }
18199:
18200: StringBuffer isinvoke = new StringBuffer("");
18201: if (isNextInstructionAnyInvoke(code[k], isinvoke)) {
18202:
18203: InstParam tos = (InstParam) stackHandler.pop();
18204: int rem = tos.getNumberOfParamsLeft();
18205: rem = rem - 1;
18206: tos.setNumberOfParamsLeft(rem);
18207: Integer ref = (Integer) invokeinstrefpos
18208: .get(new Integer(k));
18209: if (ref != null) {
18210:
18211: tos.setCurrentParamOffsetInCode(ref.intValue());
18212: stackHandler.push(tos);
18213: if (rem == 0) {
18214: return;
18215: } else {
18216: handleBasicPrimitiveLoadOp(code, ref.intValue() - 1);
18217: return;
18218:
18219: }
18220: }
18221:
18222: }
18223:
18224: if (code[k] == JvmOpCodes.D2F || code[k] == JvmOpCodes.D2I
18225: || code[k] == JvmOpCodes.D2L) {
18226:
18227: int t = k - 1;
18228: boolean done = false;
18229: StringBuffer strb = new StringBuffer("");
18230: int dload = isInstDloadInst(code, t, strb);
18231: int foundpos = -1;
18232: if (dload != -1) {
18233: foundpos = dload;
18234: done = true;
18235: } else {
18236: strb = new StringBuffer("");
18237: int loadin = traceLoadInst(t, code, strb);
18238: if (loadin != -1) {
18239: foundpos = loadin;
18240: done = true;
18241: }
18242:
18243: }
18244:
18245: if (done) {
18246:
18247: InstParam tos = (InstParam) stackHandler.pop();
18248: int rem = tos.getNumberOfParamsLeft();
18249: rem = rem - 1;
18250: tos.setNumberOfParamsLeft(rem);
18251: tos.setCurrentParamOffsetInCode(foundpos);
18252: stackHandler.push(tos);
18253: if (rem == 0)
18254: return;
18255: else {
18256: handleBasicPrimitiveLoadOp(code, foundpos - 1);
18257: return;
18258: }
18259: }
18260:
18261: else {
18262: InstParam newentry = new InstParam();
18263: newentry.setNumberOfParamsLeft(1);
18264: newentry.setCurrentParamOffsetInCode(-1);
18265: stackHandler.push(newentry);
18266: handleBasicPrimitiveLoadOp(code, (k - 1));
18267: InstParam tos = (InstParam) stackHandler.pop();
18268: int entry = tos.getCurrentParamOffsetInCode();
18269: tos = (InstParam) stackHandler.pop();
18270: int r = tos.getNumberOfParamsLeft();
18271: r = r - 1;
18272: tos.setNumberOfParamsLeft(r);
18273: tos.setCurrentParamOffsetInCode(entry);
18274: stackHandler.push(tos);
18275: if (r == 0) {
18276: return;
18277: } else {
18278: handleBasicPrimitiveLoadOp(code, entry - 1);
18279: return;
18280: }
18281: }
18282: }
18283: if (code[k] == JvmOpCodes.I2B || code[k] == JvmOpCodes.I2C
18284: || code[k] == JvmOpCodes.I2S
18285: || code[k] == JvmOpCodes.I2D
18286: || code[k] == JvmOpCodes.I2F
18287: || code[k] == JvmOpCodes.I2L) {
18288:
18289: int t = k - 1;
18290: boolean done = false;
18291: StringBuffer strb = new StringBuffer("");
18292: int dload = isInstIloadInst(code, t, strb);
18293: int foundpos = -1;
18294: if (dload != -1) {
18295: foundpos = dload;
18296: done = true;
18297: } else {
18298: strb = new StringBuffer("");
18299: int loadin = traceLoadInst(t, code, strb);
18300: if (loadin != -1) {
18301: foundpos = loadin;
18302: done = true;
18303: }
18304:
18305: }
18306:
18307: if (done) {
18308:
18309: InstParam tos = (InstParam) stackHandler.pop();
18310: int rem = tos.getNumberOfParamsLeft();
18311: rem = rem - 1;
18312: tos.setNumberOfParamsLeft(rem);
18313: tos.setCurrentParamOffsetInCode(foundpos);
18314: stackHandler.push(tos);
18315: if (rem == 0)
18316: return;
18317: else {
18318: handleBasicPrimitiveLoadOp(code, foundpos - 1);
18319: return;
18320: }
18321: }
18322:
18323: else {
18324: InstParam newentry = new InstParam();
18325: newentry.setNumberOfParamsLeft(1);
18326: newentry.setCurrentParamOffsetInCode(-1);
18327: stackHandler.push(newentry);
18328: handleBasicPrimitiveLoadOp(code, (k - 1));
18329: InstParam tos = (InstParam) stackHandler.pop();
18330: int entry = tos.getCurrentParamOffsetInCode();
18331: tos = (InstParam) stackHandler.pop();
18332: int r = tos.getNumberOfParamsLeft();
18333: r = r - 1;
18334: tos.setNumberOfParamsLeft(r);
18335: tos.setCurrentParamOffsetInCode(entry);
18336: stackHandler.push(tos);
18337: if (r == 0) {
18338: return;
18339: } else {
18340: handleBasicPrimitiveLoadOp(code, entry - 1);
18341: return;
18342: }
18343: }
18344: }
18345: if (code[k] == JvmOpCodes.F2D || code[k] == JvmOpCodes.F2L
18346: || code[k] == JvmOpCodes.F2I) {
18347: int t = k - 1;
18348: boolean done = false;
18349: StringBuffer strb = new StringBuffer("");
18350: int dload = isInstFloadInst(code, t, strb);
18351: int foundpos = -1;
18352: if (dload != -1) {
18353: foundpos = dload;
18354: done = true;
18355: } else {
18356: strb = new StringBuffer("");
18357: int loadin = traceLoadInst(t, code, strb);
18358: if (loadin != -1) {
18359: foundpos = loadin;
18360: done = true;
18361: }
18362:
18363: }
18364:
18365: if (done) {
18366:
18367: InstParam tos = (InstParam) stackHandler.pop();
18368: int rem = tos.getNumberOfParamsLeft();
18369: rem = rem - 1;
18370: tos.setNumberOfParamsLeft(rem);
18371: tos.setCurrentParamOffsetInCode(foundpos);
18372: stackHandler.push(tos);
18373: if (rem == 0)
18374: return;
18375: else {
18376: handleBasicPrimitiveLoadOp(code, foundpos - 1);
18377: return;
18378: }
18379: }
18380:
18381: else {
18382: InstParam newentry = new InstParam();
18383: newentry.setNumberOfParamsLeft(1);
18384: newentry.setCurrentParamOffsetInCode(-1);
18385: stackHandler.push(newentry);
18386: handleBasicPrimitiveLoadOp(code, (k - 1));
18387: InstParam tos = (InstParam) stackHandler.pop();
18388: int entry = tos.getCurrentParamOffsetInCode();
18389: tos = (InstParam) stackHandler.pop();
18390: int r = tos.getNumberOfParamsLeft();
18391: r = r - 1;
18392: tos.setNumberOfParamsLeft(r);
18393: tos.setCurrentParamOffsetInCode(entry);
18394: stackHandler.push(tos);
18395: if (r == 0) {
18396: return;
18397: } else {
18398: handleBasicPrimitiveLoadOp(code, entry - 1);
18399: return;
18400: }
18401: }
18402: }
18403: if (code[k] == JvmOpCodes.L2D || code[k] == JvmOpCodes.L2F
18404: || code[k] == JvmOpCodes.L2I) {
18405: int t = k - 1;
18406: boolean done = false;
18407: StringBuffer strb = new StringBuffer("");
18408: int dload = isInstLloadInst(code, t, strb);
18409: int foundpos = -1;
18410: if (dload != -1) {
18411: foundpos = dload;
18412: done = true;
18413: } else {
18414: strb = new StringBuffer("");
18415: int loadin = traceLoadInst(t, code, strb);
18416: if (loadin != -1) {
18417: foundpos = loadin;
18418: done = true;
18419: }
18420:
18421: }
18422:
18423: if (done) {
18424:
18425: InstParam tos = (InstParam) stackHandler.pop();
18426: int rem = tos.getNumberOfParamsLeft();
18427: rem = rem - 1;
18428: tos.setNumberOfParamsLeft(rem);
18429: tos.setCurrentParamOffsetInCode(foundpos);
18430: stackHandler.push(tos);
18431: if (rem == 0)
18432: return;
18433: else {
18434: handleBasicPrimitiveLoadOp(code, foundpos - 1);
18435: return;
18436: }
18437: }
18438:
18439: else {
18440: InstParam newentry = new InstParam();
18441: newentry.setNumberOfParamsLeft(1);
18442: newentry.setCurrentParamOffsetInCode(-1);
18443: stackHandler.push(newentry);
18444: handleBasicPrimitiveLoadOp(code, (k - 1));
18445: InstParam tos = (InstParam) stackHandler.pop();
18446: int entry = tos.getCurrentParamOffsetInCode();
18447: tos = (InstParam) stackHandler.pop();
18448: int r = tos.getNumberOfParamsLeft();
18449: r = r - 1;
18450: tos.setNumberOfParamsLeft(r);
18451: tos.setCurrentParamOffsetInCode(entry);
18452: stackHandler.push(tos);
18453: if (r == 0) {
18454: return;
18455: } else {
18456: handleBasicPrimitiveLoadOp(code, entry - 1);
18457: return;
18458: }
18459: }
18460: }
18461:
18462: }
18463:
18464: /***
18465: * belurs:
18466: * The below 2 are used in handleBasicPrimitiveLoadOp
18467: * Could Think of an appropriate names here.
18468: * Refactor later if better names can be thpught of
18469: */
18470:
18471: private Stack stackHandler = null; // will contain InstParam Objects
18472:
18473: class InstParam {
18474:
18475: private int numberOfParamsLeft; // Example imul takes 2 so initially 2 is populated
18476: private int currentParamOffsetInCode; // Example for imul the first one cane be iload_1..So once
18477:
18478: // This is encountered, currentParamOffsetInCode will be
18479: // set to iload_1 position in code.
18480:
18481: public int getNumberOfParamsLeft() {
18482: return numberOfParamsLeft;
18483: }
18484:
18485: public void setNumberOfParamsLeft(int numberOfParamsLeft) {
18486: this .numberOfParamsLeft = numberOfParamsLeft;
18487: }
18488:
18489: public int getCurrentParamOffsetInCode() {
18490: return currentParamOffsetInCode;
18491: }
18492:
18493: public void setCurrentParamOffsetInCode(
18494: int currentParamOffsetInCode) {
18495: this .currentParamOffsetInCode = currentParamOffsetInCode;
18496: }
18497:
18498: }
18499:
18500: private Operand createOperand(Object val, int type, int categ) {
18501: Operand opr = new Operand();
18502: opr.setOperandValue(val);
18503: opr.setOperandType(type);
18504: opr.setCategory(categ);
18505: return opr;
18506:
18507: }
18508:
18509: private Operand createOperand(Object val) {
18510: Operand opr = new Operand();
18511: opr.setOperandValue(val);
18512: return opr;
18513:
18514: }
18515:
18516: private int getSwitchOffset(byte[] info, int counter,
18517: java.lang.String lbl) {
18518: int b1 = info[++counter];
18519: int b2 = info[++counter];
18520: int b3 = info[++counter];
18521: int b4 = info[++counter];
18522:
18523: if (b1 < 0)
18524: b1 = (256 + b1);
18525: if (b2 < 0)
18526: b2 = (256 + b2);
18527: if (b3 < 0)
18528: b3 = (256 + b3);
18529: if (b4 < 0)
18530: b4 = (256 + b4);
18531:
18532: int jmp = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
18533: if (jmp > 65535)
18534: jmp = jmp - 65536;
18535: if (lbl.equals("label"))
18536: return jmp;
18537: if (jmp < 0)
18538: jmp = 512 + jmp;
18539: return jmp;
18540:
18541: }
18542:
18543: private java.lang.String getReturnTypeIfPreviousInvoke(int j,
18544: byte[] info) {
18545:
18546: //Terminator t;
18547: java.lang.String s = "0";
18548: if (invokeStartEnd != null) {
18549: Integer in = (Integer) invokeStartEnd
18550: .get(new Integer(j - 1));
18551: if (in != null) {
18552: int iin = in.intValue();
18553: switch (info[iin]) {
18554:
18555: case JvmOpCodes.INVOKEINTERFACE:
18556: int classIndex = getOffset(info, iin);
18557: InterfaceMethodRef iref = cd
18558: .getInterfaceMethodAtCPoolPosition(classIndex);
18559: java.lang.String classname = iref.getClassname();
18560: java.lang.String typeofmet = iref.getTypeofmethod();
18561: int br = typeofmet.indexOf(")");
18562: if (br != -1) {
18563: java.lang.String ret = typeofmet
18564: .substring(br + 1);
18565: if (ret.trim().equals("Z")) {
18566: return "false";
18567: }
18568:
18569: }
18570:
18571: break;
18572:
18573: case JvmOpCodes.INVOKESPECIAL:
18574:
18575: classIndex = getOffset(info, iin);
18576: MethodRef mref = cd
18577: .getMethodRefAtCPoolPosition(classIndex);
18578: java.lang.String classtype = mref.getClassname();
18579: typeofmet = mref.getTypeofmethod();
18580: br = typeofmet.indexOf(")");
18581: if (br != -1) {
18582: java.lang.String ret = typeofmet
18583: .substring(br + 1);
18584: if (ret.trim().equals("Z")) {
18585: return "false";
18586: }
18587:
18588: }
18589:
18590: break;
18591:
18592: case JvmOpCodes.INVOKESTATIC:
18593: classIndex = getOffset(info, iin);
18594: mref = cd.getMethodRefAtCPoolPosition(classIndex);
18595: classname = mref.getClassname();
18596: typeofmet = mref.getTypeofmethod();
18597: br = typeofmet.indexOf(")");
18598: if (br != -1) {
18599: java.lang.String ret = typeofmet
18600: .substring(br + 1);
18601: if (ret.trim().equals("Z")) {
18602: return "false";
18603: }
18604:
18605: }
18606:
18607: break;
18608:
18609: case JvmOpCodes.INVOKEVIRTUAL:
18610: classIndex = getOffset(info, iin);
18611: mref = cd.getMethodRefAtCPoolPosition(classIndex);
18612: classname = mref.getClassname();
18613: typeofmet = mref.getTypeofmethod();
18614: br = typeofmet.indexOf(")");
18615: if (br != -1) {
18616: java.lang.String ret = typeofmet
18617: .substring(br + 1);
18618: if (ret.trim().equals("Z")) {
18619: return "false";
18620: }
18621:
18622: }
18623:
18624: break;
18625:
18626: default:
18627: return s;
18628:
18629: }
18630: }
18631:
18632: return s;
18633:
18634: } else {
18635: int iin = j - 3;
18636: int classIndex = -1;
18637: switch (info[iin]) {
18638:
18639: /*case JvmOpCodes.INVOKEINTERFACE:
18640: int classIndex=getOffset(info,iin);
18641: InterfaceMethodRef iref=cd.getInterfaceMethodAtCPoolPosition(classIndex);
18642: java.lang.String classname=iref.getClassname();
18643: java.lang.String typeofmet=iref.getTypeofmethod();
18644: int br=typeofmet.indexOf(")");
18645: if(br!=-1)
18646: {
18647: java.lang.String ret=typeofmet.substring(br+1);
18648: if(ret.trim().equals("Z"))
18649: {
18650: return "false";
18651: }
18652:
18653: }
18654:
18655: break; */
18656:
18657: case JvmOpCodes.INVOKESPECIAL:
18658:
18659: classIndex = getOffset(info, iin);
18660: MethodRef mref = cd
18661: .getMethodRefAtCPoolPosition(classIndex);
18662: java.lang.String classtype = mref.getClassname();
18663: java.lang.String typeofmet = mref.getTypeofmethod();
18664: int br = typeofmet.indexOf(")");
18665: if (br != -1) {
18666: java.lang.String ret = typeofmet.substring(br + 1);
18667: if (ret.trim().equals("Z")) {
18668: return "false";
18669: }
18670:
18671: }
18672:
18673: break;
18674:
18675: case JvmOpCodes.INVOKESTATIC:
18676: classIndex = getOffset(info, iin);
18677: mref = cd.getMethodRefAtCPoolPosition(classIndex);
18678: java.lang.String classname = mref.getClassname();
18679: typeofmet = mref.getTypeofmethod();
18680: br = typeofmet.indexOf(")");
18681: if (br != -1) {
18682: java.lang.String ret = typeofmet.substring(br + 1);
18683: if (ret.trim().equals("Z")) {
18684: return "false";
18685: }
18686:
18687: }
18688:
18689: break;
18690:
18691: case JvmOpCodes.INVOKEVIRTUAL:
18692: classIndex = getOffset(info, iin);
18693: mref = cd.getMethodRefAtCPoolPosition(classIndex);
18694: classname = mref.getClassname();
18695: typeofmet = mref.getTypeofmethod();
18696: br = typeofmet.indexOf(")");
18697: if (br != -1) {
18698: java.lang.String ret = typeofmet.substring(br + 1);
18699: if (ret.trim().equals("Z")) {
18700: return "false";
18701: }
18702:
18703: }
18704:
18705: }
18706: if (isThisInstrStart(behaviour
18707: .getInstructionStartPositions(), j - 5)
18708: && info[j - 5] == JvmOpCodes.INVOKEINTERFACE) {
18709:
18710: classIndex = getOffset(info, iin);
18711: InterfaceMethodRef iref = cd
18712: .getInterfaceMethodAtCPoolPosition(classIndex);
18713: java.lang.String classname = iref.getClassname();
18714: java.lang.String typeofmet = iref.getTypeofmethod();
18715: int br = typeofmet.indexOf(")");
18716: if (br != -1) {
18717: java.lang.String ret = typeofmet.substring(br + 1);
18718: if (ret.trim().equals("Z")) {
18719: return "false";
18720: }
18721:
18722: }
18723: }
18724: }
18725: return s;
18726: }
18727:
18728: ArrayList startlist = null;
18729:
18730: private void findSkipRangesWRTSynchronizedBlocks() {
18731:
18732: startlist = behaviour.getInstructionStartPositions();
18733: synchSkips = new Hashtable();
18734: byte code[] = behaviour.getCode();
18735: if (code == null)
18736: return;
18737: for (int j = 0; j < code.length; j++) {
18738:
18739: if (isThisInstrStart(behaviour
18740: .getInstructionStartPositions(), j)
18741: && code[j] == JvmOpCodes.MONITOREXIT) {
18742: int loadpos = -1;
18743: boolean simple = true;
18744: int index = -1;
18745: switch (code[j + 1]) {
18746:
18747: case JvmOpCodes.ALOAD:
18748: simple = false;
18749: loadpos = j + 1;
18750:
18751: break;
18752: case JvmOpCodes.ALOAD_0:
18753: simple = true;
18754: loadpos = j + 1;
18755: index = 0;
18756: break;
18757: case JvmOpCodes.ALOAD_1:
18758: simple = true;
18759: loadpos = j + 1;
18760: index = 1;
18761: break;
18762: case JvmOpCodes.ALOAD_2:
18763: simple = true;
18764: loadpos = j + 1;
18765: index = 2;
18766: break;
18767: case JvmOpCodes.ALOAD_3:
18768: simple = true;
18769: loadpos = j + 1;
18770: index = 3;
18771: break;
18772: default:
18773: loadpos = -1;
18774:
18775: }
18776:
18777: if (loadpos != -1) {
18778:
18779: if (simple) {
18780:
18781: if (code[j + 1 + 1] == JvmOpCodes.ATHROW) {
18782: int start = j;
18783: while (start >= 0) {
18784:
18785: int st = code[start];
18786: if (isThisInstrStart(startlist, start)) {
18787: int storeindex = -1;
18788:
18789: switch (st) {
18790: case JvmOpCodes.ASTORE_0:
18791: storeindex = 0;
18792: break;
18793:
18794: case JvmOpCodes.ASTORE_1:
18795: storeindex = 1;
18796: break;
18797:
18798: case JvmOpCodes.ASTORE_2:
18799: storeindex = 2;
18800: break;
18801:
18802: case JvmOpCodes.ASTORE_3:
18803: storeindex = 3;
18804: break;
18805:
18806: default:
18807: storeindex = -1;
18808: break;
18809:
18810: }
18811:
18812: if (storeindex == index) {
18813: synchSkips.put(new Integer(
18814: start), new Integer(
18815: j + 2));
18816: break;
18817: }
18818: }
18819: start--;
18820:
18821: }
18822:
18823: }
18824: } else {
18825: if (code[j + 1 + 2] == JvmOpCodes.ATHROW) {
18826: index = code[j + 1 + 1];
18827: if (index < 0)
18828: index += 256; // TODO: apply this to elsewhere
18829: int start = j;
18830: while (start >= 0) {
18831:
18832: int st = code[start];
18833: if (isThisInstrStart(startlist, start)) {
18834: int storeindex = -1;
18835:
18836: switch (st) {
18837: case JvmOpCodes.ASTORE_0:
18838: storeindex = 0;
18839: break;
18840:
18841: case JvmOpCodes.ASTORE_1:
18842: storeindex = 1;
18843: break;
18844:
18845: case JvmOpCodes.ASTORE_2:
18846: storeindex = 2;
18847: break;
18848:
18849: case JvmOpCodes.ASTORE_3:
18850: storeindex = 3;
18851: break;
18852:
18853: case JvmOpCodes.ASTORE:
18854: storeindex = code[start + 1];
18855: if (storeindex < 0)
18856: storeindex += 256;
18857: break;
18858:
18859: default:
18860: storeindex = -1;
18861: break;
18862:
18863: }
18864:
18865: if (storeindex == index) {
18866: synchSkips.put(new Integer(
18867: start), new Integer(
18868: j + 3));
18869: break;
18870: }
18871: }
18872: start--;
18873:
18874: }
18875:
18876: }
18877:
18878: }
18879:
18880: }
18881: }
18882:
18883: }
18884:
18885: }
18886:
18887: private void handleAloadCase(byte[] info, int i,
18888: OperandStack OpStack) {
18889: Operand op = null;
18890: int opValueI = info[++i];
18891: //addParsedOutput("Instruction Pos "+currentForIndex+"\t:- "+" aload "+opValueI+"\n");
18892:
18893: LocalVariable local = getLocalVariable(opValueI, "load",
18894: "java.lang.Object", false, currentForIndex);
18895: if (local != null) {
18896: prevLocalGenerated = local;
18897: op = new Operand();
18898: op.setOperandName(local.getVarName());
18899: op.setOperandValue(local.getVarName());
18900: op.setOperandType(Constants.IS_OBJECT_REF);
18901: opStack.push(op);
18902: op.setClassType(local.getDataType());
18903:
18904: } else {
18905: op = new Operand();
18906: op.setOperandName("this");
18907: op.setOperandValue("this");
18908: op.setOperandType(Constants.IS_OBJECT_REF);
18909: opStack.push(op);
18910: op
18911: .setClassType(ConsoleLauncher.getClazzRef() != null ? ConsoleLauncher
18912: .getClazzRef().getClassName()
18913: : "Object");
18914: }
18915:
18916: java.lang.String t = "Instruction Pos " + currentForIndex
18917: + "\t:- " + " aload " + opValueI;
18918: if (cd.isClassCompiledWithMinusG() && local != null) {
18919: t += " This LocalVariable :- " + local.getVarName();
18920: }
18921: t += "\n";
18922: addParsedOutput(t);
18923:
18924: }
18925:
18926: // belurs:
18927: // only polls for end of synch tables . Not start(MonitorEnter)
18928:
18929: private java.lang.String pollsynchblocks(int cur) {
18930:
18931: ArrayList synchlist = behaviour.getSynchronizedEntries();
18932: if (synchlist != null && synchlist.size() > 0) {
18933:
18934: for (int s = 0; s < synchlist.size(); s++) {
18935: ExceptionTable table = (ExceptionTable) synchlist
18936: .get(s);
18937: int end = table.getSynchEnd();
18938: if (end == cur) {
18939: return "}";
18940: }
18941:
18942: }
18943:
18944: }
18945: return "";
18946:
18947: }
18948:
18949: private void resetEndOfSynchBlockIfNecessary(int current) {
18950:
18951: // Step 1 : Determine the applicable IF block
18952: // fOR EACH MONITORENTER FIND out the closest if and end of that... ~ to try handling
18953: ArrayList synchtables = behaviour.getSynchronizedEntries();
18954: byte code[] = behaviour.getCode();
18955:
18956: if (synchtables != null && synchtables.size() > 0) {
18957: ArrayList starts = behaviour.getInstructionStartPositions();
18958: for (int s = 0; s < synchtables.size(); s++) {
18959:
18960: ExceptionTable tab = (ExceptionTable) synchtables
18961: .get(s);
18962: int start = tab.getStartPC();
18963: if (tab.getMonitorEnterPosInCode() == currentMonitorEnterPos) {
18964:
18965: int synchend = tab.getEndPC(); // belurs:
18966: if (current - 3 >= 0
18967: && isNextInstructionIf(code[current - 3])) // Actually The previous Instruction
18968: {
18969: boolean switchfound = false;
18970: int switchstartpos = -1;
18971: java.lang.String switchtype = null;
18972: for (int x = current - 3 - 1; x > start; x--) {
18973: if (isThisInstrStart(starts, x)
18974: && code[x] == JvmOpCodes.MONITOREXIT) {
18975: currentMonitorEnterPos = -1;
18976: return;
18977:
18978: }
18979: if (isThisInstrStart(starts, x)
18980: && isNextInstructionIf(code[x])) {
18981: currentMonitorEnterPos = -1; // Actually This should never happen
18982: return;
18983: }
18984: if (isThisInstrStart(starts, x)
18985: && (code[x] == JvmOpCodes.TABLESWITCH || code[x] == JvmOpCodes.LOOKUPSWITCH)) {
18986: switchfound = true;
18987: switchstartpos = x;
18988: if (code[x] == JvmOpCodes.TABLESWITCH)
18989: switchtype = "table";
18990: else
18991: switchtype = "lookup";
18992:
18993: }
18994: }
18995:
18996: if (switchfound) {
18997: if (switchstartpos != -1) {
18998: Switch swblk = getSwitchBlockGivenStart(switchstartpos);
18999: if (swblk != null) {
19000:
19001: ArrayList cases = swblk
19002: .sortCasesByEnd(swblk
19003: .getAllCases());
19004: Case endcase = null;
19005: if (cases != null) {
19006: endcase = (Case) cases.get(0);
19007: }
19008: int defend = swblk.getDefaultEnd();
19009: if (defend != -1) {
19010: if (defend > endcase
19011: .getCaseEnd()) {
19012: if (swblk
19013: .getStartOfSwitch() > start
19014: && defend > synchend) {
19015: tab.setSynchEnd(defend);
19016: currentMonitorEnterPos = -1;
19017: return;
19018: }
19019: } else {
19020: if (swblk
19021: .getStartOfSwitch() > start
19022: && endcase
19023: .getCaseEnd() > synchend) {
19024: tab.setSynchEnd(endcase
19025: .getCaseEnd());
19026: currentMonitorEnterPos = -1;
19027: return;
19028: }
19029: }
19030: } else {
19031: if (swblk.getStartOfSwitch() > start
19032: && endcase.getCaseEnd() > synchend) {
19033: tab.setSynchEnd(endcase
19034: .getCaseEnd());
19035: currentMonitorEnterPos = -1;
19036: return;
19037: }
19038: }
19039:
19040: }
19041: }
19042:
19043: } else // reset w.r.t if
19044: {
19045:
19046: IFBlock reqdif = null;
19047: Collection ifs = getCurrentIFStructues();
19048: Iterator it = ifs.iterator();
19049: while (it.hasNext()) {
19050: IFBlock IF = (IFBlock) it.next();
19051: if (IF.getIfStart() == current - 3) {
19052: reqdif = IF;
19053: break;
19054: }
19055: }
19056: if (reqdif != null) {
19057: int ifend = reqdif
19058: .getIfCloseFromByteCode();
19059: int elseend = reqdif
19060: .getElseCloseLineNumber();
19061: if (elseend == -1) {
19062: if (ifend > reqdif.getIfStart()) {
19063: if (reqdif.getIfStart() > start) {
19064: if (ifend > synchend) {
19065: currentMonitorEnterPos = -1;
19066: tab.setSynchEnd(ifend);
19067: return;
19068:
19069: }
19070:
19071: }
19072: }
19073:
19074: } else {
19075: if (elseend > reqdif.getIfStart()) {
19076: if (reqdif.getIfStart() > start) {
19077: if (elseend > synchend) {
19078: currentMonitorEnterPos = -1;
19079: tab
19080: .setSynchEnd(elseend);
19081: return;
19082:
19083: }
19084:
19085: }
19086: }
19087:
19088: }
19089: }
19090:
19091: }
19092:
19093: }
19094:
19095: return;
19096: }
19097:
19098: }
19099:
19100: }
19101:
19102: }
19103:
19104: private int currentMonitorEnterPos = -1; // gets set when every monitorenter is encountered
19105:
19106: private Switch getSwitchBlockGivenStart(int start) {
19107: Switch sw = null;
19108: ArrayList allswitches = behaviour.getAllSwitchBlks();
19109: for (int s = 0; s < allswitches.size(); s++) {
19110:
19111: Switch switchblk = (Switch) allswitches.get(s);
19112: if (switchblk.getStartOfSwitch() == start) {
19113: return switchblk;
19114: }
19115: }
19116: return sw;
19117:
19118: }
19119:
19120: private boolean instanceof found = false;
19121:
19122: private void handleSwapInst(OperandStack stack) {
19123: Operand op1 = stack.getTopOfStack();
19124: Operand op2 = stack.getTopOfStack();
19125: opStack.push(op2);
19126: opStack.push(op1);
19127: }
19128:
19129: private void handleAALOAD(OperandStack stack) {
19130: addParsedOutput("Instruction Pos " + currentForIndex + "\t:- "
19131: + " aaload\n");
19132: Operand sourcePos = (Operand) stack.pop();
19133: Operand srcarrayRef = (Operand) stack.pop(); //
19134: Operand op = createOperand(srcarrayRef.getOperandValue() + "["
19135: + sourcePos.getOperandValue() + "]",
19136: Constants.IS_OBJECT_REF, Constants.CATEGORY1);
19137: opStack.push(op);
19138: }
19139:
19140: private boolean isInstReturnInst(byte[] code, int pos,
19141: StringBuffer sb) {
19142:
19143: boolean ret = false;
19144: if (isThisInstrStart(behaviour.getInstructionStartPositions(),
19145: pos)) {
19146: switch (code[pos]) {
19147: case JvmOpCodes.IRETURN:
19148: sb.append("ireturn");
19149: ret = true;
19150: break;
19151:
19152: case JvmOpCodes.LRETURN:
19153: sb.append("lreturn");
19154: ret = true;
19155: break;
19156: case JvmOpCodes.FRETURN:
19157: sb.append("freturn");
19158: ret = true;
19159: break;
19160: case JvmOpCodes.DRETURN:
19161: sb.append("dreturn");
19162: ret = true;
19163: break;
19164: case JvmOpCodes.ARETURN:
19165: sb.append("areturn");
19166: ret = true;
19167: break;
19168: case JvmOpCodes.RETURN:
19169: sb.append("return");
19170: ret = true;
19171: break;
19172: }
19173: }
19174:
19175: return ret;
19176:
19177: }
19178:
19179: private void addAnyReturnBeforeIfClose(byte[] info, IFBlock IF,
19180: java.lang.StringBuffer S, int j, OperandStack stack) {
19181: int ifend = IF.getIfCloseLineNumber();
19182: boolean addret = addReturnAtIFElseEnd(j);
19183: if (addret) {
19184: if (info[ifend] == JvmOpCodes.GOTO) {
19185: int gotojump = getJumpAddress(info, ifend);
19186: StringBuffer sg = new StringBuffer("");
19187: boolean r = isInstReturnInst(info, gotojump, sg);
19188:
19189: if (r) {
19190: if (sg.toString().equals("return") == false
19191: && stack.size() > 0) {
19192: java.lang.String t = stack.getTopOfStack()
19193: .getOperandValue();
19194: boolean b = isMethodRetBoolean(behaviour);
19195: if (t != null) {
19196: if (t.equals("1") && b)
19197: t = "true";
19198: if (t.equals("0") && b)
19199: t = "false";
19200: java.lang.String retst = "return " + t
19201: + ";";
19202: boolean a = addRETURNatI(ifend, IF);
19203: if (a) {
19204: S
19205: .append(Util
19206: .formatDecompiledStatement(retst));// if end\n");
19207: returnsAtI.put(new Integer(ifend),
19208: "true");
19209: }
19210: }
19211:
19212: } else if (sg.toString().equals("return") == true) {
19213: boolean a = addRETURNatI(ifend, IF);
19214: if (a) {
19215: java.lang.String retst = "return ;";
19216: S.append(Util
19217: .formatDecompiledStatement(retst));// if end\n");
19218: returnsAtI.put(new Integer(ifend), "true");
19219: }
19220: } else {
19221:
19222: }
19223: }
19224:
19225: } else {
19226:
19227: StringBuffer sg = new StringBuffer("");
19228: boolean r = isInstReturnInst(info, ifend, sg);
19229: if (r) {
19230: if (sg.toString().equals("return") == false
19231: && stack.size() > 0) {
19232: java.lang.String t = stack.getTopOfStack()
19233: .getOperandValue();
19234: boolean b = isMethodRetBoolean(behaviour);
19235: if (t != null) {
19236: if (t.equals("1") && b)
19237: t = "true";
19238: if (t.equals("0") && b)
19239: t = "false";
19240: java.lang.String retst = "return " + t
19241: + ";";
19242: boolean a = addRETURNatI(ifend, IF);
19243: if (a) {
19244: S
19245: .append(Util
19246: .formatDecompiledStatement(retst));// if end\n");
19247: returnsAtI.put(new Integer(ifend),
19248: "true");
19249: }
19250: }
19251:
19252: } else if (sg.toString().equals("return") == true) {
19253: boolean a = addRETURNatI(ifend, IF);
19254: if (a) {
19255: java.lang.String retst = "return ;";
19256: S.append(Util
19257: .formatDecompiledStatement(retst));// if end\n");
19258: returnsAtI.put(new Integer(ifend), "true");
19259: }
19260: } else {
19261:
19262: }
19263: }
19264:
19265: }
19266:
19267: }
19268: }
19269:
19270: private void addAnyReturnBeforeElseClose(byte[] info, IFBlock IF,
19271: java.lang.StringBuffer S, int j, OperandStack stack) {
19272:
19273: int end = IF.getElseCloseLineNumber();
19274:
19275: StringBuffer sg = new StringBuffer("");
19276: boolean r = isInstReturnInst(info, end, sg);
19277: if (!r) {
19278: if (info[end] == JvmOpCodes.GOTO) {
19279: int gotoj = getJumpAddress(info, end);
19280: sg = new StringBuffer("");
19281: r = isInstReturnInst(info, gotoj, sg);
19282: }
19283: }
19284: if (r) {
19285: if (sg.toString().equals("return") == false) {
19286: if (stack.size() > 0) {
19287: java.lang.String t = stack.getTopOfStack()
19288: .getOperandValue();
19289: boolean b = isMethodRetBoolean(behaviour);
19290: if (t != null) {
19291: if (t.equals("1") && b)
19292: t = "true";
19293: if (t.equals("0") && b)
19294: t = "false";
19295: java.lang.String retst = "return " + t + ";";
19296: S.append(Util.formatDecompiledStatement(retst));
19297: returnsAtI.put(new Integer(end), "true");
19298: }
19299: }
19300: }
19301: if (sg.toString().equals("return") == true) {
19302: java.lang.String retst = "return ;";
19303: S.append(Util.formatDecompiledStatement(retst));
19304: returnsAtI.put(new Integer(end), "true");
19305: }
19306: }
19307:
19308: }
19309:
19310: private void checkForIFElseEndStatement(byte[] info,
19311: Hashtable ifHashTable, int i, StringBuffer reset,
19312: OperandStack stack, StringBuffer ifelsecode,
19313: java.lang.String w)
19314:
19315: {
19316:
19317: Iterator iter = ifHashTable.keySet().iterator();
19318: while (iter.hasNext()) {
19319: Object key = iter.next();
19320: IFBlock chk_ifst = (IFBlock) ifHashTable.get(key);
19321: int chk_ifCloseLineNo = chk_ifst.getIfCloseLineNumber();
19322: int chk_elseCloseLineNo = chk_ifst.getElseCloseLineNumber();
19323: if (chk_elseCloseLineNo != -1)// && w.equals("else"))
19324: {
19325: if (i == chk_elseCloseLineNo) {
19326: // boolean print=isThisLoopEndAlso(behaviour.getBehaviourLoops(),i);
19327: boolean addelseend = true;//addElseEnd(i);
19328: if (addelseend) {
19329: StringBuffer sb = new StringBuffer();
19330: java.lang.String lbl = getBranchTypeAtI(i,
19331: chk_ifst, sb);
19332: java.lang.String lbl2 = getIfElseReturnAtI(i);
19333: if (lbl2 != null) {
19334: ifelsecode.append(Util
19335: .formatDecompiledStatement(lbl2
19336: + ";\n"));
19337: }
19338:
19339: // BigInteger b
19340: if (lbl != null && !lbl.equals("")
19341: && !lbl.equals("continue")
19342: && lbl2 == null) {
19343:
19344: ifelsecode.append(Util
19345: .formatDecompiledStatement(lbl
19346: + " " + sb.toString()
19347: + ";\n"));
19348:
19349: }
19350: if (lbl != null && !lbl.equals("")
19351: && lbl.equals("continue")
19352: && lbl2 == null) {
19353: ifelsecode.append(Util
19354: .formatDecompiledStatement(lbl
19355: + " " + sb.toString()
19356: + ";\n"));
19357:
19358: }
19359: if (lbl2 == null) {
19360: StringBuffer sr = new StringBuffer("");
19361: addAnyReturnBeforeElseClose(info, chk_ifst,
19362: sr, currentForIndex, stack);
19363: ifelsecode.append(sr.toString());
19364: }
19365:
19366: StringBuffer in = new StringBuffer("");
19367: StringBuffer t = new StringBuffer("");
19368:
19369: boolean isstore = isStoreInst(i, info, in, t);
19370: if (isstore) {
19371:
19372: int ind = Integer.parseInt(in.toString());
19373: if (ind != -1 && opStack.size() > 0) {
19374: boolean simple = false;
19375: if ((ind == 0) || (ind == 1)
19376: || (ind == 2) || (ind == 3))
19377: simple = true;
19378: LocalVariable loc = getLocalVariable(
19379: ind, "store", t.toString(),
19380: simple, i);
19381: Operand objref = (Operand) opStack
19382: .pop(); // Pop The Object Ref
19383: doNotPop = true;
19384: if (loc.wasCreated()
19385: && objref != null
19386: && objref.getClassType().trim()
19387: .length() > 0)
19388: loc.setDataType(objref
19389: .getClassType());
19390: java.lang.String temp = (java.lang.String) objref
19391: .getOperandValue();
19392: if (!loc.isDeclarationGenerated()) {
19393: temp = loc.getDataType().replace(
19394: '/', '.')
19395: + " "
19396: + loc.getVarName()
19397: + "=" + temp + ";\n";
19398: //codeStatements += Util.formatDecompiledStatement(temp);
19399:
19400: } else {
19401:
19402: temp = " " + loc.getVarName()
19403: + " =" + temp + ";\n";
19404: //codeStatements += Util.formatDecompiledStatement(temp);
19405:
19406: }
19407: } else {
19408: if (opStack.size() >= 3) {
19409: doNotPop = true;
19410: Operand value = opStack
19411: .getTopOfStack(); // Value
19412: Operand index = opStack
19413: .getTopOfStack(); // Index into target
19414: Operand arRef = opStack
19415: .getTopOfStack(); // Target Arref
19416: java.lang.String temp = arRef
19417: .getOperandValue()
19418: + "["
19419: + index.getOperandValue()
19420: + "] ="
19421: + value.getOperandValue()
19422: + ";";
19423: //codeStatements+="\n"+Util.formatDecompiledStatement(temp)+"\n";
19424: }
19425: }
19426:
19427: } else {
19428: if (info[chk_ifCloseLineNo] == JvmOpCodes.GOTO) {
19429: int gotojumpa = getJumpAddress(info,
19430: chk_ifCloseLineNo);
19431: if (isThisInstrStart(
19432: behaviour
19433: .getInstructionStartPositions(),
19434: gotojumpa)) {
19435: in = new StringBuffer("");
19436: t = new StringBuffer("");
19437:
19438: isstore = isStoreInst(gotojumpa,
19439: info, in, t);
19440: if (isstore) {
19441: int ind = Integer.parseInt(in
19442: .toString());
19443: if (ind != -1
19444: && opStack.size() > 0) {
19445: boolean simple = false;
19446: if ((ind == 0)
19447: || (ind == 1)
19448: || (ind == 2)
19449: || (ind == 3))
19450: simple = true;
19451: LocalVariable loc = getLocalVariable(
19452: ind, "store",
19453: t.toString(),
19454: simple, gotojumpa);
19455: Operand objref = (Operand) opStack
19456: .pop(); // Pop The Object Ref
19457: doNotPop = true;
19458: if (loc.wasCreated()
19459: && objref != null
19460: && objref
19461: .getClassType()
19462: .trim()
19463: .length() > 0)
19464: loc
19465: .setDataType(objref
19466: .getClassType());
19467: java.lang.String temp = (java.lang.String) objref
19468: .getOperandValue();
19469: if (!loc
19470: .isDeclarationGenerated()) {
19471: temp = loc
19472: .getDataType()
19473: .replace('/',
19474: '.')
19475: + " "
19476: + loc
19477: .getVarName()
19478: + "="
19479: + temp
19480: + ";\n";
19481: //codeStatements += Util.formatDecompiledStatement(temp);
19482:
19483: } else {
19484:
19485: temp = " "
19486: + loc
19487: .getVarName()
19488: + " =" + temp
19489: + ";\n";
19490: //codeStatements += Util.formatDecompiledStatement(temp);
19491:
19492: }
19493: } else {
19494: if (opStack.size() >= 3) {
19495: doNotPop = true;
19496: Operand value = opStack
19497: .getTopOfStack(); // Value
19498: Operand index = opStack
19499: .getTopOfStack(); // Index into target
19500: Operand arRef = opStack
19501: .getTopOfStack(); // Target Arref
19502: java.lang.String temp = arRef
19503: .getOperandValue()
19504: + "["
19505: + index
19506: .getOperandValue()
19507: + "] ="
19508: + value
19509: .getOperandValue()
19510: + ";";
19511: //codeStatements+="\n"+Util.formatDecompiledStatement(temp)+"\n";
19512: }
19513: }
19514:
19515: } else {
19516: if (info[gotojumpa] == JvmOpCodes.PUTFIELD) {
19517: // Add here
19518: doNotPop = true;
19519: int pos = getOffset(info,
19520: gotojumpa);
19521:
19522: FieldRef fref = cd
19523: .getFieldRefAtCPoolPosition(pos);
19524: Operand value = opStack
19525: .getTopOfStack();
19526: Operand objRef = null;
19527: objRef = checkAnyStoredPUTFIELDObjRef(gotojumpa);
19528: if (objRef == null
19529: && opStack.size() > 0) {
19530: objRef = opStack
19531: .getTopOfStack();
19532: }
19533:
19534: java.lang.String temp = "";
19535: java.lang.String freftype = fref
19536: .getTypeoffield();
19537: if (objRef != null) {
19538: StringBuffer stb = new StringBuffer(
19539: "");
19540: checkForImport(
19541: objRef
19542: .getOperandValue(),
19543: stb);
19544: temp = stb.toString()
19545: + "."
19546: + fref
19547: .getFieldName()
19548: + " = "
19549: + value
19550: .getOperandValue()
19551: + ";";
19552: } else {
19553: temp = fref
19554: .getFieldName()
19555: + " = "
19556: + value
19557: .getOperandValue()
19558: + ";";
19559: }
19560: //codeStatements+="\n"+Util.formatDecompiledStatement(temp)+"\n";
19561: }
19562: if (info[gotojumpa] == JvmOpCodes.PUTSTATIC) {
19563: doNotPop = true;
19564: int pos = getOffset(info,
19565: gotojumpa);
19566: /*parsedString+="PUTSTATIC\t";
19567: parsedString+="#"+pos;
19568: parsedString+="\n";
19569: parsedString+="\t";parsedString+="\t";*/
19570: FieldRef fref = cd
19571: .getFieldRefAtCPoolPosition(pos);
19572: Operand value = opStack
19573: .getTopOfStack();
19574: java.lang.String freftype = fref
19575: .getTypeoffield();
19576:
19577: // For the code statement
19578: int classpointer = fref
19579: .getClassPointer();
19580: ClassInfo cinfo = cd
19581: .getClassInfoAtCPoolPosition(classpointer);
19582: java.lang.String classname = cd
19583: .getUTF8String(cinfo
19584: .getUtf8pointer());
19585: java.lang.String v = value
19586: .getOperandValue()
19587: .toString();
19588: if (v.indexOf("(") == -1
19589: && v.indexOf(")") != -1) {
19590: v = v.replaceAll("\\)",
19591: "");
19592:
19593: }
19594: v = v.trim();
19595: StringBuffer stb = new StringBuffer(
19596: "");
19597: checkForImport(classname,
19598: stb);
19599: java.lang.String temp = stb
19600: .toString()
19601: + "."
19602: + fref
19603: .getFieldName()
19604: + " = " + v + ";";
19605: //codeStatements+="\n"+Util.formatDecompiledStatement(temp)+"\n";
19606: }
19607:
19608: }
19609:
19610: }
19611: }
19612: }
19613:
19614: checkForATHROWAtIFelseEnd(chk_ifst, ifelsecode,
19615: i);
19616: ifelsecode.append(Util
19617: .formatDecompiledStatement("}\n")); // Else End\n");
19618: reset.append("true");
19619: //elseendsadded.add(new Integer(i));
19620: }
19621: // ABove commmented by belurs
19622: //ifHashTable.remove(key);
19623: //ifLevel--;
19624: }
19625:
19626: }
19627: //else
19628: //{
19629: if (i == chk_ifCloseLineNo)// && w.equals("if"))// && !chk_ifst.hasIfBeenClosed())
19630: {
19631: // boolean print=isThisLoopEndAlso(behaviour.getBehaviourLoops(),i);
19632: // System.out.println(print+"print"+i);
19633: // boolean print =isThisIfALoopCondition(chk_ifst,info,behaviour.getBehaviourLoops());
19634: //if(!print) // TODO:
19635: //{
19636: StringBuffer sb = new StringBuffer();
19637: java.lang.String lbl = getBranchTypeAtI(i, chk_ifst, sb);
19638: //System.out.println(lbl+"lbl"+i);
19639: java.lang.String lbl2 = getIfElseReturnAtI(i);
19640: if (lbl2 != null) {
19641: ifelsecode.append(Util
19642: .formatDecompiledStatement(lbl2 + ";\n"));
19643: }
19644:
19645: if (lbl != null && !lbl.equals("")
19646: && !lbl.equals("continue") && lbl2 == null) {
19647: ////codeStatements+= Util.formatDecompiledStatement(lbl+";\n");
19648: ifelsecode.append(Util
19649: .formatDecompiledStatement(lbl + " "
19650: + sb.toString() + ";\n"));
19651:
19652: }
19653: if (lbl != null && !lbl.equals("")
19654: && lbl.equals("continue") && lbl2 == null) {
19655: ifelsecode.append(Util
19656: .formatDecompiledStatement(lbl + " "
19657: + sb.toString() + ";\n"));
19658:
19659: }
19660: if (lbl2 == null) {
19661: StringBuffer sr = new StringBuffer("");
19662: addAnyReturnBeforeIfClose(info, chk_ifst, sr,
19663: currentForIndex, stack);
19664: ifelsecode.append(sr.toString());
19665: }
19666: if (info[i] == JvmOpCodes.GOTO) {
19667: int gotojumpa = getJumpAddress(info, i);
19668: boolean k = storealreadyhandledatifend(i);
19669: if (isThisInstrStart(behaviour
19670: .getInstructionStartPositions(), gotojumpa)
19671: && !k) {
19672: StringBuffer in = new StringBuffer("");
19673: StringBuffer t = new StringBuffer("");
19674:
19675: boolean isstore = isStoreInst(gotojumpa, info,
19676: in, t);
19677: if (isstore) {
19678: int ind = Integer.parseInt(in.toString());
19679: if (ind != -1 && opStack.size() > 0) {
19680: boolean simple = false;
19681: if ((ind == 0) || (ind == 1)
19682: || (ind == 2) || (ind == 3))
19683: simple = true;
19684: LocalVariable loc = getLocalVariable(
19685: ind, "store", t.toString(),
19686: simple, gotojumpa);
19687: Operand objref = (Operand) opStack
19688: .pop(); // Pop The Object Ref
19689: doNotPop = true;
19690: if (loc.wasCreated()
19691: && objref != null
19692: && objref.getClassType().trim()
19693: .length() > 0)
19694: loc.setDataType(objref
19695: .getClassType());
19696: java.lang.String temp = (java.lang.String) objref
19697: .getOperandValue();
19698: if (!loc.isDeclarationGenerated()) {
19699: temp = loc.getDataType().replace(
19700: '/', '.')
19701: + " "
19702: + loc.getVarName()
19703: + "=" + temp + ";\n";
19704: //codeStatements += Util.formatDecompiledStatement(temp);
19705:
19706: } else {
19707:
19708: temp = " " + loc.getVarName()
19709: + " =" + temp + ";\n";
19710: //codeStatements += Util.formatDecompiledStatement(temp);
19711:
19712: }
19713: storesatifend.add(new Integer(i));
19714: } else {
19715: if (opStack.size() >= 3) {
19716: doNotPop = true;
19717: Operand value = opStack
19718: .getTopOfStack(); // Value
19719: Operand index = opStack
19720: .getTopOfStack(); // Index into target
19721: Operand arRef = opStack
19722: .getTopOfStack(); // Target Arref
19723: java.lang.String temp = arRef
19724: .getOperandValue()
19725: + "["
19726: + index.getOperandValue()
19727: + "] ="
19728: + value.getOperandValue()
19729: + ";";
19730: //codeStatements+="\n"+Util.formatDecompiledStatement(temp)+"\n";
19731: storesatifend.add(new Integer(i));
19732: }
19733: }
19734:
19735: } else {
19736: if (info[gotojumpa] == JvmOpCodes.PUTFIELD) {
19737: // Add here
19738: doNotPop = true;
19739: int pos = getOffset(info, gotojumpa);
19740:
19741: FieldRef fref = cd
19742: .getFieldRefAtCPoolPosition(pos);
19743: Operand value = opStack.getTopOfStack();
19744: Operand objRef = opStack
19745: .getTopOfStack();
19746: putfieldObjRefMap.put(new Integer(
19747: gotojumpa), objRef);
19748: java.lang.String freftype = fref
19749: .getTypeoffield();
19750: StringBuffer stb = new StringBuffer("");
19751: checkForImport(
19752: objRef.getOperandValue(), stb);
19753: java.lang.String temp = stb.toString()
19754: + "." + fref.getFieldName()
19755: + " = "
19756: + value.getOperandValue() + ";";
19757: //codeStatements+="\n"+Util.formatDecompiledStatement(temp)+"\n";
19758: }
19759: if (info[gotojumpa] == JvmOpCodes.PUTSTATIC) {
19760: doNotPop = true;
19761: int pos = getOffset(info, gotojumpa);
19762: /*parsedString+="PUTSTATIC\t";
19763: parsedString+="#"+pos;
19764: parsedString+="\n";
19765: parsedString+="\t";parsedString+="\t";*/
19766: FieldRef fref = cd
19767: .getFieldRefAtCPoolPosition(pos);
19768: Operand value = opStack.getTopOfStack();
19769: java.lang.String freftype = fref
19770: .getTypeoffield();
19771:
19772: // For the code statement
19773: int classpointer = fref
19774: .getClassPointer();
19775: ClassInfo cinfo = cd
19776: .getClassInfoAtCPoolPosition(classpointer);
19777: java.lang.String classname = cd
19778: .getUTF8String(cinfo
19779: .getUtf8pointer());
19780: java.lang.String v = value
19781: .getOperandValue().toString();
19782: if (v.indexOf("(") == -1
19783: && v.indexOf(")") != -1) {
19784: v = v.replaceAll("\\)", "");
19785:
19786: }
19787: v = v.trim();
19788: StringBuffer stb = new StringBuffer("");
19789: checkForImport(classname, stb);
19790: java.lang.String temp = stb.toString()
19791: + "." + fref.getFieldName()
19792: + " = " + v + ";";
19793: //codeStatements+="\n"+Util.formatDecompiledStatement(temp)+"\n";
19794: }
19795:
19796: }
19797:
19798: }
19799: }
19800: if (!chk_ifst.IfHasBeenClosed()
19801: && chk_ifst.getDonotclose() == false) {
19802: checkForATHROWAtIFelseEnd(chk_ifst, ifelsecode, i);
19803: ifelsecode.append(Util
19804: .formatDecompiledStatement("\n}\n"));// if end\nIFEND"+chk_ifst.getIfCloseLineNumber()+"");
19805: //System.out.println(chk_ifst.getIfCloseLineNumber()+" "+chk_ifst.getIfCloseFromByteCode());
19806: ifhasbegun = false;
19807: chk_ifst.setIfHasBeenClosed(true);
19808: }
19809:
19810: // }
19811: //iter.remove();
19812: //ifHashTable.remove(key);
19813: //ifLevel--;
19814: }
19815:
19816: // }
19817: }
19818:
19819: }
19820:
19821: /* private boolean pushOnStackForStoreInst(byte[] info,int cur,boolean type)
19822: {
19823: if(type)
19824: {
19825: int next=cur+1;
19826: switch(info[next])
19827: {
19828:
19829: case JvmOpCodes.IADD:
19830: case JvmOpCodes.IAND:
19831: case JvmOpCodes.I
19832:
19833:
19834:
19835:
19836: }
19837:
19838:
19839: }
19840: else
19841: {
19842:
19843: }
19844:
19845: }*/
19846:
19847: // belurs:
19848: /***
19849: * NOTE:
19850: Currently This method takes into account only dup and dup2 NOT dup2_x1 and dup_x2
19851: So the Disassembler might not output correctly if the dup inst if one of dup2_x1 and dup_x2
19852: TODO: Need to revisit This Item and fix the problem
19853: This method is used by primitive store blocks to check whether to print
19854: Or add tp stack
19855: */
19856:
19857: private boolean isPrevInstDup(byte[] info, int cur) {
19858:
19859: if (isThisInstrStart(behaviour.getInstructionStartPositions(),
19860: cur - 1)
19861: && (info[cur - 1] == JvmOpCodes.DUP || info[cur - 1] == JvmOpCodes.DUP2))
19862: return true;
19863: else
19864: return false;
19865: }
19866:
19867: private void popFromStackIFNec(byte[] info, int cur,
19868: OperandStack stack)
19869:
19870: {
19871: ArrayList list = behaviour.getInstructionStartPositions();
19872:
19873: if (info[cur - 5] == JvmOpCodes.INVOKEINTERFACE
19874: && isThisInstrStart(list, cur - 5)) {
19875: stack.getTopOfStack();
19876: }
19877: if (info[cur - 3] == JvmOpCodes.INVOKESPECIAL
19878: && isThisInstrStart(list, cur - 3)) {
19879: stack.getTopOfStack();
19880: }
19881: if (info[cur - 3] == JvmOpCodes.INVOKEVIRTUAL
19882: && isThisInstrStart(list, cur - 3)) {
19883: stack.getTopOfStack();
19884: }
19885: if (info[cur - 3] == JvmOpCodes.INVOKESTATIC
19886: && isThisInstrStart(list, cur - 3)) {
19887: stack.getTopOfStack();
19888: }
19889:
19890: }
19891:
19892: private void handleSimpleLStoreCase(OperandStack stack,
19893: byte[] info, StringBuffer code, int index) {
19894:
19895: java.lang.String tempString = "";
19896: LocalVariable local;
19897: local = getLocalVariable(index, "store", "long", true,
19898: currentForIndex);
19899: if (local != null && cd.isClassCompiledWithMinusG()) {
19900: addParsedOutput("Instruction Pos " + currentForIndex
19901: + "\t:- " + "lstore_ " + index
19902: + " THIS LocalVariable:- " + local.getVarName()
19903: + "\n");
19904: } else
19905: addParsedOutput("Instruction Pos " + currentForIndex
19906: + "\t:- " + "lstore_" + index + "\n");
19907:
19908: if (local != null && !doNotPop) {
19909: Operand op = stack.getTopOfStack();
19910: prevLocalGenerated = local;
19911: boolean push = isPrevInstDup(info, currentForIndex);
19912: if (!push) {
19913: if (!local.isDeclarationGenerated()) {
19914: local.setBlockIndex(blockLevel);
19915: tempString = local.getDataType() + " "
19916: + local.getVarName() + "="
19917: + op.getOperandValue() + ";\n";
19918: code.append(Util
19919: .formatDecompiledStatement(tempString));
19920: local.setDeclarationGenerated(true);
19921: } else {
19922: tempString = local.getVarName() + "="
19923: + op.getOperandValue() + ";\n";
19924: code.append(Util
19925: .formatDecompiledStatement(tempString));
19926: }
19927: } else {
19928: if (isThisInstrStart(behaviour
19929: .getInstructionStartPositions(),
19930: currentForIndex - 1)
19931: && info[currentForIndex - 1] == JvmOpCodes.DUP)
19932: opStack.getTopOfStack();
19933: if (isThisInstrStart(behaviour
19934: .getInstructionStartPositions(),
19935: currentForIndex - 1)
19936: && info[currentForIndex - 1] == JvmOpCodes.DUP2) {
19937: opStack.getTopOfStack();
19938: opStack.getTopOfStack();
19939: }
19940: code.append(Util.formatDecompiledStatement(local
19941: .getVarName()
19942: + "=(" + op.getOperandValue() + ");\n"));
19943: Operand op2 = createOperand(local.getVarName());
19944: stack.push(op2);
19945: }
19946: }
19947: if (doNotPop == true)
19948: doNotPop = false;
19949: }
19950:
19951: private void handleSimpleFstoreCaseInst(OperandStack stack,
19952: byte[] info, int index, StringBuffer srb) {
19953: LocalVariable local = getLocalVariable(index, "store", "float",
19954: true, currentForIndex);
19955: java.lang.String tempString = "";
19956: if (cd.isClassCompiledWithMinusG() && local != null) {
19957: addParsedOutput("Instruction Pos " + currentForIndex
19958: + "\t:- " + " fstore_" + index
19959: + " THIS LocalVariable :- " + local.getVarName()
19960: + "\n");
19961: } else {
19962: addParsedOutput("Instruction Pos " + currentForIndex
19963: + "\t:- " + " fstore_" + index + "\n");
19964: }
19965: if (local != null && !doNotPop) {
19966: Operand op = (Operand) stack.pop();
19967: prevLocalGenerated = local;
19968: boolean push = isPrevInstDup(info, currentForIndex);
19969: if (!push) {
19970: if (!local.isDeclarationGenerated()) {
19971: local.setBlockIndex(blockLevel);
19972: tempString = local.getDataType() + " "
19973: + local.getVarName() + "="
19974: + op.getOperandValue() + ";\n";
19975: srb.append(Util
19976: .formatDecompiledStatement(tempString));
19977: local.setDeclarationGenerated(true);
19978: } else {
19979: tempString = local.getVarName() + "="
19980: + op.getOperandValue() + ";\n";
19981: srb.append(Util
19982: .formatDecompiledStatement(tempString));
19983: }
19984: } else {
19985: if (isThisInstrStart(behaviour
19986: .getInstructionStartPositions(),
19987: currentForIndex - 1)
19988: && info[currentForIndex - 1] == JvmOpCodes.DUP)
19989: opStack.getTopOfStack();
19990: if (isThisInstrStart(behaviour
19991: .getInstructionStartPositions(),
19992: currentForIndex - 1)
19993: && info[currentForIndex - 1] == JvmOpCodes.DUP2) {
19994: opStack.getTopOfStack();
19995: opStack.getTopOfStack();
19996: }
19997: srb.append(Util.formatDecompiledStatement(local
19998: .getVarName()
19999: + "=(" + op.getOperandValue() + ");\n"));
20000: Operand op2 = createOperand(local.getVarName());
20001: stack.push(op2);
20002: }
20003: }
20004: if (doNotPop == true)
20005: doNotPop = false;
20006: }
20007:
20008: private void handleSimpleDstoreCaseInst(OperandStack stack,
20009: byte[] info, int index, StringBuffer srb) {
20010: LocalVariable local = getLocalVariable(index, "store",
20011: "double", true, currentForIndex);
20012: if (cd.isClassCompiledWithMinusG())
20013: addParsedOutput("Instruction Pos " + currentForIndex
20014: + "\t:- " + " dstore_" + index
20015: + " THIS LOCALVARIABLE :- " + local.getVarName()
20016: + "\n");
20017: else
20018: addParsedOutput("Instruction Pos " + currentForIndex
20019: + "\t:- " + " dstore_" + index + "\n");
20020: java.lang.String tempString = "";
20021:
20022: if (local != null && !doNotPop) {
20023: Operand op = (Operand) stack.pop();
20024: prevLocalGenerated = local;
20025: boolean push = isPrevInstDup(info, currentForIndex);
20026: if (!push) {
20027: if (!local.isDeclarationGenerated()) {
20028: local.setBlockIndex(blockLevel);
20029: //if(local.wasCreated())local.setDataType(op.getClassType());
20030: int semiColon = op.getOperandValue().toString()
20031: .indexOf(";");
20032: if (semiColon == -1) {
20033: tempString = local.getDataType() + " "
20034: + local.getVarName() + "="
20035: + op.getOperandValue() + ";\n";
20036: srb.append(Util
20037: .formatDecompiledStatement(tempString));
20038: } else {
20039: tempString = local.getDataType() + " "
20040: + local.getVarName() + "="
20041: + op.getOperandValue();
20042: srb.append(Util
20043: .formatDecompiledStatement(tempString));
20044: }
20045: local.setDeclarationGenerated(true);
20046: } else {
20047: int semiColon = op.getOperandValue().toString()
20048: .indexOf(";");
20049: if (semiColon == -1) {
20050: tempString = local.getVarName() + "="
20051: + op.getOperandValue() + ";\n";
20052: srb.append(Util
20053: .formatDecompiledStatement(tempString));
20054: } else {
20055: tempString = local.getVarName() + "="
20056: + op.getOperandValue();
20057: srb.append(Util
20058: .formatDecompiledStatement(tempString));
20059: }
20060: }
20061: } else {
20062: if (isThisInstrStart(behaviour
20063: .getInstructionStartPositions(),
20064: currentForIndex - 1)
20065: && info[currentForIndex - 1] == JvmOpCodes.DUP)
20066: opStack.getTopOfStack();
20067: if (isThisInstrStart(behaviour
20068: .getInstructionStartPositions(),
20069: currentForIndex - 1)
20070: && info[currentForIndex - 1] == JvmOpCodes.DUP2) {
20071: opStack.getTopOfStack();
20072: opStack.getTopOfStack();
20073: }
20074: srb.append(Util.formatDecompiledStatement(local
20075: .getVarName()
20076: + "=(" + op.getOperandValue() + ");\n"));
20077: Operand op2 = createOperand(local.getVarName());
20078: stack.push(op2);
20079: }
20080: }
20081: if (doNotPop == true)
20082: doNotPop = false;
20083: }
20084:
20085: private Hashtable anewarrayrefpos;
20086:
20087: private boolean processANEWARRAYb4Invoke(byte[] code, int s,
20088: StringBuffer invokepos) {
20089:
20090: int startpos = s + 2 + 1;
20091: ArrayList starts = behaviour.getInstructionStartPositions();
20092: boolean donotprocess = false;
20093: boolean foundinvoke = false;
20094: int pos = -1;
20095: for (int k = startpos; k < code.length; k++) {
20096:
20097: boolean startinst = isThisInstrStart(starts, k);
20098: if (code[k] == JvmOpCodes.INVOKEINTERFACE
20099: || code[k] == JvmOpCodes.INVOKEVIRTUAL
20100: || code[k] == JvmOpCodes.INVOKESTATIC) {
20101: foundinvoke = true;
20102: pos = k;
20103: break;
20104: }
20105: }
20106:
20107: if (pos != -1) {
20108: for (int k = startpos; k < pos; k++) {
20109: boolean startinst = isThisInstrStart(starts, k);
20110: if (startinst) {
20111:
20112: switch (code[k]) {
20113:
20114: case JvmOpCodes.NEW:
20115: case JvmOpCodes.NEWARRAY:
20116: case JvmOpCodes.MULTIANEWARRAY:
20117: invokepos.append(pos);
20118: donotprocess = true;
20119: return donotprocess;
20120:
20121: }
20122:
20123: }
20124: }
20125: }
20126:
20127: return donotprocess;
20128:
20129: }
20130:
20131: private ArrayList problematicInvokes;
20132:
20133: private void resetMethodParameters(OperandStack stack,
20134: ArrayList methodParams, int j) {
20135: // Check if reset needs to be done in the first place
20136: if (problematicInvokes == null
20137: || problematicInvokes.size() == 0)
20138: return;
20139: boolean ok = false;
20140: for (int n = 0; n < problematicInvokes.size(); n++) {
20141:
20142: Integer in = (Integer) problematicInvokes.get(n);
20143: if (in.intValue() == j) {
20144: ok = true; // Yes Disassembler
20145: break;
20146: } else
20147: ok = false;
20148:
20149: }
20150: if (!ok)
20151: return;
20152:
20153: // some validations
20154: if (methodParams == null || stack == null)
20155: return;
20156: int count = methodParams.size();
20157: if (count == 0)
20158: return;
20159: if (stack.size() < count)
20160: return; // Should Not happen: A Bug in jdec
20161: Operand reqdops[] = new Operand[count];
20162: boolean needtoresetstack = false;
20163: for (int h = 0; h < count; h++) {
20164: reqdops[h] = stack.getTopOfStack();
20165: needtoresetstack = true;
20166: }
20167:
20168: // IMPORTANT : IF needtoresetstack IS TRUE method shud return only after resetting stack .NOT before that
20169:
20170: // start Resetting
20171: int opstart = 0;
20172: for (int z = count - 1; z >= 0; z--) {
20173:
20174: Operand current = reqdops[opstart];
20175: opstart++;
20176: if (current != null) {
20177: java.lang.String type = current.getLocalVarType();
20178: boolean needtoreset = false;
20179: java.lang.String param = (java.lang.String) methodParams
20180: .get(z);
20181: if (type != null && type.trim().equals("int")) {
20182:
20183: if (param.trim().equals("byte")) {
20184: needtoreset = true;
20185: } else if (param.trim().equals("boolean")) {
20186: needtoreset = true;
20187: } else if (param.trim().equals("short")) {
20188: needtoreset = true;
20189: } else if (param.trim().equals("char")) {
20190: needtoreset = true;
20191: } else {
20192: needtoreset = false;
20193: }
20194: if (needtoreset) {
20195: int localIndex = current.getLocalVarIndex();
20196: java.lang.String searchFor = "#REPLACE_INT_"
20197: + localIndex + "#";
20198: int len = searchFor.length();
20199: int start = -1;//codeStatements.indexOf(searchFor);
20200: java.lang.String name = "";
20201: if (start != -1) {
20202: java.lang.String tp = "";//codeStatements.substring(start+len,start+len+3);
20203: int equalTo = -1;
20204: StringBuffer newpos = new StringBuffer("");
20205: if (tp.equals("int")) {
20206: //java.lang.String=//codeStatements.replaceFirst(searchFor+"int",param.trim());
20207: name = (java.lang.String) current
20208: .getOperandValue();
20209:
20210: //codeStatements=getStringAfterReplacement(//codeStatements,start,searchFor+"int",param.trim(),newpos, name,false,param.trim());
20211:
20212: }
20213: try {
20214: equalTo = Integer.parseInt(newpos
20215: .toString());
20216: } catch (NumberFormatException ne) {
20217: equalTo = -1;
20218: }
20219:
20220: if (equalTo != -1) {
20221: int valueIn = -1;//codeStatements.indexOf("#VALUE"+localIndex+"#",equalTo);
20222: if (valueIn != -1) {
20223: java.lang.String valuehash = "#VALUE"
20224: + localIndex + "#";
20225: java.lang.String val = "";//codeStatements.substring(valueIn+valuehash.length(),valueIn+valuehash.length()+1);
20226:
20227: //codeStatements=getStringAfterReplacement(//codeStatements,valueIn,"#VALUE"+localIndex+"#",val,newpos,name,true,param.trim());
20228: }
20229: }
20230: }
20231:
20232: }
20233:
20234: } else if (type != null && type.trim().equals("")) {
20235:
20236: if (param.trim().equals("byte")
20237: || param.trim().equals("short")
20238: || param.trim().equals("char")) {
20239:
20240: current.setOperandValue("(" + param + ")"
20241: + current.getOperandValue());
20242:
20243: }
20244: }
20245: // Check for multidimensional.....
20246:
20247: if (param.trim().indexOf("[") != -1) {
20248: int first = param.trim().indexOf("[");
20249: int last = param.trim().lastIndexOf("[");
20250: int howmany = last - first + 1;
20251: boolean isMulti = current.isMultiDimension();
20252: if (isMulti) {
20253: java.lang.String value = (java.lang.String) current
20254: .getOperandValue();
20255: /*if(value.indexOf("[")!=-1)
20256: {
20257: /*int cnt=1;
20258: int start=value.indexOf("[");
20259: int next=start+1;
20260: while(next < value.length())
20261: {
20262:
20263: if(value.charAt(next)=='[')
20264: {
20265: cnt++;
20266: }
20267: next++;
20268:
20269: }
20270:
20271: int total=cnt+howmany;*/
20272: java.lang.String bracks = "";
20273: for (int s = 0; s < howmany; s++) {
20274:
20275: bracks += "[]";
20276: }
20277: value += bracks;
20278: current.setOperandValue(value);
20279:
20280: }
20281:
20282: }
20283:
20284: } else // Again should not happen at all. Returning if this happens , so that jdec will not reset a wrong operand's value
20285: {
20286: // Restore Stack
20287: for (int l = reqdops.length - 1; l >= 0; l--) {
20288: Operand op = reqdops[l];
20289: stack.push(op);
20290: }
20291: return;
20292: }
20293:
20294: }
20295:
20296: // This should be final step before returning
20297: if (needtoresetstack) {
20298: // Restore Stack
20299: for (int l = reqdops.length - 1; l >= 0; l--) {
20300: Operand op = reqdops[l];
20301: stack.push(op);
20302: }
20303: }
20304:
20305: }
20306:
20307: private java.lang.String getStringAfterReplacement(
20308: java.lang.String codeStatements, int fromwhere,
20309: java.lang.String lookfor, java.lang.String replaceString,
20310: StringBuffer sb, java.lang.String name, boolean skipone,
20311: java.lang.String methodparam) {
20312: int equal = -1;
20313:
20314: java.lang.String orig = "";//codeStatements;
20315: java.lang.String temp1 = "";//codeStatements.substring(0,fromwhere);
20316: java.lang.String temp2 = replaceString;
20317: java.lang.String temp3 = "";
20318: if (skipone) {
20319: if (methodparam.equalsIgnoreCase("boolean")) {
20320:
20321: if (replaceString.trim().equalsIgnoreCase("0")) {
20322: temp2 = "false";
20323: } else if (replaceString.trim().equalsIgnoreCase("1")) {
20324: temp2 = "true";
20325: } else {
20326:
20327: }
20328:
20329: }
20330: temp3 = "";//codeStatements.substring(fromwhere+lookfor.length()+1);
20331: } else {
20332: temp3 = "";//codeStatements.substring(fromwhere+lookfor.length());
20333: }
20334:
20335: orig = temp1 + temp2 + temp3;
20336: equal = orig.indexOf("=", orig.indexOf(replaceString + "\t"
20337: + name));
20338: sb.append(equal);
20339: return orig;
20340: }
20341:
20342: private boolean isNextInstAStore(byte[] info, int pos) {
20343:
20344: if (isThisInstrStart(behaviour.getInstructionStartPositions(),
20345: pos)) {
20346: if (info[pos] == JvmOpCodes.ASTORE) {
20347:
20348: return true;
20349: }
20350: if (info[pos] == JvmOpCodes.ASTORE_0) {
20351: return true;
20352:
20353: }
20354: if (info[pos] == JvmOpCodes.ASTORE_1) {
20355:
20356: return true;
20357: }
20358: if (info[pos] == JvmOpCodes.ASTORE_2) {
20359: return true;
20360:
20361: }
20362: if (info[pos] == JvmOpCodes.ASTORE_3) {
20363: return true;
20364:
20365: }
20366: }
20367: return false;
20368:
20369: }
20370:
20371: private void handleACONSTNULL() {
20372: addParsedOutput("Instruction Pos " + currentForIndex + "\t:- "
20373: + " aconst_null\n");
20374: NullObject nullobj = new NullObject();
20375: Operand op = createOperand(nullobj.getIdentification());
20376: op.setOperandType(Constants.IS_NULL);
20377: opStack.push(op);
20378: }
20379:
20380: private void handlesimpleaload(int index) {
20381:
20382: LocalVariable local = getLocalVariable(index, "load",
20383: "java.lang.Object", true, currentForIndex);
20384: if (local == null) {
20385: local = new LocalVariable();
20386: local.setVarName("this");
20387: }
20388:
20389: prevLocalGenerated = local;
20390: Operand op = new Operand();
20391: op.setOperandName(local.getVarName());
20392: op.setOperandValue(local.getVarName());
20393: op.setOperandType(Constants.IS_OBJECT_REF);
20394: opStack.push(op);
20395: op.setClassType(local.getDataType());
20396: java.lang.String t = "Instruction Pos " + currentForIndex
20397: + "\t:- " + " aload_" + index;
20398: if (cd.isClassCompiledWithMinusG() && local != null) {
20399: t += " This LocalVariable :- " + local.getVarName();
20400: }
20401: t += "\n";
20402: addParsedOutput(t);
20403:
20404: }
20405:
20406: private void handleARRAYLENGTHCase() {
20407: addParsedOutput("Instruction Pos " + currentForIndex + "\t:- "
20408: + " arraylength\n");
20409: Operand op = (Operand) opStack.pop();
20410: Operand tempOperand = op;
20411: op = new Operand();
20412: op.setOperandValue(tempOperand.getOperandValue() + ".length");
20413: //op.setCategory(Constants.CATEGORY1);
20414: //op.setOperandType(Constants.IS_CONSTANT_INT);
20415: opStack.push(op);
20416: }
20417:
20418: private void handleARETURNCase(int i, HashMap returnsAtI) {
20419: boolean oktoadd = true;
20420: Iterator mapIT = returnsAtI.entrySet().iterator();
20421: while (mapIT.hasNext()) {
20422: Map.Entry entry = (Map.Entry) mapIT.next();
20423: Object key = entry.getKey();
20424: Object retStatus = entry.getValue().toString();
20425: if (key instanceof Integer) {
20426: Integer pos = (Integer) key;
20427: int temp = pos.intValue();
20428: if (temp == i) {
20429: if (retStatus.equals("true")) {
20430:
20431: oktoadd = false;
20432: break;
20433: }
20434: }
20435: }
20436:
20437: }
20438:
20439: if (!oktoadd) {
20440: returnsAtI.remove(new Integer(i));
20441: }
20442: Object obj = returnsAtI.get(new Integer(i));
20443: java.lang.String tempString = "";
20444: if (oktoadd && opStack.size() > 0) {
20445: //System.out.println(currentForIndex+"i"+behaviour.getBehaviourName());
20446: Operand op = (Operand) opStack.pop();
20447:
20448: if (op.getOperandValue() != null
20449: && op.getOperandValue().toString().indexOf(";") == -1)
20450: tempString = "return " + op.getOperandValue() + ";\n";
20451: else
20452: tempString = "return " + op.getOperandValue() + "\n";
20453: //codeStatements+=Util.formatDecompiledStatement(tempString);
20454:
20455: }
20456: }
20457:
20458: private void handleSIPUSH(byte[] info) {
20459: int opValueI = getOffset(info, currentForIndex);
20460: addParsedOutput("Instruction Pos " + currentForIndex + "\t:- "
20461: + " sipush " + opValueI + "\n");
20462: Operand op = new Operand();
20463: java.lang.String tp = null;
20464: if (pushTypes != null) {
20465: tp = (java.lang.String) pushTypes.get(new Integer(
20466: currentForIndex));
20467: if (tp != null) {
20468: tp = "(" + tp + ")" + opValueI;
20469: }
20470:
20471: }
20472:
20473: if (tp != null)
20474:
20475: op.setOperandValue(tp);// // new Integer(opValueI));
20476: else
20477: op.setOperandValue(new Integer(opValueI));
20478: op.setOperandType(Constants.IS_CONSTANT_SHORT);
20479: opStack.push(op);
20480: }
20481:
20482: private void handleBIPush(byte[] info) {
20483: int opValueB = info[(currentForIndex + 1)];
20484: addParsedOutput("Instruction Pos " + currentForIndex + "\t:- "
20485: + " bipush " + opValueB + "\n");
20486: Operand op = new Operand();
20487: java.lang.String tp = null;
20488: if (pushTypes != null) {
20489: tp = (java.lang.String) pushTypes.get(new Integer(
20490: currentForIndex));
20491: if (tp != null) {
20492: tp = "(" + tp + ")" + opValueB;
20493: }
20494:
20495: }
20496:
20497: if (tp != null)
20498:
20499: op.setOperandValue(tp);// // new Integer(opValueI));
20500: else
20501: op.setOperandValue(new Integer(opValueB));
20502:
20503: //op.setOperandType(Constants.IS_CONSTANT_BYTE);
20504: //op.setCategory(Constants.CATEGORY1);
20505: opStack.push(op);
20506:
20507: }
20508:
20509: private void handleSASTORE() {
20510: Operand value = opStack.getTopOfStack(); // Value
20511: Operand index = opStack.getTopOfStack(); // Index into target
20512: Operand arRef = opStack.getTopOfStack(); // Target Arref
20513: java.lang.String temp = arRef.getOperandValue() + "["
20514: + index.getOperandValue() + "] ="
20515: + value.getOperandValue() + ";";
20516: //codeStatements+="\n"+Util.formatDecompiledStatement(temp)+"\n";
20517: }
20518:
20519: private void handleSALOAD() {
20520: Operand index = opStack.getTopOfStack();
20521: Operand arRef = opStack.getTopOfStack();
20522: java.lang.String result = arRef.getOperandValue() + "["
20523: + index.getOperandValue() + "]";
20524: Operand op = new Operand();
20525: op.setOperandValue(result);
20526: op.setOperandType(Constants.IS_CONSTANT_SHORT);
20527: opStack.push(op);
20528: }
20529:
20530: private void handleSimpleReturn() {
20531: java.lang.String temp = behaviour.getReturnType();
20532:
20533: boolean oktoadd = true;
20534: Iterator mapIT = returnsAtI.entrySet().iterator();
20535: while (mapIT.hasNext()) {
20536: Map.Entry entry = (Map.Entry) mapIT.next();
20537: Object key = entry.getKey();
20538: Object retStatus = entry.getValue().toString();
20539: if (key instanceof Integer) {
20540: Integer position = (Integer) key;
20541: int posValue = position.intValue();
20542: if (posValue == currentForIndex) {
20543: if (retStatus.equals("true")) {
20544:
20545: oktoadd = false;
20546: break;
20547: }
20548: }
20549: }
20550:
20551: }
20552:
20553: if (!oktoadd) {
20554: returnsAtI.remove(new Integer(currentForIndex));
20555: }
20556:
20557: if (oktoadd) {
20558: java.lang.String tempString = Util
20559: .formatDecompiledStatement("return;\n");
20560: //codeStatements+=tempString;
20561:
20562: }
20563:
20564: }
20565:
20566: private void handleNEWARRAYCase(byte[] info) {
20567: java.lang.String temp = "";
20568: switch (info[(currentForIndex + 1)]) {
20569: case 4:
20570:
20571: temp = "boolean[";
20572: break;
20573: case 5:
20574:
20575: temp = "char[";
20576: break;
20577: case 6:
20578:
20579: temp = "float[";
20580: break;
20581: case 7:
20582:
20583: temp = "double[";
20584: break;
20585: case 8:
20586:
20587: temp = "byte[";
20588: break;
20589: case 9:
20590:
20591: temp = "short[";
20592: break;
20593: case 10:
20594:
20595: temp = "int[";
20596: break;
20597: case 11:
20598:
20599: temp = "long[";
20600: break;
20601: }
20602:
20603: // Pop The Size
20604: Operand arSize = opStack.getTopOfStack();
20605:
20606: // A check
20607: /*if(arSize.getOperandType()!=Constants.IS_CONSTANT_INT && arSize.getOperandType()!=Constants.IS_CONSTANT_BYTE) {
20608: throw new StackOperationException("Error While handling newarray instruction. The SIze of array is not of type int . \nType Found to be "+arSize.getOperandType());
20609:
20610: } else {*/
20611: addParsedOutput("Instruction Pos " + currentForIndex + "\t:- "
20612: + " newarray :- " + temp + "\n");
20613: Operand op = new Operand();
20614: op.setOperandType(Constants.IS_ARRAY_REF);
20615: java.lang.String Reference = "JdecGenerated"
20616: + (currentForIndex + 1);
20617: op.setClassType(temp + "]");
20618: temp = temp + "] " + Reference + " = new " + temp
20619: + arSize.getOperandValue() + "]";
20620: //codeStatements+="\n"+Util.formatDecompiledStatement(temp)+";\n";
20621: //temp="new "+temp+arSize.getOperandValue()+"]";
20622: op.setOperandValue(Reference);
20623: opStack.push(op);
20624: }
20625:
20626: private void handleAASTORECase() {
20627: addParsedOutput("Instruction Pos " + currentForIndex + "\t:- "
20628: + " AAstore\n");
20629: if (!doNotPop) {
20630: Operand value = (Operand) opStack.pop();
20631: Operand arindex = (Operand) opStack.pop();
20632: Operand arRef = (Operand) opStack.pop();
20633: java.lang.String tempString = arRef.getOperandValue() + "["
20634: + arindex.getOperandValue() + "]="
20635: + value.getOperandValue() + ";\n";
20636: //codeStatements += Util.formatDecompiledStatement(tempString);
20637: }
20638: if (doNotPop == true)
20639: doNotPop = false;
20640: }
20641:
20642: private void handleANEWARRAYCase(byte[] info) {
20643:
20644: int temp1 = info[(currentForIndex + 1)];
20645: int temp2 = info[(currentForIndex + 2)];
20646: int classIndex = getOffset(info, currentForIndex);//(temp1 << 8) | temp2);
20647: // if(classIndex < 0)classIndex=(temp1+1)*256-Math.abs(temp2);
20648: ClassInfo cinfo = cd.getClassInfoAtCPoolPosition(classIndex);
20649: java.lang.String Type = cd
20650: .getUTF8String(cinfo.getUtf8pointer());
20651: int bracketCount = Type.lastIndexOf("[");
20652: bracketCount = bracketCount + 2; // the one which is required.
20653: java.lang.String tempString = "";
20654: Type = parse(Type);
20655: int brk = Type.indexOf("[");
20656: if (brk >= 0)
20657: Type = Type.substring(0, brk);
20658: Type = Type.replace('/', '.');
20659: tempString += Type;
20660: java.lang.String brackets = "";
20661:
20662: for (int counter = 0; counter < bracketCount; counter++) {
20663: brackets += "[]";
20664: }
20665: java.lang.String Ref = "JdecGeneratedVar"
20666: + (currentForIndex + 2);
20667: tempString += " " + brackets + " " + Ref + "= new " + Type;
20668: brackets = "";
20669: Operand count = (Operand) opStack.pop();
20670: Integer intsize = null;
20671: java.lang.String SizeofArray = "";
20672:
20673: SizeofArray = count.getOperandValue();
20674: for (int counter = 0; counter < bracketCount; counter++) {
20675: if (counter == 0)
20676: brackets += "[" + SizeofArray + "]";
20677: else
20678: brackets += "[]";
20679: }
20680: tempString += brackets + ";";
20681: //codeStatements+=Util.formatDecompiledStatement(tempString)+";\n";
20682: tempString = "";
20683: //parsedString+=Type;
20684: //parsedString+="\n";
20685: Operand op = new Operand();
20686:
20687: /**
20688: * IMPORTANT NOTE:
20689: */
20690: // Previous Code Statement
20691: // Needed to modify so as to produce code
20692: // for statement like short s[][]={ {1,2} ,{3,4} );
20693: // Side Effect of this will be to produce extra statements in the
20694: // decompiled code which will have ConsoleLauncher generated temporary variables
20695: // This however will REFLECT the actual code produced by the compiler
20696: // and not anuthing extra
20697: //op.setOperandValue("new "+(cd.getUTF8String(cinfo.getUtf8pointer())).replace('/','.')+"["+arraySize+"]");
20698: op.setOperandValue(Ref);
20699: op.setOperandType(Constants.IS_ARRAY_REF);
20700: op.setClassType(Type);
20701: opStack.push(op);
20702:
20703: java.lang.String t = "Instruction Pos " + currentForIndex
20704: + "\t:- " + " anewaray ";
20705: t += temp1 + " " + temp2;
20706: t += "new " + Type + "\n";
20707: addParsedOutput(t);
20708:
20709: }
20710:
20711: private void checkForImport(java.lang.String input, StringBuffer sb) {
20712:
20713: if (input.indexOf(".") == -1 && input.indexOf("/") == -1) {
20714: sb.append(input);
20715: return;
20716: }
20717: if (Configuration.getShowImport().equalsIgnoreCase("false")) {
20718:
20719: sb.append(input);
20720: return;
20721: }
20722: if (Configuration.getShowImport().equalsIgnoreCase("true")) {
20723: java.lang.String simplename = "";
20724: java.lang.String fullName = input;
20725: int lastSlash = fullName.lastIndexOf("/");
20726: if (lastSlash == -1) {
20727: lastSlash = fullName.lastIndexOf(".");
20728: }
20729: if (lastSlash != -1) {
20730: simplename = fullName.substring(lastSlash + 1);
20731: } else
20732: simplename = fullName;
20733: fullName = fullName.replace('/', '.');
20734: ConsoleLauncher.addImportClass(fullName);
20735: sb.append(simplename);
20736: return;
20737:
20738: }
20739: // Default
20740: sb.append(input);
20741: return;
20742:
20743: }
20744:
20745: private int getPrevStartCodePos(byte[] info, int i) {
20746: int current = i;
20747: ArrayList allstarts = behaviour.getInstructionStartPositions();
20748: int z;
20749: for (z = current - 1; z >= 0; z--) {
20750:
20751: boolean ok = isThisInstrStart(allstarts, z);
20752: if (ok) {
20753: return z;
20754: }
20755: }
20756: return z;
20757:
20758: }
20759:
20760: private boolean isStoreInst(int index, byte[] info,
20761: StringBuffer varindex, StringBuffer t) {
20762:
20763: boolean b = isThisInstrStart(behaviour
20764: .getInstructionStartPositions(), index);
20765: if (b == false)
20766: return false;
20767: switch (info[index]) {
20768: case JvmOpCodes.AASTORE:
20769: case JvmOpCodes.BASTORE:
20770: case JvmOpCodes.CASTORE:
20771: case JvmOpCodes.DASTORE:
20772: case JvmOpCodes.FASTORE:
20773: case JvmOpCodes.IASTORE:
20774: case JvmOpCodes.LASTORE:
20775: case JvmOpCodes.SASTORE:
20776: varindex.append("-1");
20777: return true;
20778:
20779: case JvmOpCodes.ASTORE:
20780: varindex.append(info[(index + 1)]);
20781: t.append("java.lang.Object");
20782: return true;
20783: case JvmOpCodes.DSTORE:
20784: varindex.append(info[(index + 1)]);
20785: t.append("double");
20786: return true;
20787: case JvmOpCodes.FSTORE:
20788: varindex.append(info[(index + 1)]);
20789: t.append("float");
20790: return true;
20791: case JvmOpCodes.ISTORE:
20792: varindex.append(info[(index + 1)]);
20793: t.append("int");
20794: return true;
20795: case JvmOpCodes.LSTORE:
20796: varindex.append(info[(index + 1)]);
20797: t.append("long");
20798: return true;
20799:
20800: case JvmOpCodes.ASTORE_0:
20801: varindex.append("0");
20802: t.append("java.lang.Object");
20803: return true;
20804:
20805: case JvmOpCodes.DSTORE_0:
20806: varindex.append("0");
20807: t.append("double");
20808: return true;
20809: case JvmOpCodes.FSTORE_0:
20810: varindex.append("0");
20811: t.append("float");
20812: return true;
20813: case JvmOpCodes.ISTORE_0:
20814: varindex.append("0");
20815: t.append("int");
20816: return true;
20817: case JvmOpCodes.LSTORE_0:
20818: varindex.append("0");
20819: t.append("long");
20820: return true;
20821:
20822: case JvmOpCodes.ASTORE_1:
20823: varindex.append("1");
20824: t.append("java.lang.Object");
20825: return true;
20826: case JvmOpCodes.DSTORE_1:
20827: varindex.append("1");
20828: t.append("double");
20829: return true;
20830: case JvmOpCodes.FSTORE_1:
20831: varindex.append("1");
20832: t.append("float");
20833: return true;
20834: case JvmOpCodes.ISTORE_1:
20835: varindex.append("1");
20836: t.append("int");
20837: return true;
20838: case JvmOpCodes.LSTORE_1:
20839: varindex.append("1");
20840: t.append("long");
20841: return true;
20842:
20843: case JvmOpCodes.ASTORE_2:
20844: varindex.append("2");
20845: t.append("java.lang.Object");
20846: return true;
20847: case JvmOpCodes.DSTORE_2:
20848: varindex.append("2");
20849: t.append("double");
20850: return true;
20851: case JvmOpCodes.FSTORE_2:
20852: varindex.append("2");
20853: t.append("float");
20854: return true;
20855: case JvmOpCodes.ISTORE_2:
20856: varindex.append("2");
20857: t.append("int");
20858: return true;
20859: case JvmOpCodes.LSTORE_2:
20860: varindex.append("2");
20861: t.append("long");
20862: return true;
20863:
20864: case JvmOpCodes.ASTORE_3:
20865: varindex.append("3");
20866: t.append("java.lang.Object");
20867: return true;
20868: case JvmOpCodes.DSTORE_3:
20869: varindex.append("3");
20870: t.append("double");
20871: return true;
20872: case JvmOpCodes.FSTORE_3:
20873: varindex.append("3");
20874: t.append("float");
20875: return true;
20876: case JvmOpCodes.ISTORE_3:
20877: varindex.append("3");
20878: t.append("int");
20879: return true;
20880: case JvmOpCodes.LSTORE_3:
20881: varindex.append("3");
20882: t.append("long");
20883: return true;
20884:
20885: default:
20886: return false;
20887:
20888: }
20889:
20890: }
20891:
20892: private boolean doNotPop = false;
20893:
20894: private void handleComplexAStore(byte[] info, int i) {
20895: int instructionPos = i;
20896: ArrayList methodTries = behaviour.getAllTriesForMethod();
20897: int classIndex = info[++i];
20898: boolean add = checkForStartOfCatch(instructionPos, methodTries);
20899:
20900: //
20901: java.lang.String t = "Instruction Pos " + currentForIndex
20902: + "\t:- " + "astore " + classIndex;
20903: LocalVariable local = null;
20904: if (cd.isClassCompiledWithMinusG()) {
20905: local = getLocalVariable(classIndex, "store",
20906: "java.lang.Object", false, currentForIndex);
20907: if (local != null) {
20908: t += " THIS localvariable :- " + local.getVarName();
20909: }
20910: }
20911: t += "\n";
20912: addParsedOutput(t);
20913: if (add == true && !doNotPop) {
20914:
20915: //local=getLocalVariable(classIndex,"store","java.lang.Object",false,currentForIndex);
20916: if (local != null) {
20917: prevLocalGenerated = local;
20918: // temp has new <Class Name>[<size>]
20919: boolean push = isPrevInstDup(info, currentForIndex);
20920: if (!push) {
20921: Operand objref = (Operand) opStack.pop(); // Pop The Object Ref
20922: if (local.wasCreated()
20923: && objref != null
20924: && objref.getClassType().trim().length() > 0)
20925: local.setDataType(objref.getClassType());
20926: java.lang.String temp = (java.lang.String) objref
20927: .getOperandValue();
20928: if (!local.isDeclarationGenerated()) {
20929: local.setBlockIndex(i - 1);
20930: if (!multinewound) {
20931: StringBuffer m = new StringBuffer("");
20932: checkForImport(local.getDataType().replace(
20933: '/', '.'), m);
20934: temp = m + " " + local.getVarName() + "="
20935: + temp; // This shbud contain the actual Line in the method
20936: } else {
20937: multinewound = false;
20938: if (variableDimAss != null) {
20939: Integer n = (Integer) variableDimAss
20940: .get(new Integer(classIndex));
20941: java.lang.String bracks = "";
20942: if (n != null) {
20943: for (int o = 0; o < n.intValue(); o++) {
20944: bracks += "[]";
20945: }
20946: }
20947: StringBuffer m = new StringBuffer("");
20948: checkForImport(local.getDataType()
20949: .replace('/', '.'), m);
20950: temp = m + " " + bracks + " "
20951: + local.getVarName() + "="
20952: + temp;
20953: } else {
20954: // TODO: IMPORTANT FIXME
20955: temp = local.getDataType().replace('/',
20956: '.')
20957: + " "
20958: + " "
20959: + local.getVarName()
20960: + "="
20961: + temp;
20962: }
20963: }
20964: local.setDeclarationGenerated(true);
20965: //codeStatements += Util.formatDecompiledStatement(temp);
20966: //codeStatements += ";\n";
20967: } else {
20968: temp = " " + local.getVarName() + " =" + temp; // This shbud contain the actual Line in the method
20969: //codeStatements += Util.formatDecompiledStatement(temp);
20970: //codeStatements += ";\n";
20971: }
20972: } else {
20973:
20974: Operand top = opStack.getTopOfStack();
20975: opStack.getTopOfStack();
20976: if (local.wasCreated() && top != null
20977: && top.getClassType().trim().length() > 0)
20978: local.setDataType(top.getClassType());
20979: java.lang.String temp = top.getOperandValue();
20980: temp = local.getVarName() + " =" + "(" + temp + ")";
20981: //codeStatements += Util.formatDecompiledStatement(temp);
20982: Operand op6 = createOperand(local.getVarName());
20983: opStack.push(op6);
20984: }
20985:
20986: }
20987:
20988: }
20989:
20990: if (doNotPop == true)
20991: doNotPop = false;
20992: }
20993:
20994: private boolean isMethodRetBoolean(Behaviour b) {
20995:
20996: java.lang.String type = b.getReturnType();
20997: if (type.equals("boolean"))
20998: return true;
20999: return false;
21000:
21001: }
21002:
21003: private void handleSimpleASTORECase(int i, int index) {
21004: int instructionPos = i;
21005: ArrayList methodTries = behaviour.getAllTriesForMethod();
21006: byte[] info = behaviour.getCode();
21007: java.lang.String t = "Instruction Pos " + currentForIndex
21008: + "\t:- " + "astore_" + index;
21009: LocalVariable local = getLocalVariable(index, "store",
21010: "java.lang.Object", true, currentForIndex);
21011: if (cd.isClassCompiledWithMinusG()) {
21012: local = getLocalVariable(index, "store",
21013: "java.lang.Object", false, currentForIndex);
21014: if (local != null) {
21015: t += " THIS localvariable :- " + local.getVarName();
21016: }
21017: }
21018: t += "\n";
21019: addParsedOutput(t);
21020: boolean add = checkForStartOfCatch(instructionPos, methodTries);
21021: if (add == true && !doNotPop) {
21022:
21023: if (local != null) {
21024: prevLocalGenerated = local;
21025:
21026: boolean push = isPrevInstDup(info, currentForIndex);
21027: if (!push) {
21028: Operand objref = (Operand) opStack.pop(); // Pop The Object Ref
21029:
21030: if (local.wasCreated()
21031: && objref != null
21032: && objref.getClassType().trim().length() > 0)
21033: local.setDataType(objref.getClassType());
21034: java.lang.String temp = (java.lang.String) objref
21035: .getOperandValue(); // temp has new <Class Name>[<size>]
21036: if (!local.isDeclarationGenerated()) {
21037: local.setBlockIndex(blockLevel);
21038: //temp=local.getDataType().replace('/','.')+" "+local.getVarName()+" ="+temp; // This shbud contain the actual Line in the method
21039: if (!multinewound) {
21040: StringBuffer m = new StringBuffer("");
21041: checkForImport(local.getDataType().replace(
21042: '/', '.'), m);
21043: temp = m.toString() + " "
21044: + local.getVarName() + "=" + temp; // This shbud contain the actual Line in the method
21045: } else {
21046: multinewound = false;
21047: Integer n = (Integer) variableDimAss
21048: .get(new Integer(0));
21049: java.lang.String bracks = "";
21050: if (n != null) {
21051: for (int o = 0; o < n.intValue(); o++) {
21052: bracks += "[]";
21053: }
21054: }
21055: StringBuffer m = new StringBuffer("");
21056: checkForImport(local.getDataType().replace(
21057: '/', '.'), m);
21058: temp = m.toString() + " " + bracks + " "
21059: + local.getVarName() + "=" + temp;
21060:
21061: }
21062: //codeStatements += Util.formatDecompiledStatement(temp);
21063:
21064: //codeStatements += ";\n";
21065: local.setDeclarationGenerated(true);
21066: } else {
21067: temp = " " + local.getVarName() + " =" + temp;
21068: //codeStatements += Util.formatDecompiledStatement(temp);
21069:
21070: //codeStatements += ";\n";
21071: }
21072: } else {
21073: Operand top = opStack.getTopOfStack();
21074: opStack.getTopOfStack();
21075: java.lang.String temp = top.getOperandValue();
21076: temp = local.getVarName() + " =" + temp + ";\n";
21077: if (local.wasCreated() && top != null
21078: && top.getClassType().trim().length() > 0)
21079: local.setDataType(top.getClassType());
21080: //codeStatements += Util.formatDecompiledStatement(temp);
21081: Operand op6 = createOperand(local.getVarName());//"("+local.getVarName()+"=("+op.getOperandValue()+"))");
21082: opStack.push(op6);
21083: }
21084:
21085: }
21086:
21087: }
21088: if (doNotPop == true)
21089: doNotPop = false;
21090: }
21091:
21092: private boolean isThisInstASTOREInst(byte[] info, int pos,
21093: StringBuffer sb) {
21094:
21095: if (isThisInstrStart(behaviour.getInstructionStartPositions(),
21096: pos)) {
21097: if (info[pos] == JvmOpCodes.ASTORE) {
21098: sb.append(info[(pos + 1)]);
21099: return true;
21100: }
21101: if (info[pos] == JvmOpCodes.ASTORE_0) {
21102: sb.append(0);
21103: return true;
21104:
21105: }
21106: if (info[pos] == JvmOpCodes.ASTORE_1) {
21107: sb.append(1);
21108: return true;
21109: }
21110: if (info[pos] == JvmOpCodes.ASTORE_2) {
21111: sb.append(2);
21112: return true;
21113:
21114: }
21115: if (info[pos] == JvmOpCodes.ASTORE_3) {
21116: sb.append(3);
21117: return true;
21118:
21119: }
21120: }
21121: return false;
21122:
21123: }
21124:
21125: private boolean isPrevInstALOADInst(byte[] info, int pos,
21126: StringBuffer s) {
21127: if (isThisInstrStart(behaviour.getInstructionStartPositions(),
21128: (pos - 1))) {
21129:
21130: switch (info[(pos - 1)]) {
21131:
21132: case JvmOpCodes.ALOAD_0:
21133: s.append(0);
21134: return true;
21135:
21136: case JvmOpCodes.ALOAD_1:
21137: s.append(1);
21138: return true;
21139:
21140: case JvmOpCodes.ALOAD_2:
21141: s.append(2);
21142: return true;
21143:
21144: case JvmOpCodes.ALOAD_3:
21145: s.append(3);
21146: return true;
21147:
21148: }
21149:
21150: }
21151: if (isThisInstrStart(behaviour.getInstructionStartPositions(),
21152: (pos - 2))) {
21153:
21154: switch (info[(pos - 2)]) {
21155: case JvmOpCodes.ALOAD:
21156: s.append(info[(pos - 2 + 1)]);
21157: return true;
21158:
21159: }
21160: }
21161: return false;
21162: }
21163:
21164: private boolean checkForMatchingLoopAgain(ArrayList loops,
21165: int start, StringBuffer S) {
21166: boolean b = false;
21167: if (loops == null || loops.size() == 0)
21168: return b;
21169: else {
21170: for (int s = 0; s < loops.size(); s++) {
21171: Loop l = (Loop) loops.get(s);
21172: int loopstart = l.getStartIndex();
21173: if (loopstart == start) {
21174: b = true;
21175: S.append(l.getEndIndex());
21176: return b;
21177: }
21178:
21179: }
21180: }
21181: return b;
21182: }
21183:
21184: private int getClosestLoopEndForThisIf(int s, ArrayList loops,
21185: byte[] info)
21186:
21187: {
21188:
21189: int end = -1;
21190: if (loops == null || loops.size() == 0)
21191: return end;
21192: int gotos = s + 3;
21193: if (info[gotos] == JvmOpCodes.GOTO
21194: && isThisInstrStart(behaviour
21195: .getInstructionStartPositions(), gotos)) {
21196: int gotoj = getJumpAddress(info, gotos);
21197: int starts[] = new int[loops.size()];
21198: for (int z = 0; z < loops.size(); z++) {
21199: starts[z] = ((Loop) loops.get(z)).getEndIndex();
21200: }
21201: Arrays.sort(starts);
21202: int reqdloopend = -1;
21203: for (int x = starts.length - 1; x >= 0; x--) {
21204: int cur = starts[x];
21205: if (gotoj > cur) {
21206: reqdloopend = cur;
21207: break;
21208: }
21209: }
21210:
21211: if (reqdloopend != -1) {
21212: int lstart = getLoopStartForEnd(reqdloopend, loops);
21213: if (lstart < s) {
21214: return reqdloopend;
21215: }
21216: } else {
21217: return -1;
21218: }
21219:
21220: }
21221:
21222: return end;
21223: }
21224:
21225: private int checkElseCloseWRTAnyParentLoop(IFBlock ifs,
21226: int gotostart, byte[] info) {
21227:
21228: ArrayList allloops = behaviour.getBehaviourLoops();
21229: if (allloops == null || allloops.size() == 0)
21230: return -1;
21231: int gotojump = getJumpAddress(info, gotostart);
21232: Object[] sortedLoops = sortLoops(allloops);
21233:
21234: for (int k = 0; k < sortedLoops.length; k++) {
21235: Loop cur = (Loop) sortedLoops[k];
21236: if (cur.getStartIndex() == gotojump) {
21237: int parentLoopStart = getParentLoopStartForIf(
21238: sortedLoops, ifs.getIfStart());
21239: if (parentLoopStart == gotojump) {
21240: int loopend = getloopEndForStart(allloops,
21241: parentLoopStart);
21242: return loopend;
21243:
21244: }
21245: }
21246: }
21247: return -1;
21248: }
21249:
21250: private boolean isPreviousInst(byte[] info, int current, int lookfor) {
21251:
21252: ArrayList starts = behaviour.getInstructionStartPositions();
21253: if (list == null || list.size() == 0)
21254: return false;
21255: for (int s = current - 1; s >= 0; s--) {
21256: boolean ok = isThisInstrStart(starts, s);
21257: if (ok) {
21258: if (s == lookfor) {
21259: return true;
21260: }
21261: return false;
21262: }
21263: }
21264:
21265: return false;
21266: }
21267:
21268: public boolean addCodeStatementWRTShortcutOR(IFBlock ifst,
21269: java.lang.String s, boolean print, java.lang.String ifw,
21270: boolean last, java.lang.String alt) {
21271: if (!print)
21272: return true;
21273: boolean add = true;
21274: int current = currentForIndex;
21275: byte[] code = behaviour.getCode();
21276: java.lang.String str = "\nif(";
21277: if (ifw.equals("while")) {
21278: str = "\nwhile(";
21279: }
21280: java.lang.String string = "";
21281: if (last) {
21282: if (isInstAnyCMPInst(code, current - 1) == false) {
21283: string = alt;
21284: } else
21285: string = s;
21286: } else
21287: string = s;
21288:
21289: string = "(" + string + ")";
21290: if (encounteredOrComp == false) {
21291:
21292: int jump = getJumpAddress(code, current);
21293: int i = jump - 3;
21294: if (jump > current
21295: && i > 0
21296: && isThisInstrStart(behaviour
21297: .getInstructionStartPositions(), i)
21298: && isInstructionIF(code[i])) {
21299: encounteredOrComp = true;
21300: //codeStatements+=Util.formatDecompiledStatement(str+string+" || ");
21301: return false;
21302: } else if (jump < current) {
21303: int close = ifst.getIfCloseLineNumber();
21304: int x = close - 3;
21305: if (x > 0
21306: && isThisInstrStart(behaviour
21307: .getInstructionStartPositions(), x)
21308: && isInstructionIF(code[x])) {
21309: encounteredOrComp = true;
21310: //codeStatements+=Util.formatDecompiledStatement(str+string+" || ");
21311: return false;
21312: } else {
21313: return true;
21314: }
21315: } else {
21316: return true;
21317: }
21318:
21319: } else {
21320:
21321: // codes
21322: //codeStatements+=Util.formatDecompiledStatement(string);
21323: int jump = getJumpAddress(code, current);
21324: int i = jump - 3;
21325:
21326: if (jump > current
21327: && i > 0
21328: && isThisInstrStart(behaviour
21329: .getInstructionStartPositions(), i)
21330: && isInstructionIF(code[i])) {
21331: encounteredOrComp = true;
21332: //codes
21333: //codeStatements+=" || ";
21334: return false;
21335: } else if (jump < current) { //BigInteger
21336: int close = ifst.getIfCloseLineNumber();
21337: int x = close - 3;
21338: if (x > 0
21339: && isThisInstrStart(behaviour
21340: .getInstructionStartPositions(), x)
21341: && isInstructionIF(code[x])) {
21342: encounteredOrComp = true;
21343: //codes
21344: //codeStatements+=" || ";
21345: return false;
21346: } else {
21347: //codeStatements+=Util.formatDecompiledStatement(")\n{\n");
21348: encounteredOrComp = false;
21349: return false;
21350: }
21351: } else {
21352: //codeStatements+=Util.formatDecompiledStatement(")\n{\n");
21353: encounteredOrComp = false;
21354: return false;
21355: }
21356:
21357: }
21358:
21359: }
21360:
21361: private boolean isInstructionIF(int instruction) {
21362:
21363: switch (instruction) {
21364:
21365: case JvmOpCodes.IF_ACMPEQ:
21366: return true;
21367: case JvmOpCodes.IF_ACMPNE:
21368: return true;
21369: case JvmOpCodes.IF_ICMPEQ:
21370: return true;
21371: case JvmOpCodes.IF_ICMPGE:
21372: return true;
21373: case JvmOpCodes.IF_ICMPGT:
21374: return true;
21375: case JvmOpCodes.IF_ICMPLE:
21376: return true;
21377: case JvmOpCodes.IF_ICMPLT:
21378: return true;
21379: case JvmOpCodes.IF_ICMPNE:
21380: return true;
21381:
21382: case JvmOpCodes.IFEQ:
21383: return true;
21384: case JvmOpCodes.IFGE:
21385: return true;
21386: case JvmOpCodes.IFGT:
21387: return true;
21388: case JvmOpCodes.IFLE:
21389: return true;
21390: case JvmOpCodes.IFNE:
21391: return true;
21392: case JvmOpCodes.IFLT:
21393: return true;
21394: case JvmOpCodes.IFNULL:
21395: return true;
21396: case JvmOpCodes.IFNONNULL:
21397: return true;
21398: default:
21399: return false;
21400:
21401: }
21402:
21403: }
21404:
21405: private boolean encounteredOrComp = false;
21406:
21407: private HashMap athrowmap = new HashMap();
21408:
21409: private void checkForATHROWAtIFelseEnd(IFBlock ifst,
21410: StringBuffer ifelsecode, int i) {
21411: boolean start = isThisInstrStart(behaviour
21412: .getInstructionStartPositions(), i);
21413: byte[] info = behaviour.getCode();
21414: if (start && info[i] == JvmOpCodes.ATHROW) {
21415: boolean x = addATHROWOutput(i);
21416: if (opStack.size() > 0 && x) {
21417: Operand op = (Operand) opStack.pop();
21418: opStack.push(op);
21419: java.lang.String tempString = "throw "
21420: + op.getOperandValue() + ";\n";
21421: ifelsecode.append(Util.formatDecompiledStatement("\n"
21422: + tempString + "\n"));
21423: athrowmap.put(new Integer(i), "true");
21424: }
21425:
21426: }
21427:
21428: }
21429:
21430: private boolean addATHROWOutput(int i) {
21431: if (athrowmap.size() == 0)
21432: return true;
21433: Set entries = athrowmap.entrySet();
21434: Iterator it = entries.iterator();
21435: while (it.hasNext()) {
21436: Map.Entry entry = (Map.Entry) it.next();
21437: Integer pos = (Integer) entry.getKey();
21438: if (pos.intValue() == i) {
21439: java.lang.String str = (java.lang.String) entry
21440: .getValue();
21441: if (str.equals("true")) {
21442: return false;
21443: }
21444: }
21445: }
21446:
21447: return true;
21448:
21449: }
21450:
21451: private void handleBALOAD(OperandStack stack) {
21452: addParsedOutput("Instruction Pos " + currentForIndex + "\t:- "
21453: + " baload\n");
21454: Operand op = (Operand) stack.pop();
21455: Operand op1 = (Operand) stack.pop();
21456: Operand op2 = new Operand();
21457: op2.setOperandValue(op1.getOperandValue() + "["
21458: + op.getOperandValue() + "]");
21459: stack.push(op2);
21460: }
21461:
21462: private void handleBASTORE(OperandStack stack) {
21463: Operand op = (Operand) stack.pop();
21464: Operand op1 = (Operand) stack.pop();
21465: Operand op2 = (Operand) opStack.pop();
21466: //parsedString += "BASTORE\n";
21467: //parsedString+="\t";parsedString+="\t";
21468: java.lang.String tempString = op2.getOperandValue() + "["
21469: + op1.getOperandValue() + "]=" + op.getOperandValue()
21470: + ";\n";
21471: //codeStatements+=Util.formatDecompiledStatement(tempString);
21472: }
21473:
21474: private void handleCALOAD(OperandStack stack) {
21475: Operand op = (Operand) stack.pop();
21476: Operand op1 = (Operand) stack.pop();
21477: Operand op2 = createOperand(op1.getOperandValue() + "["
21478: + op.getOperandValue() + "]",
21479: Constants.IS_CONSTANT_CHARACTER, Constants.CATEGORY1);
21480: stack.push(op2);
21481: }
21482:
21483: private void handleCASTORE(OperandStack stack) {
21484: Operand op = (Operand) stack.pop();
21485: Operand op1 = (Operand) opStack.pop();
21486: Operand op2 = (Operand) opStack.pop();
21487: java.lang.String tempString = op2.getOperandValue() + "["
21488: + op1.getOperandValue() + "]=" + op.getOperandValue()
21489: + ";\n";
21490: ;
21491: //codeStatements+=Util.formatDecompiledStatement(tempString);
21492: }
21493:
21494: private void handleCheckCast(OperandStack stack, byte[] info) {
21495: java.lang.String t = "Instruction Pos " + currentForIndex
21496: + "\t:- " + " checkcast";
21497: addParsedOutput(t);
21498: int i = currentForIndex;
21499: Operand op = (Operand) stack.pop();
21500: int classIndex = getOffset(info, i);
21501: ClassInfo cinfo = cd.getClassInfoAtCPoolPosition(classIndex);
21502: Object o = op.getOperandValue();
21503: op = new Operand();
21504: java.lang.String castedRef = "("
21505: + cd.getUTF8String(cinfo.getUtf8pointer()).replace('/',
21506: '.') + ")" + o.toString();
21507: op.setOperandValue(castedRef);
21508: opStack.push(op);
21509: addParsedOutput(castedRef + "\n");
21510: }
21511:
21512: private void handleDALOAD(OperandStack stack) {
21513: Operand op = (Operand) stack.pop();
21514: Operand op1 = (Operand) stack.pop();
21515: Operand op2 = new Operand();
21516: op2.setOperandValue(op1.getOperandValue() + "["
21517: + op.getOperandValue() + "]");
21518: //op2.setCategory(Constants.IS_CONSTANT_DOUBLE);
21519: stack.push(op2);
21520: }
21521:
21522: private void handleDASTORE(OperandStack stack) {
21523: Operand op = (Operand) stack.pop();
21524: Operand op1 = (Operand) stack.pop();
21525: Operand op2 = (Operand) stack.pop();
21526: java.lang.String tempString = op2.getOperandValue() + "["
21527: + op1.getOperandValue() + "]=" + op.getOperandValue()
21528: + ";\n";
21529: //codeStatements+=Util.formatDecompiledStatement(tempString);
21530: }
21531:
21532: private void handleDCONST(OperandStack stack, double val) {
21533: Operand op = new Operand();
21534: java.lang.String str = "" + val;
21535: op.setOperandValue(new Double(str));
21536: op.setOperandType(Constants.IS_CONSTANT_DOUBLE);
21537: //(Constants.CATEGORY2);
21538: stack.push(op);
21539: }
21540:
21541: private void handleDDIV(OperandStack stack) {
21542: Operand op = (Operand) stack.pop();
21543: Operand op1 = (Operand) stack.pop();
21544: Operand op2 = new Operand();
21545: op2.setOperandValue("(" + op1.getOperandValue() + "/"
21546: + op.getOperandValue() + ")");
21547:
21548: //op2.setCategory(Constants.CATEGORY2);
21549: stack.push(op2);
21550: }
21551:
21552: private void handleDLOADCase(int in, OperandStack stack, boolean b) {
21553:
21554: LocalVariable local = getLocalVariable(in, "load", "double", b,
21555: currentForIndex);
21556: if (local != null) {
21557: prevLocalGenerated = local;
21558: Operand op = new Operand();
21559: op.setOperandValue(local.getVarName());
21560: stack.push(op);
21561: if (cd.isClassCompiledWithMinusG() && local != null) {
21562: addParsedOutput(" THIS LocalVariable "
21563: + local.getVarName() + "\n");
21564: }
21565: }
21566: }
21567:
21568: private void handleDMUL(OperandStack stack) {
21569: Operand op = (Operand) stack.pop();
21570: Operand op1 = (Operand) stack.pop();
21571:
21572: Operand op2 = new Operand();
21573: op2.setOperandValue("(" + op.getOperandValue() + "*"
21574: + op1.getOperandValue() + ")");
21575:
21576: //op2.setCategory(Constants.CATEGORY1);
21577: stack.push(op2);
21578: }
21579:
21580: private void handleDNEG(OperandStack stack) {
21581: Operand op = (Operand) stack.pop();
21582:
21583: Operand op1 = new Operand();
21584: // op1.setCategory(Constants.CATEGORY1);
21585:
21586: op1.setOperandValue("-" + "(" + op.getOperandValue() + ")");
21587: stack.push(op1);
21588: }
21589:
21590: private void handleDREM(OperandStack stack) {
21591: Operand op = (Operand) stack.pop();
21592: Operand op1 = (Operand) stack.pop();
21593:
21594: Operand op2 = new Operand();
21595: // op2.setCategory(Constants.CATEGORY1);
21596:
21597: op2.setOperandValue("(" + op.getOperandValue() + " % "
21598: + op1.getOperandValue() + ")");
21599: stack.push(op2);
21600: }
21601:
21602: private void handleDUP2X2(OperandStack stack) {
21603: Operand op1 = (Operand) stack.pop();
21604: Operand op2 = (Operand) stack.pop();
21605: Operand op3 = (Operand) stack.pop();
21606: Operand op4 = (Operand) stack.pop();
21607:
21608: stack.push(op2);
21609: stack.push(op1);
21610: stack.push(op4);
21611: stack.push(op3);
21612: stack.push(op2);
21613: stack.push(op1);
21614: }
21615:
21616: private void handleFCONST(OperandStack stack, java.lang.String val) {
21617: Operand op = new Operand();
21618: op.setOperandValue(new Float(val));
21619:
21620: stack.push(op);
21621: }
21622:
21623: private void handleFDIV(OperandStack stack) {
21624: Operand op = (Operand) stack.pop();
21625: Operand op1 = (Operand) stack.pop();
21626:
21627: Operand op2 = new Operand();
21628: op2.setOperandValue("(" + op.getOperandValue() + " / " + ""
21629: + op1.getOperandValue() + ")");
21630: stack.push(op2);
21631:
21632: }
21633:
21634: private void handleFLOAD(int opValueI, OperandStack stack, boolean b) {
21635: addParsedOutput("Instruction Pos " + currentForIndex + "\t:- "
21636: + " fload " + opValueI + "\n");
21637: LocalVariable local = getLocalVariable(opValueI, "load",
21638: "float", b, currentForIndex);
21639:
21640: if (local != null && local != null) {
21641: addParsedOutput(" THIS LocalVariable :- "
21642: + local.getVarName());
21643: Operand op = new Operand();
21644: op.setOperandValue(local.getVarName());
21645: stack.push(op);
21646: }
21647: }
21648:
21649: private boolean isIFShortcutORComp(byte[] info, int j) {
21650:
21651: if (isThisInstrStart(behaviour.getInstructionStartPositions(),
21652: j)) {
21653: int jump = getJumpAddress(info, j);
21654: int k = jump - 3;
21655: if (isThisInstrStart(behaviour
21656: .getInstructionStartPositions(), k)
21657: && jump > j) {
21658: boolean b = isInstructionIF(info[k]);
21659: if (b) {
21660: return true;
21661: }
21662: }
21663:
21664: }
21665:
21666: return false;
21667: }
21668:
21669: private void handleLCONST(OperandStack stack, java.lang.String str) {
21670: Operand op = new Operand();
21671: op.setOperandValue(new Long(str));
21672: op.setOperandType(Constants.IS_CONSTANT_LONG);
21673: //(Constants.CATEGORY2);
21674: stack.push(op);
21675: }
21676:
21677: private void handleLDIV(OperandStack stack) {
21678: Operand operand1 = stack.getTopOfStack();
21679: Operand operand2 = stack.getTopOfStack();
21680: java.lang.String result = "(" + operand1.getOperandValue()
21681: + "/" + operand2.getOperandValue() + ")";
21682: Operand op = new Operand();
21683: op.setOperandValue(result);
21684: op.setOperandType(Constants.IS_CONSTANT_LONG);
21685: //(Constants.CATEGORY2);
21686: stack.push(op);
21687: }
21688:
21689: private void handleSIMPLELLOAD(OperandStack stack, int index) {
21690: LocalVariable local = getLocalVariable(index, "load", "long",
21691: true, currentForIndex);
21692: if (local != null && cd.isClassCompiledWithMinusG()) {
21693: addParsedOutput("Instruction Pos " + currentForIndex
21694: + "\t:- " + "lload_" + index
21695: + " THIS LocalVariable:- " + local.getVarName()
21696: + "\n");
21697: } else {
21698: addParsedOutput("Instruction Pos " + currentForIndex
21699: + "\t:- " + "lload_" + index + "\n");
21700: }
21701: if (local != null) {
21702:
21703: Operand op = new Operand();
21704: op.setOperandType(Constants.IS_CONSTANT_LONG);
21705: //(Constants.CATEGORY2);
21706: op.setOperandValue(local.getVarName());
21707: stack.push(op);
21708:
21709: }
21710: }
21711:
21712: private void handleDCMPG(OperandStack stack, byte[] info) {
21713: int i = currentForIndex;
21714: Operand op = (Operand) stack.pop();
21715: Operand op1 = (Operand) stack.pop();
21716: Operand op2 = new Operand();
21717: //op2.setCategory(Constants.CATEGORY1);
21718: //op2.setOperandType(Constants.IS_CONSTANT_INT);
21719: int j = i + 1;
21720: int nextInstruction = info[j];
21721: boolean sh = isIFShortcutORComp(info, j);
21722: if (!sh) {
21723: int ifclose = getIfCloseNumberForThisIF(info,
21724: (currentForIndex + 1));
21725: ifclose = ifclose - 3;
21726: if (isThisInstrStart(behaviour
21727: .getInstructionStartPositions(), ifclose)) {
21728: if (isInstructionIF(info[ifclose]) && ifclose != j) {
21729: sh = true;
21730: }
21731: }
21732:
21733: }
21734: switch (nextInstruction) {
21735: case JvmOpCodes.IFEQ:
21736: if (!sh)
21737: op2.setOperandValue(op1.getOperandValue() + "!="
21738: + op.getOperandValue());
21739: else
21740: op2.setOperandValue(op1.getOperandValue() + "=="
21741: + op.getOperandValue());
21742: break;
21743: case JvmOpCodes.IFNE:
21744: if (!sh)
21745: op2.setOperandValue(op1.getOperandValue() + "=="
21746: + op.getOperandValue());
21747: else
21748: op2.setOperandValue(op1.getOperandValue() + "!="
21749: + op.getOperandValue());
21750: break;
21751: case JvmOpCodes.IFLT:
21752: if (!sh)
21753: op2.setOperandValue(op1.getOperandValue() + ">="
21754: + op.getOperandValue());
21755: else
21756: op2.setOperandValue(op1.getOperandValue() + "<"
21757: + op.getOperandValue());
21758: break;
21759: case JvmOpCodes.IFGE:
21760: if (!sh)
21761: op2.setOperandValue(op1.getOperandValue() + "<"
21762: + op.getOperandValue());
21763: else
21764: op2.setOperandValue(op1.getOperandValue() + ">="
21765: + op.getOperandValue());
21766: break;
21767: case JvmOpCodes.IFGT:
21768: if (!sh)
21769: op2.setOperandValue(op1.getOperandValue() + "<="
21770: + op.getOperandValue());
21771: else
21772: op2.setOperandValue(op1.getOperandValue() + ">"
21773: + op.getOperandValue());
21774: break;
21775: case JvmOpCodes.IFLE:
21776: if (!sh)
21777: op2.setOperandValue(op1.getOperandValue() + ">"
21778: + op.getOperandValue());
21779: else
21780: op2.setOperandValue(op1.getOperandValue() + "<="
21781: + op.getOperandValue());
21782: break;
21783: }
21784: stack.push(op2);
21785: }
21786:
21787: private void handleDCMPL(OperandStack stack, byte[] info) {
21788: int i = currentForIndex;
21789: Operand op = (Operand) stack.pop();
21790: Operand op1 = (Operand) stack.pop();
21791: Operand op2 = new Operand();
21792: //op2.setCategory(Constants.CATEGORY1);
21793: op2.setOperandType(Constants.IS_CONSTANT_INT);
21794: int j = i + 1;
21795: int nextInstruction = info[j];
21796: boolean sh = isIFShortcutORComp(info, j);
21797: if (!sh) {
21798: int ifclose = getIfCloseNumberForThisIF(info,
21799: (currentForIndex + 1));
21800: ifclose = ifclose - 3;
21801: if (isThisInstrStart(behaviour
21802: .getInstructionStartPositions(), ifclose)) {
21803: if (isInstructionIF(info[ifclose]) && ifclose != j) {
21804: sh = true;
21805: }
21806: }
21807:
21808: }
21809: switch (nextInstruction) {
21810: case JvmOpCodes.IFEQ:
21811: if (!sh)
21812: op2.setOperandValue(op1.getOperandValue() + "!="
21813: + op.getOperandValue());
21814: else
21815: op2.setOperandValue(op1.getOperandValue() + "=="
21816: + op.getOperandValue());
21817: break;
21818: case JvmOpCodes.IFNE:
21819: if (!sh)
21820: op2.setOperandValue(op1.getOperandValue() + "=="
21821: + op.getOperandValue());
21822: else
21823: op2.setOperandValue(op1.getOperandValue() + "!="
21824: + op.getOperandValue());
21825: break;
21826: case JvmOpCodes.IFLT:
21827: if (!sh)
21828: op2.setOperandValue(op1.getOperandValue() + ">="
21829: + op.getOperandValue());
21830: else
21831: op2.setOperandValue(op1.getOperandValue() + "<"
21832: + op.getOperandValue());
21833: break;
21834: case JvmOpCodes.IFGE:
21835: if (!sh)
21836: op2.setOperandValue(op1.getOperandValue() + "<"
21837: + op.getOperandValue());
21838: else
21839: op2.setOperandValue(op1.getOperandValue() + ">="
21840: + op.getOperandValue());
21841: break;
21842: case JvmOpCodes.IFGT:
21843: if (!sh)
21844: op2.setOperandValue(op1.getOperandValue() + "<="
21845: + op.getOperandValue());
21846: else
21847: op2.setOperandValue(op1.getOperandValue() + ">"
21848: + op.getOperandValue());
21849: break;
21850:
21851: case JvmOpCodes.IFLE:
21852: if (!sh)
21853: op2.setOperandValue(op1.getOperandValue() + ">"
21854: + op.getOperandValue());
21855: else
21856: op2.setOperandValue(op1.getOperandValue() + "<="
21857: + op.getOperandValue());
21858: break;
21859: }
21860: stack.push(op2); // TODO: check whether it is ok to push the operand into switch loop
21861: }
21862:
21863: private boolean addRETURNatI(int i, IFBlock ifst) {
21864:
21865: /*byte[] info=behaviour.getCode();
21866:
21867: boolean shortcut=isIFShortcutORComp(info,ifst.getIfStart());
21868: if(shortcut)return true;
21869: int ifclose=ifst.getIfCloseLineNumber();
21870: int x=ifclose-3;
21871: if(isThisInstrStart(behaviour.getInstructionStratPositions(),x) && x!=ifst.getIfStart())
21872: {
21873: boolean isif=isInstructionIF(info[x]);
21874: if(isif)return true;
21875: } */
21876:
21877: boolean oktoadd = true;
21878: Iterator mapIT = returnsAtI.entrySet().iterator();
21879: while (mapIT.hasNext()) {
21880: Map.Entry entry = (Map.Entry) mapIT.next();
21881: Object key = entry.getKey();
21882: Object retStatus = entry.getValue().toString();
21883: if (key instanceof Integer) {
21884: Integer position = (Integer) key;
21885: int posValue = position.intValue();
21886: if (posValue == i) {
21887: if (retStatus.equals("true")) {
21888:
21889: oktoadd = false;
21890: break;
21891: }
21892: }
21893: }
21894:
21895: }
21896: return oktoadd;
21897: }
21898:
21899: private boolean lastIFinShortCutChain(byte[] info, IFBlock ifst,
21900: int i) {
21901:
21902: int jump = getJumpAddress(info, i);
21903: if (jump > i) {
21904:
21905: int x = jump - 3;
21906: if (isInstructionIF(info[x])) {
21907: return false;
21908: }
21909: return true;
21910: } else {
21911: int x = ifst.getIfCloseLineNumber();
21912:
21913: int y = x - 3;
21914: if (isInstructionIF(info[y])) {
21915: return false;
21916: }
21917: return true;
21918:
21919: }
21920:
21921: }
21922:
21923: private boolean isInstAnyCMPInst(byte[] info, int i) {
21924: ArrayList starts = behaviour.getInstructionStartPositions();
21925: if (isThisInstrStart(starts, i)) {
21926: switch (info[i]) {
21927: case JvmOpCodes.DCMPG:
21928: case JvmOpCodes.DCMPL:
21929: case JvmOpCodes.FCMPG:
21930: case JvmOpCodes.FCMPL:
21931: case JvmOpCodes.LCMP:
21932: return true;
21933: }
21934: }
21935: return false;
21936: }
21937:
21938: private void handleFCMPG(OperandStack stack, byte[] info) {
21939: int i = currentForIndex;
21940: Operand op = (Operand) stack.pop();
21941: Operand op1 = (Operand) stack.pop();
21942: Operand op2 = new Operand();
21943: //op2.setCategory(Constants.CATEGORY1);
21944: op2.setOperandType(Constants.IS_CONSTANT_INT);
21945: int j = i + 1;
21946: int nextInstruction = info[j];
21947: boolean sh = isIFShortcutORComp(info, j);
21948: if (!sh) {
21949: int ifclose = getIfCloseNumberForThisIF(info,
21950: (currentForIndex + 1));
21951: ifclose = ifclose - 3;
21952: if (isThisInstrStart(behaviour
21953: .getInstructionStartPositions(), ifclose)) {
21954: if (isInstructionIF(info[ifclose]) && ifclose != j) {
21955: sh = true;
21956: }
21957: }
21958:
21959: }
21960: switch (nextInstruction) {
21961: case JvmOpCodes.IFEQ:
21962: if (!sh)
21963: op2.setOperandValue(op1.getOperandValue() + "!="
21964: + op.getOperandValue());
21965: else
21966: op2.setOperandValue(op1.getOperandValue() + "=="
21967: + op.getOperandValue());
21968: break;
21969: case JvmOpCodes.IFNE:
21970: if (!sh)
21971: op2.setOperandValue(op1.getOperandValue() + "=="
21972: + op.getOperandValue());
21973: else
21974: op2.setOperandValue(op1.getOperandValue() + "!="
21975: + op.getOperandValue());
21976: break;
21977: case JvmOpCodes.IFLT:
21978: if (!sh)
21979: op2.setOperandValue(op1.getOperandValue() + ">="
21980: + op.getOperandValue());
21981: else
21982: op2.setOperandValue(op1.getOperandValue() + "<"
21983: + op.getOperandValue());
21984: break;
21985: case JvmOpCodes.IFGE:
21986: if (!sh)
21987: op2.setOperandValue(op1.getOperandValue() + "<"
21988: + op.getOperandValue());
21989: else
21990: op2.setOperandValue(op1.getOperandValue() + ">="
21991: + op.getOperandValue());
21992: break;
21993: case JvmOpCodes.IFGT:
21994: if (!sh)
21995: op2.setOperandValue(op1.getOperandValue() + "<="
21996: + op.getOperandValue());
21997: else
21998: op2.setOperandValue(op1.getOperandValue() + ">"
21999: + op.getOperandValue());
22000: break;
22001: case JvmOpCodes.IFLE:
22002: if (!sh)
22003: op2.setOperandValue(op1.getOperandValue() + ">"
22004: + op.getOperandValue());
22005: else
22006: op2.setOperandValue(op1.getOperandValue() + "<="
22007: + op.getOperandValue());
22008: break;
22009: }
22010:
22011: stack.push(op2);
22012: }
22013:
22014: private void handleFCMPL(OperandStack stack, byte[] info) {
22015: int i = currentForIndex;
22016: Operand op = (Operand) stack.pop();
22017: Operand op1 = (Operand) stack.pop();
22018: Operand op2 = new Operand();
22019: // op2.setCategory(Constants.CATEGORY1);
22020: op2.setOperandType(Constants.IS_CONSTANT_INT);
22021: int j = i + 1;
22022: int nextInstruction = info[j];
22023: boolean sh = isIFShortcutORComp(info, j);
22024: if (!sh) {
22025: int ifclose = getIfCloseNumberForThisIF(info,
22026: (currentForIndex + 1));
22027: ifclose = ifclose - 3;
22028: if (isThisInstrStart(behaviour
22029: .getInstructionStartPositions(), ifclose)) {
22030: if (isInstructionIF(info[ifclose]) && ifclose != j) {
22031: sh = true;
22032: }
22033: }
22034:
22035: }
22036: switch (nextInstruction) {
22037: case JvmOpCodes.IFEQ:
22038: if (!sh)
22039: op2.setOperandValue(op1.getOperandValue() + "!="
22040: + op.getOperandValue());
22041: else
22042: op2.setOperandValue(op1.getOperandValue() + "=="
22043: + op.getOperandValue());
22044: break;
22045: case JvmOpCodes.IFNE:
22046: if (!sh)
22047: op2.setOperandValue(op1.getOperandValue() + "=="
22048: + op.getOperandValue());
22049: else
22050: op2.setOperandValue(op1.getOperandValue() + "!="
22051: + op.getOperandValue());
22052: break;
22053: case JvmOpCodes.IFLT:
22054: if (!sh)
22055: op2.setOperandValue(op1.getOperandValue() + ">="
22056: + op.getOperandValue());
22057: else
22058: op2.setOperandValue(op1.getOperandValue() + "<"
22059: + op.getOperandValue());
22060: break;
22061: case JvmOpCodes.IFGE:
22062: if (!sh)
22063: op2.setOperandValue(op1.getOperandValue() + "<"
22064: + op.getOperandValue());
22065: else
22066: op2.setOperandValue(op1.getOperandValue() + ">="
22067: + op.getOperandValue());
22068: break;
22069: case JvmOpCodes.IFGT:
22070: if (!sh)
22071: op2.setOperandValue(op1.getOperandValue() + "<="
22072: + op.getOperandValue());
22073: else
22074: op2.setOperandValue(op1.getOperandValue() + ">"
22075: + op.getOperandValue());
22076: break;
22077: case JvmOpCodes.IFLE:
22078: if (!sh)
22079: op2.setOperandValue(op1.getOperandValue() + ">"
22080: + op.getOperandValue());
22081: else
22082: op2.setOperandValue(op1.getOperandValue() + "<="
22083: + op.getOperandValue());
22084: break;
22085: }
22086:
22087: stack.push(op2);
22088: }
22089:
22090: private void handleLCMP(OperandStack stack, byte[] info) {
22091: int i = currentForIndex;
22092: int j;
22093: Operand op = (Operand) stack.pop();
22094: Operand op1 = (Operand) stack.pop();
22095: Operand op2 = new Operand();
22096: op2.setCategory(Constants.CATEGORY1);
22097: op2.setOperandType(Constants.IS_CONSTANT_INT);
22098: j = i + 1;
22099: int nextInstruction = info[j];
22100: boolean sh = isIFShortcutORComp(info, j);
22101: if (!sh) {
22102: int ifclose = getIfCloseNumberForThisIF(info,
22103: (currentForIndex + 1));
22104: ifclose = ifclose - 3;
22105: if (isThisInstrStart(behaviour
22106: .getInstructionStartPositions(), ifclose)) {
22107: if (isInstructionIF(info[ifclose]) && ifclose != j) {
22108: sh = true;
22109: }
22110: }
22111:
22112: }
22113: switch (nextInstruction) {
22114: case JvmOpCodes.IFEQ:
22115: if (!sh)
22116: op2.setOperandValue(op1.getOperandValue() + "!="
22117: + op.getOperandValue());
22118: else
22119: op2.setOperandValue(op1.getOperandValue() + "=="
22120: + op.getOperandValue());
22121: break;
22122: case JvmOpCodes.IFNE:
22123: if (!sh)
22124: op2.setOperandValue(op1.getOperandValue() + "=="
22125: + op.getOperandValue());
22126: else
22127: op2.setOperandValue(op1.getOperandValue() + "!="
22128: + op.getOperandValue());
22129: break;
22130: case JvmOpCodes.IFLT:
22131: if (!sh)
22132: op2.setOperandValue(op1.getOperandValue() + ">="
22133: + op.getOperandValue());
22134: else
22135: op2.setOperandValue(op1.getOperandValue() + "<"
22136: + op.getOperandValue());
22137: break;
22138: case JvmOpCodes.IFGE:
22139: if (!sh)
22140: op2.setOperandValue(op1.getOperandValue() + "<"
22141: + op.getOperandValue());
22142: else
22143: op2.setOperandValue(op1.getOperandValue() + ">="
22144: + op.getOperandValue());
22145: break;
22146: case JvmOpCodes.IFGT:
22147: if (!sh)
22148: op2.setOperandValue(op1.getOperandValue() + "<="
22149: + op.getOperandValue());
22150: else
22151: op2.setOperandValue(op1.getOperandValue() + ">"
22152: + op.getOperandValue());
22153: break;
22154: case JvmOpCodes.IFLE:
22155: if (!sh)
22156: op2.setOperandValue(op1.getOperandValue() + ">"
22157: + op.getOperandValue());
22158: else
22159: op2.setOperandValue(op1.getOperandValue() + "<="
22160: + op.getOperandValue());
22161: break;
22162: }
22163:
22164: stack.push(op2);
22165: }
22166:
22167: private void handleISTORE(OperandStack stack, byte[] info,
22168: int classIndex, boolean b) {
22169: //java.net.URLStreamHandler u;
22170: LocalVariable local = getLocalVariable(classIndex, "store",
22171: "int", b, currentForIndex);
22172: if (cd.isClassCompiledWithMinusG() && local != null) {
22173: addParsedOutput(" THIS LocalVariable:- "
22174: + local.getVarName() + "\n");
22175: }
22176: if (local != null && !doNotPop) {
22177: Operand op = (Operand) stack.pop();
22178:
22179: if (local.getDataType().equalsIgnoreCase("boolean")) {
22180: if (op.getOperandValue().toString().equals("0")) {
22181: op.setOperandValue("false");
22182: }
22183: if (op.getOperandValue().toString().equals("1")) {
22184: op.setOperandValue("true");
22185: }
22186: }
22187: boolean push = isPrevInstDup(info, currentForIndex);
22188: if (!push) {
22189: if (!local.isDeclarationGenerated()) {
22190: local.setBlockIndex(blockLevel);
22191: java.lang.String tempString = "#REPLACE_INT_"
22192: + classIndex + "#" + local.getDataType()
22193: + "\t" + local.getVarName() + "="
22194: + "#VALUE" + classIndex + "#"
22195: + op.getOperandValue() + ";\n";
22196: //codeStatements +=Util.formatDecompiledStatement(tempString);
22197: local.setDeclarationGenerated(true);
22198: if (ifLevel > 0) {
22199: local.setWithinBlock(true);
22200: local.setBlockIndex(blockLevel);
22201: }
22202: } else {
22203: java.lang.String tempString = local.getVarName()
22204: + "=" + op.getOperandValue() + ";\n";
22205: //codeStatements +=Util.formatDecompiledStatement(tempString);
22206: }
22207: } else {
22208: if (isThisInstrStart(behaviour
22209: .getInstructionStartPositions(),
22210: currentForIndex - 1)
22211: && info[currentForIndex - 1] == JvmOpCodes.DUP)
22212: stack.getTopOfStack();
22213: if (isThisInstrStart(behaviour
22214: .getInstructionStartPositions(),
22215: currentForIndex - 1)
22216: && info[currentForIndex - 1] == JvmOpCodes.DUP2) {
22217: stack.getTopOfStack();
22218: stack.getTopOfStack();
22219: }
22220: //codeStatements +=Util.formatDecompiledStatement(local.getVarName()+"=("+op.getOperandValue()+");\n");
22221: op = createOperand(local.getVarName());
22222: stack.push(op);
22223: }
22224: }
22225:
22226: if (doNotPop == true)
22227: doNotPop = false;
22228: }
22229:
22230: private boolean checkForLoadAfterIINC(byte[] info,
22231: OperandStack opStack, int current, LocalVariable local,
22232: int index, java.lang.String c) {
22233:
22234: boolean b = false;
22235: int j = current + 1 + 1 + 1;
22236: int loadindex = -1;
22237: if (isThisInstrStart(behaviour.getInstructionStartPositions(),
22238: j)) {
22239:
22240: switch (info[j]) {
22241: case JvmOpCodes.ILOAD:
22242: loadindex = info[(j + 1)];
22243: break;
22244:
22245: case JvmOpCodes.ILOAD_0:
22246: loadindex = 0;
22247: break;
22248:
22249: case JvmOpCodes.ILOAD_1:
22250: loadindex = 1;
22251: break;
22252:
22253: case JvmOpCodes.ILOAD_2:
22254: loadindex = 2;
22255: break;
22256:
22257: case JvmOpCodes.ILOAD_3:
22258: loadindex = 3;
22259: break;
22260: }
22261:
22262: if (loadindex != -1) {
22263: if (loadindex == index) {
22264:
22265: if (c.trim().indexOf("-1") != -1) {
22266: b = true;
22267: local.setTempVarName("--" + local.getVarName());
22268: } else if (c.trim().indexOf("1") != -1) {
22269: b = true;
22270: local.setTempVarName("++" + local.getVarName());
22271: } else {
22272: b = false;
22273: }
22274: }
22275: } else {
22276: b = false;
22277: }
22278:
22279: }
22280:
22281: return b;
22282: }
22283:
22284: private boolean isPrevInstIINC(byte[] info, int current, int index) {
22285: int prev = current - 3;
22286: if (isThisInstrStart(behaviour.getInstructionStartPositions(),
22287: prev)) {
22288:
22289: if (info[prev] == JvmOpCodes.IINC) {
22290: int j = info[prev + 1];
22291: if (index == j) {
22292: return true;
22293: }
22294: }
22295:
22296: }
22297:
22298: return false;
22299:
22300: }
22301:
22302: private boolean addReturnAtIFElseEnd(int i) {
22303:
22304: if (returnsaddedAtIfElse.size() == 0)
22305: return true;
22306: for (int z = 0; z < returnsaddedAtIfElse.size(); z++) {
22307: Integer in = new Integer(i);
22308: Integer val = (Integer) returnsaddedAtIfElse.get(z);
22309: if (val.intValue() == in.intValue()) {
22310: return false;
22311: }
22312: }
22313: return true;
22314: }
22315:
22316: private boolean isByteCodeALoopStart(ArrayList loops,
22317: int bytecodeend) {
22318: if (loops == null || loops.size() == 0)
22319: return false;
22320: for (int z = 0; z < loops.size(); z++) {
22321: Loop loop = (Loop) loops.get(z);
22322: int loopstart = loop.getStartIndex();
22323: if (loopstart == bytecodeend) {
22324: return true;
22325: }
22326: }
22327: return false;
22328: }
22329:
22330: private int getIfCloseNumberForThisIF(byte[] info, int k) {
22331: IFBlock ifst = new IFBlock();
22332: ifst.setIfStart(k);
22333: ifst.setHasIfBeenGenerated(true);
22334: int t = ifLevel + 1;
22335: ifHashTable.put("" + (t), ifst);
22336: //addBranchLabel(classIndex,i,ifst,currentForIndex,info);
22337: int i = k;
22338: int classIndex = getJumpAddress(info, i);
22339: i++;
22340: i++;
22341: boolean continuetofind = false;
22342: if (classIndex < i) {
22343: ifst.setIfCloseLineNumber(findCodeIndexFromInfiniteLoop(
22344: ifst, behaviour.getBehaviourLoops(), classIndex));
22345: if (ifst.getIfCloseLineNumber() == -1)
22346: continuetofind = true;
22347: }
22348: if (classIndex > i || continuetofind) {
22349: if (isThisInstrStart(behaviour
22350: .getInstructionStartPositions(), classIndex - 3)
22351: && info[classIndex - 3] == JvmOpCodes.GOTO) // GOTO_W?
22352: {
22353:
22354: int resetVal = checkIfElseCloseNumber(classIndex - 3,
22355: ifst);
22356: ifst.setIfCloseLineNumber(resetVal);
22357: } else {
22358:
22359: int resetVal = checkIfElseCloseNumber(classIndex, ifst);
22360: ifst.setIfCloseLineNumber(resetVal);
22361: }
22362:
22363: }
22364:
22365: int if_start = ifst.getIfStart();
22366: int if_end = ifst.getIfCloseLineNumber();
22367: if (if_end == -1 || if_end < if_start) {
22368: boolean b = false;
22369: int bytecodeend = ifst.getIfCloseFromByteCode();
22370: b = isByteCodeALoopStart(behaviour.getBehaviourLoops(),
22371: bytecodeend);
22372: if (b) {
22373: int loopend = getloopEndForStart(behaviour
22374: .getBehaviourLoops(), bytecodeend);
22375: if (loopend != -1) {
22376: ifst.setIfCloseLineNumber(loopend);
22377: }
22378: }
22379: }
22380:
22381: return ifst.getIfCloseLineNumber();
22382:
22383: }
22384:
22385: private ArrayList addedHandlerEnds = new ArrayList();
22386:
22387: private boolean isHandlerEndPresentAtGuardEnd(int i) {
22388: if (addedHandlerEnds.size() == 0)
22389: return false;
22390: for (int z = 0; z < addedHandlerEnds.size(); z++) {
22391: Integer in = (Integer) addedHandlerEnds.get(z);
22392: if (in.intValue() == i) {
22393: return true;
22394: }
22395: }
22396: return false;
22397: }
22398:
22399: private boolean isThisTryStart(int i) {
22400: ArrayList tries = behaviour.getAllTriesForMethod();
22401: if (tries != null) {
22402: for (int z = 0; z < tries.size(); z++) {
22403:
22404: TryBlock TRY = (TryBlock) tries.get(z);
22405: if (TRY.getEnd() == i)
22406: return true;
22407:
22408: }
22409:
22410: }
22411: return false;
22412:
22413: }
22414:
22415: private ArrayList storesatifend = new ArrayList();
22416:
22417: private boolean storealreadyhandledatifend(int i) {
22418: if (storesatifend.size() == 0)
22419: return false;
22420: for (int z = 0; z < storesatifend.size(); z++) {
22421: Integer in = (Integer) storesatifend.get(z);
22422: if (in.intValue() == i) {
22423: return true;
22424: }
22425: }
22426:
22427: return false;
22428: }
22429:
22430: private ArrayList elsestartadded = new ArrayList();
22431:
22432: private boolean addElseStart(int i) {
22433: if (elsestartadded.size() == 0) {
22434: return true;
22435: }
22436: for (int z = 0; z < elsestartadded.size(); z++) {
22437: Integer in = (Integer) elsestartadded.get(z);
22438: if (in.intValue() == i) {
22439: return false;
22440: }
22441: }
22442: return true;
22443: }
22444:
22445: private boolean isInstStore0(byte[] info, int i) {
22446:
22447: boolean flag = false;
22448: boolean b = isThisInstrStart(behaviour
22449: .getInstructionStartPositions(), i);
22450: if (!b)
22451: return false;
22452: switch (info[i]) {
22453: case JvmOpCodes.AASTORE:
22454: flag = true;
22455: break;
22456:
22457: case JvmOpCodes.BASTORE:
22458: flag = true;
22459: break;
22460: case JvmOpCodes.CASTORE:
22461: flag = true;
22462: break;
22463: case JvmOpCodes.DASTORE:
22464: flag = true;
22465: break;
22466:
22467: case JvmOpCodes.FASTORE:
22468: flag = true;
22469: break;
22470:
22471: case JvmOpCodes.IASTORE:
22472: flag = true;
22473: break;
22474:
22475: case JvmOpCodes.LASTORE:
22476: flag = true;
22477: break;
22478:
22479: case JvmOpCodes.SASTORE:
22480: flag = true;
22481: break;
22482:
22483: default:
22484: flag = false;
22485: }
22486: return flag;
22487: }
22488:
22489: private HashMap putfieldObjRefMap = new HashMap();
22490:
22491: private Operand checkAnyStoredPUTFIELDObjRef(int i) {
22492: if (putfieldObjRefMap.size() == 0)
22493: return null;
22494: Set s = putfieldObjRefMap.entrySet();
22495: Iterator it = s.iterator();
22496: while (it.hasNext()) {
22497: Map.Entry entry = (Map.Entry) it.next();
22498: Integer in = (Integer) entry.getKey();
22499: if (in.intValue() == i) {
22500: return (Operand) entry.getValue();
22501: }
22502: }
22503: return null;
22504: }
22505:
22506: private java.lang.String disOutput = "";
22507:
22508: public void addParsedOutput(java.lang.String input) {
22509:
22510: if (input.startsWith("Instruction Pos")) {
22511: if (disOutput.length() - 1 > 0) {
22512: char last = disOutput.charAt(disOutput.length() - 1);
22513: if (last != '\n')
22514: input = "\n" + input;
22515: }
22516: }
22517: disOutput += Util.formatDisassembledOutput(input);
22518:
22519: }
22520:
22521: private void handlePUTSTATIC(int pos) {
22522: FieldRef fref = cd.getFieldRefAtCPoolPosition(pos);
22523: addParsedOutput("Instruction Pos " + currentForIndex + "\t:- "
22524: + " putstatic " + fref.getFieldName() + "\n");
22525: if (doNotPop == false) {
22526: Operand value = opStack.getTopOfStack();
22527: java.lang.String freftype = fref.getTypeoffield();
22528:
22529: // For the code statement
22530: int classpointer = fref.getClassPointer();
22531: ClassInfo cinfo = cd
22532: .getClassInfoAtCPoolPosition(classpointer);
22533: java.lang.String classname = cd.getUTF8String(cinfo
22534: .getUtf8pointer());
22535: java.lang.String v = value.getOperandValue().toString();
22536: if (v.indexOf("(") == -1 && v.indexOf(")") != -1) {
22537: v = v.replaceAll("\\)", "");
22538:
22539: }
22540: v = v.trim();
22541: StringBuffer sb = new StringBuffer("");
22542: checkForImport(classname, sb);
22543: java.lang.String temp = sb.toString() + "."
22544: + fref.getFieldName() + " = " + v + ";";
22545: //codeStatements+="\n"+Util.formatDecompiledStatement(temp)+"\n";
22546: }
22547: if (doNotPop)
22548: doNotPop = false;
22549: }
22550:
22551: private void printAnyReturnATEndOfGuard(int i, byte[] info) {
22552:
22553: boolean end = isIEndOfGuard(i, behaviour);
22554: boolean returnadded = false;
22555: int returnposincode = -1;
22556: if (end) {
22557: StringBuffer sb = new StringBuffer("");
22558: java.lang.String returnString = isAnyReturnPresentInSkipRegion(
22559: info, i, behaviour, sb);
22560: java.lang.String str = sb.toString();
22561: try {
22562: returnposincode = Integer.parseInt(str);
22563: } catch (NumberFormatException ne) {
22564: }
22565:
22566: if (returnString != null
22567: && returnString.trim().length() == 0) {
22568: if (i == (info.length - 1)) {
22569: returnString = getReturnTypeInst(info, i);
22570: returnposincode = i;
22571:
22572: }
22573: }
22574: java.lang.Object val = null;
22575:
22576: if (returnString != null
22577: && returnString.trim().length() > 0) {
22578: int loadIndex = -1;
22579: StringBuffer stb = new StringBuffer("");
22580: if (returnposincode != -1)
22581: loadIndex = getLoadIndexForReturn(info,
22582: returnposincode, stb);
22583: if (loadIndex != -1) {
22584: LocalVariableStructure struck = behaviour
22585: .getLocalVariables();
22586: int rangeinx = Integer.parseInt(stb.toString());
22587: if (rangeinx != -1) {
22588: if (cd.isClassCompiledWithMinusG()) {
22589: LocalVariable temp = struck
22590: .getVariabelAtIndex(loadIndex,
22591: rangeinx);
22592: if (temp != null) {
22593: Operand op = new Operand();
22594: op.setOperandValue(temp.getVarName());
22595: op.setOperandName(temp.getVarName());
22596: opStack.push(op);
22597: }
22598:
22599: } else {
22600: LocalVariable temp = struck
22601: .getVariabelAtIndex(loadIndex);
22602: if (temp != null) {
22603: Operand op = new Operand();
22604: op.setOperandValue(temp.getVarName());
22605: op.setOperandName(temp.getVarName());
22606: opStack.push(op);
22607: }
22608: }
22609: }
22610: }
22611: int returnPos = getReturnStringPosInCode(info, i,
22612: behaviour);
22613: if (returnString.equals("return") == false
22614: && opStack.size() > 0) {
22615: // StackTop=opStack.peekTopOfStack();
22616: Operand StackTop = opStack.getTopOfStack();
22617: if (StackTop != null) {
22618: val = StackTop.getOperandValue();
22619: if (val != null)
22620: val = val.toString();
22621: }
22622: if (StackTop != null) {
22623:
22624: // if(val!=null)tempString="return "+val;
22625: // else tempString="return ";
22626: //codeStatements+=Util.formatDecompiledStatement(tempString);
22627:
22628: returnadded = true;
22629: }
22630:
22631: } else if (returnString.equals("return") == true) {
22632: // tempString="return ";
22633: //codeStatements+=Util.formatDecompiledStatement(tempString);
22634:
22635: returnadded = true;
22636: }
22637: returnsAtI.put(new Integer(returnPos), "true");
22638: }
22639:
22640: }
22641:
22642: }
22643:
22644: private void addTBSWITCHtoDISSTMT(int Default, int[] offsetValues,
22645: int low, int high) {
22646: java.lang.String desc = "";
22647: desc += "[DEFAULT " + Default + "]\n";
22648: desc += "[LOW " + low + "]\n";
22649: desc += "[high " + high + "]\n";
22650: for (int z = 0; z < offsetValues.length; z++) {
22651: desc += "[Offset" + z + " Value->" + offsetValues[z]
22652: + "]\n";
22653: }
22654: addParsedOutput("Instruction Pos " + currentForIndex
22655: + "\t:- tableswitch\n\n");
22656: addParsedOutput(desc + "\n");
22657: }
22658: }
22659:
22660: // TODO: replace unnecesary -200s with -100z
|