Gnash
0.8.10
|
SWF stream wrapper class. More...
#include <SWFStream.h>
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. |
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:
gnash::SWFStream::SWFStream | ( | IOChannel * | input | ) |
gnash::SWFStream::~SWFStream | ( | ) |
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(), read(), read_u8(), read_u16(), read_u32(), read_string(), read_string_with_length(), seek(), open_tag(), gnash::readSWFMatrix(), gnash::readRect(), gnash::readCxFormRGB(), and gnash::readCxFormRGBA().
void gnash::SWFStream::close_tag | ( | ) |
Seek to the end of the most-recently-opened tag.
References assert, endPos, gnash::IOChannel::seek(), and _.
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(), and _.
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::ShapeRecord::read(), gnash::SWF::TextRecord::read(), gnash::readSWFMatrix(), gnash::readRect(), gnash::readCxFormRGB(), and gnash::readCxFormRGBA().
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::CSMTextSettingsTag::loader(), gnash::SWF::DefineBitsTag::loader(), gnash::SWF::DefineButtonCxformTag::loader(), gnash::SWF::DefineButtonSoundTag::loader(), gnash::SWF::DefineButtonTag::loader(), gnash::SWF::DefineButton2Tag::loader(), gnash::SWF::ButtonAction::ButtonAction(), gnash::SWF::ButtonRecord::read(), gnash::SWF::DefineEditTextTag::loader(), gnash::SWF::DefineFontAlignZonesTag::loader(), gnash::SWF::DefineFontNameTag::loader(), gnash::SWF::DefineFontTag::loader(), gnash::SWF::DefineFontTag::readCodeTable(), gnash::SWF::DefineFontInfoTag::loader(), gnash::SWF::DefineMorphShapeTag::loader(), gnash::SWF::DefineScalingGridTag::loader(), gnash::SWF::DefineShapeTag::loader(), gnash::SWF::DefineTextTag::loader(), gnash::SWF::DefineText2Tag::loader(), gnash::SWF::DefineVideoStreamTag::loader(), gnash::SWF::DoABCTag::loader(), gnash::SWF::DoInitActionTag::loader(), gnash::filter_factory::read(), gnash::DropShadowFilter::read(), gnash::BlurFilter::read(), gnash::GlowFilter::read(), gnash::BevelFilter::read(), gnash::GradientGlowFilter::read(), gnash::ConvolutionFilter::read(), gnash::ColorMatrixFilter::read(), gnash::GradientBevelFilter::read(), gnash::LineStyle::read_morph(), gnash::LineStyle::read(), gnash::SWF::RemoveObjectTag::read(), gnash::SWF::SetTabIndexTag::loader(), gnash::SWF::ShapeRecord::read(), gnash::SWF::SoundInfoRecord::read(), gnash::SWF::SoundStreamHeadTag::loader(), gnash::SWF::StartSoundTag::loader(), gnash::SWF::StreamSoundBlockTag::loader(), read_string(), read_string_with_length(), open_tag(), gnash::SWF::SymbolClassTag::loader(), gnash::SWF::sprite_loader(), gnash::SWF::define_sound_loader(), gnash::SWF::file_attributes_loader(), gnash::SWF::serialnumber_loader(), gnash::SWF::reflex_loader(), gnash::SWF::TextRecord::read(), gnash::readRGBA(), gnash::readRGB(), gnash::readFills(), and gnash::SWF::VideoFrameTag::loader().
unsigned long gnash::SWFStream::get_tag_end_position | ( | ) |
Return the file position of the end of the current tag.
References assert.
Referenced by gnash::action_buffer::read(), gnash::SWF::jpeg_tables_loader(), gnash::SWF::DoActionTag::read(), gnash::SWF::SoundStreamHeadTag::loader(), gnash::SWF::StreamSoundBlockTag::loader(), ensureBytes(), gnash::SWF::frame_label_loader(), gnash::SWF::define_sound_loader(), and gnash::SWF::VideoFrameTag::loader().
SWF::TagType gnash::SWFStream::open_tag | ( | ) |
Open an SWF tag and return it's type.
aligned read
References align(), tell(), ensureBytes(), read_u16(), assert, read_u32(), _, and IF_VERBOSE_PARSE.
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, tell(), assert, and gnash::IOChannel::read().
Referenced by gnash::action_buffer::read(), gnash::SWF::StreamSoundBlockTag::loader(), read_long_float(), read_d64(), read_u16(), read_u32(), gnash::SWF::define_sound_loader(), and gnash::SWF::VideoFrameTag::loader().
bool gnash::SWFStream::read_bit | ( | ) |
Reads a single bit off the stream and returns it.
bitwise read
References gnash::IOChannel::read_byte().
Referenced by gnash::DropShadowFilter::read(), gnash::GlowFilter::read(), gnash::BevelFilter::read(), gnash::GradientGlowFilter::read(), gnash::ConvolutionFilter::read(), gnash::GradientBevelFilter::read(), gnash::SWF::ShapeRecord::read(), gnash::SWF::SoundStreamHeadTag::loader(), gnash::SWF::define_sound_loader(), gnash::SWF::file_attributes_loader(), and gnash::readSWFMatrix().
double gnash::SWFStream::read_d64 | ( | ) |
float gnash::SWFStream::read_fixed | ( | ) |
Read a 16.16 fixed point signed value.
aligned read
References read_s32(), and gnash::key::f.
Referenced by gnash::DropShadowFilter::read(), gnash::GlowFilter::read(), gnash::BevelFilter::read(), gnash::GradientGlowFilter::read(), and gnash::GradientBevelFilter::read().
float gnash::SWFStream::read_long_float | ( | ) |
Read a 32bit (1:sign 8:exp 23:mantissa) floating point value.
aligned read
References data, read(), and _.
Referenced by gnash::SWF::CSMTextSettingsTag::loader(), gnash::ConvolutionFilter::read(), and gnash::ColorMatrixFilter::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 gnash::SWF::SoundStreamHeadTag::loader(), read_short_sfixed(), read_short_float(), gnash::SWF::define_sound_loader(), and gnash::SWF::TextRecord::read().
boost::int32_t gnash::SWFStream::read_s32 | ( | ) |
Read a aligned signed 32-bit value from the stream.
aligned read
References read_u32().
Referenced by read_fixed().
boost::int8_t gnash::SWFStream::read_s8 | ( | ) |
float gnash::SWFStream::read_short_float | ( | ) |
float gnash::SWFStream::read_short_sfixed | ( | ) |
Read a 8.8 fixed point signed value.
aligned read
References read_s16().
Referenced by gnash::DropShadowFilter::read(), gnash::GlowFilter::read(), gnash::BevelFilter::read(), gnash::GradientGlowFilter::read(), gnash::GradientBevelFilter::read(), and gnash::readFills().
float gnash::SWFStream::read_short_ufixed | ( | ) |
Read a 8.8 fixed point unsigned value.
aligned read
References read_u16().
Referenced by gnash::LineStyle::read_morph(), and gnash::LineStyle::read().
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::ShapeRecord::read(), gnash::SWF::TextRecord::read(), gnash::readSWFMatrix(), gnash::readRect(), gnash::readCxFormRGB(), and gnash::readCxFormRGBA().
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(), ensureBytes(), gnash::key::c, and read_u8().
Referenced by gnash::SWF::DefineFontNameTag::loader(), gnash::SWF::DoABCTag::loader(), gnash::SWF::StartSound2Tag::loader(), gnash::SWF::SymbolClassTag::loader(), gnash::SWF::frame_label_loader(), and gnash::SWF::metadata_loader().
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.
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().
void gnash::SWFStream::read_string_with_length | ( | unsigned | len, |
std::string & | to | ||
) |
Reads a sized string into a provided std::string.
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().
boost::uint16_t gnash::SWFStream::read_u16 | ( | ) |
Read a aligned unsigned 16-bit value from the stream.
aligned read
References align(), gnash::IOChannel::read_le16(), read(), and _.
Referenced by gnash::SWF::CSMTextSettingsTag::loader(), gnash::SWF::DefineBitsTag::loader(), gnash::SWF::DefineButtonCxformTag::loader(), gnash::SWF::DefineButtonSoundTag::loader(), gnash::SWF::DefineButtonTag::loader(), gnash::SWF::DefineButton2Tag::loader(), gnash::SWF::ButtonAction::ButtonAction(), gnash::SWF::ButtonRecord::read(), gnash::SWF::DefineEditTextTag::loader(), gnash::SWF::DefineFontAlignZonesTag::loader(), gnash::SWF::DefineFontNameTag::loader(), gnash::SWF::DefineFontTag::loader(), gnash::SWF::DefineFontTag::readCodeTable(), gnash::SWF::DefineFontInfoTag::loader(), gnash::SWF::DefineMorphShapeTag::loader(), gnash::SWF::DefineScalingGridTag::loader(), gnash::SWF::DefineShapeTag::loader(), gnash::SWF::DefineTextTag::loader(), gnash::SWF::DefineText2Tag::loader(), gnash::SWF::DefineVideoStreamTag::loader(), gnash::SWF::DoInitActionTag::loader(), gnash::LineStyle::read_morph(), gnash::LineStyle::read(), gnash::SWF::RemoveObjectTag::read(), gnash::SWF::SetTabIndexTag::loader(), gnash::SWF::ShapeRecord::read(), gnash::SWF::SoundInfoRecord::read(), gnash::SWF::SoundStreamHeadTag::loader(), gnash::SWF::StartSoundTag::loader(), gnash::SWF::StreamSoundBlockTag::loader(), read_short_ufixed(), read_s16(), open_tag(), gnash::SWF::SymbolClassTag::loader(), gnash::SWF::sprite_loader(), gnash::SWF::define_sound_loader(), gnash::SWF::TextRecord::read(), and gnash::SWF::VideoFrameTag::loader().
boost::uint32_t gnash::SWFStream::read_u32 | ( | ) |
Read a aligned unsigned 32-bit value from the stream.
aligned read
References align(), gnash::IOChannel::read_le32(), read(), and _.
Referenced by gnash::SWF::DoABCTag::loader(), gnash::SWF::SoundInfoRecord::read(), read_ufixed(), read_s32(), open_tag(), gnash::SWF::define_sound_loader(), and gnash::SWF::serialnumber_loader().
boost::uint8_t gnash::SWFStream::read_u8 | ( | ) |
Read a aligned unsigned 8-bit value from the stream.
aligned read
References align(), and gnash::IOChannel::read_byte().
Referenced by gnash::abc::Trait::read(), gnash::SWF::CSMTextSettingsTag::loader(), gnash::SWF::ButtonRecord::read(), gnash::SWF::DefineFontAlignZonesTag::loader(), gnash::SWF::DefineFontTag::readCodeTable(), gnash::SWF::DefineFontInfoTag::loader(), gnash::filter_factory::read(), gnash::DropShadowFilter::read(), gnash::GlowFilter::read(), gnash::BevelFilter::read(), gnash::GradientGlowFilter::read(), gnash::ConvolutionFilter::read(), gnash::GradientBevelFilter::read(), gnash::LineStyle::read_morph(), gnash::LineStyle::read(), gnash::SWF::ShapeRecord::read(), gnash::SWF::SoundInfoRecord::read(), read_s8(), read_string(), read_string_with_length(), gnash::SWF::serialnumber_loader(), gnash::SWF::reflex_loader(), gnash::SWF::TextRecord::read(), gnash::readRGBA(), gnash::readRGB(), gnash::readFills(), and gnash::SWF::VideoFrameTag::loader().
float gnash::SWFStream::read_ufixed | ( | ) |
Read a 16.16 fixed point unsigned value.
aligned read
References read_u32(), and gnash::key::f.
Referenced by gnash::BlurFilter::read().
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 assert, gnash::IOChannel::read(), gnash::key::i, and gnash::IOChannel::read_byte().
Referenced by gnash::SWF::CSMTextSettingsTag::loader(), gnash::DropShadowFilter::read(), gnash::BlurFilter::read(), gnash::GlowFilter::read(), gnash::BevelFilter::read(), gnash::GradientGlowFilter::read(), gnash::ConvolutionFilter::read(), gnash::GradientBevelFilter::read(), gnash::SWF::ShapeRecord::read(), gnash::SWF::SoundStreamHeadTag::loader(), read_sint(), gnash::SWF::define_sound_loader(), gnash::SWF::file_attributes_loader(), gnash::SWF::TextRecord::read(), gnash::readSWFMatrix(), gnash::readRect(), gnash::readCxFormRGB(), and gnash::readCxFormRGBA().
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
Referenced by gnash::abc::Trait::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.
References align(), endPos, _, startPos, and gnash::IOChannel::seek().
bool gnash::SWFStream::skip_bytes | ( | unsigned | num | ) | [inline] |
Discard given number of bytes.
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::CSMTextSettingsTag::loader(), gnash::SWF::DefineFontAlignZonesTag::loader(), and gnash::SWF::StartSound2Tag::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
Referenced by gnash::abc::Trait::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.
References gnash::IOChannel::tell().
Referenced by gnash::action_buffer::read(), gnash::SWF::jpeg_tables_loader(), gnash::SWF::ButtonAction::ButtonAction(), gnash::SWF::ButtonRecord::read(), gnash::SWF::DefineFontTag::readCodeTable(), gnash::SWF::SoundStreamHeadTag::loader(), gnash::SWF::StreamSoundBlockTag::loader(), gnash::SWFParser::read(), ensureBytes(), read(), open_tag(), gnash::SWF::frame_label_loader(), gnash::SWF::define_sound_loader(), and gnash::SWF::VideoFrameTag::loader().