jellyj.classfile.javaclass
Class Utility


public abstract class Utility
implements Constants

Utility functions that do not really belong to any class in particular.

Author:
JellyJ Design Group

Method Summary
 final static StringaccessToString(int access_flags)
          Convert bit field of flags into string such as `static final'.
 final static StringaccessToString(int access_flags, boolean for_class)
          Convert bit field of flags into string such as `static final'.
 final static intbytesToInt(byte b0, byte b1, byte b2, byte b3)
          Obtains the signed 32-bit value from 4 bytes, bytesToInt((byte) 0, (byte) 0, b1, b1) obtains the unsigned 16-bit value from 2 bytes.
 final static shortbytesToShort(byte b0, byte b1)
          bytesToShort(b0, b1) obtains the signed 16-bit value from 2 bytes.
 final static intbytesToUnsignedShort(byte b0, byte b1)
          bytesToUnsignedShort(b0, b1) obtains the unsigned 16-bit value from 2 bytes.
 final static shortbyteToShort(byte b)
          Convert (signed) byte to (unsigned) short value, i.e.
 final static StringcodeToString(byte[] code, ConstantPool constant_pool, int index, int length)
          Disassemble a byte array of JVM byte codes starting from code line `index' and return the dissambled string representation.
 final static StringcodeToString(ByteSequence bytes, ConstantPool constant_pool)
          Disassemble a stream of byte codes and return the string representation.
 final static StringcompactClassName(String str)
          Shorten long class names, java/lang/String becomes String.
 final static StringcompactClassName(String str, String prefix, boolean chopit)
          Shorten long class name str, i.e.
 final static StringcompactClassName(String str, boolean chopit)
          Shorten long class names, java/lang/String becomes java.lang.String, e.g..
 final static String[]methodSignatureArgumentTypes(String signature)
           
 final static String[]methodSignatureArgumentTypes(String signature, boolean chopit)
           
 final static StringmethodSignatureReturnType(String signature)
           
 final static StringmethodSignatureReturnType(String signature, boolean chopit)
           
 final static StringmethodSignatureToString(String signature, String name, String access)
          Converts method signature to string with all class names compacted.
 final static StringmethodSignatureToString(String signature, String name, String access, boolean chopit)
          A return\u00adtype signature represents the return value from a method.
 final static StringmethodTypeToSignature(String ret, String[] argv)
          Converts string containing the method return and argument types to a byte code method signature.
 final static Stringreplace(String str, String old, String new_)
          Replace all occurences of old in str with new.
 final static StringsignatureToString(String signature)
          Converts signature to string with all class names compacted.
 final static StringsignatureToString(String signature, boolean chopit)
          The field signature represents the value of an argument to a function or the value of a variable.
 final static StringtoHexString(byte[] bytes)
           
 final static bytetypeOfMethodSignature(String signature)
           
 final static bytetypeOfSignature(String signature)
          Return type of signature as a byte value as defined in Constants
 final static StringtypeToSignature(String str)
          Gets Java conformant type like `String[]' and returns a string containing the type in byte code format, i.e.

Method Detail

accessToString

public final static String accessToString(int access_flags)
Convert bit field of flags into string such as `static final'.
Parameters:
access_flags - Access flags
Returns: String representation of flags

accessToString

public final static String accessToString(int access_flags, boolean for_class)
Convert bit field of flags into string such as `static final'. Special case: Classes compiled with new compilers and with the `ACC_SUPER' flag would be said to be "synchronized". This is because SUN used the same value for the flags `ACC_SUPER' and `ACC_SYNCHRONIZED'.
Parameters:
access_flags - Access flags
for_class - access flags are for class qualifiers ?
Returns: String representation of flags

bytesToInt

public final static int bytesToInt(byte b0, byte b1, byte b2, byte b3)
Obtains the signed 32-bit value from 4 bytes, bytesToInt((byte) 0, (byte) 0, b1, b1) obtains the unsigned 16-bit value from 2 bytes.

bytesToShort

public final static short bytesToShort(byte b0, byte b1)
bytesToShort(b0, b1) obtains the signed 16-bit value from 2 bytes.

bytesToUnsignedShort

public final static int bytesToUnsignedShort(byte b0, byte b1)
bytesToUnsignedShort(b0, b1) obtains the unsigned 16-bit value from 2 bytes.

byteToShort

public final static short byteToShort(byte b)
Convert (signed) byte to (unsigned) short value, i.e. all negative values become positive.

codeToString

