Ejemplo n.º 1
0
void BaseSerializedObj::readUInt64Array(uint64_t** o)
{
    uint64_t size = readUInt64();
    *o = (uint64_t *) malloc(size*byteSize_writeInt64);
    uint64_t i = 0;
    while(i != size)
    {
        (*o)[i] = readUInt64();
        i++;
    }
}
Ejemplo n.º 2
0
Archivo: udif.c Proyecto: 1butler1/xpwn
void readUDIFResourceFile(AbstractFile* file, UDIFResourceFile* o) {
  o->fUDIFSignature = readUInt32(file);
  
  ASSERT(o->fUDIFSignature == 0x6B6F6C79, "readUDIFResourceFile - signature incorrect");
  
  o->fUDIFVersion = readUInt32(file);
  o->fUDIFHeaderSize = readUInt32(file);
  o->fUDIFFlags = readUInt32(file);
  
  o->fUDIFRunningDataForkOffset = readUInt64(file);
  o->fUDIFDataForkOffset = readUInt64(file);
  o->fUDIFDataForkLength = readUInt64(file);
  o->fUDIFRsrcForkOffset = readUInt64(file);
  o->fUDIFRsrcForkLength = readUInt64(file);
  
  o->fUDIFSegmentNumber = readUInt32(file);
  o->fUDIFSegmentCount = readUInt32(file);
  readUDIFID(file, &(o->fUDIFSegmentID));
  
  readUDIFChecksum(file, &(o->fUDIFDataForkChecksum));
  
  o->fUDIFXMLOffset = readUInt64(file);
  o->fUDIFXMLLength = readUInt64(file);
  
  ASSERT(file->read(file, &(o->reserved1), 0x78) == 0x78, "fread");
  
  readUDIFChecksum(file, &(o->fUDIFMasterChecksum));
  
  o->fUDIFImageVariant = readUInt32(file);
  o->fUDIFSectorCount = readUInt64(file);
  
  o->reserved2 = readUInt32(file);
  o->reserved3 = readUInt32(file);
  o->reserved4 = readUInt32(file);
}
Ejemplo n.º 3
0
void BaseSerializedObj::readDoubleArray(double** o)
{
    uint64_t size = readUInt64();
    *o = (double *) malloc(size*8);
    uint64_t i = 0;
    while(i != size)
    {
        (*o)[i] = readDouble();
        i++;
    }
}
Ejemplo n.º 4
0
int GameState::readDouble(double* pDouble) {
	union {
		uint64_t ull;
		double db;
	} double_union;

	if (readUInt64(&double_union.ull))
		return -1;		// error retrieving 64-bits value

	*pDouble = double_union.db;
	return 0;
}
Ejemplo n.º 5
0
TEST(CommonTest, StoreUInt64SomethingElse) {
  uint64_t const value = 0xab12760039;
  storeUInt64(&LocalBuffer[0], value);
  ASSERT_EQ(0x39, LocalBuffer[0]);
  ASSERT_EQ(0x00, LocalBuffer[1]);
  ASSERT_EQ(0x76, LocalBuffer[2]);
  ASSERT_EQ(0x12, LocalBuffer[3]);
  ASSERT_EQ(0xab, LocalBuffer[4]);
  ASSERT_EQ(0x00, LocalBuffer[5]);
  ASSERT_EQ(0x00, LocalBuffer[6]);
  ASSERT_EQ(0x00, LocalBuffer[7]);

  ASSERT_EQ(value, readUInt64(&LocalBuffer[0]));
}
Ejemplo n.º 6
0
TEST(CommonTest, StoreUInt64Something) {
  uint64_t const value = 259;
  storeUInt64(&LocalBuffer[0], value);
  ASSERT_EQ(0x03, LocalBuffer[0]);
  ASSERT_EQ(0x01, LocalBuffer[1]);
  ASSERT_EQ(0x00, LocalBuffer[2]);
  ASSERT_EQ(0x00, LocalBuffer[3]);
  ASSERT_EQ(0x00, LocalBuffer[4]);
  ASSERT_EQ(0x00, LocalBuffer[5]);
  ASSERT_EQ(0x00, LocalBuffer[6]);
  ASSERT_EQ(0x00, LocalBuffer[7]);

  ASSERT_EQ(value, readUInt64(&LocalBuffer[0]));
}
Ejemplo n.º 7
0
TEST(CommonTest, StoreUInt64SomethingMore) {
  uint64_t const value = 0x7f9831ab12761339;

  storeUInt64(&LocalBuffer[0], value);
  ASSERT_EQ(0x39, LocalBuffer[0]);
  ASSERT_EQ(0x13, LocalBuffer[1]);
  ASSERT_EQ(0x76, LocalBuffer[2]);
  ASSERT_EQ(0x12, LocalBuffer[3]);
  ASSERT_EQ(0xab, LocalBuffer[4]);
  ASSERT_EQ(0x31, LocalBuffer[5]);
  ASSERT_EQ(0x98, LocalBuffer[6]);
  ASSERT_EQ(0x7f, LocalBuffer[7]);

  ASSERT_EQ(value, readUInt64(&LocalBuffer[0]));
}
Ejemplo n.º 8
0
TEST(CommonTest, StoreUInt64Zero) {
  uint64_t const value = 0;
  storeUInt64(&LocalBuffer[0], value);

  ASSERT_EQ(0UL, LocalBuffer[0]);
  ASSERT_EQ(0UL, LocalBuffer[1]);
  ASSERT_EQ(0UL, LocalBuffer[2]);
  ASSERT_EQ(0UL, LocalBuffer[3]);
  ASSERT_EQ(0UL, LocalBuffer[4]);
  ASSERT_EQ(0UL, LocalBuffer[5]);
  ASSERT_EQ(0UL, LocalBuffer[6]);
  ASSERT_EQ(0UL, LocalBuffer[7]);

  ASSERT_EQ(value, readUInt64(&LocalBuffer[0]));
}
Ejemplo n.º 9
0
TEST(CommonTest, StoreUInt64Max) {
  uint64_t const value = 0xffffffffffffffffULL;

  storeUInt64(&LocalBuffer[0], value);
  ASSERT_EQ(0xff, LocalBuffer[0]);
  ASSERT_EQ(0xff, LocalBuffer[1]);
  ASSERT_EQ(0xff, LocalBuffer[2]);
  ASSERT_EQ(0xff, LocalBuffer[3]);
  ASSERT_EQ(0xff, LocalBuffer[4]);
  ASSERT_EQ(0xff, LocalBuffer[5]);
  ASSERT_EQ(0xff, LocalBuffer[6]);
  ASSERT_EQ(0xff, LocalBuffer[7]);

  ASSERT_EQ(value, readUInt64(&LocalBuffer[0]));
}
Ejemplo n.º 10
0
static inline char * readString (FILE * file, Key * errorKey)
{
	kdb_unsigned_long_long_t size;
	if (!readUInt64 (file, &size, errorKey))
	{
		ELEKTRA_SET_ERROR (ELEKTRA_ERROR_READ_FAILED, errorKey, feof (file) ? "premature end of file" : "unknown error");
		return NULL;
	}

	char * string = elektraMalloc (size + 1);
	if (fread (string, sizeof (char), size, file) < size)
	{
		ELEKTRA_SET_ERROR (ELEKTRA_ERROR_READ_FAILED, errorKey, feof (file) ? "premature end of file" : "unknown error");
		elektraFree (string);
		return NULL;
	}
	string[size] = '\0';
	return string;
}
Ejemplo n.º 11
0
int GameState::readInt64(int64_t* pInt64) {
	return readUInt64((uint64_t*)pInt64);
}
Ejemplo n.º 12
0
INT64 DataInputStream::readInt64()
{
  return (INT64)readUInt64();
}
Ejemplo n.º 13
0
std::ostream& ossimJp2Info::print(std::ostream& out) const
{
    if ( m_file.size() )
    {
        // Open the file.
        std::ifstream str( m_file.c_str(), std::ios_base::in | std::ios_base::binary );
        if (str.good())
        {
            //---
            // ISO/IEC 15444-1:2004 (E)
            // LBox, Box Length. This field specifies the length of the box, stored
            // as a 4-byte big endian unsigned integer. This value includes all of
            // the fields of the box, including the length and type. If the value
            // of this field is 1, then the XLBox field shall exist and the value
            // of that field shall be the actual length of the box. If the value
            // of this field is 0, then the length of the box was not known when
            // the LBox field was written. In this case, this box contains all
            // bytes up to the end of the file. If a box of length 0 is contained
            // within another box (its superbox), then the length of that superbox
            // shall also be 0.  This means that this box is the last box in the
            // file. The values 2-7 are reserved for ISO use.
            //---
            ossim_uint32 lbox  = 0;
            ossim_uint32 tbox  = 0;
            ossim_uint64 xlbox = 0;

            const ossim_uint32 UUID_TYPE = 0x75756964;
            const ossim_uint8 GEOTIFF_UUID[GEOTIFF_UUID_SIZE] =
            {
                0xb1, 0x4b, 0xf8, 0xbd,
                0x08, 0x3d, 0x4b, 0x43,
                0xa5, 0xae, 0x8c, 0xd7,
                0xd5, 0xa6, 0xce, 0x03
            };

            while ( str.good() )
            {
                std::streamoff boxPos = str.tellg();

                readUInt32( lbox, str );
                readUInt32( tbox, str );

                if ( 1 == lbox )
                {
                    readUInt64( xlbox, str );
                }

                if ( traceDebug() )
                {
                    ossimNotify(ossimNotifyLevel_DEBUG)
                            << "jp2.lbox: " << std::dec << lbox << "\n"
                            << "jp2.tbox: " << std::hex << tbox << std::dec << "\n";
                    printTboxType( tbox, ossimNotify(ossimNotifyLevel_DEBUG)  );

                    if ( 1 == lbox )
                    {
                        ossimNotify(ossimNotifyLevel_DEBUG) << "jp2.xlbox: " << xlbox << std::endl;
                    }
                }

                if (tbox == UUID_TYPE)
                {
                    // Check for GeoTIFF box.

                    ossim_uint8 geotiffUuid[GEOTIFF_UUID_SIZE];

                    // Read in the id.
                    str.read((char*)geotiffUuid, GEOTIFF_UUID_SIZE);

#if 0
                    bool foundIt = true;
                    for (ossim_uint32 i = 0; i < GEOTIFF_UUID_SIZE; ++i)
                    {
                        if (geotiffUuid[i] != GEOTIFF_UUID[i])
                        {
                            foundIt = false;
                            break;
                        }
                    }
#endif

                    if( memcmp( (char*)geotiffUuid, GEOTIFF_UUID, GEOTIFF_UUID_SIZE) == 0)
                    {
                        //---
                        // Feed the stream to the tiff info object to get a keyword
                        // list with geometry/projection info.
                        //---
                        ossimTiffInfo info;

                        //---
                        // Have geotiff boxes with badly terminated geotiffs. So to keep
                        // the tag parser from walking past the first image file directory
                        // (IFD) into garbage we will set the process overview flag to false.
                        //
                        // Note if we ever get multiple entries we will need to take this out.
                        //---
                        info.setProcessOverviewFlag(false);

                        // Do a print to a memory stream.
                        std::ostringstream os;
                        info.print(str, os);

                        // Open an input stream to pass to the keyword list.
                        std::istringstream in( os.str() );

                        ossimKeywordlist kwl;
                        if ( kwl.parseStream(in) )
                        {
                            kwl.addPrefixToAll( ossimString("jp2.") );

                            // Print it:
                            out << kwl << std::endl;
                        }

                        // Get out of while loop.
                        // break;
                    }
                }

                if (lbox == 0) // last box?
                {
                    break;
                }

                // Seek to the next box.  If xlbox is 1
                if (lbox == 1)
                {
                    boxPos += (std::streamoff)xlbox;
                }
                else
                {
                    boxPos += (std::streamoff)lbox;
                }

                // Go to next box:
                str.seekg(boxPos, std::ios_base::beg);

            } // matches: while ( str.good() )

            // Close the stream.
            str.close();

        } // matches: if ( str.is_open() )

    } // matches: if ( m_file.size() )

    return out;
}
Ejemplo n.º 14
0
std::streamoff ossimJp2Info::getBox( const ossim_uint32& type,
                                     bool includeAll,
                                     std::ifstream& str,
                                     std::vector<ossim_uint8>& box ) const
{
    std::streamoff boxPos = 0;
    std::streamoff boxPosOfType = 0;
    box.clear();

    if ( str.good() )
    {
        ossim_uint32   lbox   = 0;
        ossim_uint32   tbox   = 0;
        ossim_uint64   xlbox  = 0;
        std::streamoff offsetToDbox = 0;

        while ( str.good() )
        {
            boxPos = str.tellg();

            readUInt32( lbox, str );
            readUInt32( tbox, str );

            if ( lbox == 1 )
            {
                readUInt64( xlbox, str );
                offsetToDbox = 16;
            }

            if ( !includeAll )
            {
                if ( lbox == 1 )
                {
                    offsetToDbox = 16;
                }
                else
                {
                    offsetToDbox = 8;
                }
            }

            if ( traceDebug() )
            {
                ossimNotify(ossimNotifyLevel_DEBUG)
                        << "jp2.lbox: " << std::dec << lbox << "\n"
                        << "jp2.tbox: " << std::hex << tbox << std::dec << "\n";
                printTboxType( tbox, ossimNotify(ossimNotifyLevel_DEBUG)  );

                if ( 1 == lbox )
                {
                    ossimNotify(ossimNotifyLevel_DEBUG) << "jp2.xlbox: " << xlbox << std::endl;
                }
            }


            if ( tbox == type )
            {
                //---
                // This is our box, copy it to box.
                // Not copying the lbox,tbox or xlbox
                std::streamoff boxSize = 0;
                if ( lbox == 0 )
                {
                    // Last box, goes to end of file.
                    str.seekg( 0, std::ios_base::end );
                    boxSize = str.tellg() - boxPos;
                }
                else if ( lbox == 1 )
                {
                    boxSize = xlbox;
                }
                else
                {
                    boxSize = lbox;
                }
                boxSize -= offsetToDbox;

                // Seek to box data start
                str.seekg( boxPos + offsetToDbox, std::ios_base::beg );

                // std::vector::resize can throw a std::bad_alloc so wrap it...
                try
                {
                    box.resize( boxSize );
                    str.read( (char*)&box.front(), boxSize );
                }
                catch( std::exception& e )
                {
                    std::ostringstream errMsg;
                    errMsg << "ossimJp2Info::getBox caught exception on resize:\n"
                           << "Buffer size in bytes: " << boxSize
                           << "\n" << e.what() << std::endl;
                    throw ossimException( errMsg.str() );
                }

                boxPosOfType = boxPos; // set up return value
                break; // done...
            }

            if (lbox == 0) // last box?
            {
                break;
            }

            // Seek to the next box.
            std::streamoff nextBoxPos = boxPos;
            if (lbox == 1)
            {
                nextBoxPos+= (std::streamoff)xlbox;
            }
            else
            {
                nextBoxPos+= (std::streamoff)lbox;
            }

            // Go to next box:
            str.seekg(nextBoxPos, std::ios_base::beg);

        } // matches: while ( str.good() )

    } // matches: if ( str.good() )

    return boxPosOfType;

} // End: ossimJp2Info::getBox( type, includeAll, str, box ) const
Ejemplo n.º 15
0
std::streamoff ossimJp2Info::findBoxData( const ossim_uint32& type,
        std::ifstream& str,
        ossim_uint32& length ) const
{
    std::streamoff boxPos = 0;
    std::streamoff dataPosOfType = 0;

    if ( str.good() )
    {
        ossim_uint32   lbox   = 0;
        ossim_uint32   tbox   = 0;
        ossim_uint64   xlbox  = 0;
        std::streamoff offsetToDbox = 0;

        while ( str.good() )
        {
            boxPos = str.tellg();

            readUInt32( lbox, str );
            readUInt32( tbox, str );

            if ( lbox == 1 )
            {
                readUInt64( xlbox, str );
                offsetToDbox = 16;
            }
            else
            {
                offsetToDbox = 8;
            }

            if ( traceDebug() )
            {
                ossimNotify(ossimNotifyLevel_DEBUG)
                        << "jp2.lbox: " << std::dec << lbox << "\n"
                        << "jp2.tbox: " << std::hex << tbox << std::dec << "\n";
                printTboxType( tbox, ossimNotify(ossimNotifyLevel_DEBUG)  );

                if ( lbox == 1 )
                {
                    ossimNotify(ossimNotifyLevel_DEBUG) << "jp2.xlbox: " << xlbox << std::endl;
                }
            }

            if ( tbox == type )
            {
                dataPosOfType = boxPos + offsetToDbox; // set up return value
                length = lbox;
                break; // done...
            }

            if ( lbox == 0 ) // last box?
            {
                break;
            }

            // Seek to the next box.
            std::streamoff nextBoxPos = boxPos;
            if (lbox == 1)
            {
                nextBoxPos+= (std::streamoff)xlbox;
            }
            else
            {
                nextBoxPos+= (std::streamoff)lbox;
            }

            // Go to next box:
            str.seekg(nextBoxPos, std::ios_base::beg);

        } // matches: while ( str.good() )

    } // matches: if ( str.good() )

    return dataPosOfType;
}