org.ow2.asmdex.lowLevelUtils
Class DalvikValueReader

java.lang.Object
  extended by org.ow2.asmdex.lowLevelUtils.DalvikValueReader
All Implemented Interfaces:
IDalvikValueReader

public class DalvikValueReader
extends java.lang.Object
implements IDalvikValueReader

Reads the different kinds of primitive Dalvik values from an encapsulated stream.

Author:
Pierre Crégut, Julien névo (slight modifications)

Field Summary
protected  int pos
          Position in stream
 
Constructor Summary
DalvikValueReader(byte[] contents)
          Constructor encapsulating an array of bytes.
DalvikValueReader(byte[] dexBytes, int size_offset)
          Constructor encapsulating an input stream.
 
Method Summary
 void bytes(byte[] b)
          Reads a given number of bytes and fills the given array.
 long completeSignSizedLong(long l, int sz)
          Extends a long read with SizedLong of length sz according to its sign.
 byte[] getContents()
          Returns the byte array included to this reader.
 int getPos()
          Get the current position of the pointer in the stream.
 boolean hasMore()
          Check if there are still data to read in the stream.
 void relativeSeek(int offset)
          Adds an offset to the current position of the pointer in the stream.
 byte sbyte()
          Reads next signed byte value.
 void seek(int pos)
          Set the position of the pointer in the stream.
 int sint()
          Reads next signed integer value.
static int sint(java.io.InputStream stream)
          Reads an integer directly from an input stream.
 long sizedLong(int sz)
          Reads a long of a given size.
 void skipByte()
          Skips a Byte (signed or not).
 void skipInt()
          Skips an Int (signed or not).
 void skipShort()
          Skips a Short (signed or not).
 int sleb128()
          Reads next signed integer value coded in leb128 format
 short sshort()
          Reads next signed short value.
 short ubyte()
          Reads next unsigned byte value.
 int uint()
          Reads next unsigned integer value.
 long uleb128_16()
          Reads next unsigned integer value coded in leb128 format but with 16 bits chars.
 int uleb128_p1()
          Reads next unsigned integer value coded in leb128_p1 format
 int uleb128()
          Reads next unsigned integer value coded in leb128 format
 java.lang.String unicodeString(int strSize)
          Parse a string coded as 16 bit character
 int ushort()
          Reads next unsigned short value.
 java.lang.String utf8String()
          Reads a null terminated UTF8 string as handled by Dalvik (limited to unicode)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pos

protected int pos
Position in stream

Constructor Detail

DalvikValueReader

public DalvikValueReader(byte[] contents)
Constructor encapsulating an array of bytes.

Parameters:
contents -

DalvikValueReader

public DalvikValueReader(byte[] dexBytes,
                         int size_offset)
                  throws java.io.IOException
Constructor encapsulating an input stream. We need to find the size of the file This is given by the offset. We first read up to the size, and then fill the byte array. The size in the byte array is NOT correct.

Parameters:
dexBytes - the bytes containing the resource/dex
size_offset - offset from the begining to find the total file size
Throws:
java.io.IOException
Method Detail

getContents

public byte[] getContents()
Returns the byte array included to this reader. It is not copied.

Specified by:
getContents in interface IDalvikValueReader
Returns:
the byte array included to this reader.

sint

public static final int sint(java.io.InputStream stream)
                      throws java.io.IOException
Reads an integer directly from an input stream. Usually used while builder the value reader.

Parameters:
stream -
Returns:
the value read
Throws:
java.io.IOException

sbyte

public final byte sbyte()
Description copied from interface: IDalvikValueReader
Reads next signed byte value.

Specified by:
sbyte in interface IDalvikValueReader
Returns:
value read from stream

ubyte

public final short ubyte()
Description copied from interface: IDalvikValueReader
Reads next unsigned byte value.

Specified by:
ubyte in interface IDalvikValueReader
Returns:
value read from stream

sshort

public final short sshort()
Description copied from interface: IDalvikValueReader
Reads next signed short value.

Specified by:
sshort in interface IDalvikValueReader
Returns:
value read from stream

