Public Member Functions

gnash::SWFStream Class Reference

SWF stream wrapper class. More...

#include <SWFStream.h>

Collaboration diagram for gnash::SWFStream:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 SWFStream (IOChannel *input)
 ~SWFStream ()
unsigned read_uint (unsigned short bitcount)
 Reads a bit-packed unsigned integer from the stream and returns it. The given bitcount determines the number of bits to read.
bool read_bit ()
 Reads a single bit off the stream and returns it.
int read_sint (unsigned short bitcount)
 Reads a bit-packed little-endian signed integer from the stream. The given bitcount determines the number of bits to read.
float read_fixed ()
 Read a 16.16 fixed point signed value.
float read_ufixed ()
 Read a 16.16 fixed point unsigned value.
float read_short_ufixed ()
 Read a 8.8 fixed point unsigned value.
float read_short_sfixed ()
 Read a 8.8 fixed point signed value.
float read_short_float ()
 Read a 16bit (1:sign 5:exp 10:mantissa) floating point value.
float read_long_float ()
 Read a 32bit (1:sign 8:exp 23:mantissa) floating point value.
double read_d64 ()
 Read a 64-bit double value.
void align ()
 Consume all bits of current byte.
unsigned read (char *buf, unsigned count)
 Read <count> bytes from the source stream and copy that data to <buf>.
boost::uint8_t read_u8 ()
 Read a aligned unsigned 8-bit value from the stream.
boost::int8_t read_s8 ()
 Read a aligned signed 8-bit value from the stream.
boost::uint16_t read_u16 ()
 Read a aligned unsigned 16-bit value from the stream.
boost::int16_t read_s16 ()
 Read a aligned signed 16-bit value from the stream.
boost::uint32_t read_u32 ()
 Read a aligned unsigned 32-bit value from the stream.
boost::int32_t read_s32 ()
 Read a aligned signed 32-bit value from the stream.
boost::uint32_t read_V32 ()
 Read a variable length unsigned 32-bit value from the stream. These values continue until either the high bit is not set or until 5 bytes have been read.
void skip_V32 ()
 Skip a variable length unsigned 32-bit value in the stream. This is faster than doing the bitwise arithmetic of full reading.
unsigned read_variable_count ()
 Read a length in a byte or three.
void read_string (std::string &to)
 Reads a null-terminated string from the given file and assigns it to the given std::string, overriding any previous value of it.
void read_string_with_length (std::string &to)
 Reads a sized string into a provided std::string.
void read_string_with_length (unsigned len, std::string &to)
 Reads a sized string into a provided std::string.
unsigned long tell ()
 Return our current (byte) position in the input stream.
bool seek (unsigned long pos)
 Set the file position to the given value (byte aligned).
unsigned long get_tag_end_position ()
 Return the file position of the end of the current tag.
SWF::TagType open_tag ()
 Open an SWF tag and return it's type.
void close_tag ()
 Seek to the end of the most-recently-opened tag.
bool skip_bytes (unsigned num)
 Discard given number of bytes.
void skip_to_tag_end ()
 Discard all bytes up to end of tag.
void ensureBytes (unsigned long needed)
 Ensure the requested number of bytes are available for an aligned read in the currently opened tag.
void ensureBits (unsigned long needed)
 Ensure the requested number of bits are available for a bitwise read in currently opened tag.
void consumeInput ()
 Consume any pending input.

Detailed Description

SWF stream wrapper class.

This class is used for loading variable-length data from a stream, and keeping track of SWF tag boundaries.

Provides 'aligned' and 'bitwise' read functions:


Constructor & Destructor Documentation

gnash::SWFStream::SWFStream ( IOChannel input  ) 
gnash::SWFStream::~SWFStream (  ) 

Member Function Documentation

void gnash::SWFStream::align (  )  [inline]

Consume all bits of current byte.

This method is implicitly called by all 'aligned' reads.

