jreversepro.revengine
Class JBranchEntry

java.lang.Object
  extended by jreversepro.revengine.JBranchEntry
All Implemented Interfaces:
KeyWords, BranchConstants, OperandConstants

public class JBranchEntry
extends java.lang.Object
implements KeyWords, BranchConstants, OperandConstants

JBranchEntry refers to a single conditional BranchEntry only.

Author:
Karthik Kumar

Field Summary
 
Fields inherited from interface jreversepro.common.KeyWords
ANY, BOOLEAN, BREAK, BYTE, CASE, CHAR, CLASS, CLASS_STRING, CLINIT, CLOSE_BRACKET, COND_AND, COND_NOT, COND_OR, CONTINUE, DEFAULT, DEFAULT_PACKAGE, DOUBLE, EQUALTO, FALSE, FLOAT, FOREIGN_CLASS, FOREIGN_OBJ, GOTO, INIT, INSTANCEOF, INT, INTERFACE, JVM_BOOLEAN, JVM_CHAR, JVM_VOID, LANG_OBJECT, LENGTH, LONG, NEW, NULL, OPEN_BRACKET, OPR_EQ, OPR_GE, OPR_GT, OPR_LE, OPR_LT, OPR_NE, OPR_NOT, REFERENCE, RET_ADDR, RETURN, SHORT, SPACE, STATIC, SUPER, SWITCH, THIS, THISCLASS, THROW, TRUE, VOID
 
Fields inherited from interface jreversepro.revengine.BranchConstants
TYPE_BRANCH, TYPE_CASE, TYPE_CATCH, TYPE_CATCH_ANY, TYPE_DO_WHILE, TYPE_ELSE, TYPE_ELSE_IF, TYPE_GOTO, TYPE_IF, TYPE_INVALID, TYPE_JSR, TYPE_RET, TYPE_SWITCH, TYPE_SYNC, TYPE_TRY, TYPE_TRY_ANY, TYPE_WHILE
 
Fields inherited from interface jreversepro.runtime.OperandConstants
L_ADD, L_BITAND, L_BITOR, L_BITXOR, L_CAST, L_COMMA, L_DIV, L_EVAL, L_INDEX, L_LOGAND, L_LOGEQ, L_LOGIOF, L_LOGNEQ, L_LOGOR, L_LOGREL, L_MOD, L_MUL, L_REF, L_SHIFT, L_SUB, L_TERN, L_UNARY, VALUE
 
Constructor Summary
JBranchEntry(JMethod method, int startPc, int targetPc, int type)
           
JBranchEntry(JMethod method, int startPc, int nextPc, int targetPc, int type, java.lang.String opr1, java.lang.String opr2, java.lang.String operator)
           
 
Method Summary
 boolean appendEndBlockStmt(JDecompiler decomp, JOperandStack jos)
          Appends end block statement for a branch entry.
 void appendStartBlockStmtX(JDecompiler decomp)
          Append the code for the beginning of a block
 void complementOperator()
          Complements the conditional operator of the branch
 void convertToWhile()
          This is invoked under the following circumstances.
 boolean doesContain(int aPc)
          Returns if the given Pc is enclosed in the mentioned block
 boolean doesStartWith(int rhsStartPc)
          This method checks if this particular branch block starts with the given Pc.
 int getEndBlockPc()
           
 java.lang.String getExpression()
          Trims the expression for a condition here.
 int getNextPc()
           
 java.lang.String getOpr1()
           
 int getStartBlockPc()
           
 int getStartExecPc()
           
 int getStartPc()
           
 int getTargetPc()
           
 int getType()
           
 boolean independent()
          Lets us know if the block is independent.
 boolean isWhile()
          Returns if the branch mentioned can be a TYPE_WHILE.
 void resetWrittenFlag()
          Resets the written flag
 void rewriteCondition(JBranchEntry nextEntry, java.lang.String conditionType, boolean complement)
          This merges the current condition represented by the current JBranchEntry.
 void setEndBlockPc(int aNewPc)
          Sets the end pc of this block.
 void setNextPc(int nextPc)
          Setter method for NextPc.
 void setOpr1(java.lang.String opr1)
           
 void setOpr2(java.lang.String opr2)
           
 void setStartPc(int startPc)
           
 void setTargetPc(int targetPc)
           
 void setType(int type)
          Setter method for type.
 void setWrittenFlag()
          Sets the written flag.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JBranchEntry

public JBranchEntry(JMethod method,
                    int startPc,
                    int targetPc,
                    int type)
Parameters:
method - Method to which this branch entry belongs to.
startPc - StartPc
targetPc - TargetPc
type - Type of the branch

JBranchEntry

public JBranchEntry(JMethod method,
                    int startPc,
                    int nextPc,
                    int targetPc,
                    int type,
                    java.lang.String opr1,
                    java.lang.String opr2,
                    java.lang.String operator)
