Utility functions that do not really belong to any class in particular.
accessToString
public static final String accessToString(int access_flags)
Convert bit field of flags into string such as `static final'.
access_flags
- Access flags
- String representation of flags
accessToString
public static final 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'.
access_flags
- Access flagsfor_class
- access flags are for class qualifiers ?
- String representation of flags
classOrInterface
public static final String classOrInterface(int access_flags)
- "class" or "interface", depending on the ACC_INTERFACE flag
clearBit
public static final int clearBit(int flag,
int i)
- `flag' with bit `i' set to 0
codeToString
public static final String codeToString(byte[] code,
ConstantPool constant_pool,
int index,
int length)
codeToString
public static final String codeToString(byte[] code,
ConstantPool constant_pool,
int index,
int length,
boolean verbose)
Disassemble a byte array of JVM byte codes starting from code line
`index' and return the disassembled string representation. Decode only
`num' opcodes (including their operands), use -1 if you want to
decompile everything.
code
- byte code arrayconstant_pool
- Array of constantsindex
- offset in `code' array
(number of opcodes, not bytes!)length
- number of opcodes to decompile, -1 for allverbose
- be verbose, e.g. print constant pool index
- String representation of byte codes
codeToString
public static final String codeToString(ByteSequence bytes,
ConstantPool constant_pool,
boolean verbose)
throws IOException
Disassemble a stream of byte codes and return the
string representation.
bytes
- stream of bytesconstant_pool
- Array of constantsverbose
- be verbose, e.g. print constant pool index
- String representation of byte code
compactClassName
public static final String compactClassName(String str)
Shorten long class names, java/lang/String becomes
String.
str
- The long class name
compactClassName
public static final 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 ..
str
- The long class nameprefix
- The prefix the get rid offchopit
- Flag that determines whether chopping is executed or not
compactClassName
public static final 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.
str
- The long class namechopit
- Flag that determines whether chopping is executed or not
convertString
public static final String convertString(String label)
Escape all occurences of newline chars '\n', quotes \", etc.
decode
public static byte[] decode(String s,
boolean uncompress)
throws IOException
Decode a string back to a byte array.
uncompress
- use gzip to uncompress the stream of bytes
encode
public static String encode(byte[] bytes,
boolean compress)
throws IOException
Encode byte array it into Java identifier string, i.e., a string
that only contains the following characters: (a, ... z, A, ... Z,
0, ... 9, _, $). The encoding algorithm itself is not too
clever: if the current byte's ASCII value already is a valid Java
identifier part, leave it as it is. Otherwise it writes the
escape character($) followed by
- the ASCII value as a
hexadecimal string, if the value is not in the range
200..247
- a Java identifier char not used in a lowercase
hexadecimal string, if the value is in the range
200..247
bytes
- the byte array to convertcompress
- use gzip to minimize string
fillup
public static final String fillup(String str,
int length,
boolean left_justify,
char fill)
Fillup char with up to length characters with char `fill' and justify it left or right.
str
- string to formatlength
- length of desired stringleft_justify
- format left or rightfill
- fill character
format
public static final String format(int i,
int length,
boolean left_justify,
char fill)
Return a string for an integer justified left or right and filled up with
`fill' characters if necessary.
i
- integer to formatlength
- length of desired stringleft_justify
- format left or rightfill
- fill character
getSignature
public static String getSignature(String type)
Parse Java type such as "char", or "java.lang.String[]" and return the
signature in byte code format, e.g. "C" or "[Ljava/lang/String;" respectively.
isJavaIdentifierPart
public static boolean isJavaIdentifierPart(char ch)
- true, if character is one of (a, ... z, A, ... Z, 0, ... 9, _)
isSet
public static final boolean isSet(int flag,
int i)
- true, if bit `i' in `flag' is set
methodSignatureArgumentTypes
public static final String[] methodSignatureArgumentTypes(String signature)
throws ClassFormatException
signature
- Method signature
methodSignatureArgumentTypes
public static final String[] methodSignatureArgumentTypes(String signature,
boolean chopit)
throws ClassFormatException
signature
- Method signaturechopit
- Shorten class names ?
methodSignatureReturnType
public static final String methodSignatureReturnType(String signature)
throws ClassFormatException
signature
- Method signature
methodSignatureReturnType
public static final String methodSignatureReturnType(String signature,
boolean chopit)
throws ClassFormatException
signature
- Method signaturechopit
- Shorten class names ?
methodSignatureToString
public static final String methodSignatureToString(String signature,
String name,
String access)
Converts method signature to string with all class names compacted.
signature
- to convertname
- of methodaccess
- flags of method
methodSignatureToString
public static final String methodSignatureToString(String signature,
String name,
String access,
boolean chopit)
methodSignatureToString
public static final String methodSignatureToString(String signature,
String name,
String access,
boolean chopit,
LocalVariableTable vars)
throws ClassFormatException
A return?type 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 `ClassFormatException' when the parsed
type is invalid.
signature
- Method signaturename
- Method nameaccess
- Method access rights
methodTypeToSignature
public static final String methodTypeToSignature(String ret,
String[] argv)
throws ClassFormatException
Converts string containing the method return and argument types
to a byte code method signature.
ret
- Return type of methodargv
- Types of method arguments
- Byte code representation of method signature
printArray
public static final String printArray(Object[] obj)
printArray
public static final String printArray(Object[] obj,
boolean braces)
printArray
public static final String printArray(Object[] obj,
boolean braces,
boolean quote)
printArray
public static final void printArray(PrintStream out,
Object[] obj)
printArray
public static final void printArray(PrintWriter out,
Object[] obj)
replace
public static final String replace(String str,
String old,
String new_)
Replace all occurences of old in str with new.
str
- String to permuteold
- String to be replaced
searchOpcode
public static short searchOpcode(String name)
Map opcode names to opcode numbers. E.g., return Constants.ALOAD for "aload"
setBit
public static final int setBit(int flag,
int i)
- `flag' with bit `i' set to 1
signatureToString
public static final String signatureToString(String signature)
Converts signature to string with all class names compacted.
signatureToString
public static final String signatureToString(String signature,
boolean chopit)
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;
::= [
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 `ClassFormatException' when the parsed type is
invalid.
signature
- Class signaturechopit
- Flag that determines whether chopping is executed or not
toHexString
public static final String toHexString(byte[] bytes)
Convert bytes into hexidecimal string
- bytes as hexidecimal string, e.g. 00 FA 12 ...
typeOfMethodSignature
public static final byte typeOfMethodSignature(String signature)
throws ClassFormatException
Return type of method signature as a byte value as defined in Constants
signature
- in format described above
typeOfSignature
public static final byte typeOfSignature(String signature)
throws ClassFormatException
Return type of signature as a byte value as defined in Constants
signature
- in format described above