做题的时候遇到的一个知识点,记录下来以备以后使用。

转载来源:http://xiaobaoqiu.github.io/blog/2014/08/26/file-magic-number/

什么是File magic number?

Magic numbers are the first bits of a file which uniquely identify the type of file. This makes programming easier because complicated file structures need not be searched in order to identify the file type.

简单的说File magic number就是用文件的一些bit位来唯一标志这个文件的类型.

典型文件的File magic number

总结一些典型文件的File magic number:

图片

文件类型典型扩展名Hex字符Ascii digits
Bitmap format.bmp42 4dBM
FITS format.bits53 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 /

压缩文件

文件类型典型扩展名Hex字符Ascii digits
Bzip.bz42 5aBZ
Compress.Z1f 9d..
gzip format.gz1f 8b..
pkzip format.zip50 4b 03 04PK..

可执行文件

文件类型典型扩展名Hex字符Ascii digits
MS-DOS, OS/2 or MS Windows 4d 5aMZ
Unix elf 7f 45 4c 46.ELF
Last modification:June 12th, 2019 at 08:42 pm
If you think my article is useful to you, please feel free to appreciate