com.cmpware.elf
Class ElfInputStream

java.lang.Object
  extended by com.cmpware.elf.ElfInputStream

public class ElfInputStream
extends java.lang.Object

This class is similar to the DataInputStream but with optional byte swapping performed. This is useful for "endian" conversion when reading an ELF file.

Copyright (c) 2004 Cmpware, Inc. All Rights Reserved.

Author:
SAG

Field Summary
static java.lang.String copyright
          Copyright string
 
Constructor Summary
ElfInputStream(byte[] b, boolean byteSwap)
          This constructor that sets up the ELF Input Stream.
ElfInputStream(byte[] b, int offset, boolean byteSwap)
          This constructor that sets up the ELF Input Stream.
ElfInputStream(java.io.InputStream in)
          The constructor that sets up the ELF Input Stream.
ElfInputStream(java.io.InputStream in, boolean byteSwap)
          This constructor that sets up the ELF Input Stream.
ElfInputStream(java.lang.String filename)
          The constructor that sets up the ELF Input Stream.
 
Method Summary
 int getOffset()
          The method returns the current byte offset into the Elf Input Stream.
 boolean isByteSwap()
          This method returns the current byte swapping status for this Input Stream.
 int read(byte[] b)
          This method reads a byte array from the input stream.
 long readAddr()
          This method reads an address from the input stream.
 byte readByte()
          This method reads a byte from the input stream.
 int readInt()
          This method reads an integer from the input stream and does byte swapping if necessary.
 long readLong()
          This method reads a long integer from the input stream and does byte swapping if necessary.
 short readShort()
          This method reads a short from the input stream and does byte swapping if necessary.
 java.lang.String readString()
          This method reads String from the input stream.
 int readUnsignedByte()
          This method reads an unsigned byte from the input stream.
 int readUnsignedShort()
          This method reads an unsigned short from the input stream.
 void setAddrBytes(int bytes)
          This method sets the default address size in bytes.
 void setByteSwap(boolean b)
          This method sets the byte-swapping flag used by the integer and halfword read methods.
 int skipBytes(int i)
          This method skips bytes from the input stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

copyright

public static final java.lang.String copyright
Copyright string

See Also:
Constant Field Values
Constructor Detail

ElfInputStream

public ElfInputStream(java.lang.String filename)
               throws java.io.FileNotFoundException
The constructor that sets up the ELF Input Stream.

Parameters:
filename - The file name of the ELF Input Stream.
Throws:
java.io.FileNotFoundException

ElfInputStream

public ElfInputStream(java.io.InputStream in)
The constructor that sets up the ELF Input Stream.

Parameters:
in - The Input Stream used by the ELF Input Stream.

ElfInputStream

public ElfInputStream(java.io.InputStream in,
                      boolean byteSwap)
This constructor that sets up the ELF Input Stream.

Parameters:
in - The Input Stream used by the ELF Input Stream.
byteSwap - This parameter is set to true if "endian" byte swapping should be used on this input stream and false otherwise.

ElfInputStream

public ElfInputStream(byte[] b,
                      boolean byteSwap)
This constructor that sets up the ELF Input Stream.

Parameters:
b - The byte array used by the ELF Input Stream.
byteSwap - This parameter is set to true if "endian" byte swapping should be used on this input stream and false otherwise.

ElfInputStream

public ElfInputStream(byte[] b,
                      int offset,
                      boolean byteSwap)
This constructor that sets up the ELF Input Stream.

Parameters:
b - The byte array used by the ELF Input Stream.
byteSwap - This parameter is set to true if "endian" byte swapping should be used on this input stream and false otherwise.
Method Detail

setByteSwap

public void setByteSwap(boolean b)
This method sets the byte-swapping flag used by the integer and halfword read methods.

Parameters:
b - The boolean flag used to enable byte swapping.

isByteSwap

public boolean isByteSwap()
This method returns the current byte swapping status for this Input Stream. True indicates that byte swapping is enabled, false indicates that no byte swapping occurs on reads.

Returns:
This method returns the current byte swapping status for this Input Stream. True indicates that byte swapping is enabled, false indicates that no byte swapping occurs on reads.

getOffset

public int getOffset()
The method returns the current byte offset into the Elf Input Stream. This is useful for getting offsets used by some data structures.

Returns:
The method returns the current byte offset of the Elf Input Stream.

setAddrBytes

public void setAddrBytes(int bytes)
This method sets the default address size in bytes. Currently only sizes of 4 and 8 bytes are supported.


readLong

public long readLong()
              throws java.io.IOException,
                     java.io.EOFException
This method reads a long integer from the input stream and does byte swapping if necessary.

Returns:
This method reads a long integer from the input stream and does byte swapping if necessary.
Throws:
java.io.IOException - if an error is encountered in reading the Data Input Stream.
java.io.EOFException - if an end of file is encountered in reading the Data Input Stream.

readInt

public int readInt()
            throws java.io.IOException,
                   java.io.EOFException
This method reads an integer from the input stream and does byte swapping if necessary.

Returns:
This method reads an integer from the input stream and does byte swapping if necessary.
Throws:
java.io.IOException - if an error is encountered in reading the Data Input Stream.
java.io.EOFException - if an end of file is encountered in reading the Data Input Stream.

readShort

public short readShort()
                throws java.io.IOException,
                       java.io.EOFException
This method reads a short from the input stream and does byte swapping if necessary.

Returns:
This method reads a short from the input stream and does byte swapping if necessary.
Throws:
java.io.IOException - if an error is encountered in reading the Data Input Stream.
java.io.EOFException - if an end of file is encountered in reading the Data Input Stream.

readUnsignedShort

public int readUnsignedShort()
                      throws java.io.IOException,
                             java.io.EOFException
This method reads an unsigned short from the input stream. and does byte swapping if necessary.

Returns:
This method reads an unsigned short from the input stream.
Throws:
java.io.IOException - if an error is encountered in reading the Data Input Stream.
java.io.EOFException - if an end of file is encountered in reading the Data Input Stream.

readByte

public byte readByte()
              throws java.io.IOException,
                     java.io.EOFException
This method reads a byte from the input stream.

Returns:
This method reads a byte from the input stream.
Throws:
java.io.IOException - if an error is encountered in reading the Data Input Stream.
java.io.EOFException - if an end of file is encountered in reading the Data Input Stream.

readUnsignedByte

public int readUnsignedByte()
                     throws java.io.IOException,
                            java.io.EOFException
This method reads an unsigned byte from the input stream.

Returns:
This method reads an unsigned byte from the input stream.
Throws:
java.io.IOException - if an error is encountered in reading the Data Input Stream.
java.io.EOFException - if an end of file is encountered in reading the Data Input Stream.

read

public int read(byte[] b)
         throws java.io.IOException,
                java.io.EOFException
This method reads a byte array from the input stream.

Returns:
This method reads a byte array from the input stream.
Throws:
java.io.IOException - if an error is encountered in reading the Data Input Stream.
java.io.EOFException - if an end of file is encountered in reading the Data Input Stream.

readAddr

public long readAddr()
              throws java.io.IOException,
                     java.io.EOFException
This method reads an address from the input stream. By default this is 32 bits, but can be changed with the setObjectClass() method. Currently only 32 and 64 bit objects / addresses are supported. Note that this method returns a long that may be sign-extended.

Returns:
This method reads an address from the input stream.
Throws:
java.io.IOException - if an error is encountered in reading the Data Input Stream.
java.io.EOFException - if an end of file is encountered in reading the Data Input Stream.

skipBytes

public int skipBytes(int i)
              throws java.io.IOException,
                     java.io.EOFException
This method skips bytes from the input stream.

Returns:
This method skips bytes from the input stream.
Throws:
java.io.IOException - if an error is encountered in reading the Data Input Stream.
java.io.EOFException - if an end of file is encountered in reading the Data Input Stream.

readString

public java.lang.String readString()
                            throws java.io.IOException,
                                   java.io.EOFException
This method reads String from the input stream.

Returns:
This method reads a String from the input stream.
Throws:
java.io.IOException - if an error is encountered in reading the Data Input Stream.
java.io.EOFException - if an end of file is encountered in reading the Data Input Stream.