CPLErr WEBPDataset::IRasterIO( GDALRWFlag eRWFlag,
                              int nXOff, int nYOff, int nXSize, int nYSize,
                              void *pData, int nBufXSize, int nBufYSize,
                              GDALDataType eBufType,
                              int nBandCount, int *panBandMap,
                              int nPixelSpace, int nLineSpace, int nBandSpace )

{
    if((eRWFlag == GF_Read) &&
       (nBandCount == nBands) &&
       (nXOff == 0) && (nXOff == 0) &&
       (nXSize == nBufXSize) && (nXSize == nRasterXSize) &&
       (nYSize == nBufYSize) && (nYSize == nRasterYSize) &&
       (eBufType == GDT_Byte) && 
       (nPixelSpace == nBands) &&
       (nLineSpace == (nPixelSpace*nXSize)) &&
       (nBandSpace == 1) &&
       (pData != NULL) &&
       (panBandMap != NULL) &&
       (panBandMap[0] == 1) && (panBandMap[1] == 2) && (panBandMap[2] == 3) && (nBands == 3 || panBandMap[3] == 4))
    {
        Uncompress();
        memcpy(pData, pabyUncompressed, nBands * nXSize * nYSize);
        return CE_None;
    }

    return GDALPamDataset::IRasterIO(eRWFlag, nXOff, nYOff, nXSize, nYSize,
                                     pData, nBufXSize, nBufYSize, eBufType,
                                     nBandCount, panBandMap,
                                     nPixelSpace, nLineSpace, nBandSpace);
}
Exemplo n.º 2
0
Bool CSharu::GetFileData(SFileInfo *pFileInfo, const MY_FILE_ENTRY_BASE *pBaseEntry)
{
    PByte  pbBuffer;
    UInt32 BufferSize;
    SMyPackIndex *pIndex;

    pIndex = (SMyPackIndex *)pBaseEntry;

    BufferSize = max(pIndex->CompressedSize.LowPart, pIndex->Size.LowPart);
    if (BufferSize == 0)
    {
        pbBuffer = NULL;
        goto EMPTY_FILE;
    }

    pbBuffer = (PByte)Alloc(BufferSize);
    if (pbBuffer == NULL)
        return False;

    if (file.Seek(file.FILE_SEEK_BEGIN, pIndex->Offset.LowPart, (PLong)&pIndex->Offset.HighPart) == False)
        return False;
    if (file.Read(pbBuffer, pIndex->CompressedSize.LowPart) == False)
        return False;

    if (pIndex->CompressedSize.LowPart < 0x1000000)
    {
        if (Hash(pbBuffer, pIndex->CompressedSize.LowPart) != pIndex->Hash)
        {
            Free(pbBuffer);
            return False;
        }
    }

    if (TEST_BITS(pIndex->Flags, UNPACKER_ENTRY_FLAG_ENCRYPTED))
        Decrypt(pbBuffer, pIndex->CompressedSize.LowPart, m_Key);

    if (TEST_BITS(pIndex->Flags, UNPACKER_ENTRY_FLAG_COMPRESSED))
    {
        PByte pbTemp = (PByte)Alloc(pIndex->CompressedSize.LowPart);
        if (pbTemp == NULL)
        {
            Free(pbBuffer);
            return False;
        }

        memcpy(pbTemp, pbBuffer, pIndex->CompressedSize.LowPart);
        Uncompress(pbTemp, pIndex->CompressedSize.LowPart, pbBuffer);

        Free(pbTemp);
    }

EMPTY_FILE:
    pFileInfo->FileType = UNPACKER_FILE_TYPE_BIN;
    pFileInfo->lpExtraData = NULL;
    pFileInfo->BinData.pbBuffer = pbBuffer;
    pFileInfo->BinData.BufferSize = pIndex->Size.LowPart;

    return True;
}
Exemplo n.º 3
0
        inline size_t Read(void* ptr, size_t len) {
            size_t ret = 0;

            do {
                ret = Uncompressed_.Read(ptr, len);
            } while (!ret && Uncompress());

            return ret;
        }
Exemplo n.º 4
0
CPLErr WEBPDataset::IRasterIO( GDALRWFlag eRWFlag,
                              int nXOff, int nYOff, int nXSize, int nYSize,
                              void *pData, int nBufXSize, int nBufYSize,
                              GDALDataType eBufType,
                              int nBandCount, int *panBandMap,
                              GSpacing nPixelSpace, GSpacing nLineSpace,
                              GSpacing nBandSpace,
                              GDALRasterIOExtraArg* psExtraArg )

