文件格式的唯一标识-魔法数

起因:

要对处理图片文件组件做fuzz,github搜到了一篇文章(如何使用Fuzzing挖掘ImageMagick的漏洞),对ImageMagick做fuzz,看到了有magic这个宏定义,于是kimi搜了下,原来是每个文件都有一个魔法数。

什么是魔法数?

魔法数是文件的前几位,它唯一地标识了文件的类型。这使得编程更容易,因为不需要搜索复杂的文件结构来识别文件类型。

例如,jpeg文件以ffd8 ffe0 0010 4a46 4946 0001 0101 0047......JFIF........G开头,ffd8表示它是JPEG文件,ffe0标识JFIF类型结构。有一个ascii编码“JFIF”,它在长度代码之后出现,但这不是识别文件所必需的。前4个字节唯一地做到这一点。

这给出了一个正在进行的文件类型魔法数列表。

Image Files

File typeTypical
extension
Hex digits
xx = variable
Ascii digits
. = not an ascii char
Bitmap format.bmp42 4dBM
FITS format.fits53 49 4d 50 4c 45SIMPLE
GIF format.gif47 49 46 38GIF8
Graphics Kernel System.gks47 4b 53 4dGKSM
IRIS rgb format.rgb01 da..
ITC (CMU WM) format.itcf1 00 40 bb....
JPEG File Interchange Format.jpgff d8 ff e0....
NIFF (Navy TIFF).nif49 49 4e 31IIN1
PM format.pm56 49 45 57VIEW
PNG format.png89 50 4e 47.PNG
Postscript format.[e]ps25 21%!
Sun Rasterfile.ras59 a6 6a 95Y.j.
Targa format.tgaxx xx xx...
TIFF format (Motorola - big endian).tif4d 4d 00 2aMM.*
TIFF format (Intel - little endian).tif49 49 2a 00II*.
X11 Bitmap format.xbmxx xx
XCF Gimp file structure.xcf67 69 6d 70 20 78 63 66 20 76gimp xcf
Xfig format.fig23 46 49 47#FIG
XPM format.xpm2f 2a 20 58 50 4d 20 2a 2f/* XPM */

Compressed files

File typeTypical
extension
Hex digits
xx = variable
Ascii digits
. = not an ascii char
Bzip.bz42 5aBZ
Compress.Z1f 9d..
gzip format.gz1f 8b..
pkzip format.zip50 4b 03 04PK..

参考:

File Magic Numbers

  • 12
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值