NOTE: The position returned by tell() won't be changed by calls to this function, altought any subsequent reads will start on next byte. See tell() for more info.

Referenced by gnash::SWF::StartSoundTag::loader(), main(), open_tag(), read(), gnash::SWFRect::read(), gnash::SWFCxForm::read_rgb(), gnash::SWFCxForm::read_rgba(), read_string(), read_string_with_length(), read_u16(), read_u32(), read_u8(), and seek().

void gnash::SWFStream::close_tag (  ) 

Seek to the end of the most-recently-opened tag.

References _, endPos, and gnash::IOChannel::seek().

void gnash::SWFStream::consumeInput (  ) 

Consume any pending input.

This method is useful to force full consumption of the SWFStream's underlying IOChannel for the cases in which it is a pipe and a writer would hang on it unless someone is reading.

This method will NOT be called automatically on SWFStream destruction as in the current design SWFStream does NOT own the underlying IOChannel. TODO: rethink about ownership.

NOTE: the stream position will be updated by this call, so that tell will basically return the full input size.

References gnash::IOChannel::go_to_end().

void gnash::SWFStream::ensureBits ( unsigned long  needed  )  [inline]

Ensure the requested number of bits are available for a bitwise read in currently opened tag.

Throws a ParserException on a short count. This method should be called before any attempt to read bits from the SWF.

NOTE: if GNASH_TRUST_SWF_INPUT is defined this function is a no-op

Referenced by gnash::SWF::TextRecord::read(), gnash::SWFRect::read(), gnash::SWF::ShapeRecord::read(), gnash::SWFCxForm::read_rgb(), and gnash::SWFCxForm::read_rgba().

void gnash::SWFStream::ensureBytes ( unsigned long  needed  ) 

Ensure the requested number of bytes are available for an aligned read in the currently opened tag.

Throws a ParserException on a short count. This method should be called before any attempt to read fields from the SWF.

NOTE: if GNASH_TRUST_SWF_INPUT is defined this function is a no-op

References get_tag_end_position(), and tell().

Referenced by gnash::SWF::ButtonAction::ButtonAction(), gnash::SWF::VideoFrameTag::loader(), gnash::SWF::SymbolClassTag::loader(), gnash::SWF::StreamSoundBlockTag::loader(), gnash::SWF::StartSoundTag::loader(), gnash::SWF::SetTabIndexTag::loader(), gnash::SWF::DoInitActionTag::loader(), gnash::SWF::DoABCTag::loader(), gnash::SWF::DefineVideoStreamTag::loader(), gnash::SWF::DefineText2Tag::loader(), gnash::SWF::DefineTextTag::loader(), gnash::SWF::DefineShapeTag::loader(), gnash::SWF::DefineScalingGridTag::loader(), gnash::SWF::DefineMorphShapeTag::loader(), gnash::SWF::DefineFontInfoTag::loader(), gnash::SWF::DefineFontTag::loader(), gnash::SWF::DefineFontNameTag::loader(), gnash::SWF::DefineFontAlignZonesTag::loader(), gnash::SWF::DefineEditTextTag::loader(), gnash::SWF::DefineButton2Tag::loader(), gnash::SWF::DefineButtonTag::loader(), gnash::SWF::DefineButtonSoundTag::loader(), gnash::SWF::DefineButtonCxformTag::loader(), open_tag(), gnash::SWF::TextRecord::read(), gnash::SWF::SoundInfoRecord::read(), gnash::SWF::ShapeRecord::read(), gnash::SWF::RemoveObjectTag::read(), gnash::LineStyle::read(), gnash::SWF::ButtonRecord::read(), gnash::LineStyle::read_morph(), read_string(), read_string_with_length(), and gnash::SWF::DefineFontTag::readCodeTable().

unsigned long gnash::SWFStream::get_tag_end_position (  ) 
SWF::TagType gnash::SWFStream::open_tag (  ) 

Open an SWF tag and return it's type.

aligned read

