public abstract class Utility
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
private static class |
Utility.JavaReader
Decode characters into bytes.
|
private static class |
Utility.JavaWriter
Encode bytes into valid java identifier characters.
|
Modifier and Type | Field and Description |
---|---|
private static int[] |
CHAR_MAP |
private static java.lang.ThreadLocal<java.lang.Integer> |
consumed_chars |
private static char |
ESCAPE_CHAR |
private static int |
FREE_CHARS |
private static int[] |
MAP_CHAR |
private static boolean |
wide |
Constructor and Description |
---|
Utility() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
accessToString(int access_flags)
Convert bit field of flags into string such as `static final'.
|
static java.lang.String |
accessToString(int access_flags,
boolean for_class)
Convert bit field of flags into string such as `static final'.
|
private static short |
byteToShort(byte b)
Convert (signed) byte to (unsigned) short value, i.e., all negative
values become positive.
|
static java.lang.String |
classOrInterface(int access_flags) |
static int |
clearBit(int flag,
int i) |
static java.lang.String |
codeToString(byte[] code,
ConstantPool constant_pool,
int index,
int length) |
static java.lang.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.
|
static java.lang.String |
codeToString(ByteSequence bytes,
ConstantPool constant_pool) |
static java.lang.String |
codeToString(ByteSequence bytes,
ConstantPool constant_pool,
boolean verbose)
Disassemble a stream of byte codes and return the
string representation.
|
static java.lang.String |
compactClassName(java.lang.String str)
Shorten long class names, java/lang/String becomes
String.
|
static java.lang.String |
compactClassName(java.lang.String str,
boolean chopit)
Shorten long class names, java/lang/String becomes
java.lang.String,
e.g..
|
static java.lang.String |
compactClassName(java.lang.String str,
java.lang.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.
|
static java.lang.String |
convertString(java.lang.String label)
Escape all occurences of newline chars '\n', quotes \", etc.
|
private static int |
countBrackets(java.lang.String brackets) |
static byte[] |
decode(java.lang.String s,
boolean uncompress)
Decode a string back to a byte array.
|
static java.lang.String |
encode(byte[] bytes,
boolean compress)
Encode byte array it into Java identifier string, i.e., a string
that only contains the following characters: (a, ...
|
(package private) static boolean |
equals(byte[] a,
byte[] b) |
static java.lang.String |
fillup(java.lang.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.
|
static java.lang.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.
|
static java.lang.String |
getSignature(java.lang.String type)
Parse Java type such as "char", or "java.lang.String[]" and return the
signature in byte code format, e.g.
|
static boolean |
isJavaIdentifierPart(char ch) |
static boolean |
isSet(int flag,
int i) |
static java.lang.String[] |
methodSignatureArgumentTypes(java.lang.String signature) |
static java.lang.String[] |
methodSignatureArgumentTypes(java.lang.String signature,
boolean chopit) |
static java.lang.String |
methodSignatureReturnType(java.lang.String signature) |
static java.lang.String |
methodSignatureReturnType(java.lang.String signature,
boolean chopit) |
static java.lang.String |
methodSignatureToString(java.lang.String signature,
java.lang.String name,
java.lang.String access)
Converts method signature to string with all class names compacted.
|
static java.lang.String |
methodSignatureToString(java.lang.String signature,
java.lang.String name,
java.lang.String access,
boolean chopit) |
static java.lang.String |
methodSignatureToString(java.lang.String signature,
java.lang.String name,
java.lang.String access,
boolean chopit,
LocalVariableTable vars)
A returntype signature represents the return value from a method.
|
static java.lang.String |
methodTypeToSignature(java.lang.String ret,
java.lang.String[] argv)
Converts string containing the method return and argument types
to a byte code method signature.
|
private static int |
pow2(int n) |
static java.lang.String |
printArray(java.lang.Object[] obj) |
static java.lang.String |
printArray(java.lang.Object[] obj,
boolean braces) |
static java.lang.String |
printArray(java.lang.Object[] obj,
boolean braces,
boolean quote) |
static void |
printArray(java.io.PrintStream out,
java.lang.Object[] obj) |
static void |
printArray(java.io.PrintWriter out,
java.lang.Object[] obj) |
static java.lang.String |
replace(java.lang.String str,
java.lang.String old,
java.lang.String new_)
Replace all occurrences of old in str with new.
|
static short |
searchOpcode(java.lang.String name)
Map opcode names to opcode numbers.
|
static int |
setBit(int flag,
int i) |
static java.lang.String |
signatureToString(java.lang.String signature)
Converts signature to string with all class names compacted.
|
static java.lang.String |
signatureToString(java.lang.String signature,
boolean chopit)
The field signature represents the value of an argument to a function or
the value of a variable.
|
static java.lang.String |
toHexString(byte[] bytes)
Convert bytes into hexadecimal string
|
static byte |
typeOfMethodSignature(java.lang.String signature)
Return type of method signature as a byte value as defined in Constants
|
static byte |
typeOfSignature(java.lang.String signature)
Return type of signature as a byte value as defined in Constants
|
private static int |
unwrap(java.lang.ThreadLocal<java.lang.Integer> tl) |
private static void |
wrap(java.lang.ThreadLocal<java.lang.Integer> tl,
int value) |
private static java.lang.ThreadLocal<java.lang.Integer> consumed_chars
private static boolean wide
private static final int FREE_CHARS
private static int[] CHAR_MAP
private static int[] MAP_CHAR
private static final char ESCAPE_CHAR
private static int unwrap(java.lang.ThreadLocal<java.lang.Integer> tl)
private static void wrap(java.lang.ThreadLocal<java.lang.Integer> tl, int value)
public static java.lang.String accessToString(int access_flags)
access_flags
- Access flagspublic static java.lang.String accessToString(int access_flags, boolean for_class)
access_flags
- Access flagsfor_class
- access flags are for class qualifiers ?public static java.lang.String classOrInterface(int access_flags)
access_flags
- the class flagspublic static java.lang.String codeToString(byte[] code, ConstantPool constant_pool, int index, int length, boolean verbose)
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 indexpublic static java.lang.String codeToString(byte[] code, ConstantPool constant_pool, int index, int length)
public static java.lang.String codeToString(ByteSequence bytes, ConstantPool constant_pool, boolean verbose) throws java.io.IOException
bytes
- stream of bytesconstant_pool
- Array of constantsverbose
- be verbose, e.g. print constant pool indexjava.io.IOException
- if a failure from reading from the bytes argument occurspublic static java.lang.String codeToString(ByteSequence bytes, ConstantPool constant_pool) throws java.io.IOException
java.io.IOException
public static java.lang.String compactClassName(java.lang.String str)
str
- The long class namepublic static java.lang.String compactClassName(java.lang.String str, java.lang.String prefix, boolean chopit)
str
- The long class nameprefix
- The prefix the get rid offchopit
- Flag that determines whether chopping is executed or notpublic static java.lang.String compactClassName(java.lang.String str, boolean chopit)
str
- The long class namechopit
- Flag that determines whether chopping is executed or notpublic static int setBit(int flag, int i)
public static int clearBit(int flag, int i)
public static boolean isSet(int flag, int i)
public static java.lang.String methodTypeToSignature(java.lang.String ret, java.lang.String[] argv) throws ClassFormatException
ret
- Return type of methodargv
- Types of method argumentsClassFormatException
- if the signature is for Voidpublic static java.lang.String[] methodSignatureArgumentTypes(java.lang.String signature) throws ClassFormatException
signature
- Method signatureClassFormatException
public static java.lang.String[] methodSignatureArgumentTypes(java.lang.String signature, boolean chopit) throws ClassFormatException
signature
- Method signaturechopit
- Shorten class names ?ClassFormatException
public static java.lang.String methodSignatureReturnType(java.lang.String signature) throws ClassFormatException
signature
- Method signatureClassFormatException
public static java.lang.String methodSignatureReturnType(java.lang.String signature, boolean chopit) throws ClassFormatException
signature
- Method signaturechopit
- Shorten class names ?ClassFormatException
public static java.lang.String methodSignatureToString(java.lang.String signature, java.lang.String name, java.lang.String access)
signature
- to convertname
- of methodaccess
- flags of methodpublic static java.lang.String methodSignatureToString(java.lang.String signature, java.lang.String name, java.lang.String access, boolean chopit)
public static java.lang.String methodSignatureToString(java.lang.String signature, java.lang.String name, java.lang.String access, boolean chopit, LocalVariableTable vars) throws ClassFormatException
<return_signature> ::= <field_type> | VThe 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:
<argument_signature> ::= <field_type>A method signature represents the arguments that the method expects, and the value that it returns.
<method_signature> ::= (<arguments_signature>) <return_signature> <arguments_signature>::= <argument_signature>*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 rightschopit
- vars
- ClassFormatException
private static int pow2(int n)
public static java.lang.String replace(java.lang.String str, java.lang.String old, java.lang.String new_)
str
- String to permuteold
- String to be replacednew_
- Replacement stringpublic static java.lang.String signatureToString(java.lang.String signature)
signature
- to convertpublic static java.lang.String signatureToString(java.lang.String signature, boolean chopit)
<field_signature> ::= <field_type> <field_type> ::= <base_type>|<object_type>|<array_type> <base_type> ::= B|C|D|F|I|J|S|Z <object_type> ::= L<fullclassname>; <array_type> ::= [<field_type> 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<fullclassname>; ... an object of the given class S short signed short Z boolean true or false [<field sig> ... arrayThis 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 notClassFormatException
public static java.lang.String getSignature(java.lang.String type)
type
- Java typeprivate static int countBrackets(java.lang.String brackets)
public static byte typeOfMethodSignature(java.lang.String signature) throws ClassFormatException
signature
- in format described aboveClassFormatException
- if signature is not a method signatureConst
public static byte typeOfSignature(java.lang.String signature) throws ClassFormatException
signature
- in format described aboveClassFormatException
- if signature isn't a known typeConst
public static short searchOpcode(java.lang.String name)
private static short byteToShort(byte b)
public static java.lang.String toHexString(byte[] bytes)
bytes
- an array of bytes to convert to hexadecimalpublic static java.lang.String format(int i, int length, boolean left_justify, char fill)
i
- integer to formatlength
- length of desired stringleft_justify
- format left or rightfill
- fill characterpublic static java.lang.String fillup(java.lang.String str, int length, boolean left_justify, char fill)
str
- string to formatlength
- length of desired stringleft_justify
- format left or rightfill
- fill characterstatic boolean equals(byte[] a, byte[] b)
public static void printArray(java.io.PrintStream out, java.lang.Object[] obj)
public static void printArray(java.io.PrintWriter out, java.lang.Object[] obj)
public static java.lang.String printArray(java.lang.Object[] obj)
public static java.lang.String printArray(java.lang.Object[] obj, boolean braces)
public static java.lang.String printArray(java.lang.Object[] obj, boolean braces, boolean quote)
public static boolean isJavaIdentifierPart(char ch)
ch
- the character to test if it's part of an identifierpublic static java.lang.String encode(byte[] bytes, boolean compress) throws java.io.IOException
This operation inflates the original byte array by roughly 40-50%
bytes
- the byte array to convertcompress
- use gzip to minimize stringjava.io.IOException
- if there's a gzip exceptionpublic static byte[] decode(java.lang.String s, boolean uncompress) throws java.io.IOException
s
- the string to convertuncompress
- use gzip to uncompress the stream of bytesjava.io.IOException
- if there's a gzip exceptionpublic static java.lang.String convertString(java.lang.String label)