Example #1
0
unsigned char	*CYmMusic::depackFile(void)
 {
 lzhHeader_t *pHeader;
 ymu8	*pNew;
 ymu8	*pSrc;

		pHeader = (lzhHeader_t*)pBigMalloc;

		if ((pHeader->size==0) ||					// NOTE: Endianness works because value is 0
			(strncmp(pHeader->id,"-lh5-",5)))
		{ // Le fichier n'est pas compresse, on retourne l'original.
			return pBigMalloc;
		}

		fileSize = (ymu32)-1;

		if (pHeader->level != 0)					// NOTE: Endianness works because value is 0
		{ // Compression LH5, header !=0 : Error.
			free(pBigMalloc);
			pBigMalloc = NULL;
			setLastError("LHARC Header must be 0 !");
			return NULL;
		}

		fileSize = ReadLittleEndian32((ymu8*)&pHeader->original);
		pNew = (ymu8*)malloc(fileSize);
		if (!pNew)
		{
			setLastError("MALLOC Failed !");
			free(pBigMalloc);
			pBigMalloc = NULL;
			return NULL;
		}

		pSrc = pBigMalloc+sizeof(lzhHeader_t)+pHeader->name_lenght;			// NOTE: Endianness works because name_lenght is a byte

		pSrc += 2;		// skip CRC16

		const int		packedSize = ReadLittleEndian32((ymu8*)&pHeader->packed);

		// alloc space for depacker and depack data
		CLzhDepacker *pDepacker = new CLzhDepacker;	
		const bool bRet = pDepacker->LzUnpack(pSrc,packedSize,pNew,fileSize);
		delete pDepacker;

		if (!bRet)
		{	// depacking error
			setLastError("LH5 Depacking Error !");
			free(pNew);
			free(pBigMalloc);
			pNew = NULL;
		}
		else 
			free(pBigMalloc); // @ALEX: depacking success, release packed

		return pNew;
 }
Example #2
0
unsigned char	*CYmMusic::depackFile(void)
 {
 lzhHeader_t *pHeader;
 ymu8	*pNew;
 ymu8	*pSrc;

		pHeader = (lzhHeader_t*)pBigMalloc;
		if ((pHeader->size==0) ||					// NOTE: Endianness works because value is 0
			(strncmp(pHeader->id,"-lh5-",5)))
		{ // Le fichier n'est pas compresse, on retourne l'original.
			return pBigMalloc;
		}

		fileSize = (ymu32)-1;

		if (pHeader->level != 0)					// NOTE: Endianness works because value is 0
		{ // Compression LH5, header !=0 : Error.
			free(pBigMalloc);
			pBigMalloc = NULL;
			setLastError("LHARC Header must be 0 !");
			return NULL;
		}

		fileSize = ReadLittleEndian32((ymu8*)&pHeader->original);
		pNew = (ymu8*)malloc(fileSize);
		if (!pNew)
		{
			setLastError("MALLOC Failed !");
			free(pBigMalloc);
			pBigMalloc = NULL;
			return NULL;
		}

		pSrc = pBigMalloc+sizeof(lzhHeader_t)+pHeader->name_lenght;			// NOTE: Endianness works because name_lenght is a byte

		pSrc += 2;		// skip CRC16

		if (!LzhDepackBlock(pSrc,pNew,fileSize))
		{
			setLastError("LH5 Depacking Error !");
			free(pNew);
			free(pBigMalloc);
			pNew = NULL;
			pBigMalloc = NULL;
			return NULL;
		}

		// Tout est bon, le fichier est depack‚, on free le bloque
		// pack‚ et on retourne le nouveau...
		free(pBigMalloc);
		return pNew;
 }
