mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-08 22:07:07 -06:00
4.45 beta
This commit is contained in:
committed by
Kornel Lesiński
parent
d9666cf046
commit
a145bfc7cf
@@ -10,6 +10,11 @@
|
||||
|
||||
#include "../../Common/StreamUtils.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "../../../../C/7zCrc.h"
|
||||
}
|
||||
|
||||
namespace NArchive {
|
||||
namespace NGZip {
|
||||
|
||||
@@ -23,43 +28,44 @@ HRESULT CInArchive::ReadBytes(ISequentialInStream *inStream, void *data, UInt32
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CInArchive::ReadByte(ISequentialInStream *inStream, Byte &value)
|
||||
HRESULT CInArchive::ReadByte(ISequentialInStream *inStream, Byte &value, UInt32 &crc)
|
||||
{
|
||||
return ReadBytes(inStream, &value, 1);
|
||||
HRESULT res = ReadBytes(inStream, &value, 1);
|
||||
crc = CRC_UPDATE_BYTE(crc, value);
|
||||
return res;
|
||||
}
|
||||
|
||||
HRESULT CInArchive::ReadUInt16(ISequentialInStream *inStream, UInt16 &value)
|
||||
HRESULT CInArchive::ReadUInt16(ISequentialInStream *inStream, UInt16 &value, UInt32 &crc)
|
||||
{
|
||||
value = 0;
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
Byte b;
|
||||
RINOK(ReadByte(inStream, b));
|
||||
RINOK(ReadByte(inStream, b, crc));
|
||||
value |= (UInt16(b) << (8 * i));
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CInArchive::ReadUInt32(ISequentialInStream *inStream, UInt32 &value)
|
||||
HRESULT CInArchive::ReadUInt32(ISequentialInStream *inStream, UInt32 &value, UInt32 &crc)
|
||||
{
|
||||
value = 0;
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
Byte b;
|
||||
RINOK(ReadByte(inStream, b));
|
||||
RINOK(ReadByte(inStream, b, crc));
|
||||
value |= (UInt32(b) << (8 * i));
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CInArchive::ReadZeroTerminatedString(ISequentialInStream *inStream, AString &resString, CCRC &crc)
|
||||
HRESULT CInArchive::ReadZeroTerminatedString(ISequentialInStream *inStream, AString &resString, UInt32 &crc)
|
||||
{
|
||||
resString.Empty();
|
||||
for (;;)
|
||||
{
|
||||
Byte c;
|
||||
RINOK(ReadByte(inStream, c));
|
||||
crc.UpdateByte(c);
|
||||
RINOK(ReadByte(inStream, c, crc));
|
||||
if (c == 0)
|
||||
return S_OK;
|
||||
resString += char(c);
|
||||
@@ -72,31 +78,24 @@ HRESULT CInArchive::ReadHeader(ISequentialInStream *inStream, CItem &item)
|
||||
m_Position = 0;
|
||||
|
||||
UInt16 signature;
|
||||
RINOK(ReadUInt16(inStream, signature));
|
||||
UInt32 crc = CRC_INIT_VAL;;
|
||||
RINOK(ReadUInt16(inStream, signature, crc));
|
||||
if (signature != kSignature)
|
||||
return S_FALSE;
|
||||
RINOK(ReadByte(inStream, item.CompressionMethod));
|
||||
RINOK(ReadByte(inStream, item.Flags));
|
||||
RINOK(ReadUInt32(inStream, item.Time));
|
||||
RINOK(ReadByte(inStream, item.ExtraFlags));
|
||||
RINOK(ReadByte(inStream, item.HostOS));
|
||||
|
||||
CCRC crc;
|
||||
crc.Update(&signature, 2);
|
||||
crc.UpdateByte(item.CompressionMethod);
|
||||
crc.UpdateByte(item.Flags);
|
||||
crc.UpdateUInt32(item.Time);
|
||||
crc.UpdateByte(item.ExtraFlags);
|
||||
crc.UpdateByte(item.HostOS);
|
||||
|
||||
RINOK(ReadByte(inStream, item.CompressionMethod, crc));
|
||||
RINOK(ReadByte(inStream, item.Flags, crc));
|
||||
RINOK(ReadUInt32(inStream, item.Time, crc));
|
||||
RINOK(ReadByte(inStream, item.ExtraFlags, crc));
|
||||
RINOK(ReadByte(inStream, item.HostOS, crc));
|
||||
|
||||
if (item.ExtraFieldIsPresent())
|
||||
{
|
||||
UInt16 extraSize;
|
||||
RINOK(ReadUInt16(inStream, extraSize));
|
||||
crc.UpdateUInt16(extraSize);
|
||||
RINOK(ReadUInt16(inStream, extraSize, crc));
|
||||
item.Extra.SetCapacity(extraSize);
|
||||
RINOK(ReadBytes(inStream, item.Extra, extraSize));
|
||||
crc.Update(item.Extra, extraSize);
|
||||
crc = CrcUpdate(crc, item.Extra, extraSize);
|
||||
}
|
||||
if (item.NameIsPresent())
|
||||
RINOK(ReadZeroTerminatedString(inStream, item.Name, crc));
|
||||
@@ -105,8 +104,9 @@ HRESULT CInArchive::ReadHeader(ISequentialInStream *inStream, CItem &item)
|
||||
if (item.HeaderCRCIsPresent())
|
||||
{
|
||||
UInt16 headerCRC;
|
||||
RINOK(ReadUInt16(inStream, headerCRC));
|
||||
if ((UInt16)crc.GetDigest() != headerCRC)
|
||||
UInt32 dummy = 0;
|
||||
RINOK(ReadUInt16(inStream, headerCRC, dummy));
|
||||
if ((UInt16)CRC_GET_DIGEST(crc) != headerCRC)
|
||||
return S_FALSE;
|
||||
}
|
||||
return S_OK;
|
||||
@@ -114,8 +114,9 @@ HRESULT CInArchive::ReadHeader(ISequentialInStream *inStream, CItem &item)
|
||||
|
||||
HRESULT CInArchive::ReadPostHeader(ISequentialInStream *inStream, CItem &item)
|
||||
{
|
||||
RINOK(ReadUInt32(inStream, item.FileCRC));
|
||||
return ReadUInt32(inStream, item.UnPackSize32);
|
||||
UInt32 dummy = 0;
|
||||
RINOK(ReadUInt32(inStream, item.FileCRC, dummy));
|
||||
return ReadUInt32(inStream, item.UnPackSize32, dummy);
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user