Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

ClassFile Class Reference

Inheritance diagram for ClassFile:
[legend]
Collaboration diagram for ClassFile:
[legend]
List of all members.

Public Methods

Body buildBodyOfFrom (SootMethod m, Body sourceBody, int options)
boolean readClass (DataInputStream d)
String toString ()

Static Public Methods

ClassFile v ()

Public Attributes

cp_info constant_pool []
int this_class

Protected Methods

boolean readAttributes (DataInputStream d, int attributes_count, attribute_info[] ai) throws IOException
boolean readConstantPool (DataInputStream d) throws IOException
boolean readFields (DataInputStream d) throws IOException
boolean readMethods (DataInputStream d) throws IOException
boolean writeAttributes (DataOutputStream dd, int attributes_count, attribute_info[] ai) throws IOException
boolean writeConstantPool (DataOutputStream dd) throws IOException
boolean writeFields (DataOutputStream dd) throws IOException
boolean writeMethods (DataOutputStream dd) throws IOException

Private Methods

 ClassFile ()
 ClassFile (String nfn)
boolean descendsFrom (ClassFile cf)
boolean descendsFrom (String cname)
String fieldName (int i)
method_info findMethod (String s)
boolean isSterile ()
void listConstantPool ()
void listFields ()
void listMethods ()
boolean loadClassFile ()
void moveMethod (String m, int pos)
void parse ()
Instruction parseMethod (method_info m)
int relabel (Instruction i)
boolean sameClass (String cfn)
boolean saveClassFile ()
void unparse ()
byte[] unparseMethod (method_info m)
boolean writeClass (DataOutputStream dd)

Static Private Methods

String access_string (int af, String separator)
String parseDesc (String desc, String sep)
String parseMethodDesc_params (String s)
String parseMethodDesc_return (String s)

Private Attributes

boolean debug
String fn
long magic
int minor_version
int major_version
int constant_pool_count
int access_flags
int super_class
int interfaces_count
int interfaces []
int fields_count
field_info fields []
int methods_count
method_info methods []
int attributes_count
attribute_info attributes []

Static Private Attributes

ClassFile classFileRepresentation = new ClassFile()
final long MAGIC = 0xCAFEBABEL
final short ACC_PUBLIC = 0x0001
final short ACC_PRIVATE = 0x0002
final short ACC_PROTECTED = 0x0004
final short ACC_STATIC = 0x0008
final short ACC_FINAL = 0x0010
final short ACC_SUPER = 0x0020
final short ACC_VOLATILE = 0x0040
final short ACC_TRANSIENT = 0x0080
final short ACC_INTERFACE = 0x0200
final short ACC_ABSTRACT = 0x0400
final short ACC_UNKNOWN = 0x7800
final String DESC_BYTE = "B"
final String DESC_CHAR = "C"
final String DESC_DOUBLE = "D"
final String DESC_FLOAT = "F"
final String DESC_INT = "I"
final String DESC_LONG = "J"
final String DESC_OBJECT = "L"
final String DESC_SHORT = "S"
final String DESC_BOOLEAN = "Z"
final String DESC_VOID = "V"
final String DESC_ARRAY = "["

Detailed Description

A ClassFile object represents the contents of a .class file.

A ClassFile contains code for manipulation of its constituents.

Author:
Clark Verbrugge

Definition at line 78 of file ClassFile.java.


Constructor & Destructor Documentation

ClassFile::ClassFile String   nfn [inline, private]
 

Creates a new ClassFile object given the name of the file.

Parameters:
nfn   file name which this ClassFile will represent.

Definition at line 435 of file coffi/ClassFile.java.


Member Function Documentation

String ClassFile::access_string int   af,
String   separator
[inline, static, private]
 

Returns a String constructed by parsing the bits in the given access code (as defined by the ACC_* constants).

Parameters:
af   access code.
separator   String used to separate words used for access bits.
See also:
ClassFile::access_flags , method_info::access_flags , field_info::access_flags

Definition at line 444 of file coffi/ClassFile.java.

Body ClassFile::buildBodyOfFrom SootMethod   m,
Body   sourceBody,
int   options
[inline]
 