References _, align(), ensureBytes(), IF_VERBOSE_PARSE, read_u16(), read_u32(), and tell().

unsigned gnash::SWFStream::read ( char *  buf,
unsigned  count 
)

Read <count> bytes from the source stream and copy that data to <buf>.

aligned read

References align(), endPos, gnash::IOChannel::read(), and tell().

Referenced by gnash::SWF::VideoFrameTag::loader(), gnash::SWF::StreamSoundBlockTag::loader(), gnash::action_buffer::read(), read_d64(), read_long_float(), read_u16(), and read_u32().

bool gnash::SWFStream::read_bit (  ) 

Reads a single bit off the stream and returns it.

bitwise read

References gnash::IOChannel::read_byte().

Referenced by main(), and gnash::SWF::ShapeRecord::read().

double gnash::SWFStream::read_d64 (  ) 

Read a 64-bit double value.

aligned read

References _, s2x::d, and read().

float gnash::SWFStream::read_fixed (  ) 

Read a 16.16 fixed point signed value.

aligned read

References s2x::f, and read_s32().

float gnash::SWFStream::read_long_float (  ) 

Read a 32bit (1:sign 8:exp 23:mantissa) floating point value.

aligned read

References _, data, and read().

boost::int16_t gnash::SWFStream::read_s16 (  ) 

Read a aligned signed 16-bit value from the stream.

aligned read

References read_u16().

Referenced by main(), gnash::SWF::TextRecord::read(), read_short_float(), and read_short_sfixed().

boost::int32_t gnash::SWFStream::read_s32 (  ) 

Read a aligned signed 32-bit value from the stream.

aligned read

References read_u32().

Referenced by main(), and read_fixed().

boost::int8_t gnash::SWFStream::read_s8 (  ) 

Read a aligned signed 8-bit value from the stream.

aligned read

References read_u8().

float gnash::SWFStream::read_short_float (  ) 

Read a 16bit (1:sign 5:exp 10:mantissa) floating point value.

aligned read

References read_s16().

float gnash::SWFStream::read_short_sfixed (  ) 

Read a 8.8 fixed point signed value.

aligned read

References read_s16().

float gnash::SWFStream::read_short_ufixed (  ) 

Read a 8.8 fixed point unsigned value.

aligned read

References read_u16().

Referenced by gnash::LineStyle::read(), and gnash::LineStyle::read_morph().

int gnash::SWFStream::read_sint ( unsigned short  bitcount  ) 

Reads a bit-packed little-endian signed integer from the stream. The given bitcount determines the number of bits to read.

bitwise read

References read_uint().

Referenced by gnash::SWF::TextRecord::read(), gnash::SWFRect::read(), gnash::SWF::ShapeRecord::read(), gnash::SWFCxForm::read_rgb(), and gnash::SWFCxForm::read_rgba().

void gnash::SWFStream::read_string ( std::string &  to  ) 

Reads a null-terminated string from the given file and assigns it to the given std::string, overriding any previous value of it.

aligned read

Will throw ParserException if no terminating null is found within tag boundaries

References align(), s2x::c, ensureBytes(), and read_u8().

Referenced by gnash::SWF::SymbolClassTag::loader(), gnash::SWF::StartSound2Tag::loader(), gnash::SWF::DoABCTag::loader(), and gnash::SWF::DefineFontNameTag::loader().

void gnash::SWFStream::read_string_with_length ( unsigned  len,
std::string &  to 
)

Reads a sized string into a provided std::string.

Parameters:
len Length of string to read.
to Output argument. Any previous value will be overriden.

aligned read

Will throw ParserException if len crosses tag boundaries

References align(), ensureBytes(), gnash::key::i, and read_u8().

void gnash::SWFStream::read_string_with_length ( std::string &  to  ) 

Reads a sized string into a provided std::string.

Length of string is read from the first byte.

Parameters:
to Output argument. Any previous value will be overriden.

aligned read

Will throw ParserException if advertised length crosses tag boundaries

