1*898496eeSXin LI 2*898496eeSXin LI#------------------------------------------------------------------------------ 3*898496eeSXin LI# $File: dwarfs,v 1.2 2023/05/23 13:37:32 christos Exp $ 4*898496eeSXin LI# dwarfs: file(1) magic for DwarFS File System Image files 5*898496eeSXin LI# URL: https://github.com/mhx/dwarfs for details about DwarFS 6*898496eeSXin LI# From: Marcus Holland-Moritz <github@mhxnet.de> 7*898496eeSXin LI 8*898496eeSXin LI#### DwarFS Version Macro 9*898496eeSXin LI0 name dwarfsversion 10*898496eeSXin LI>&0 byte x \b, version %d 11*898496eeSXin LI>&1 byte x \b.%d 12*898496eeSXin LI 13*898496eeSXin LI#### DwarFS Compression Macro 14*898496eeSXin LI0 name dwarfscompression 15*898496eeSXin LI>&0 leshort =0 \b, uncompressed 16*898496eeSXin LI>&0 leshort =1 \b, LZMA compression 17*898496eeSXin LI>&0 leshort =2 \b, ZSTD compression 18*898496eeSXin LI>&0 leshort =3 \b, LZ4 compression 19*898496eeSXin LI>&0 leshort =4 \b, LZ4HC compression 20*898496eeSXin LI>&0 leshort =5 \b, BROTLI compression 21*898496eeSXin LI 22*898496eeSXin LI#### DwarFS files without header 23*898496eeSXin LI## We first check against a DWARFS magic at the start of the file, then 24*898496eeSXin LI## validate by checking the block count / section type to be all zeros 25*898496eeSXin LI## for the first block. Finally, we check that the *next* block also 26*898496eeSXin LI## has the correct DWARFS magic. 27*898496eeSXin LI0 string DWARFS 28*898496eeSXin LI>&0x2A string/b \0\0\0\0\0\0 29*898496eeSXin LI>>&(&0x02.q+0x0A) string DWARFS DwarFS File System Image 30*898496eeSXin LI>>>&0 use dwarfsversion 31*898496eeSXin LI>>&0 use dwarfscompression 32*898496eeSXin LI 33*898496eeSXin LI#### DwarFS files with header 34*898496eeSXin LI## We search for a DWARFS magic in the first 64k of the file (images with 35*898496eeSXin LI## headers longer than 64k won't be recognized), then validate by checking 36*898496eeSXin LI## the block count / section type to be all zeros for the first block. 37*898496eeSXin LI## Finally, we check that the *next* block also has the correct DWARFS magic. 38*898496eeSXin LI## If we find a DWARFS magic that doesn't pass validation, we continue with 39*898496eeSXin LI## an indirect match recursively. 40*898496eeSXin LI1 search/65536/b DWARFS 41*898496eeSXin LI>&0x2A string/b \0\0\0\0\0\0 42*898496eeSXin LI>>&(&0x02.q+0x0A) string DWARFS DwarFS File System Image (with header) 43*898496eeSXin LI>>>&0 use dwarfsversion 44*898496eeSXin LI>>&0 use dwarfscompression 45*898496eeSXin LI>&-1 indirect x 46