jreversepro.reflect
Class JMethod

java.lang.Object
  extended by jreversepro.reflect.JMember
      extended by jreversepro.reflect.JMethod
All Implemented Interfaces:
KeyWords

public class JMethod
extends JMember
implements KeyWords

JMethod is the abstract representation of a method in the class method..

Author:
Karthik Kumar

Field Summary
 
Fields inherited from class jreversepro.reflect.JMember
ACC_ABSTRACT, ACC_FINAL, ACC_NATIVE, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_STATIC, ACC_STRICT, ACC_SYNCHRONIZED, ACC_TRANSIENT, ACC_VOLATILE, datatype, name, qualifier
 
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
 
Constructor Summary
JMethod(JClassInfo info)
           
 
Method Summary
 void addBlock(JBlockObject jbo)
          Add a new JBlockObject to the stack - indicates that a block is opening
 void addExceptionBlock(int startPc, int endPc, int handlerPc, java.lang.String datatype)
          Add an exception block.
 void addLineOfCode(JLineOfCode loc)
          Adds a line of code to the current block
 void closeBlock()
          Close the current JBlockObject -- pop it from the stack Called when an end of block is reached.
protected  int dealLookupSwitch(int index)
          This method returns the length of the variable instruction lookupswitch.
protected  int dealTableSwitch(int index)
          This method returns the length of the variable instruction tableswitch.
 java.util.Map<java.lang.Integer,java.lang.String> getAllCatchJExceptions()
          Returns a map
protected  byte[] getArgArray(int start, int end)
          Given the start index and the end index this method returns a byte array that contain the byte values with the start array value included and end array excluded.
 java.util.List<java.lang.String> getArgList()
          Returns the argument list.
 JMethodBlock getBlock()
           
protected  byte[] getBytes()
          Returns the bytecode array of the method
 java.util.List<JException> getexceptionBlocks()
          Returns the exception table.
 JInstruction getInstruction(int ind)
          Returns the JInstruction having the specified byte offset
 java.util.List<JInstruction> getInstructions()
          Returns the list of bytecodes in the method.
 JLineNumberTable getLineTable()
          Returns the LineNumberTable of the method.
 java.lang.String getLocalStackInfo()
          Returns the initial code / information about the method.
 int getMaxLocals()
          Returns the maximum local members of this method.
 int getMaxStack()
          Returns the max.
 java.lang.String getMethodAsString(boolean getBytecode, boolean includeStackInfo)
           
 java.lang.String getMethodHeader(boolean includeStackInfo)
          Returns the headers for the method.
 JInstruction getNextInstruction(int ind)
          Returns the JInstruction following the instruction having the specified byte offset
 java.lang.String getReturnType()
          Returns the return type of the method.
 java.lang.String getSignature()
          Returns the signature of the method.
 java.lang.String getStringifiedBytecode()
           
 java.util.List<java.lang.String> getThrowsClasses()
          Returns the .list of classes thrown by this method.
 java.lang.String getThrowsClause(JImport importInfo)
          returns a throws clause for the method
 boolean isStatic()
          Returns ifthis method is static.
 void normalize()
          Normalization of the bytecodes into JVM codes.
 JBlockObject removeCurrentBlock()
          Removes and returns the last block added
 JLineOfCode removeLastLineOfCode()
          Removes and returns the last line of code added from the current block
 void setBytes(byte[] bytecodes)
          Sets the bytecode array.
 void setLineTable(JLineNumberTable rhsLineTable)
          Sets the line number table.
 void setMaxLocals(int maxLocals)
          Sets the max.
 void setMaxStack(int maxStack)
          Sets the max.
 void setSignature(java.lang.String rhsSign)
          Setter method for Signature
 void setStringifiedBytecode(java.lang.String str)
          Sets the bytecode for this method;
 void setSymbolTable(JSymbolTable st)
           
 void setThrowsClasses(java.util.List<java.lang.String> throwsClasses)
          Sets the .list of classes thrown by this method.
 