References align(), ensureBytes(), and read_u8().

Referenced by gnash::SWF::DefineFontInfoTag::loader().

boost::uint16_t gnash::SWFStream::read_u16 (  ) 
boost::uint32_t gnash::SWFStream::read_u32 (  ) 

Read a aligned unsigned 32-bit value from the stream.

aligned read

References _, align(), read(), and gnash::IOChannel::read_le32().

Referenced by gnash::SWF::DoABCTag::loader(), main(), open_tag(), gnash::SWF::SoundInfoRecord::read(), read_s32(), and read_ufixed().

boost::uint8_t gnash::SWFStream::read_u8 (  ) 
float gnash::SWFStream::read_ufixed (  ) 

Read a 16.16 fixed point unsigned value.

aligned read

References s2x::f, and read_u32().

unsigned gnash::SWFStream::read_uint ( unsigned short  bitcount  ) 

Reads a bit-packed unsigned integer from the stream and returns it. The given bitcount determines the number of bits to read.

bitwise read

References gnash::key::i, gnash::IOChannel::read(), and gnash::IOChannel::read_byte().

Referenced by main(), gnash::SWF::TextRecord::read(), gnash::SWFRect::read(), gnash::SWF::ShapeRecord::read(), gnash::SWFCxForm::read_rgb(), gnash::SWFCxForm::read_rgba(), and read_sint().

boost::uint32_t gnash::SWFStream::read_V32 (  )  [inline]

Read a variable length unsigned 32-bit value from the stream. These values continue until either the high bit is not set or until 5 bytes have been read.

aligned read

unsigned gnash::SWFStream::read_variable_count (  )  [inline]

Read a length in a byte or three.

If the byte == 0xff, read the lenght in next two bytes.

Takes care of integrity check (ensureByte)

aligned read

bool gnash::SWFStream::seek ( unsigned long  pos  ) 

Set the file position to the given value (byte aligned).

If we're scanning a tag, don't allow seeking past the end or before start of it.

Returns:
true on success, false on failure Possible failures:
  • given position is after end of stream.
  • given position is after end of current tag, if any.
  • given position is before start of current tag, if any.

References _, align(), endPos, gnash::IOChannel::seek(), and startPos.

Referenced by main().

bool gnash::SWFStream::skip_bytes ( unsigned  num  )  [inline]

Discard given number of bytes.

Returns:
true on success, false on failure Possible failures:
  • skipping given number of bytes reaches end of stream.
  • skipping given number of bytes reaches end of current tag, if any.

WARNING: alignment is not specified here, the method uses tell() which is known NOT to consider a fully-read byte as already "skipped" TODO: force alignment and see what happens !!

void gnash::SWFStream::skip_to_tag_end (  )  [inline]

Discard all bytes up to end of tag.

Referenced by gnash::SWF::StartSound2Tag::loader(), and gnash::SWF::DefineFontAlignZonesTag::loader().

void gnash::SWFStream::skip_V32 (  )  [inline]

Skip a variable length unsigned 32-bit value in the stream. This is faster than doing the bitwise arithmetic of full reading.

aligned read

unsigned long gnash::SWFStream::tell (  ) 

Return our current (byte) position in the input stream.

NOTE: This is not necessarely the byte you'll read on next read.

  • For bitwise reads the currenty byte will be used only if not completely consumed. See align().
  • For aligned reads the current byte will not be used (already used)

References gnash::IOChannel::tell().

Referenced by gnash::SWF::ButtonAction::ButtonAction(), gnash::SWF::end_loader(), ensureBytes(), gnash::SWF::VideoFrameTag::loader(), gnash::SWF::StreamSoundBlockTag::loader(), main(), open_tag(), read(), gnash::SWFParser::read(), gnash::SWF::ButtonRecord::read(), gnash::action_buffer::read(), and gnash::SWF::DefineFontTag::readCodeTable().


The documentation for this class was generated from the following files: