soot.coffi
Class ClassFile

java.lang.Object
  |
  +--soot.coffi.ClassFile

public class ClassFile
extends java.lang.Object

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

A ClassFile contains code for manipulation of its constituents.


Field Summary
 int access_flags
          Access flags for this Class.
 int attributes_count
          Count of attributes this class contains.
 soot.coffi.cp_info[] constant_pool
          Array of constant pool items.
 int constant_pool_count
          Number of items in the constant pool.
 field_info[] fields
          Array of field_info objects describing each field.
 int fields_count
          Count of fields this Class contains.
 int[] interfaces
          Array of constant pool indices of Class constants describing each interace implemented by this class, as given in the source for this class.
 int interfaces_count
          Count of interfaces implemented.
 method_info[] methods
          Array of method_info objects describing each field.
 int methods_count
          Count of methods this Class contains.
 int super_class
          Constant pool index of the Class constant describing super.
 int this_class
          Constant pool index of the Class constant describing this.
 
Constructor Summary
ClassFile(java.lang.String nfn)
          Creates a new ClassFile object given the name of the file.
 
Method Summary
 boolean loadClassFile()
          Main entry point for reading in a class file.
 boolean loadClassFile(java.io.InputStream is)
           
 void parse()
          For every method, this calls parseMethod, storing the list of Instructions in the method_info object, and also constructs the corresponding CFG.
 soot.coffi.Instruction parseMethod(method_info m)
          Parses the given method, converting its bytecode array into a list of Instruction objects.
protected  boolean readAttributes(java.io.DataInputStream d, int attributes_count, soot.coffi.attribute_info[] ai)
          Reads in the given number of attributes from the given stream.
 boolean readClass(java.io.DataInputStream d)
          Builds the internal representation of this Class by reading in the given class file.
protected  boolean readConstantPool(java.io.DataInputStream d)
          Reads in the constant pool from the given stream.
protected  boolean readFields(java.io.DataInputStream d)
          Reads in the fields from the given stream.
protected  boolean readMethods(java.io.DataInputStream d)
          Reads in the methods from the given stream.
 java.lang.String toString()
          Returns the name of this Class.
protected  boolean writeAttributes(java.io.DataOutputStream dd, int attributes_count, soot.coffi.attribute_info[] ai)
          Writes the given array of attributes to the given stream.
protected  boolean writeConstantPool(java.io.DataOutputStream dd)
          Writes the current constant pool to the given stream.
protected  boolean writeFields(java.io.DataOutputStream dd)
          Writes the fields to the given stream.
protected  boolean writeMethods(java.io.DataOutputStream dd)
          Writes the methods to the given stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

constant_pool_count

public int constant_pool_count
Number of items in the constant pool.

constant_pool

public soot.coffi.cp_info[] constant_pool
Array of constant pool items.
See Also:
cp_info

access_flags

public int access_flags
Access flags for this Class.

this_class

public int this_class
Constant pool index of the Class constant describing this.
See Also:
CONSTANT_Class_info

super_class

public int super_class
Constant pool index of the Class constant describing super.
See Also:
CONSTANT_Class_info

interfaces_count

public int interfaces_count
Count of interfaces implemented.

interfaces

public int[] interfaces
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

fields_count

public int fields_count
Count of fields this Class contains.

fields

public field_info[] fields
Array of field_info objects describing each field.
See Also:
field_info

methods_count

public int methods_count
Count of methods this Class contains.

methods

public method_info[] methods
Array of method_info objects describing each field.
See Also:
method_info

attributes_count

public int attributes_count
Count of attributes this class contains.
Constructor Detail

ClassFile

public ClassFile(java.lang.String nfn)
Creates a new ClassFile object given the name of the file.
Parameters:
nfn - file name which this ClassFile will represent.
Method Detail

toString

public java.lang.String toString()
Returns the name of this Class.
Overrides:
toString in class java.lang.Object

loadClassFile

public boolean loadClassFile()
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.

loadClassFile

public boolean loadClassFile(java.io.InputStream is)

readClass

public boolean readClass(java.io.DataInputStream d)
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.

readConstantPool

protected boolean readConstantPool(java.io.DataInputStream d)
                            throws java.io.IOException
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.
Throws:
java.io.IOException - on error.

readAttributes

protected boolean readAttributes(java.io.DataInputStream d,
                                 int attributes_count,
                                 soot.coffi.attribute_info[] ai)
                          throws java.io.IOException
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.
Throws:
java.io.IOException - on error.

readFields

protected boolean readFields(java.io.DataInputStream d)
                      throws java.io.IOException
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.
Throws:
java.io.IOException - on error.

readMethods

protected boolean readMethods(java.io.DataInputStream d)
                       throws java.io.IOException
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.
Throws:
java.io.IOException - on error.

writeConstantPool

protected boolean writeConstantPool(java.io.DataOutputStream dd)
                             throws java.io.IOException
Writes the current constant pool to the given stream.
Parameters:
dd - output stream.
Returns:
true if write was successful, false on some error.
Throws:
java.io.IOException - on error.

writeAttributes

protected boolean writeAttributes(java.io.DataOutputStream dd,
                                  int attributes_count,
                                  soot.coffi.attribute_info[] ai)
                           throws java.io.IOException
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.
Throws:
java.io.IOException - on error.

writeFields

protected boolean writeFields(java.io.DataOutputStream dd)
                       throws java.io.IOException
Writes the fields to the given stream.
Parameters:
dd - output stream.
Returns:
true if write was successful, false on some error.
Throws:
java.io.IOException - on error.

writeMethods

protected boolean writeMethods(java.io.DataOutputStream dd)
                        throws java.io.IOException
Writes the methods to the given stream.
Parameters:
dd - output stream.
Returns:
true if write was successful, false on some error.
Throws:
java.io.IOException - on error.

parseMethod

public soot.coffi.Instruction parseMethod(method_info m)
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(byte[], int)

parse

public void parse()
For every method, this calls parseMethod, storing the list of Instructions in the method_info object, and also constructs the corresponding CFG.
See Also:
parseMethod(soot.coffi.method_info), CFG