Methods inherited from class jreversepro.reflect.JMember
getDatatype, getName, getQualifier, getQualifierName, getStringRep, isFinal, setDatatype, setName, setQualifier
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JMethod

public JMethod(JClassInfo info)
Parameters:
info - The JSymbolTable associated with this class Creates a new JMethod
Method Detail

getBlock

public JMethodBlock getBlock()
Returns:
The method block for this method

addBlock

public void addBlock(JBlockObject jbo)
Add a new JBlockObject to the stack - indicates that a block is opening

Parameters:
jbo - JBlockObject to be added.

closeBlock

public void closeBlock()
Close the current JBlockObject -- pop it from the stack Called when an end of block is reached.


addLineOfCode

public void addLineOfCode(JLineOfCode loc)
Adds a line of code to the current block

Parameters:
loc - Line Of Code to be added.

removeLastLineOfCode

public JLineOfCode removeLastLineOfCode()
Removes and returns the last line of code added from the current block

Returns:
Returns the last line of code added to the current block.

removeCurrentBlock

public JBlockObject removeCurrentBlock()
Removes and returns the last block added

Returns:
Returns the last block added.

setSymbolTable

public void setSymbolTable(JSymbolTable st)
Parameters:
st - The JSymbolTable associated with this class Set the Symbol table

setSignature

public void setSignature(java.lang.String rhsSign)
Setter method for Signature

Parameters:
rhsSign - Signature field value.

addExceptionBlock

public void addExceptionBlock(int startPc,
                              int endPc,
                              int handlerPc,
                              java.lang.String datatype)
Add an exception block.

Parameters:
startPc - Start of the try block
endPc - End of try block
handlerPc - Beginning of handler block
datatype - Type of the class that the handler is going to handle.

setLineTable

public void setLineTable(JLineNumberTable rhsLineTable)
Sets the line number table.

Parameters:
rhsLineTable - Line number Table that is created by the compiler if the debugging option is on.

getReturnType

public java.lang.String getReturnType()
Returns the return type of the method.

Returns:
Returns the return type of the method.

getSignature

public java.lang.String getSignature()
Returns the signature of the method.

Returns:
Returns the signature of the method.

getArgList

public java.util.List<java.lang.String> getArgList()
Returns the argument list. The members of the list are String.

Returns:
Returns the argument list.

getThrowsClasses

public java.util.List<java.lang.String> getThrowsClasses()
Returns the .list of classes thrown by this method. The individual members are string.

Returns:
Returns the list of thrown classes

getMaxLocals

public int getMaxLocals()
Returns the maximum local members of this method.

Returns:
Returns the Max Locals

getMaxStack

public int getMaxStack()
Returns the max. stack

Returns:
Returns max stack.

setThrowsClasses

public void setThrowsClasses(java.util.List<java.lang.String> throwsClasses)
Sets the .list of classes thrown by this method. The individual members are string.

Parameters:
throwsClasses - Classes Thrown

setMaxLocals

public void setMaxLocals(int maxLocals)
Sets the max. local variable field

Parameters:
maxLocals - Max Locals

setMaxStack

public void setMaxStack(int maxStack)
Sets the max. stack variable field.

Parameters:
maxStack - Max. Stack length

getBytes

protected byte[] getBytes()
Returns the bytecode array of the method

Returns:
bytecode array.

setBytes

public void setBytes(byte[] bytecodes)
Sets the bytecode array.

Parameters:
bytecodes - the bytecode array input.

getexceptionBlocks

public java.util.List<JException> getexceptionBlocks()
Returns the exception table. The individual members contain JException.

Returns:
Returns the exception table.

getAllCatchJExceptions

public java.util.Map<java.lang.Integer,java.lang.String> getAllCatchJExceptions()
Returns a map

Returns:
Returns a map of exception tables.

getInstructions

public java.util.List<JInstruction> getInstructions()
Returns the list of bytecodes in the method. The individual members of the list are JInstruction.

Returns:
Returns the bytecodes in the method.

getInstruction