ushort

public final int ushort()
Description copied from interface: IDalvikValueReader
Reads next unsigned short value.

Specified by:
ushort in interface IDalvikValueReader
Returns:
value read from stream

sint

public final int sint()
Description copied from interface: IDalvikValueReader
Reads next signed integer value.

Specified by:
sint in interface IDalvikValueReader
Returns:
value read from stream

uint

public final int uint()
Description copied from interface: IDalvikValueReader
Reads next unsigned integer value.

Specified by:
uint in interface IDalvikValueReader
Returns:
value read from stream

sleb128

public final int sleb128()
Description copied from interface: IDalvikValueReader
Reads next signed integer value coded in leb128 format

Specified by:
sleb128 in interface IDalvikValueReader
Returns:
value read from stream

uleb128

public final int uleb128()
Description copied from interface: IDalvikValueReader
Reads next unsigned integer value coded in leb128 format

Specified by:
uleb128 in interface IDalvikValueReader
Returns:
value read from stream

uleb128_p1

public final int uleb128_p1()
Description copied from interface: IDalvikValueReader
Reads next unsigned integer value coded in leb128_p1 format

Specified by:
uleb128_p1 in interface IDalvikValueReader
Returns:
value read from stream

uleb128_16

public final long uleb128_16()
Description copied from interface: IDalvikValueReader
Reads next unsigned integer value coded in leb128 format but with 16 bits chars.

Specified by:
uleb128_16 in interface IDalvikValueReader
Returns:
value read from stream

sizedLong

public final long sizedLong(int sz)
Description copied from interface: IDalvikValueReader
Reads a long of a given size. Considered as unsigned.

Specified by:
sizedLong in interface IDalvikValueReader
Returns:
a positive long

completeSignSizedLong

public final long completeSignSizedLong(long l,
                                        int sz)
Extends a long read with SizedLong of length sz according to its sign.

Specified by:
completeSignSizedLong in interface IDalvikValueReader
Parameters:
l -
sz - size-1 of the encoded number.
Returns:
the value read

bytes

public void bytes(byte[] b)
Reads a given number of bytes and fills the given array.

Parameters:
b - the byte array to be filled.

utf8String

public java.lang.String utf8String()
Description copied from interface: IDalvikValueReader
Reads a null terminated UTF8 string as handled by Dalvik (limited to unicode)

Specified by:
utf8String in interface IDalvikValueReader
Returns:
string

seek

public final void seek(int pos)
Description copied from interface: IDalvikValueReader
Set the position of the pointer in the stream.

Specified by:
seek in interface IDalvikValueReader
Parameters:
pos - positive absolute position

relativeSeek

public void relativeSeek(int offset)
Description copied from interface: IDalvikValueReader
Adds an offset to the current position of the pointer in the stream.

Specified by:
relativeSeek in interface IDalvikValueReader
Parameters:
offset - positive or negative offset to add.

getPos

public final int getPos()
Description copied from interface: IDalvikValueReader
Get the current position of the pointer in the stream. Usually to make a save restore.

Specified by:
getPos in interface IDalvikValueReader
Returns:
positive absolute position

unicodeString

public java.lang.String unicodeString(int strSize)
Description copied from interface: IDalvikValueReader
Parse a string coded as 16 bit character

Specified by:
unicodeString in interface IDalvikValueReader
Returns:
string

hasMore

public final boolean hasMore()
Description copied from interface: IDalvikValueReader
Check if there are still data to read in the stream.

Specified by:
hasMore in interface IDalvikValueReader
Returns:
true if more data

skipInt

public final void skipInt()
Description copied from interface: IDalvikValueReader
Skips an Int (signed or not).

Specified by:
skipInt in interface IDalvikValueReader

skipShort

public final void skipShort()
Description copied from interface: IDalvikValueReader
Skips a Short (signed or not).

Specified by:
skipShort in interface IDalvikValueReader

skipByte

public final void skipByte()
Description copied from interface: IDalvikValueReader
Skips a Byte (signed or not).

Specified by:
skipByte in interface IDalvikValueReader