Beispiel #1
0
UInt32 MY_FAST_CALL CrcUpdate(UInt32 v, const void *data, size_t size)
{
  const Byte *p = (const Byte *)data;
  for (; size > 0 ; size--, p++)
    v = CRC_UPDATE_BYTE(v, *p);
  return v;
}
Beispiel #2
0
static UInt32 CrcUpdateUInt32(UInt32 crc, UInt32 v)
{
  crc = CRC_UPDATE_BYTE(crc, (Byte)(v & 0xFF));
  crc = CRC_UPDATE_BYTE(crc, (Byte)((v >> 8) & 0xFF));
  crc = CRC_UPDATE_BYTE(crc, (Byte)((v >> 16) & 0xFF));
  crc = CRC_UPDATE_BYTE(crc, (Byte)((v >> 24) & 0xFF));
  return crc;
}
Beispiel #3
0
bool CInArchive::ReadMarkerAndArchiveHeader(const UInt64 *searchHeaderSizeLimit)
{
  if (!FindAndReadMarker(searchHeaderSizeLimit))
    return false;

  Byte buf[NHeader::NArchive::kArchiveHeaderSize];
  UInt32 processedSize;
  ReadBytes(buf, sizeof(buf), &processedSize);
  if (processedSize != sizeof(buf))
    return false;
  m_CurData = buf;
  m_CurPos  = 0;
  m_PosLimit = sizeof(buf);

  m_ArchiveHeader.CRC = ReadUInt16();
  m_ArchiveHeader.Type = ReadByte();
  m_ArchiveHeader.Flags = ReadUInt16();
  m_ArchiveHeader.Size = ReadUInt16();
  m_ArchiveHeader.Reserved1 = ReadUInt16();
  m_ArchiveHeader.Reserved2 = ReadUInt32();
  m_ArchiveHeader.EncryptVersion = 0;

  UInt32 crc = CRC_INIT_VAL;
  crc = CRC_UPDATE_BYTE(crc, m_ArchiveHeader.Type);
  crc = CrcUpdateUInt16(crc, m_ArchiveHeader.Flags);
  crc = CrcUpdateUInt16(crc, m_ArchiveHeader.Size);
  crc = CrcUpdateUInt16(crc, m_ArchiveHeader.Reserved1);
  crc = CrcUpdateUInt32(crc, m_ArchiveHeader.Reserved2);

  if (m_ArchiveHeader.IsThereEncryptVer() && m_ArchiveHeader.Size > NHeader::NArchive::kArchiveHeaderSize)
  {
    ReadBytes(&m_ArchiveHeader.EncryptVersion, 1, &processedSize);
    if (processedSize != 1)
      return false;
    crc = CRC_UPDATE_BYTE(crc, m_ArchiveHeader.EncryptVersion);
  }

  if(m_ArchiveHeader.CRC != (CRC_GET_DIGEST(crc) & 0xFFFF))
    ThrowExceptionWithCode(CInArchiveException::kArchiveHeaderCRCError);
  if (m_ArchiveHeader.Type != NHeader::NBlockType::kArchiveHeader)
    return false;
  m_ArchiveCommentPosition = m_Position;
  m_SeekOnArchiveComment = true;
  return true;
}
Beispiel #4
0
void COutArchive::WriteByte(Byte b)
{
  if (_countMode)
    _countSize++;
  else if (_writeToStream)
  {
    _outByte.WriteByte(b);
    _crc = CRC_UPDATE_BYTE(_crc, b);
  }
  else
    _outByte2.WriteByte(b);
}