public JInstruction getInstruction(int ind)
Returns the JInstruction having the specified byte offset

Parameters:
ind - Index of the instruction.
Returns:
Returns the JInstruction in the method.

getNextInstruction

public JInstruction getNextInstruction(int ind)
Returns the JInstruction following the instruction having the specified byte offset

Parameters:
ind - Index of the instruction.
Returns:
Returns the JInstruction in the method.

getLineTable

public JLineNumberTable getLineTable()
Returns the LineNumberTable of the method.

Returns:
Returns the LineNumberTable of the method.

getLocalStackInfo

public java.lang.String getLocalStackInfo()
Returns the initial code / information about the method. It consists of maximum local information maximum stack information and the exception class handler information.

Returns:
Returns the code/information about the method.

isStatic

public boolean isStatic()
Returns ifthis method is static.

Overrides:
isStatic in class JMember
Returns:
Returns true, if this is a static method. false, otherwise.

normalize

public void normalize()
Normalization of the bytecodes into JVM codes. This method is responsible for converting the bytecode stream of the method into JVM opcodes. By default all JVM opcodes are of fixed length in all contexts, except some. tableswitch and lookupswitch are basically variable length opcodes and their length primarily depend on the number of switch legs in the source code since they are one componsite statement that contains information about all the possible targets.


dealTableSwitch

protected int dealTableSwitch(int index)
This method returns the length of the variable instruction tableswitch.

Parameters:
index - beginning index of the tableswitch statement into the bytecode stream of the method. The format is as follows. The first 4 bytes are for defaultbyte. The next 4 for the lowest value in the case leg values. The next 4 for the highest value in the case high values. Then we will have ( high - low ) * 4 bytes - all containing the target index to be junmped into relative to the index of the current switch instruction.
Returns:
Returns the integer that is Index + length of the instruction so that the next JVM opcode can proceed from there.

dealLookupSwitch

protected int dealLookupSwitch(int index)
This method returns the length of the variable instruction lookupswitch.

Parameters:
index - beginning index of the lookupswitch statement into the bytecode stream of the method. The format is as follows. The first 4 bytes are for defaultbyte. The next 4 for the number of pairs of ( case leg value, target) that will appear as follows, say N. Then there will be (2 * N) * 4 bytes , ( N pairs of integers ), with each pair containing the case leg value first and the second integer letting us know the target of the case leg relative to the index of the method.
Returns:
Returns the integer that is Index + length of the instruction so that the next JVM opcode can proceed from there.

getArgArray

protected byte[] getArgArray(int start,
                             int end)
Given the start index and the end index this method returns a byte array that contain the byte values with the start array value included and end array excluded.

Parameters:
start - start index into the byte array.
end - end index into the byte array.
Returns:
Returns a byte array containing the bytes from start to end , end exclusive and start inclusive.

getThrowsClause

public java.lang.String getThrowsClause(JImport importInfo)
returns a throws clause for the method

Parameters:
importInfo - containing the import information.
Returns:
Returns a string that contains the code representation.

getMethodHeader

public java.lang.String getMethodHeader(boolean includeStackInfo)
Returns the headers for the method.

Parameters:
includeStackInfo - Denotes if the stack information like maximum local variables, stack information are supposed to be included in the reverse engineered code. Moved from JDecompiler by pazandak@objs.com
Returns:
Returns the method header information.

getMethodAsString

public java.lang.String getMethodAsString(boolean getBytecode,
                                          boolean includeStackInfo)
Parameters:
getBytecode - TRUE if bytecode is to be returned, FALSE if decompiled code should be returned.
includeStackInfo - TRUE if stack & exception info should be output
Returns:
Returns the stringified method

getStringifiedBytecode

public java.lang.String getStringifiedBytecode()
Returns:
Returns the bytecode for this method;

setStringifiedBytecode

public void setStringifiedBytecode(java.lang.String str)
Sets the bytecode for this method;

Parameters:
str - Bytecode disassembled string representation.


Submit Feedback to akkumar@users.sourceforge.net