diff options
Diffstat (limited to '7zip/Archive/Zip/ZipItem.h')
-rwxr-xr-x | 7zip/Archive/Zip/ZipItem.h | 131 |
1 files changed, 113 insertions, 18 deletions
diff --git a/7zip/Archive/Zip/ZipItem.h b/7zip/Archive/Zip/ZipItem.h index 92d670ce..765bfd85 100755 --- a/7zip/Archive/Zip/ZipItem.h +++ b/7zip/Archive/Zip/ZipItem.h @@ -27,6 +27,46 @@ struct CExtraSubBlock CByteBuffer Data; }; +struct CWzAesExtraField +{ + UInt16 VendorVersion; // 0x0001 - AE-1, 0x0002 - AE-2, + // UInt16 VendorId; // "AE" + Byte Strength; // 1 - 128-bit , 2 - 192-bit , 3 - 256-bit + UInt16 Method; + + CWzAesExtraField(): VendorVersion(2), Strength(3), Method(0) {} + + bool NeedCrc() const { return (VendorVersion == 1); } + + bool ParseFromSubBlock(const CExtraSubBlock &sb) + { + if (sb.ID != NFileHeader::NExtraID::kWzAES) + return false; + if (sb.Data.GetCapacity() < 7) + return false; + const Byte *p = (const Byte *)sb.Data; + VendorVersion = (((UInt16)p[1]) << 8) | p[0]; + if (p[2] != 'A' || p[3] != 'E') + return false; + Strength = p[4]; + Method = (((UInt16)p[6]) << 16) | p[5]; + return true; + } + void SetSubBlock(CExtraSubBlock &sb) const + { + sb.Data.SetCapacity(7); + sb.ID = NFileHeader::NExtraID::kWzAES; + Byte *p = (Byte *)sb.Data; + p[0] = (Byte)VendorVersion; + p[1] = (Byte)(VendorVersion >> 8); + p[2] = 'A'; + p[3] = 'E'; + p[4] = Strength; + p[5] = (Byte)Method; + p[6] = (Byte)(Method >> 8); + } +}; + struct CExtraBlock { CObjectVector<CExtraSubBlock> SubBlocks; @@ -38,13 +78,38 @@ struct CExtraBlock res += SubBlocks[i].Data.GetCapacity() + 2 + 2; return res; } + bool GetWzAesField(CWzAesExtraField &aesField) const + { + // size_t res = 0; + for (int i = 0; i < SubBlocks.Size(); i++) + if (aesField.ParseFromSubBlock(SubBlocks[i])) + return true; + return false; + } + + bool HasWzAesField() const + { + CWzAesExtraField aesField; + return GetWzAesField(aesField); + } + + void RemoveUnknownSubBlocks() + { + for (int i = SubBlocks.Size() - 1; i >= 0;) + { + const CExtraSubBlock &subBlock = SubBlocks[i]; + if (subBlock.ID != NFileHeader::NExtraID::kWzAES) + SubBlocks.Delete(i); + else + i--; + } + } }; -class CItem +class CLocalItem { public: - CVersion MadeByVersion; CVersion ExtractVersion; UInt16 Flags; UInt16 CompressionMethod; @@ -52,16 +117,10 @@ public: UInt32 FileCRC; UInt64 PackSize; UInt64 UnPackSize; - UInt16 InternalAttributes; - UInt32 ExternalAttributes; AString Name; - - UInt64 LocalHeaderPosition; - UInt16 LocalExtraSize; - - CExtraBlock CentralExtra; - CByteBuffer Comment; + + CExtraBlock LocalExtra; bool IsEncrypted() const; @@ -74,19 +133,55 @@ public: bool HasDescriptor() const; - WORD GetCodePage() const - { - return (MadeByVersion.HostOS == NFileHeader::NHostOS::kFAT - || MadeByVersion.HostOS == NFileHeader::NHostOS::kNTFS - ) ? CP_OEMCP : CP_ACP; - } - private: void SetFlagBits(int startBitNumber, int numBits, int value); void SetBitMask(int bitMask, bool enable); public: - void ClearFlags(); + void ClearFlags() { Flags = 0; } void SetEncrypted(bool encrypted); + + WORD GetCodePage() const + { + return CP_OEMCP; + } +}; + +class CItem: public CLocalItem +{ +public: + CVersion MadeByVersion; + UInt16 InternalAttributes; + UInt32 ExternalAttributes; + + UInt64 LocalHeaderPosition; + + CExtraBlock CentralExtra; + CByteBuffer Comment; + + bool FromLocal; + bool FromCentral; + + bool IsDirectory() const; + UInt32 GetWinAttributes() const; + + bool IsThereCrc() const + { + if (CompressionMethod == NFileHeader::NCompressionMethod::kWzAES) + { + CWzAesExtraField aesField; + if (CentralExtra.GetWzAesField(aesField)) + return aesField.NeedCrc(); + } + return true; + } + + WORD GetCodePage() const + { + return (WORD)((MadeByVersion.HostOS == NFileHeader::NHostOS::kFAT + || MadeByVersion.HostOS == NFileHeader::NHostOS::kNTFS + ) ? CP_OEMCP : CP_ACP); + } + CItem() : FromLocal(false), FromCentral(false) {} }; }} |