1#------------------------------------------------------------------------------ 2# $File: zip,v 1.10 2025/10/22 19:31:31 christos Exp $ 3# zip: file(1) magic for zip files; this is not use 4# Note the version of magic in archive is currently stronger, this is 5# just an example until negative offsets are supported better 6# Note: All fields unless otherwise noted are unsigned! 7 8# Zip Central Directory record 90 name zipcd 10>0 string PK\001\002 Zip archive data 11!:mime application/zip 12# no "made by" in local file header with PK\3\4 magic 13>>4 leshort x \b, made by 14>>4 use zipversion 15>>4 use ziphost 16# inside ./archive 1.151 called "at least" zipversion "to extract" 17>>6 leshort x \b, extract using at least 18>>6 use zipversion 19# This is DOS date like: ledate 21:00:48 19 Dec 2001 != DOS 00:00 1 Jan 2010 ~ 0000213C 20>>14 lemsdosdate x \b, last modified %s 21>>12 lemsdostime x %s 22# uncompressed size of 1st entry; FFffFFff means real value stored in ZIP64 record 23>>24 ulelong !0xFFffFFff \b, uncompressed size %u 24# inside ./archive 1.151 called "compression method="zipcompression 25>>10 leshort x \b, method= 26>>10 use zipcompression 27 28# URL: https://en.wikipedia.org/wiki/Zip_(file_format) 29# reference: https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT (Version: 6.3.9) 30# Zip known compressions 310 name zipcompression 32>0 leshort 0 \bstore 33>0 leshort 1 \bShrinking 34>0 leshort 6 \bImploding 35>0 leshort 7 \bTokenizing 36>0 leshort 8 \bdeflate 37>0 leshort 9 \bdeflate64 38>0 leshort 10 \bLibrary imploding 39#>0 leshort 11 \bReserved by PKWARE 40>0 leshort 12 \bbzip2 41#>0 leshort 13 \bReserved by PKWARE 42>0 leshort 14 \blzma 43#>0 leshort 15 \bReserved by PKWARE 44>0 leshort 16 \bCMPSC (IBM z/OS) 45#>0 leshort 17 \bReserved by PKWARE 46>0 leshort 18 \bIBM TERSE 47>0 leshort 19 \bIBM LZ77 (z/Architecture) 48>0 leshort 20 \bZstd (deprecated) 49>0 leshort 93 \bZstd 50>0 leshort 94 \bMP3 51>0 leshort 95 \bxz 52>0 leshort 96 \bJpeg 53>0 leshort 97 \bWavPack 54>0 leshort 98 \bPPMd 55>0 leshort 99 \bAES Encrypted 56>0 default x 57>>0 leshort x \b[%#x] 58 59# Zip known versions 600 name zipversion 61# The lower byte indicates the ZIP version of this file. The value/10 indicates 62# the major version number, and the value mod 10 is the minor version number. 63>0 ubyte/10 x v%u 64>0 ubyte%10 x \b.%u 65# >0 leshort 0x09 v0.9 66# >0 leshort 0x0a v1.0 67# >0 leshort 0x0b v1.1 68# >0 leshort 0x14 v2.0 69# >0 leshort 0x15 v2.1 70# >0 leshort 0x19 v2.5 71# >0 leshort 0x1b v2.7 72# >0 leshort 0x2d v4.5 73# >0 leshort 0x2e v4.6 74# >0 leshort 0x32 v5.0 75# >0 leshort 0x33 v5.1 76# >0 leshort 0x34 v5.2 77# >0 leshort 0x3d v6.1 78# >0 leshort 0x3e v6.2 79# >0 leshort 0x3f v6.3 80# >0 default x 81# >>0 leshort x v?[%#x] 82 83# display compatible host system name of ZIP archive 840 name ziphost 85# The upper byte indicates the compatibility of the file attribute information. 86# If the file is compatible with MS-DOS (v 2.04g) then this value will be zero. 87#>1 ubyte 0 DOS 88>1 ubyte 1 Amiga 89>1 ubyte 2 OpenVMS 90>1 ubyte 3 UNIX 91>1 ubyte 4 VM/CMS 92>1 ubyte 6 OS/2 93>1 ubyte 7 Macintosh 94>1 ubyte 11 MVS 95>1 ubyte 13 Acorn Risc 96>1 ubyte 16 BeOS 97>1 ubyte 17 Tandem 98# 9 untested 99>1 ubyte 5 Atari ST 100>1 ubyte 8 Z-System 101>1 ubyte 9 CP/M 102>1 ubyte 10 Windows NTFS 103>1 ubyte 12 VSE 104>1 ubyte 14 VFAT 105>1 ubyte 15 alternate MVS 106>1 ubyte 18 OS/400 107>1 ubyte 19 OS X 108# unused 109#>1 ubyte >19 unused %#x 110 111# Zip End Of Central Directory record 112# GRR: wrong for ZIP with comment archive 113-22 string PK\005\006 114#>4 uleshort !0xFFff \b, %u disks 115#>6 uleshort !0xFFff \b, central directory disk %u 116#>8 uleshort !0xFFff \b, %u central directories on this disk 117#>10 uleshort !0xFFff \b, %u central directories 118#>12 ulelong !0xFFffFFff \b, %u central directory bytes 119# offset of central directory 120#>16 ulelong x \b, central directory offset %#x 121>(16.l) use zipcd 122# archive comment length n 123#>>20 uleshort >0 \b, comment length %u 124# archive comment 125>>20 pstring/l >0 \b, %s 126 127# The end directory record does not work for piped input 128# so try one that looks from the beginning of the file. 1290 string PK\003\004 130>0 search/1024 PK\001\002 131>>&-4 use zipcd 132