jreversepro.common
Class Helper

java.lang.Object
  extended by jreversepro.common.Helper
All Implemented Interfaces:
KeyWords

public class Helper
extends java.lang.Object
implements KeyWords

Helper contains a list of assorted methods that 'helps' in manipulating the data present in the class file.

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
 
Method Summary
static java.util.List<java.lang.String> getArguments(java.lang.String aSignature)
          Returns the arguments in array form given the JVM signature.
static java.lang.String getJavaDataType(java.lang.String aDataType, boolean associated)
          Determines the Java representation , given the JVM representation of data types.
static java.lang.String getPackageName(java.lang.String aFullName)
          Returns the Package name alone from a fully qualified name.
static java.lang.String getReturnType(java.lang.String aSignature)
          Given the Signature of the method , this provides us the return type.
static int getSignTokenLength(java.lang.String aDataType)
          Determines the length of the JVM datatype representation given the JVM signature.
static java.lang.String getValue(java.lang.String value, java.lang.String datatype)
          Both boolean and char are represented as integers .
static boolean isBasicType(java.lang.String type)
          Checks if the given datatype is a basic data type or not.
static boolean isDebug()
           
static void log(java.lang.Exception ex)
           
static void log(java.lang.String logMsg)
           
static void logNoEol(java.lang.String logMsg)
          Log without end-of-line at the end.
static java.lang.String lowNbits(java.lang.String aValue, int aNumBits)
          Extracts the value of a particular number of bits.
static java.lang.String replaceEscapeChars(java.lang.String aLiteral)
          Inserts a '\' before all the escape characters , line '\n' , '\t' to provide better readability.
static int signedToUnsigned(int aByteVal)
          Converts a signed 'byte' to an unsigned integer.
static boolean toggleDebug()
          Toggles the debug flag.
static boolean versionCheck()
          Checks for the version compatibility between the system JRE and the JRE for which the application is written for.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

log

public static void log(java.lang.String logMsg)
Parameters:
logMsg - Message to be logged.

log

public static void log(java.lang.Exception ex)
Parameters:
ex - Exception to be logged.

logNoEol

public static void logNoEol(java.lang.String logMsg)
Log without end-of-line at the end.

Parameters:
logMsg - Message to be logged.

toggleDebug

public static boolean toggleDebug()
Toggles the debug flag.

Returns:
Returns the new debug flag after toggling.

isDebug

public static boolean isDebug()
Returns:
the value of debug flag.

getPackageName

public static java.lang.String getPackageName(java.lang.String aFullName)
Returns the Package name alone from a fully qualified name.

For Example , if FullName = java/lang/StringBuffer,
then a call to getPackageName(arg) returns the value java.lang.

Parameters:
aFullName - A Fully Qualified Name.
Returns:
the package name , alone with the dots separating the classes.

getJavaDataType

public static java.lang.String getJavaDataType(java.lang.String aDataType,
                                               boolean associated)
Determines the Java representation , given the JVM representation of data types.

dataType formatDataType(dataType)
Bbyte
Cchar
Ddouble
Ffloat
Iint
Jlong
Sshort
Vvoid
Zboolean
[Zboolean [] , array representation
Ljava/lang/String java/lang/String

Parameters:
aDataType - JVM representation of the data type.
associated - If set, then an array representation is returned.
Returns:
Java Language representation of aDataType.

getSignTokenLength

public static int getSignTokenLength(java.lang.String aDataType)
Determines the length of the JVM datatype representation given the JVM signature.

dataType getSignTokenLength(dataType)(dataType)
all basic data types1
[XYZlen(XYZ) + 1
Ljava/lang/String len(Ljava/lang/String)

Parameters:
aDataType - Signature of a method as present in the class file in JVM representation, containing a list of datatypes.
Returns:
the length of the first valid datatype.

getArguments

public static java.util.List<java.lang.String> getArguments(java.lang.String aSignature)
Returns the arguments in array form given the JVM signature.

For example , IILjava/lang/String could be returned as
( int , int , java/lang/String ).

Parameters:
aSignature - Signature of the method.
Returns:
The method arguments as a List

getReturnType

public static java.lang.String getReturnType(java.lang.String aSignature)
Given the Signature of the method , this provides us the return type.

Parameters:
aSignature - Signature of the method.
Returns:
the return type associated with the method signature, The type returned corresponds to JVM representation.

lowNbits

public static java.lang.String lowNbits(java.lang.String aValue,
                                        int aNumBits)
Extracts the value of a particular number of bits.

For example lowNBits(169 , 5 ) returns (10101001,5) -> 10101 i.e 21
.

Parameters:
aValue - Value containing the integer in string form.
aNumBits - Number of bits that is to be extracted.
Returns:
the masked value of the N Bit Number.

replaceEscapeChars

public static java.lang.String replaceEscapeChars(java.lang.String aLiteral)
Inserts a '\' before all the escape characters , line '\n' , '\t' to provide better readability.

Parameters:
aLiteral - String containing the escape characters.
Returns:
the new String containing the new escape sequence of characters.

versionCheck

public static boolean versionCheck()
Checks for the version compatibility between the system JRE and the JRE for which the application is written for.

Returns:
true , if System JRE is >= DEFAULT_VERISON ( 1.2.2 ).
false , otherwise.

isBasicType

public static boolean isBasicType(java.lang.String type)
Checks if the given datatype is a basic data type or not.

Parameters:
type - the datatype to be checked.
Returns:
true , if it is. false , otherwise.

getValue

public static java.lang.String getValue(java.lang.String value,
                                        java.lang.String datatype)
Both boolean and char are represented as integers . This takes care of the conversions

Parameters:
value - Old Value.
datatype - Datatype of the value.
Returns:
Returns the new value after making appropriate changes.

signedToUnsigned

public static int signedToUnsigned(int aByteVal)
Converts a signed 'byte' to an unsigned integer.

Parameters:
aByteVal - a Byte Value.
Returns:
unsigned integer equivalent of aByteVal.


Submit Feedback to akkumar@users.sourceforge.net