{
    if((eRWFlag == GF_Read) &&
       (nBandCount == nBands) &&
       (nXOff == 0) &&
       (nYOff == 0) && // TODO: X -> Y on this was correct?
       (nXSize == nBufXSize) && (nXSize == nRasterXSize) &&
       (nYSize == nBufYSize) && (nYSize == nRasterYSize) &&
       (eBufType == GDT_Byte) &&
       (pData != NULL) &&
       (panBandMap[0] == 1) && (panBandMap[1] == 2) && (panBandMap[2] == 3) &&
       (nBands == 3 || panBandMap[3] == 4))
    {
        if( Uncompress() != CE_None )
            return CE_Failure;
        if( nPixelSpace == nBands && nLineSpace == (nPixelSpace*nXSize) &&
            nBandSpace == 1 )
        {
            memcpy(pData, pabyUncompressed, nBands * nXSize * nYSize);
        }
        else
        {
            for(int y = 0; y < nYSize; ++y)
            {
                GByte* pabyScanline = pabyUncompressed + y * nBands * nXSize;
                for(int x = 0; x < nXSize; ++x)
                {
                    for(int iBand=0;iBand<nBands;iBand++)
                        reinterpret_cast<GByte *>(
                            pData )[(y * nLineSpace) + (x * nPixelSpace) +
                                    iBand * nBandSpace]
                            = pabyScanline[x * nBands + iBand];
                }
            }
        }

        return CE_None;
    }

    return GDALPamDataset::IRasterIO(eRWFlag, nXOff, nYOff, nXSize, nYSize,
                                     pData, nBufXSize, nBufYSize, eBufType,
                                     nBandCount, panBandMap,
                                     nPixelSpace, nLineSpace, nBandSpace,
                                     psExtraArg);
}
Exemplo n.º 5
0
bool FImageWrapperBase::GetRaw( const ERGBFormat::Type InFormat, int32 InBitDepth, const TArray<uint8>*& OutRawData )
{
	LastError.Empty();
	Uncompress(InFormat, InBitDepth);

	if (LastError.IsEmpty())
	{
		OutRawData = &RawData;
	}

	return LastError.IsEmpty();
}
Exemplo n.º 6
0
int main(int argc,char *argv[]){
	int choice;
	Welcome();
	scanf("%d",&choice);
	switch(choice)
	{
		case 0:Compress();
		break;
		case 1:Uncompress();
		break;
		case 2:	exit(0);
		break;
		default :printf(" йДхКспнС");
	}


}
Exemplo n.º 7
0
unsigned int MkZipCompressor::Uncompress
(const unsigned char* srcArray, unsigned int srcSize, MkByteArray& destBuffer, unsigned int destBufRate)
{
	if ((srcArray == 0) || (srcSize == 0))
		return 0;

	// compressedSize를 destBufRate배하거나 unsigned int의 최대 수를 버퍼사이즈로 잡음
	bool onMaxBufferSize = (srcSize >= (0xffffffff / destBufRate));
	unsigned int bufSize = (onMaxBufferSize) ? 0xffffffff : (srcSize * destBufRate);
	uLongf destSize = static_cast<uLongf>(bufSize);

	unsigned char* destArray = new unsigned char[destSize];
	int rlt = uncompress(destArray, &destSize, srcArray, srcSize);
	unsigned int newSize;
	if (rlt == Z_OK)
	{
		newSize = static_cast<unsigned int>(destSize);
		destBuffer.Clear();
		destBuffer.Fill(newSize);
		destBuffer.Overwrite(0, MkByteArrayDescriptor(destArray, newSize));
		delete [] destArray;
	}
	else if (rlt == Z_BUF_ERROR)
	{
		// 버퍼 용량 부족
		delete [] destArray;
		if (onMaxBufferSize)
		{
			newSize = 0; // 4G 버퍼로도 안됨. 실패
		}
		else
		{
			newSize = Uncompress(srcArray, srcSize, destBuffer, destBufRate * 2); // 두배로 버퍼를 키워 재시도
		}
	}
	else
	{
		// Z_MEM_ERROR, Z_DATA_ERROR
		newSize = 0;
		delete [] destArray;
	}
	return newSize;
}
Exemplo n.º 8
0
static Boolean SearchRecord
         (
         MemHandle  handle,   /* handle of record to search */
         Char*      pattern,  /* pattern to search for */
         Boolean    onlyOne   /* are we looking only for a single match? */
         )
{
    Boolean     multiple;
    Boolean     done;
    MemHandle   uncompressHandle;
    Header*     record;
    UInt16      uniqueID;
    Char*       text;
    Int16       size;
    Boolean     match;

    multiple = Prefs()->searchFlags & SEARCH_MULTIPLE;
    if ( multiple ) {
        ParseSearchString( pattern );
        if ( ! numSearchTerms )
            return false;
    }

    done                = false;
    record              = MemHandleLock( handle );
    uniqueID            = record->uid;
    lastSearchedRecordId = uniqueID;
    uncompressHandle    = NULL;
    if ( record->type == DATATYPE_PHTML_COMPRESSED ) {
        ErrTry {
            uncompressHandle    = Uncompress( record );
            text                = MemHandleLock( uncompressHandle );
            size                = MemPtrSize( text );
            ResetLastUncompressedPHTML();
        }
        ErrCatch( UNUSED_PARAM( err ) ) {
            MemHandleUnlock( handle );
            return false;
        } ErrEndCatch
    }
Exemplo n.º 9
0
//
// Loop for ever, and wait for new jobs.
// The general principle used is repeating (starting with locked mutex):
//   wait(condition)
//   pop a job from the job queue
//   unlock(mutex)
//   Do the job.
//   lock(mutex)
//   put result in outgoing queue.
//
// This means that the actual job is done with no locked semaphores. Because of that, it is important that no data is
// manipulated that can also be accessed from the main process.
void ChunkProcess::Task(void) {
	std::unique_lock<std::mutex> lock(fMutex); // This will lock the mutex

	// The condition variable will not have any effect if not waiting for it. And that may happen
	// as the mutex is unlocked in the loop now and then.
	bool waitForCondition = true;

	// Stay in a loop forever, waiting for new messages to play
	while(1) {
		if (waitForCondition)
			fCondLock.wait(lock);
		waitForCondition = true; // Wait for condition next iteration

		if (fTerminate) {
			// Used to request that the child thread terminates.
			fMutex.unlock();
			break;
		}

		if (!fComputeObjectsInput.empty()) {
			// Take out the chunk from the fifo
			chunk *ch = getNextChunk(fComputeObjectsInput);
			if (ch == 0)
				continue;
			if (ch->fScheduledForLoading) {
				ch->fScheduledForComputation = false;
				continue; // Ignore a recomputation, as the chunk will be loaded by new data anyway, later followed by a new computation
			}
			fMutex.unlock(); // Unlock the mutex while doing some heavy work
			// printf("ChunkProcess phase 1, size %d, chunk %d,%d,%d\n", fComputeObjectsInput.size()+1, ch->cc.x, ch->cc.y, ch->cc.z);
			auto co = ChunkObject::Make(ch, false, 0, 0, 0);
			co->FindSpecialObjects(ch); // This will find light sources, and should be done before FindTriangles().
			fMutex.lock();
			ASSERT(ch->fScheduledForComputation);
			co->fChunk = ch;
			fComputedObjectsOutput.insert(std::move(co)); // Add it to the list of recomputed chunks
			waitForCondition = false; // Try another iteration
		}

		if (!fNewChunksInput.empty()) {
			auto nc = getNextChunkBlock(fNewChunksInput);
			chunk *pc = nc->fChunk;
			// It may be that this chunk was also scheduled for recomputation. If so, the Uncompress() below that calls SetDirty() will not
			// schedule a new recomputation again.
			ASSERT(pc->fScheduledForLoading);
			fMutex.unlock(); // Unlock the mutex while doing some work
			// printf("ChunkProcess phase 2, size %d\n", fNewChunksInput.size()+1);
			nc->Uncompress();

			// Save chunk in cache
			ChunkCache::cachunk chunkdata;
			chunkdata.cc = pc->cc;
			chunkdata.flag = nc->flag;
			chunkdata.fCheckSum = nc->fChecksum;
			chunkdata.fOwner = nc->fOwner;
			chunkdata.compressSize = nc->compressSize;
			chunkdata.compressedChunk = nc->fCompressedChunk.get();
			ChunkCache::fgChunkCache.SaveChunkInCache(&chunkdata); // TODO: Use a ChunkProcess::ChunkBlocks as argument instead
			fMutex.lock();
			ASSERT(nc->fChunk == pc);
			fNewChunksOutput.insert(nc); // Add it to the list of loaded chunks
			waitForCondition = false; // Try another iteration
		}
	}
}
Exemplo n.º 10
0
 bool
 Compression::Uncompress(const String &zipFile, const String &targetDirectory)
 {
    return Uncompress(zipFile, targetDirectory, "*");
 }
Exemplo n.º 11
0
// управление ВМ, key - номер клавиши пульта
// 0 - OK
int VCR::IrcKeyTrn (int fdout, int key)
{
  int stat, buf, delay;
  word *sbuf, *nbuf, *pbuf;

#define IKTBNUM 5
  stat = Uncompress(key);

  if (stat)
    return (stat);

  stat = 1;
//write (fdout, Sbuffer, modesize * 2);
  sbuf = nbuf = pbuf = (word*) malloc (312*12 * 2 * IKTBNUM);
  bzero (sbuf, 312*12 * 2 * IKTBNUM);
  buf = 0;
  delay = 0;

  while (stat)
   {
    if (VCR_1950 ())
      stat = 0;

    bcopy (Sbuffer, nbuf, modesize * 2); // copy first part
    nbuf += modesize; // move pointer to begin second part

    // если следующий буфер будет больше или конец
    if (nbuf+modesize > sbuf+312*12*IKTBNUM || stat == 0)
     {
      // новый размер будет больше размера буфера
      int ctmp = 0, wtmp, cbuf;
      // расчитаем количество заполненых буферов
      cbuf = (nbuf - sbuf) / (312 * 12);
      // размер для вывода
      wtmp = 312*12*2 * cbuf;
#ifdef DEBUG_IRCOUT
      printf ("cbuf: %d, wtmp: %d\n", cbuf, wtmp);
#endif
      // выводим
      for (pbuf = sbuf; wtmp && (ctmp != -1);)
       {
	do
	 {
	  /// ctmp = write (fdout, pbuf, 312*12*2);
	  ctmp = SendIRCCommand ((byte*)pbuf, 312*12*2);
	 } while (ctmp != 312*12*2 && ctmp != -1);

	pbuf += ctmp/2;
	wtmp -= ctmp;
       }

      // оставшуюся информацию
      wtmp = nbuf - sbuf - cbuf*312*12;
      wtmp *= 2;
#ifdef DEBUG_IRCOUT
      printf ("wtmp: %d\n", wtmp);
#endif
      // если конец выводим
      if (stat == 0 && wtmp)
       {
	do
	 {
	  /// ctmp = write (fdout, pbuf, wtmp);
	  ctmp = SendIRCCommand ((byte*)pbuf, wtmp);
	 }
	while (ctmp != wtmp && ctmp != -1);

	nbuf = sbuf;
       }
      else
       {
	// перенесем в начало
	bcopy (pbuf, sbuf, wtmp);

	// и запомним
	nbuf = sbuf + wtmp/2;
       }
     } // end if
   } // end while

  free (sbuf);
  // подождем
  delay = svcr->a[0x8be] / 50;

  if (!delay)
    delay++;

  printf ("IrcKeyTrn: Sleep %d/%d sec\n", svcr->a[0x8be], delay);
  sleep (delay);
  return (0);
};
Exemplo n.º 12
0
// управление ВМ, key - номер клавиши пульта
// 0 - OK
int VCR::IrcKeyTrn (int fdout, int key)
{
  int stat, delay = 0, crc32 = 0;
  word *sbuf, *nbuf, *pbuf;

#define IKTBNUM 11

  if ((stat = Uncompress (key)) != 0)
    return (stat);

  stat = 1;
//write (fdout, Sbuffer, modesize * 2);
  sbuf = nbuf = pbuf = (word*) malloc (SSIZE_IRC_FRAME * IKTBNUM);
  bzero (sbuf, SSIZE_IRC_FRAME * IKTBNUM);

  while (stat)
   {
    if (VCR_1950 ())
      stat = 0;

    bcopy (Sbuffer, nbuf, modesize * 2); // copy first part
    //imemcpy (nbuf, Sbuffer, modesize * 2); // copy first part
    nbuf += modesize; // move pointer to begin second part

    // если следующий буфер будет больше или конец
    if (nbuf+modesize > sbuf + (SSIZE_IRC_FRAME/2) * IKTBNUM || stat == 0)
     {
      // новый размер будет больше размера буфера
      // int bsend = 0;
      // расчитаем количество заполненых буферов
      int fullfr = (nbuf - sbuf) / (SSIZE_IRC_FRAME/2);
      // размер для вывода
      int szfullfr = SSIZE_IRC_FRAME * fullfr;

#ifdef DEBUG_IRCOUT
      printf ("fullfr: %d, szfullfr: %d\n", fullfr, szfullfr);
#endif
      // выводим
      /*
      for (pbuf = sbuf; szfullfr && (bsend != -1);)
       {
	do
	 {
	  /// bsend = write (fdout, pbuf, 312*12*2);
	  bsend = SendIRCCommand ((byte*)pbuf, SSIZE_IRC_FRAME);
	 } while (bsend != SSIZE_IRC_FRAME && bsend != -1);

	pbuf += bsend/2;
	szfullfr -= bsend;
       }
      */

      pbuf = sbuf;
      SendIRCCommand ((byte*)pbuf, szfullfr);

      for (int i = 0; i < szfullfr; i++)
	crc32 += *((byte*)((int)pbuf + i));

      pbuf += szfullfr/2;

      // оставшуюся информацию
      int last = nbuf - sbuf - (fullfr * (SSIZE_IRC_FRAME/2));
      last *= 2;
#ifdef DEBUG_IRCOUT
      printf ("last: %d\n", last);
#endif

      // если конец выводим
      if (stat == 0 && last)
       {
	/*
	do
	 {
	  /// bsend = write (fdout, pbuf, last);
	  bsend = SendIRCCommand ((byte*)pbuf, last);
	 }
	while (bsend != last && bsend != -1);
	*/

	SendIRCCommand ((byte*)pbuf, last);

	for (int i = 0; i < last; i++)
	  crc32 += *((byte*)((int)pbuf + i));

#ifdef DEBUG_IRCOUT
	printf ("send last\n");
#endif
	nbuf = sbuf;
       }
      else
       {
	// перенесем в начало
	bcopy (pbuf, sbuf, last);
	//imemcpy (sbuf, pbuf, last);
	// и запомним
	nbuf = sbuf + last/2;
       }
     } // end if
   } // end while

  free (sbuf);
  // подождем
  delay = svcr->a[0x8be] / 50;

  if (!delay)
    delay++;

  printf ("IrcKeyTrn: Sleep %d/%d sec\n", svcr->a[0x8be], delay);
  printf ("crc32: %X\n", crc32);
  sleep (delay);
  return 0;
};
Exemplo n.º 13
0
Arquivo: misc.c Projeto: aosm/X11apps
FILE *
FindManualFile(ManpageGlobals * man_globals, int section_num, int entry_num)
{
  FILE * file;
  char path[BUFSIZ], page[BUFSIZ], section[BUFSIZ], *temp;
  char filename[BUFSIZ];
  char * entry = manual[section_num].entries[entry_num];
  int len_cat = strlen(CAT);
#if defined(ISC) || defined(__SCO__) || defined(__UNIXWARE__)
  int i;
#endif

  temp = CreateManpageName(entry, 0, 0);
  snprintf(man_globals->manpage_title, sizeof(man_globals->manpage_title),
    "The current manual page is: %s.", temp);
  XtFree(temp);

  ParseEntry(entry, path, section, page);

/*
 * Look for uncompressed files first.
 */
#if defined(__OpenBSD__) || defined(__NetBSD__)
  /* look in machine subdir first */
  snprintf(filename, sizeof(filename), "%s/%s%s/%s/%s", path, CAT,
	  section + len_cat, MACHINE, page);
  if ( (file = fopen(filename,"r")) != NULL)
    return(file);
#endif

  snprintf(filename, sizeof(filename), "%s/%s%s/%s", 
    path, CAT, section + len_cat, page);
  if ( (file = fopen(filename,"r")) != NULL)
    return(file);

/*
 * Then for compressed files in an uncompressed directory.
 */

#if !defined(ISC) && !defined(__UNIXWARE__)
#if defined(__OpenBSD__) || defined(__NetBSD__)
  /* look in machine subdir first */
  snprintf(filename, sizeof(filename), "%s/%s%s/%s/%s.%s", path, CAT,
	  section + len_cat, MACHINE, page, COMPRESSION_EXTENSION);
  if ( (file = Uncompress(man_globals, filename)) != NULL)
    return(file);
#endif
  snprintf(filename, sizeof(filename), "%s/%s%s/%s.%s", path, CAT,
	  section + len_cat, page, COMPRESSION_EXTENSION);
  if ( (file = Uncompress(man_globals, filename)) != NULL)
    return(file);
#ifdef GZIP_EXTENSION
  else {
#if defined(__OpenBSD__) || defined(__NetBSD__)
      /* look in machine subdir first */
      snprintf(filename, sizeof(filename), "%s/%s%s/%s/%s.%s", path, CAT,
	      section + len_cat, MACHINE, page, GZIP_EXTENSION);
      if ( (file = Uncompress(man_globals, filename)) != NULL)
	  return(file);
#endif
    snprintf(filename, sizeof(filename), "%s/%s%s/%s.%s", path, CAT,
	    section + len_cat, page, GZIP_EXTENSION);
    if ( (file = Uncompress(man_globals, filename)) != NULL)
      return(file);
  }
#endif
#ifdef BZIP2_EXTENSION
#if defined(__OpenBSD__) || defined(__NetBSD__)
      /* look in machine subdir first */
      snprintf(filename, sizeof(filename), "%s/%s%s/%s/%s.%s", path, CAT,
	      section + len_cat, MACHINE, page, BZIP2_EXTENSION);
      if ( (file = Uncompress(man_globals, filename)) != NULL)
	  return(file);
#endif
  {
    sprintf(filename, "%s/%s%s/%s.%s", path, CAT,
	    section + len_cat, page, BZIP2_EXTENSION);
    if ( (file = Uncompress(man_globals, filename)) != NULL)
      return(file);
  }
#endif
#ifdef LZMA_EXTENSION
  {
    sprintf(filename, "%s/%s%s/%s.%s", path, CAT,
	    section + len_cat, page, LZMA_EXTENSION);
    if ( (file = Uncompress(man_globals, filename)) != NULL)
      return(file);
  }
#endif
#else
  for(i = 0; i < strlen(COMPRESSION_EXTENSIONS); i++) {
      snprintf(filename, sizeof(filename), "%s/%s%s/%s.%c", path, CAT,
            section + len_cat, page, COMPRESSION_EXTENSIONS[i]);
      uncompress_format = uncompress_formats[i];
#ifdef DEBUG
      printf("Trying .%c ...\n", COMPRESSION_EXTENSIONS[i]);
#endif
      if ( (file = Uncompress(man_globals, filename)) != NULL)
	return(file);
  }
#endif

/*
 * And lastly files in a compressed directory.
 *
 * The directory is not actually compressed it is just named man#.Z
 * and all files in it are compressed without the .Z extension.
 * HP does it this way (really :-).
 */

  snprintf(filename, sizeof(filename), "%s/%s%s.%s/%s", path, CAT, 
	   section + len_cat, COMPRESSION_EXTENSION, page);
  if ( (file = Uncompress(man_globals, filename)) != NULL)
    return(file);
/*
 * We did not find any preformatted manual pages, try to format it.
 */

  return(Format(man_globals, entry));
}
Exemplo n.º 14
0
Bool CSharu::Open(PCWChar pszFileName)
{
    ReleaseAll();

    if (file.Open(pszFileName) == False)
        return False;

    Bool ret;
    UInt32 Version, Key;
    SPackHeader header;
    SPackHashTableHeader *pHashTable;
    static Char Seed[] = "8hr48uky,8ugi8ewra4g8d5vbf5hb5s6";

    UNREFERENCED_PARAMETER(pHashTable);

    if (file.Seek(file.FILE_SEEK_END, -(Long)sizeof(header)) == False)
        return False;

    if (file.Read(&header, sizeof(header)) == False)
        return False;

    Version = *(PUInt32)&header.tag[11];
    if (Version > TAG3('3.0') || Version < TAG3('1.0'))
        return False;

    header.tag[11] = 0;
    if (StrICompareA(header.tag, "FilePackVer"))
        return False;

    Key = Hash(header.Data, sizeof(header.Data)) & 0x0FFFFFFF;
    Decrypt(header.Seed, sizeof(header.Seed), Key);

    if (Version == TAG3('3.0') && memcmp(header.Seed, Seed, sizeof(header.Seed)))
        return False;

    // what the f**k is it

#if 0
    pHashTable = (SPackHashTableHeader *)Alloc(header.HashTableSize);
    if (pHashTable == NULL)
        return False;

    if (file.Seek(file.FILE_SEEK_END, -(Long)(sizeof(header) + header.HashTableSize)) == False)
        return False;

    if (file.Read(pHashTable, header.HashTableSize) == False)
        return False;

    Version = *(PUInt32)&pHashTable->HashVer[7];

    do
    {
        ret = False;
        if (Version < TAG3('1.2') || Version > TAG3('1.3'))
            break;

        pHashTable->HashVer[7] = 0;
        if (lstrcmpiA(pHashTable->HashVer, "HashVer") || pHashTable->SubTableNum != 0x100)
            break;

        Decrypt(&pHashTable->Data, pHashTable->CompressedSize, 0x428);

        UInt32 DecompressSize;
        LPVoid lpDecrypted = Alloc(pHashTable->Data.DecompressSize);
        if (lpDecrypted == NULL)
            break;

        DecompressSize = Uncompress(&pHashTable->Data, pHashTable->CompressedSize, lpDecrypted);

        CFileDisk f;
        if (f.Open(L"K:\\galgame\\¥×¥ê¥ó¥»¥¹¥é¥Ð©`!\\GameData\\test.bin", f.W, f.N))
        {
            f.Write(pHashTable, sizeof(*pHashTable) - sizeof(pHashTable->Data));
            f.Write(lpDecrypted, DecompressSize);
        }

        Free(lpDecrypted);

    } while (0);

    Free(pHashTable);
    return False;
#endif

    if (Version == TAG3('1.0'))
        Key = 0xC4;

    ret = InitIndex(&header, Key);

    return ret;
}
Exemplo n.º 15
0
bool
PostScript::FindGraphicsFile (/*[in]*/ const char *	lpszFileName,
			      /*[out]*/ PathName &	result)
{
  if (*lpszFileName == '`')
  {
    if (pDviImpl->TryGetTempFile(lpszFileName, result))
    {
      return (true);
    }
    else if (strncmp(lpszFileName + 1, "gunzip -c ", 10) == 0)
    {
      Uncompress (lpszFileName + 11, result);
      return (true);
    }
    else if (strncmp(lpszFileName + 1, "bunzip2 -c ", 11) == 0)
    {
      Uncompress (lpszFileName + 12, result);
      return (true);
    }
    else if (! AllowShellCommand(lpszFileName + 1))
    {
      tracePS->WriteFormattedLine ("libdvi", T_("Ignoring shell command %s"), Q_(lpszFileName + 1));
      return (false);
    }
    else
    {
      char szTempFileName[_MAX_PATH];
      Utils::CopyString (szTempFileName,
	_MAX_PATH,
	PathName().SetToTempFile().Get());
      string command;
      command = lpszFileName + 1;
      command += " > ";
      command += Q_(szTempFileName);
      MIKTEX_ASSERT (pDviImpl != 0);
      PathName docDir = pDviImpl->GetDviFileName();
      docDir.RemoveFileSpec();
      StdoutReader reader;
      bool done =
	Process::ExecuteSystemCommand(command.c_str(), 0,
	&reader, docDir.Get());
      if (! done)
      {
	// <fixme>hard-coded string</fixme>
	File::Delete (szTempFileName);
	FATAL_MIKTEX_ERROR ("PostScript::FindGraphicsFile",
	  T_("Execution of an embedded shell ")
	  T_("command failed for some reason!"),
	  0);
      }
      pDviImpl->RememberTempFile (lpszFileName + 1, szTempFileName);
      result = szTempFileName;
      return (true);
    }
  }
  else if (IsZFileName(lpszFileName))
  {
    if (pDviImpl->TryGetTempFile(lpszFileName, result))
    {
      return (true);
    }
    Uncompress (lpszFileName, result);
    return (true);
  }
  else
  {
    return (pDviImpl->FindGraphicsFile(lpszFileName, result));
  }
}