bool OsmAnd::ObfPoiSectionReader_P::readTile(
    const std::unique_ptr<ObfReader_P>& reader, const std::shared_ptr<const ObfPoiSectionInfo>& section,
    QList< std::shared_ptr<Tile> >& tiles,
    Tile* parent,
    QSet<uint32_t>* desiredCategories,
    uint32_t zoom, uint32_t zoomDepth, const AreaI* bbox31,
    IQueryController* controller,
    QSet< uint64_t >* tilesToSkip)
{
    auto cis = reader->_codedInputStream.get();

    const auto zoomToSkip = zoom + zoomDepth;
    QSet< uint64_t > tilesToSkip_;
    if(parent == nullptr && !tilesToSkip)
        tilesToSkip = &tilesToSkip_;

    std::shared_ptr<Tile> tile(new Tile());
    gpb::uint32 lzoom;

    for(;;)
    {
        if(controller && controller->isAborted())
            return false;
        auto tag = cis->ReadTag();
        switch(gpb::internal::WireFormatLite::GetTagFieldNumber(tag))
        {
        case 0:
            tiles.push_back(tile);
            return true;
        case OBF::OsmAndPoiBox::kZoomFieldNumber:
            {
                cis->ReadVarint32(&lzoom);
                tile->_zoom = lzoom;
                if(parent)
                    tile->_zoom += parent->_zoom;
            }
            break;
        case OBF::OsmAndPoiBox::kLeftFieldNumber:
            {
                auto x = ObfReaderUtilities::readSInt32(cis);
                if(parent)
                    tile->_x = x + (parent->_x << lzoom);
                else
                    tile->_x = x;
            }
            break;
        case OBF::OsmAndPoiBox::kTopFieldNumber:
            {
                auto y = ObfReaderUtilities::readSInt32(cis);
                if(parent)
                    tile->_y = y + (parent->_y << lzoom);
                else
                    tile->_y = y;

                // Check that we're inside bounding box, if requested
                if(bbox31)
                {
                    AreaI area31;
                    area31.left = tile->_x << (31 - tile->_zoom);
                    area31.right = (tile->_x + 1) << (31 - tile->_zoom);
                    area31.top = tile->_y << (31 - tile->_zoom);
                    area31.bottom = (tile->_y + 1) << (31 - tile->_zoom);

                    if(!bbox31->intersects(area31))
                    {
                        // This tile is outside of bounding box
                        cis->Skip(cis->BytesUntilLimit());
                        return false;
                    }
                }
            }
            break;
        case OBF::OsmAndPoiBox::kCategoriesFieldNumber:
            {
                if(!desiredCategories)
                {
                    ObfReaderUtilities::skipUnknownField(cis, tag);
                    break;
                }
                gpb::uint32 length;
                cis->ReadLittleEndian32(&length);
                auto oldLimit = cis->PushLimit(length);
                const auto containsDesired = checkTileCategories(reader, section, desiredCategories);
                cis->PopLimit(oldLimit);
                if(!containsDesired)
                {
                    cis->Skip(cis->BytesUntilLimit());
                    return false;
                }
            }
            break;
        case OBF::OsmAndPoiBox::kSubBoxesFieldNumber:
            {
                auto length = ObfReaderUtilities::readBigEndianInt(cis);
                auto oldLimit = cis->PushLimit(length);
                auto tileOmitted = readTile(reader, section, tiles, tile.get(), desiredCategories, zoom, zoomDepth, bbox31, controller, tilesToSkip);
                cis->PopLimit(oldLimit);

                if(tilesToSkip && tile->_zoom >= zoomToSkip && tileOmitted)
                {
                    auto skipHash = (static_cast<uint64_t>(tile->_x) >> (tile->_zoom - zoomToSkip)) << zoomToSkip;
                    skipHash |= static_cast<uint64_t>(tile->_y) >> (tile->_zoom - zoomToSkip);
                    if(tilesToSkip->contains(skipHash))
                    {
                        cis->Skip(cis->BytesUntilLimit());
                        return true;
                    }
                }
            }
            break;
        case OBF::OsmAndPoiBox::kShiftToDataFieldNumber:
            {
                tile->_offset = ObfReaderUtilities::readBigEndianInt(cis);
                tile->_hash  = static_cast<uint64_t>(tile->_x) << tile->_zoom;
                tile->_hash |= static_cast<uint64_t>(tile->_y);
                tile->_hash |= tile->_zoom;

                // skipTiles - these tiles are going to be ignored, since we need only 1 POI object (x;y)@zoom
                if(tilesToSkip && tile->_zoom >= zoomToSkip)
                {
                    auto skipHash = (static_cast<uint64_t>(tile->_x) >> (tile->_zoom - zoomToSkip)) << zoomToSkip;
                    skipHash |= static_cast<uint64_t>(tile->_y) >> (tile->_zoom - zoomToSkip);
                    tilesToSkip->insert(skipHash);
                }
            }
            break;
        default:
            ObfReaderUtilities::skipUnknownField(cis, tag);
            break;
        }
Example #4
0
ymbool	CYmMusic::ymDecode(void)
 {
 ymu8 *pUD;
 ymu8	*ptr;
 ymint skip;
 ymint i;
 ymu32 sampleSize;
 yms32 tmp;
 ymu32 id;
 

		id = ReadBigEndian32((unsigned char*)pBigMalloc);
		switch (id)
		{
			case e_YM2a://'YM2!':		// MADMAX specific.
				songType = YM_V2;
				nbFrame = (fileSize-4)/14;
				loopFrame = 0;
				ymChip.setClock(ATARI_CLOCK);
				setPlayerRate(50);
				pDataStream = pBigMalloc+4;
				streamInc = 14;
				nbDrum = 0;
				setAttrib(A_STREAMINTERLEAVED|A_TIMECONTROL);
				pSongName = mstrdup("Unknown");
				pSongAuthor = mstrdup("Unknown");
				pSongComment = mstrdup("Converted by Leonard.");
				pSongType = mstrdup("YM 2");
				pSongPlayer = mstrdup("YM-Chip driver");
				break;

			case e_YM3a://'YM3!':		// Standart YM-Atari format.
				songType = YM_V3;
				nbFrame = (fileSize-4)/14;
				loopFrame = 0;
				ymChip.setClock(ATARI_CLOCK);
				setPlayerRate(50);
				pDataStream = pBigMalloc+4;
				streamInc = 14;
				nbDrum = 0;
				setAttrib(A_STREAMINTERLEAVED|A_TIMECONTROL);
				pSongName = mstrdup("Unknown");
				pSongAuthor = mstrdup("Unknown");
				pSongComment = mstrdup("");
				pSongType = mstrdup("YM 3");
				pSongPlayer = mstrdup("YM-Chip driver");
				break;

			case e_YM3b://'YM3b':		// Standart YM-Atari format + Loop info.
				pUD = (ymu8*)(pBigMalloc+fileSize-4);
				songType = YM_V3;
				nbFrame = (fileSize-4)/14;
				loopFrame = ReadLittleEndian32(pUD);
				ymChip.setClock(ATARI_CLOCK);
				setPlayerRate(50);
				pDataStream = pBigMalloc+4;
				streamInc = 14;
				nbDrum = 0;
				setAttrib(A_STREAMINTERLEAVED|A_TIMECONTROL);
				pSongName = mstrdup("Unknown");
				pSongAuthor = mstrdup("Unknown");
				pSongComment = mstrdup("");
				pSongType = mstrdup("YM 3b (loop)");
				pSongPlayer = mstrdup("YM-Chip driver");
				break;

			case e_YM4a://'YM4!':		// Extended ATARI format.
				setLastError("No more YM4! support. Use YM5! format.");
				return YMFALSE;
				break;

			case e_YM5a://'YM5!':		// Extended YM2149 format, all machines.
			case e_YM6a://'YM6!':		// Extended YM2149 format, all machines.
				if (strncmp((const char*)(pBigMalloc+4),"LeOnArD!",8))
				{
					setLastError("Not a valid YM format !");
					return YMFALSE;
				}
				ptr = pBigMalloc+12;
				nbFrame = readMotorolaDword(&ptr);
				setAttrib( readMotorolaDword(&ptr) | A_TIMECONTROL);
				nbDrum = readMotorolaWord(&ptr);
				ymChip.setClock(readMotorolaDword(&ptr));
				setPlayerRate(readMotorolaWord(&ptr));
				loopFrame = readMotorolaDword(&ptr);
				skip = readMotorolaWord(&ptr);
				ptr += skip;
				if (nbDrum>0)
				{
					pDrumTab=(digiDrum_t*)malloc(nbDrum*sizeof(digiDrum_t));
					for (i=0;i<nbDrum;i++)
					{
						pDrumTab[i].size = readMotorolaDword(&ptr);
						if (pDrumTab[i].size)
						{
							pDrumTab[i].pData = (ymu8*)malloc(pDrumTab[i].size);
							memcpy(pDrumTab[i].pData,ptr,pDrumTab[i].size);
							if (attrib&A_DRUM4BITS)
							{
								ymu32 j;
								ymu8 *pw = pDrumTab[i].pData;
								for (j=0;j<pDrumTab[i].size;j++)
								{
									*pw = ymVolumeTable[(*pw)&15]>>7;
									pw++;
								}
							}
							ptr += pDrumTab[i].size;
						}
						else
						{
Example #5
0
unsigned char	*CYmMusic::depackFile(ymu32 checkOriginalSize)
 {
 lzhHeader_t *pHeader;
 ymu8	*pNew;
 ymu8	*pSrc;

		pHeader = (lzhHeader_t*)pBigMalloc;

		if ((pHeader->size==0) ||					// NOTE: Endianness works because value is 0
			(strncmp(pHeader->id,"-lh5-",5)))
		{ // Le fichier n'est pas compresse, on retourne l'original.
			return pBigMalloc;
		}

		fileSize = (ymu32)-1;

		if (pHeader->level != 0)					// NOTE: Endianness works because value is 0
		{ // Compression LH5, header !=0 : Error.
			free(pBigMalloc);
			pBigMalloc = NULL;
			setLastError((char*)"LHARC Header must be 0 !");
			return NULL;
		}

		fileSize = ReadLittleEndian32((ymu8*)&pHeader->original);
		pNew = (ymu8*)malloc(fileSize);
		if (!pNew)
		{
			setLastError((char*)"MALLOC Failed !");
			free(pBigMalloc);
			pBigMalloc = NULL;
			return NULL;
		}

		pSrc = pBigMalloc+sizeof(lzhHeader_t)+pHeader->name_lenght;			// NOTE: Endianness works because name_lenght is a byte

		pSrc += 2;		// skip CRC16

		ymu32		packedSize = ReadLittleEndian32((ymu8*)&pHeader->packed);


		checkOriginalSize -= (ymu32(*pSrc) - ymu32(*pBigMalloc));

		if (packedSize > checkOriginalSize)
			packedSize = checkOriginalSize;

		// Check for corrupted archive
		if (packedSize <= checkOriginalSize)
		{
			// alloc space for depacker and depack data
			CLzhDepacker *pDepacker = new CLzhDepacker;	
			const bool bRet = pDepacker->LzUnpack(pSrc,packedSize,pNew,fileSize);
			delete pDepacker;

			if (!bRet)
			{	// depacking error
				setLastError((char*)"LH5 Depacking Error !");
				free(pNew);
				pNew = NULL;
			}
		}
		else
		{
			setLastError((char*)"LH5 Depacking Error !");
			free(pNew);
			pNew = NULL;
		}

		// Free up source buffer, whatever depacking fail or success
		free(pBigMalloc);

		return pNew;
 }