Esempio n. 1
0
void Archive::CheckArc(bool EnableBroken)
{
  if (!IsArchive(EnableBroken))
  {
    ErrHandler.Exit(FATAL_ERROR);
  }
}
Esempio n. 2
0
void Archive::CheckArc(bool EnableBroken)
{
  if (!IsArchive(EnableBroken))
  {
    Log(FileName,St(MBadArc),FileName);
    ErrHandler.Exit(RARX_FATAL);
  }
}
Esempio n. 3
0
bool Archive::WCheckOpen(const char *Name,const wchar *NameW)
{
  if (!WOpen(Name,NameW))
    return(false);
  if (!IsArchive(false))
  {
    Close();
    return(false);
  }
  return(true);
}
Esempio n. 4
0
void Archive::CheckArc(bool EnableBroken)
{
  if (!IsArchive(EnableBroken))
  {
    // If FailedHeaderDecryption is set, we already reported that archive
    // password is incorrect.
    if (!FailedHeaderDecryption)
      uiMsg(UIERROR_BADARCHIVE,FileName);
    ErrHandler.Exit(RARX_FATAL);
  }
}
Esempio n. 5
0
bool Archive::WCheckOpen(const wchar *Name)
{
  if (!WOpen(Name))
    return false;
  if (!IsArchive(false))
  {
    uiMsg(UIERROR_BADARCHIVE,FileName);
    Close();
    return false;
  }
  return true;
}
Esempio n. 6
0
void Archive::CheckArc(bool EnableBroken)
{
  if (!IsArchive(EnableBroken))
  {
    // If FailedHeaderDecryption is set, we already reported that archive
    // password is incorrect.
    if (!FailedHeaderDecryption)
    {
      Log(FileName,St(MBadArc),FileName);
    }
    ErrHandler.Exit(RARX_FATAL);
  }
}
Esempio n. 7
0
bool Archive::WCheckOpen(const wchar *Name)
{
  if (!WOpen(Name))
    return false;
  if (!IsArchive(false))
  {
#ifndef SHELL_EXT
    Log(FileName,St(MNotRAR),FileName);
#endif
    Close();
    return false;
  }
  return true;
}
Esempio n. 8
0
bool Archive::WCheckOpen(char *Name,wchar *NameW)
{
  if (!WOpen(Name,NameW))
    return(false);
  if (!IsArchive(false))
  {
#ifndef SHELL_EXT
    Log(FileName,St(MNotRAR),FileName);
#endif
    Close();
    return(false);
  }
  return(true);
}
Esempio n. 9
0
bool WarcArchivesLoader::LoadNextArchive() {
  // Kill exe with previous archive (we are using the same localhost server port).
  const std::string kill_cmd = "taskkill /IM " + Poco::Path(GlobalConfig::Get().archiverExePath).getFileName();
  system(kill_cmd.c_str());
  
  Poco::DirectoryIterator end;
  do {
    if (warcFilesIterator_ == end) {
      // No more archives.
      return false;
    }
    current_archive_path_ = warcFilesIterator_.path().toString();
    ++warcFilesIterator_;
  } while (!IsArchive(current_archive_path_));

  const std::string cmd = GlobalConfig::Get().archiverExePath + " " + current_archive_path_;
  const std::string dir = Poco::Path(GlobalConfig::Get().archiverExePath).makeParent().toString();
  CmdExecuteHelper(cmd.c_str(), dir.c_str());
  return true;
}
Esempio n. 10
0
int ArcPlugins::IsArchive(const char *Name,const unsigned char *Data,int DataSize)
{
  DWORD MinSFXSize=0xFFFFFFFF;
  DWORD CurSFXSize;
  int TrueArc=-1;
  int I;

  for (I=0; I < PluginsCount; I++)
  {
    if (TrueArc>-1 && PluginsData[I].TryIfNoOther)
      break;
    if (IsArchive(I, Name, Data, DataSize, &CurSFXSize))
    {
      if(CurSFXSize <= MinSFXSize)
      {
        MinSFXSize=CurSFXSize;
        TrueArc=I;
      }
    }
  }
  return TrueArc;
}
Esempio n. 11
0
bool CGzipArchive::ExtractFile()
//------------------------------
{
	#define ASSERT_CAN_READ(x) \
	if( dwMemPos > m_dwStreamLen || x > m_dwStreamLen - dwMemPos ) return false;

	if(!IsArchive())
		return false;

	DWORD dwMemPos = 0;
	GZheader *pHeader = (GZheader *)m_lpStream;
	GZtrailer *pTrailer = (GZtrailer *)(m_lpStream + m_dwStreamLen - sizeof(GZtrailer));

	dwMemPos += sizeof(GZheader);

	// Extra block present? (ignore)
	if(pHeader->flags & GZ_FEXTRA)
	{
		ASSERT_CAN_READ(sizeof(uint16_t));
		uint16_t xlen = LittleEndianW(*((uint16_t *)m_lpStream + dwMemPos));
		dwMemPos += sizeof(uint16_t);
		// We skip this.
		ASSERT_CAN_READ(xlen);
		dwMemPos += xlen;
	}

	// Filename present? (ignore)
	if(pHeader->flags & GZ_FNAME)
	{
		do 
		{
			ASSERT_CAN_READ(1);
		} while (m_lpStream[dwMemPos++] != 0);
	}

	// Comment present? (ignore)
	if(pHeader->flags & GZ_FCOMMENT)
	{
		do 
		{
			ASSERT_CAN_READ(1);
		} while (m_lpStream[dwMemPos++] != 0);
	}

	// CRC16 present?
	if(pHeader->flags & GZ_FHCRC)
	{
		ASSERT_CAN_READ(sizeof(uint16_t));
		uint16_t crc16_h = LittleEndianW(*((uint16_t *)m_lpStream + dwMemPos));
		uint16_t crc16_f = (uint16_t)(crc32(0, m_lpStream, dwMemPos) & 0xFFFF);
		dwMemPos += sizeof(uint16_t);
		if(crc16_h != crc16_f)
			return false;
	}

	// Well, this is a bit small when inflated.
	if(pTrailer->isize == 0)
		return false;

	// Check if the deflated data is a bit small as well.
	ASSERT_CAN_READ(sizeof(GZtrailer) + 1);

	// Clear the output buffer, if necessary.
	if(m_pOutputFile != nullptr)
	{
		delete[] m_pOutputFile;
	}

	DWORD destSize = LittleEndian(pTrailer->isize);

	m_pOutputFile = new Bytef[destSize];
	if(m_pOutputFile == nullptr)
		return false;

	// Inflate!
	z_stream strm;
	strm.zalloc = Z_NULL;
	strm.zfree = Z_NULL;
	strm.opaque = Z_NULL;
	strm.avail_in = m_dwStreamLen - (dwMemPos + sizeof(GZtrailer));
	strm.next_in = &m_lpStream[dwMemPos];
	if(inflateInit2(&strm, -15) != Z_OK)
		return false;
	strm.avail_out = destSize;
	strm.next_out = m_pOutputFile;

	int nRetVal = inflate(&strm, Z_NO_FLUSH);
	inflateEnd(&strm);

	// Everything went OK? Check return code, number of written bytes and CRC32.
	if(nRetVal == Z_STREAM_END && destSize == strm.total_out && LittleEndian(pTrailer->crc32) == crc32(0, m_pOutputFile, destSize))
	{
		// Success! :)
		m_dwOutputLen = destSize;
		return true;
	} else
	{
		// Fail :(
		if(m_pOutputFile != nullptr)
		{
			delete[] m_pOutputFile;
		}
		m_pOutputFile = nullptr;
		m_lpStream = nullptr;
		return false;
	}

	#undef ASSERT_CAN_READ
}
Esempio n. 12
0
BOOL WINAPI _export OpenArchive(const char *Name,int *Type)
{
  struct CFHEADER MainHeader;
  DWORD ReadSize;
  int I;

  ArcHandle = CreateFile( Name, GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,
              NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL );
  if (ArcHandle == INVALID_HANDLE_VALUE)
    return FALSE;

  *Type=0;

  SetFilePointer(ArcHandle,SFXSize,NULL,FILE_BEGIN);
  I = SFXSize;
  if (!ReadFile( ArcHandle, &MainHeader, sizeof(MainHeader), &ReadSize, NULL ) ||
    ReadSize != sizeof(MainHeader) || !IsArchive( NULL, (u1*)&MainHeader, sizeof(MainHeader) ))
  {
    HANDLE hMapFile;
    LPBYTE Data;

    if ((ReadSize = GetFileSize( ArcHandle, NULL )) == 0xFFFFFFFF)
    {
    blad:
      CloseHandle( ArcHandle );
      return FALSE;
    }
    if (ReadSize > 1024*1024)
      ReadSize = 1024*1024;
    hMapFile = CreateFileMapping( ArcHandle, NULL, PAGE_READONLY, 0, ReadSize, NULL );
    if (hMapFile == NULL)
      goto blad;
    Data = (LPBYTE)MapViewOfFile( hMapFile, FILE_MAP_READ, 0, 0, ReadSize );
    CloseHandle( hMapFile );
    if (Data == NULL)
      goto blad;
    I = IsArchive( NULL, Data, ReadSize );
    if (I)
      memcpy( &MainHeader, Data + SFXSize, sizeof(MainHeader) );
    UnmapViewOfFile( Data );
    if (I == 0)
      goto blad;
  }
  else
    SFXSize = I;

  SetFilePointer(ArcHandle,SFXSize+MainHeader.coffFiles,NULL,FILE_BEGIN);
  FilesNumber = MainHeader.cFiles;
  if (FilesNumber == 65535 && (MainHeader.flags & 8))
    FilesNumber = MainHeader.nFiles;
  UnpVer=MainHeader.versionMajor*256+MainHeader.versionMinor;

  while (FilesNumber && (MainHeader.flags & 1))
  {
    char *EndPos;
    struct CFFILE FileHeader;

    if (!ReadFile( ArcHandle, &FileHeader, sizeof(FileHeader), &ReadSize, NULL )
        || ReadSize < 18)
      goto blad;
    if (FileHeader.iFolder == 0xFFFD || FileHeader.iFolder == 0xFFFF)
    {
      EndPos = (char*)FileHeader.szName;
      while (EndPos - (char*)&FileHeader < (int)sizeof(FileHeader) && *EndPos)
        EndPos++;
      if (EndPos - (char*)&FileHeader >= (int)sizeof(FileHeader))
        goto blad;

      SetFilePointer( ArcHandle, (LONG)((EndPos-(char*)&FileHeader+1) - ReadSize), NULL, FILE_CURRENT );
      FilesNumber--;
    }
    else
    {
      SetFilePointer( ArcHandle, 0 - ReadSize, NULL, FILE_CURRENT );
      break;
    }
  }
///
  return(TRUE);
}