Parameters:
method - Method to which this branch entry belongs to.
startPc - StartPc
nextPc - NextPc
targetPc - TargetPc
type - Type of the branch
opr1 - Operand 1
opr2 - Operand 2
operator - Operator Comparison of the branch.
Method Detail

setWrittenFlag

public void setWrittenFlag()
Sets the written flag.


resetWrittenFlag

public void resetWrittenFlag()
Resets the written flag


isWhile

public boolean isWhile()
Returns if the branch mentioned can be a TYPE_WHILE. One indication of a while loop is that the startPc > targetPc.

Returns:
true, if it is a while loop. false, otherwise.

getStartPc

public int getStartPc()
Returns:
Returns the startPc

getTargetPc

public int getTargetPc()
Returns:
Returns the targetPc.

getNextPc

public int getNextPc()
Returns:
Returns the NextPc.

getType

public final int getType()
Returns:
Returns the type of the Branch.

getOpr1

public java.lang.String getOpr1()
Returns:
Returns the operand 1.

setNextPc

public void setNextPc(int nextPc)
Setter method for NextPc.

Parameters:
nextPc - Value for the nextPc.

setTargetPc

public void setTargetPc(int targetPc)
Parameters:
targetPc - TargetPC of the block.

setStartPc

public void setStartPc(int startPc)
Parameters:
startPc - StartPc of the branch. Setter method for startPc.

setType

public void setType(int type)
Setter method for type.

Parameters:
type - Type of the branch.

setOpr1

public void setOpr1(java.lang.String opr1)
Parameters:
opr1 - Operand 1. Setter method for operand 1.

setOpr2

public void setOpr2(java.lang.String opr2)
Parameters:
opr2 - Operand 2. Setter method for operand 2.

convertToWhile

public void convertToWhile()
This is invoked under the following circumstances. First this is recognized as a 'if' branch. Then afterwards recognized as 'while' branch.


complementOperator

public void complementOperator()
Complements the conditional operator of the branch


doesStartWith

public boolean doesStartWith(int rhsStartPc)
                      throws RevEngineException
This method checks if this particular branch block starts with the given Pc.

Parameters:
rhsStartPc - StartPc that is to be checked if a block starts there.
Returns:
true, if this block starts with the mentioned startPc. false, otherwise.
Throws:
RevEngineException - Thrown when any error occurs.

independent

public boolean independent()
Lets us know if the block is independent. When we say independent, we refer to blocks that can start on its own, Examples of the same - if, while, try, do..while. switch Examples of dependent branch blocks are . else_if , else, catch each dependent on one of the independent block for is existence

Returns:
true, if the block is independent. false, otherwise.

doesContain

public boolean doesContain(int aPc)
                    throws RevEngineException
Returns if the given Pc is enclosed in the mentioned block

Parameters:
aPc - the Pc for which the location is to be mentioned.
Returns:
true, if the block mentioned contains this Pc. false, otherwise.
Throws:
RevEngineException - Thrown in case any error occurs while performing this operation.

getStartBlockPc

public int getStartBlockPc()
                    throws RevEngineException
Returns:
Returns the start pc of this block.
Throws:
RevEngineException - Thrown in case of any error while geting start block Pc.

getEndBlockPc

public int getEndBlockPc()
                  throws RevEngineException
Returns:
Returns the endpc of the block under consideration.
Throws:
RevEngineException - Thrown in case there of any problem getting End block pc.

getStartExecPc

public int getStartExecPc()
                   throws RevEngineException
Returns:
Returns the Pc from which the execution for the block under consideration.
Throws:
RevEngineException - Thrown in case any error occurs.

appendStartBlockStmtX

public final void appendStartBlockStmtX(JDecompiler decomp)
Append the code for the beginning of a block

Parameters:
decomp - Reference to decempiler.

appendEndBlockStmt

public final boolean appendEndBlockStmt(JDecompiler decomp,
                                        JOperandStack jos)
Appends end block statement for a branch entry.

Parameters:
decomp - Decompiler reference.
jos - Java Operand Stack reference.
Returns:
Returns boolean.

rewriteCondition

public void rewriteCondition(JBranchEntry nextEntry,
                             java.lang.String conditionType,
                             boolean complement)
This merges the current condition represented by the current JBranchEntry.

Parameters:
nextEntry - Next Condition that is to be merged with the current condition.
conditionType - If OR or AND.
complement - if the current expression needs to be complemented.

setEndBlockPc

public void setEndBlockPc(int aNewPc)
Sets the end pc of this block.

Parameters:
aNewPc - New Pc that is to be set as the end of the block

getExpression

public java.lang.String getExpression()
Trims the expression for a condition here. For eg, an expression of the form - if ( a == true ) is converted to 'a' ( just 'a' ). These small modifications improve the readability of the code.

Returns:
Returns the new code.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
Returns the Stringified representation of the class.


Submit Feedback to akkumar@users.sourceforge.net