Question

In this question I got an answer on how to use this information to read BLB files. So I followed the instructions, and it appears that I'm reading the header properly.

However, when I try to read the file IDs, I get an end of file runtime error:

[Fault] exception, information=Error: Error #2030: End of file was encountered.

Here's my code.

Base class:

package  
{
    import flash.display.Sprite;
    import flash.filesystem.File;
    import flash.filesystem.FileStream;
    import flash.utils.ByteArray;
    import flash.utils.IDataInput;
    import flash.filesystem.FileMode;

    public class BLBDecompress extends Sprite 
    {
        private var _file:File;
        private var _stream:FileStream;

        private var _blbBytes:ByteArray;

        private var _header:Header;
        private var _fileIDs:Array;

        public function BLBDecompress() 
        {
            decompress();
        }

        private function decompress():void
        {
            _file = File.applicationDirectory.resolvePath("testfiles/t.blb");
            _blbBytes = new ByteArray();

            _stream = new FileStream();
            _stream.open(_file, FileMode.READ);
            _stream.readBytes(_blbBytes);
            _stream.close();

            _header = readHeader(_blbBytes);

            _fileIDs = new Array();

            for (var i:int = 0; i < _header.dwNumber; i++)
            {
                _fileIDs.push(readFileID(_blbBytes));
            }
        }

        private function readHeader(input:IDataInput):Header
        {
            var header:Header = new Header();

            header.szID = new ByteArray();
            input.readBytes(header.szID, 0, 4);

            header.bID = input.readUnsignedByte();
            header.bUnknown = input.readUnsignedByte();
            header.wDataSize = input.readUnsignedShort();
            header.dwFileSize = input.readUnsignedInt();
            header.dwNumber = input.readUnsignedInt();

            return header;
        }

        private function readFileID(input:IDataInput):uint
        {
            var fileID:uint = input.readUnsignedInt();

            return fileID;
        }
    }
}

Header class:

package  
{
    import flash.utils.ByteArray;

    public class Header 
    {
        public var szID:ByteArray;
        public var bID:uint;
        public var bUnknown:uint;
        public var wDataSize:uint;
        public var dwFileSize:uint;
        public var dwNumber:uint;

        public function Header() 
        {

        }
    }
}

The thing is that _header.dwNumber returns/traces as 1090650112 (41020000 in base 16), so I can imagine that would reach the end of the file. So am I reading it wrong, using it wrong, or doing something else wrong? The rest of the

If it helps, this is an AIR application, and I'm using FlashDevelop with the Flex 4 SDK.

Was it helpful?

Solution

That look like a simple Big/Little endian problem, the 4 bytes that make up the DWORD are in the file in a different order to that used by your processor.

You need to reverse the order of the bytes in the DWORD to get 00000241, and any other multibyte number

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top