Skip to content

Commit

Permalink
patterns/zip: Added parsing of general purpose bit flag (#314)
Browse files Browse the repository at this point in the history
* Add parsing of general purpose bit flag

Add "GeneralPurposeBitFlags" bitfield definition. The names are based on
the official ZIP format specification although I chose to name the
fields closer to their purpose rather than their official name. This is
intended to make reading the pattern and its output easier. Example:
official name "Language encoding flag (EFS)" my name
"filenameAndCommentAreUtf8" because this immediately explains what it
does.

I chose not to implement the specifics of the "compressionOptions" as
their meanings are specific to the compression method used and it would
make the pattern much more complicated for (in my opinion) little gain.

I also chose to unify the names of the general purpose bit filed in the
LocalFileHeader and the CentralDirectoryFileHeader. Previously, they had
different names, suggesting they might have different meaning. According
to the official docs though, these fields have the exact same meaning.

Official docs: https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT

* Fix typo and remove redundant type declaration
  • Loading branch information
targodan authored Nov 17, 2024
1 parent c8d9a8d commit 79e25fd
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions patterns/zip.hexpat
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,24 @@ enum CompressionMethod : u16 {
AE_x = 99, // AE-x encryption marker (see APPENDIX E)
};

bitfield GeneralPurposeBitFlags {
encrypted : 1;
compressionOptions : 2;
crcAndSizesInCDAndDataDescriptor : 1;
enhancedDeflating : 1;
patchedData : 1;
strongEncryption : 1;
unused : 4;
filenameAndCommentAreUtf8 : 1;
reservedPKWARE_0 : 1;
centralDirectoryEncrypted : 1;
reservedPKWARE_1 : 2;
};

struct LocalFileHeader {
u32 headerSignature [[name("LCF PK\\3\\4")]];
u16 version [[ comment("The minimum supported ZIP specification version needed to extract the file") ]];
u16 purposeBitflag [[ comment("General purpose bit flag") ]];
GeneralPurposeBitFlags generalPurposeBitFlags [[ comment("General purpose bit flag") ]];
CompressionMethod compressionMethod [[ comment("Compression method") ]];
u16 lastModifyTime [[ comment("File last modification time") ]];
u16 lastModifyDate [[ comment("File last modification date") ]];
Expand All @@ -183,7 +197,7 @@ struct CentralDirectoryFileHeader {
u32 headerSignature [[name("CDFH PK\\1\\2")]];
u16 versionMade [[comment("Version file made by")]];
u16 versionExtract [[comment("Minimum version needed to extract")]];
u16 generalFlag [[comment("General purpose bit flag")]];
GeneralPurposeBitFlags generalPurposeBitFlags [[comment("General purpose bit flag")]];
CompressionMethod compressionMethod;
u16 fileLastModifyTime [[comment("File last modification time")]];
u16 fileLastModifyDate [[comment("File last modification date")]];
Expand Down

0 comments on commit 79e25fd

Please sign in to comment.