public final static String codeToString(byte[] code, ConstantPool constant_pool, int index, int length)
Disassemble a byte array of JVM byte codes starting from code line `index' and return the dissambled string representation. Decode only `num' opcodes (including their operands), use -1 if you want to decompile everything.
Parameters:
code - byte code array
constant_pool - Array of constants
index - offset in `code' array (number of opcodes, not bytes!)
length - number of opcodes to decompile, -1 for all
Returns: String representation of byte codes

codeToString

public final static String codeToString(ByteSequence bytes, ConstantPool constant_pool)
throws java.io.IOException
Disassemble a stream of byte codes and return the string representation.
Parameters:
stream - data input stream
constant_pool - Array of constants
Returns: String representation of byte code

compactClassName

public final static String compactClassName(String str)
Shorten long class names, java/lang/String becomes String.
Parameters:
str - The long class name
Returns: Compacted class name

compactClassName

public final static String compactClassName(String str, String prefix, boolean chopit)
Shorten long class name str, i.e. chop off the prefix, if the class name starts with this string and the flag chopit is true. Slashes / are converted to dots ..
Parameters:
str - The long class name
prefix - The prefix the get rid off
chopit - Flag that determines whether chopping is executed or not
Returns: Compacted class name

compactClassName

public final static String compactClassName(String str, boolean chopit)
Shorten long class names, java/lang/String becomes java.lang.String, e.g.. If chopit is true the prefix java.lang is also removed.
Parameters:
str - The long class name
chopit - Flag that determines whether chopping is executed or not
Returns: Compacted class name

methodSignatureArgumentTypes

public final static String[] methodSignatureArgumentTypes(String signature)
throws java.lang.ClassFormatError
Parameters:
signature - Method signature
Returns: Array of argument types
throw ClassFormatError

methodSignatureArgumentTypes

public final static String[] methodSignatureArgumentTypes(String signature, boolean chopit)
throws java.lang.ClassFormatError
Parameters:
signature - Method signature
chopit - Shorten class names ?
Returns: Array of argument types
throw ClassFormatError

methodSignatureReturnType

public final static String methodSignatureReturnType(String signature)
throws java.lang.ClassFormatError
Parameters:
signature - Method signature
Returns: return type of method
throw ClassFormatError

methodSignatureReturnType

public final static String methodSignatureReturnType(String signature, boolean chopit)
throws java.lang.ClassFormatError
Parameters:
signature - Method signature
chopit - Shorten class names ?
Returns: return type of method
throw ClassFormatError

methodSignatureToString

public final static String methodSignatureToString(String signature, String name, String access)
Converts method signature to string with all class names compacted.
Parameters:
signature - to convert
name - of method
access - flags of method
Returns: Human readable signature

methodSignatureToString

public final static String methodSignatureToString(String signature, String name, String access, boolean chopit)
throws java.lang.ClassFormatError
A return\u00adtype signature represents the return value from a method. It is a series of bytes in the following grammar: ::= | V The character V indicates that the method returns no value. Otherwise, the signature indicates the type of the return value. An argument signature represents an argument passed to a method: ::= A method signature represents the arguments that the method expects, and the value that it returns. ::= () ::= * This method converts such a string into a Java type declaration like `void main(String[])' and throws a `ClassFormatError' when the parsed type is invalid.
Parameters:
signature - Method signature
name - Method name
access - Method access rights
Returns: Java type declaration
throw ClassFormatError

methodTypeToSignature

public final static String methodTypeToSignature(String ret, String[] argv)
throws java.lang.ClassFormatError
Converts string containing the method return and argument types to a byte code method signature.
Parameters:
ret - Return type of method
argv - Types of method arguements
Returns: Byte code representation of method type

replace

public final static String replace(String str, String old, String new_)
Replace all occurences of old in str with new.
Parameters:
str - String to permute
old - String to be replaced
new - Replacement string
Returns: new String object

signatureToString

public final static String signatureToString(String signature)
Converts signature to string with all class names compacted.
Parameters:
signature - to convert
Returns: Human readable signature

signatureToString

public final static String signatureToString(String signature, boolean chopit)
throws java.lang.ClassFormatError
The field signature represents the value of an argument to a function or the value of a variable. It is a series of bytes generated by the following grammar: ::= ::= || ::= B|C|D|F|I|J|S|Z ::= L; ::= [ ::= [0\u00ad9]* The meaning of the base types is as follows: B byte signed byte C char character D double double precision IEEE float F float single precision IEEE float I int integer J long long integer L; ... an object of the given class S short signed short Z boolean true or false [ ... array This method converts this string into a Java type declaration such as `String[]' and throws a `ClassFormatError' when the parsed type is invalid.
Parameters:
signature - Class signature
Returns: Java type declaration
throw ClassFormatError

toHexString

public final static String toHexString(byte[] bytes)

typeOfMethodSignature

public final static byte typeOfMethodSignature(String signature)
throws java.lang.ClassFormatError
Parameters:
signature - in format described above
Returns: type of method signature
See Also:
Constants
throw ClassFormatError

typeOfSignature

public final static byte typeOfSignature(String signature)
throws java.lang.ClassFormatError
Return type of signature as a byte value as defined in Constants
Parameters:
signature - in format described above
Returns: type of signature
See Also:
Constants
throw ClassFormatError

typeToSignature

public final static String typeToSignature(String str)
throws java.lang.ClassFormatError
Gets Java conformant type like `String[]' and returns a string containing the type in byte code format, i.e. String[] becomes [Ljava/lang/String;
Parameters:
str - Type string like int[][]
Returns: Byte code representation of type like [[I