Skip to content

Commit

Permalink
Swapping bytes on big endian platforms
Browse files Browse the repository at this point in the history
Signed-off-by: DaNiMoTh <jjdanimoth@gmail.com>
  • Loading branch information
DaNiMoTh authored and alexp-sssup committed Dec 16, 2010
1 parent 5b88311 commit 27080f0
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 34 deletions.
18 changes: 6 additions & 12 deletions parsing/flv.cpp
Expand Up @@ -28,7 +28,7 @@ FLV_HEADER::FLV_HEADER(std::istream& in):dataOffset(0),_hasAudio(false),_hasVide
{
UI8 Signature[3];
UI8 Version;
UI32 DataOffset;
UI32FLV DataOffset;

in >> Signature[0] >> Signature[1] >> Signature[2] >> Version;
version=Version;
Expand Down Expand Up @@ -61,28 +61,25 @@ FLV_HEADER::FLV_HEADER(std::istream& in):dataOffset(0),_hasAudio(false),_hasVide

in >> DataOffset;

DataOffset.bswap();
dataOffset = DataOffset;
assert_and_throw(dataOffset==9);
}

VideoTag::VideoTag(istream& s)
{
//Read dataSize
UI24 DataSize;
UI24FLV DataSize;
s >> DataSize;
DataSize.bswap();
dataSize=DataSize;

//Read and assemble timestamp
UI24 Timestamp;
UI24FLV Timestamp;
s >> Timestamp;
Timestamp.bswap();
UI8 TimestampExtended;
s >> TimestampExtended;
timestamp=Timestamp|(TimestampExtended<<24);

UI24 StreamID;
UI24FLV StreamID;
s >> StreamID;
assert_and_throw(StreamID==0);
}
Expand Down Expand Up @@ -114,11 +111,9 @@ ScriptDataTag::ScriptDataTag(istream& s):VideoTag(s)

ScriptDataString::ScriptDataString(std::istream& s)
{
UI16 Length;
UI16FLV Length;
s >> Length;
Length.bswap();
size=Length;

//TODO: use resize on tiny_string
char* buf=new char[Length+1];
s.read(buf,Length);
Expand All @@ -132,9 +127,8 @@ ScriptDataString::ScriptDataString(std::istream& s)
ScriptECMAArray::ScriptECMAArray(std::istream& s, ScriptDataTag* tag)
{
//numVar is an 'approximation' of array size
UI32 numVar;
UI32FLV numVar;
s >> numVar;
numVar.bswap();

while(1)
{
Expand Down
2 changes: 2 additions & 0 deletions scripting/abc.cpp
Expand Up @@ -2025,6 +2025,7 @@ istream& lightspark::operator>>(istream& in, u16& v)
{
uint16_t t;
in.read((char*)&t,2);
SwfToLe16(t);
v.val=t;
return in;
}
Expand All @@ -2033,6 +2034,7 @@ istream& lightspark::operator>>(istream& in, d64& v)
{
//Should check if this is right
in.read((char*)&v.val,8);
SwfToLe(v.val);
return in;
}

Expand Down
3 changes: 1 addition & 2 deletions scripting/flashnet.cpp
Expand Up @@ -769,9 +769,8 @@ void NetStream::execute()
//Check if threadAbort has been called, if so, stop this loop
if(closed)
done = true;
UI32 PreviousTagSize;
UI32FLV PreviousTagSize;
s >> PreviousTagSize;
PreviousTagSize.bswap();
assert_and_throw(PreviousTagSize==prevSize);

//Check tag type and read it
Expand Down
1 change: 1 addition & 0 deletions swftypes.cpp
Expand Up @@ -505,6 +505,7 @@ std::istream& lightspark::operator>>(std::istream& s, FOCALGRADIENT& v)
sort(v.GradientRecords.begin(),v.GradientRecords.end());
//TODO: support FocalPoint
s.read((char*)&v.FocalPoint,2);
SwfToLe(v.FocalPoint);
return s;
}

Expand Down

0 comments on commit 27080f0

Please sign in to comment.