Returns a Body representing the ClassFile body. Only 'null' can be passed as the source.

Definition at line 89 of file ClassFile.java.

boolean ClassFile::descendsFrom String   cname [inline, private]
 

Answers whether this class is an immediate descendant (as subclass or as an implementation of an interface) of the given class.

Parameters:
cname   name of supposed parent.
Returns:
true if it is a parent, false otherwise.
See also:
ClassFile::descendsFrom(ClassFile)

Definition at line 516 of file coffi/ClassFile.java.

boolean ClassFile::descendsFrom ClassFile   cf [inline, private]
 

Answers whether this class is an immediate descendant (as subclass or as an implementation of an interface) of the given class.

Parameters:
cf   ClassFile of supposed parent.
Returns:
true if it is a parent, false otherwise.
See also:
ClassFile::descendsFrom(String)

Definition at line 509 of file coffi/ClassFile.java.

String ClassFile::fieldName int   i [inline, private]
 

Returns the name of a specific field in the field array.

Parameters:
i   index of field in field array.
Returns:
name of field.

Definition at line 531 of file coffi/ClassFile.java.

method_info ClassFile::findMethod String   s [inline, private]
 

Locates a method by name.

Parameters:
s   name of method.
Returns:
method_info object representing method, or null if not found.
See also:
method_info::toName

Definition at line 539 of file coffi/ClassFile.java.

boolean ClassFile::isSterile   [inline, private]
 

Answers whether this class can have subclasses outside its package.

Returns:
true if it cannot, false if it might.

Definition at line 554 of file coffi/ClassFile.java.

void ClassFile::listConstantPool   [inline, private]
 

Displays the entire constant pool.

See also:
ClassFile::constant_pool , ClassFile::constant_pool_count , cp_info::toString

Definition at line 563 of file coffi/ClassFile.java.

void ClassFile::listFields   [inline, private]
 

Displays the list of fields defined in this ClassFile, including any static initializers (constants).

See also:
ClassFile::fields , ClassFile::fields_count , field_info::prototype , ConstantValue_attribute

Definition at line 586 of file coffi/ClassFile.java.

void ClassFile::listMethods   [inline, private]
 

Displays a the prototypes for all the methods defined in this ClassFile.

See also:
ClassFile::methods , ClassFile::methods_count , method_info::prototype

Definition at line 615 of file coffi/ClassFile.java.

boolean ClassFile::loadClassFile   [inline, private]
 

Main entry point for reading in a class file. The file name is given in the constructor; this opens the file and reads in the contents, building the representation.

Returns:
true on success.

Definition at line 627 of file coffi/ClassFile.java.

void ClassFile::moveMethod String   m,
int   pos
[inline, private]
 

Moves a method to a different index in the methods array.

Parameters:
m   name of method to move.
pos   desired index.
See also:
ClassFile::methods

Definition at line 666 of file coffi/ClassFile.java.

void ClassFile::parse   [inline, private]
 

For every method, this calls parseMethod, storing the list of Instructions in the method_info object, and also constructs the corresponding CFG.

See also:
ClassFile::parseMethod , CFG

Definition at line 693 of file coffi/ClassFile.java.

Referenced by loadClassFile().

String ClassFile::parseDesc String   desc,
String   sep
[inline, static, private]
 

Static utility method to parse the given method descriptor string.

Parameters:
desc   descriptor string.
sep   String to use as a separator between types.
Returns:
String of types parsed.
See also:
ClassFile::parseDesc , ClassFile::parseMethodDesc_return

Definition at line 711 of file coffi/ClassFile.java.

Referenced by parseMethodDesc_params(), and parseMethodDesc_return().

Instruction ClassFile::parseMethod method_info   m [inline, private]
 

Parses the given method, converting its bytecode array into a list of Instruction objects.

Parameters:
m   method to parse.
Returns:
head of a list of Instructions.
See also:
Instruction , ByteCode , ByteCode::disassemble_bytecode

Definition at line 777 of file coffi/ClassFile.java.

Referenced by parse().

String ClassFile::parseMethodDesc_params String   s [inline, static, private]
 

Static utility method to parse the given method descriptor string.

Parameters:
s   descriptor string.
Returns:
comma-separated ordered list of parameter types
See also:
ClassFile::parseDesc , ClassFile::parseMethodDesc_return

Definition at line 837 of file coffi/ClassFile.java.

String ClassFile::parseMethodDesc_return String   s [inline, static, private]
 

Static utility method to parse the given method descriptor string.

Parameters:
s   descriptor string.
Returns:
return type of method.
See also:
ClassFile::parseDesc , ClassFile::parseMethodDesc_params

Definition at line 854 of file coffi/ClassFile.java.

boolean ClassFile::readAttributes DataInputStream   d,
int   attributes_count,
attribute_info   ai[]
[inline, protected]
 

Reads in the given number of attributes from the given stream.

Parameters:
d   Stream forming the .class file.
attributes_count   number of attributes to read in.
ai   pre-allocated array of attributes to be filled in.
Returns:
true if read was successful, false on some error.
Exceptions:
java   .io.IOException on error.

Definition at line 869 of file coffi/ClassFile.java.

Referenced by readClass(), readFields(), and readMethods().

boolean ClassFile::readClass DataInputStream   d [inline]
 

Builds the internal representation of this Class by reading in the given class file.

Parameters:
d   Stream forming the .class file.
Returns:
true if read was successful, false on some error.

Definition at line 975 of file coffi/ClassFile.java.

Referenced by loadClassFile().

boolean ClassFile::readConstantPool DataInputStream   d [inline, protected]
 

Reads in the constant pool from the given stream.

Parameters:
d   Stream forming the .class file.
Returns:
true if read was successful, false on some error.
Exceptions:
java   .io.IOException on error.

Definition at line 1038 of file coffi/ClassFile.java.

Referenced by readClass().

boolean ClassFile::readFields DataInputStream   d [inline, protected]
 

Reads in the fields from the given stream.

Parameters:
d   Stream forming the .class file.
Returns:
true if read was successful, false on some error.
Exceptions:
java   .io.IOException on error.

Definition at line 1164 of file coffi/ClassFile.java.

Referenced by readClass().

boolean ClassFile::readMethods DataInputStream   d [inline, protected]
 

Reads in the methods from the given stream.

Parameters:
d   Stream forming the .class file.
Returns:
true if read was successful, false on some error.
Exceptions:
java   .io.IOException on error.

Definition at line 1193 of file coffi/ClassFile.java.

Referenced by readClass().

int ClassFile::relabel Instruction   i [inline, private]
 

Recomputes the offset of each Instruction starting from 0; used when converting references back to offsets.

Parameters:
i   list of Instructions to process.
Returns:
length of corresponding bytecode.
See also:
Instruction::nextOffset

Definition at line 1231 of file coffi/ClassFile.java.

Referenced by unparseMethod().

boolean ClassFile::sameClass String   cfn [inline, private]
 

Given the name of a class --- possibly with .class after it, this answers whether the class might refer to this ClassFile object.

Returns:
true if it does, false if it doesn't.

Definition at line 1244 of file coffi/ClassFile.java.

boolean ClassFile::saveClassFile   [inline, private]
 

Main entry point for writing a class file. The file name is given in the constructor; this opens the file and writes the internal representation.

Returns:
true on success.

Definition at line 1259 of file coffi/ClassFile.java.

String ClassFile::toString   [inline]
 

Returns the name of this Class.

Definition at line 1302 of file coffi/ClassFile.java.

Referenced by descendsFrom(), and sameClass().

void ClassFile::unparse   [inline, private]
 

Inversive to parse, this method calls unparseMethod for each method, storing the resulting bytecode in the method's code attribute, and recomputing offsets for exception handlers.

See also:
ClassFile::unparseMethod

Definition at line 1310 of file coffi/ClassFile.java.

byte [] ClassFile::unparseMethod method_info   m [inline, private]
 

Inversive to parseMethod, this converts the list of Instructions stored in a method_info object back to an array of bytecode.

Parameters:
m   method to unparse.
Returns:
array of bytecode, or null on error.
See also:
CFG::reconstructInstructions , ClassFile::parseMethod , ClassFile::relabel , Instruction::compile

Definition at line 1351 of file coffi/ClassFile.java.

Referenced by unparse().

boolean ClassFile::writeAttributes DataOutputStream   dd,
int   attributes_count,
attribute_info   ai[]
[inline, protected]
 

Writes the given array of attributes to the given stream.

Parameters:
dd   output stream.
attributes_count   number of attributes to write.
ai   array of attributes to write.
Returns:
true if write was successful, false on some error.
Exceptions:
java   .io.IOException on error.

Definition at line 1388 of file coffi/ClassFile.java.

Referenced by writeClass(), writeFields(), and writeMethods().

boolean ClassFile::writeClass DataOutputStream   dd [inline, private]
 

Writes this entire ClassFile object to the given stream.

Parameters:
dd   output stream.
Returns:
true if write was successful, false on some error.

Definition at line 1470 of file coffi/ClassFile.java.

Referenced by saveClassFile().

boolean ClassFile::writeConstantPool DataOutputStream   dd [inline, protected]
 

Writes the current constant pool to the given stream.

Parameters:
dd   output stream.
Returns:
true if write was successful, false on some error.
Exceptions:
java   .io.IOException on error.

Definition at line 1528 of file coffi/ClassFile.java.

Referenced by writeClass().

boolean ClassFile::writeFields DataOutputStream   dd [inline, protected]
 

Writes the fields to the given stream.

Parameters:
dd   output stream.
Returns:
true if write was successful, false on some error.
Exceptions:
java   .io.IOException on error.

Definition at line 1598 of file coffi/ClassFile.java.

Referenced by writeClass().

boolean ClassFile::writeMethods DataOutputStream   dd [inline, protected]
 

Writes the methods to the given stream.

Parameters:
dd   output stream.
Returns:
true if write was successful, false on some error.
Exceptions:
java   .io.IOException on error.

Definition at line 1619 of file coffi/ClassFile.java.

Referenced by writeClass().


Member Data Documentation

final short ClassFile::ACC_ABSTRACT = 0x0400 [static, private]
 

Access bit flag.

Definition at line 160 of file coffi/ClassFile.java.

final short ClassFile::ACC_FINAL = 0x0010 [static, private]
 

Access bit flag.

Definition at line 150 of file coffi/ClassFile.java.

final short ClassFile::ACC_INTERFACE = 0x0200 [static, private]
 

Access bit flag.

Definition at line 158 of file coffi/ClassFile.java.

final short ClassFile::ACC_PRIVATE = 0x0002 [static, private]
 

Access bit flag.

Definition at line 144 of file coffi/ClassFile.java.

final short ClassFile::ACC_PROTECTED = 0x0004 [static, private]
 

Access bit flag.

Definition at line 146 of file coffi/ClassFile.java.

final short ClassFile::ACC_PUBLIC = 0x0001 [static, private]
 

Access bit flag.

Definition at line 142 of file coffi/ClassFile.java.

final short ClassFile::ACC_STATIC = 0x0008 [static, private]
 

Access bit flag.

Definition at line 148 of file coffi/ClassFile.java.

final short ClassFile::ACC_SUPER = 0x0020 [static, private]
 

Access bit flag.

Definition at line 152 of file coffi/ClassFile.java.

final short ClassFile::ACC_TRANSIENT = 0x0080 [static, private]
 

Access bit flag.

Definition at line 156 of file coffi/ClassFile.java.

final short ClassFile::ACC_UNKNOWN = 0x7800 [static, private]
 

Remaining bits in the access bit flag.

Definition at line 162 of file coffi/ClassFile.java.

final short ClassFile::ACC_VOLATILE = 0x0040 [static, private]
 

Access bit flag.

Definition at line 154 of file coffi/ClassFile.java.

final String ClassFile::DESC_ARRAY = "[" [static, private]
 

Descriptor code string.

Definition at line 185 of file coffi/ClassFile.java.

final String ClassFile::DESC_BOOLEAN = "Z" [static, private]
 

Descriptor code string.

Definition at line 181 of file coffi/ClassFile.java.

final String ClassFile::DESC_BYTE = "B" [static, private]
 

Descriptor code string.

Definition at line 165 of file coffi/ClassFile.java.

final String ClassFile::DESC_CHAR = "C" [static, private]
 

Descriptor code string.

Definition at line 167 of file coffi/ClassFile.java.

final String ClassFile::DESC_DOUBLE = "D" [static, private]
 

Descriptor code string.

Definition at line 169 of file coffi/ClassFile.java.

final String ClassFile::DESC_FLOAT = "F" [static, private]
 

Descriptor code string.

Definition at line 171 of file coffi/ClassFile.java.

final String ClassFile::DESC_INT = "I" [static, private]
 

Descriptor code string.

Definition at line 173 of file coffi/ClassFile.java.

final String ClassFile::DESC_LONG = "J" [static, private]
 

Descriptor code string.

Definition at line 175 of file coffi/ClassFile.java.

final String ClassFile::DESC_OBJECT = "L" [static, private]
 

Descriptor code string.

Definition at line 177 of file coffi/ClassFile.java.

final String ClassFile::DESC_SHORT = "S" [static, private]
 

Descriptor code string.

Definition at line 179 of file coffi/ClassFile.java.

final String ClassFile::DESC_VOID = "V" [static, private]
 

Descriptor code string.

Definition at line 183 of file coffi/ClassFile.java.

final long ClassFile::MAGIC = 0xCAFEBABEL [static, private]
 

Magic number.

Definition at line 139 of file coffi/ClassFile.java.

int ClassFile::access_flags [private]
 

Access flags for this Class.

Definition at line 212 of file coffi/ClassFile.java.

attribute_info ClassFile::attributes[] [private]
 

Array of attribute_info objects for this class.

See also:
attribute_info

Definition at line 246 of file coffi/ClassFile.java.

int ClassFile::attributes_count [private]
 

Count of attributes this class contains.

Definition at line 242 of file coffi/ClassFile.java.

cp_info ClassFile::constant_pool[]
 

Array of constant pool items.

See also:
cp_info

Definition at line 209 of file coffi/ClassFile.java.

int ClassFile::constant_pool_count [private]
 

Number of items in the constant pool.

Definition at line 205 of file coffi/ClassFile.java.

boolean ClassFile::debug [private]
 

Debugging flag.

Definition at line 188 of file coffi/ClassFile.java.

field_info ClassFile::fields[] [private]
 

Array of field_info objects describing each field.

See also:
field_info

Definition at line 234 of file coffi/ClassFile.java.

int ClassFile::fields_count [private]
 

Count of fields this Class contains.

Definition at line 230 of file coffi/ClassFile.java.

String ClassFile::fn [private]
 

File name of the .class this represents.

Definition at line 191 of file coffi/ClassFile.java.

int ClassFile::interfaces[] [private]
 

Array of constant pool indices of Class constants describing each interace implemented by this class, as given in the source for this class.

See also:
CONSTANT_Class_info

Definition at line 228 of file coffi/ClassFile.java.

int ClassFile::interfaces_count [private]
 

Count of interfaces implemented.

Definition at line 222 of file coffi/ClassFile.java.

long ClassFile::magic [private]
 

Magic number read in.

See also:
ClassFile::MAGIC

Definition at line 199 of file coffi/ClassFile.java.

int ClassFile::major_version [private]
 

Major version.

Definition at line 203 of file coffi/ClassFile.java.

method_info ClassFile::methods[] [private]
 

Array of method_info objects describing each field.

See also:
method_info

Definition at line 240 of file coffi/ClassFile.java.

int ClassFile::methods_count [private]
 

Count of methods this Class contains.

Definition at line 236 of file coffi/ClassFile.java.

int ClassFile::minor_version [private]
 

Minor version.

Definition at line 201 of file coffi/ClassFile.java.

int ClassFile::super_class [private]
 

Constant pool index of the Class constant describing super.

See also:
CONSTANT_Class_info

Definition at line 220 of file coffi/ClassFile.java.

int ClassFile::this_class
 

Constant pool index of the Class constant describing this.

See also:
CONSTANT_Class_info

Definition at line 216 of file coffi/ClassFile.java.


The documentation for this class was generated from the following files:
Generated at Thu Feb 7 07:06:21 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001