2023年11月27日发(作者:)
简介
我们都知道,文件的扩展名是用来识别文件类型的。通过给他指定扩展
名,我们可以告诉自己,也告诉操作系统我们想用什么方式打开这个文
件。比如我么会把.jpg的文件默认用图片显示软件打开,.zip 文件会默
认用解压软件打开等等。
然而,扩展名完全是可以随便改改的。我们可以给文件设置一个任意的
扩展名,当然也可以不设置扩展名。这样一来我们就不能了解到这个文
件究竟是做什么的,究竟是个什么样的文件。我们或许也会疑惑,为什
么一个软件,比如视频播放器,就能用正确的方式打
开.mp4 .rmvb .wmv 等等的视频?
事实上,所有的文件都是以二进制的形式进行存储的,本质上没有差别。
之所以使用的方法不同,只是因为我们理解他的方式不同。在每一个文
件(包括图片,视频或其他的非ASCII文件)的开头(十六进制表示)
实际上都有一片区域来显示这个文件的实际用法,这就是文件头标志。
Linux下我们可以用file命令直接查看文件的实际格式,但是他本质上
也是利用文件头标志来进行文件类型判断的。下面就简要介绍下手动判
断文件真实类型的方法。
表格
扩展名 文件头标识(HEX) 文件描述
扩展名 文件头标识(HEX) 文件描述
123 00 00 1A 00 05 10 04 Lotus 1-2-3 spreadsheet (v9) file
3rd Generation Partnership
Project 3GPP (nn=0x14) and 3gg; 3gp; 3g2
3GPP2 (nn=0x20) multimedia files
7-ZIP compressed file 7z 37 7A BC AF 27 1C
Palm Address Book Archive file aba 00 01 42 41
00 00 00 nn 66 74 79
70 33 67 70
41 4F 4C 49 4E 44 45
58
扩展名 文件头标识(HEX) 文件描述
AIFF 46 4F 52 4D 00 Audio Interchange File
ain 21 12 AIN Compressed Archive File
ami 5B 76 65 72 5D Lotus Ami Pro
Adaptive Multi-Rate ACELP
(Algebraic Code Excited Linear
amr 23 21 41 4D 52 Prediction) Codec, commonly
audio format with GSM cell
phones
ANI 52 49 46 46
4D 5A 90 00 03 00 00
扩展名 文件头标识(HEX) 文件描述
30 26 B2 75 8E 66 CF
11
asf Windows Media
asf; wma;
wmv
30 26 B2 75 8E 66 CF Microsoft Windows Media
11 A6 D9 00 AA 00 62 Audio/Video File(Advanced
CE 6C Streaming Format)
3C Advanced Stream redirector file asx
SoundMachine Audio File
au 2E 73 6E 64 NeXT/Sun Microsystems μ-Law
audio file
扩展名 文件头标识(HEX) 文件描述
BMP 42 4D 3E
bz; bz2 42 5A 68 BZIP Archive
BZ2; 2;
TBZ2; TB2
CAB 49 53 63
42 5A 68 bzip2 compressed archive
Install Shield v5.x or 6.x
compressed file
扩展名 文件头标识(HEX) 文件描述
File
CHM 49 54 53
CLB 43 4D 58 31 Corel Binary metafile
CLB 43 4F 4D 2B COM+ Catalog file
cnt 3A 42 61 73 65
COM, DLL,
DRV, EXE, PIF, 4D 5A Windows/DOS executable file
QTS, QTX, SYS
扩展名 文件头标识(HEX) 文件描述
CRU 43 52 55 53 48 20 76 Crush compressed archive
49 49 1A 00 00 00 48
CRW 45 41 50 43 43 44 52 Canon digital camera RAW file
02 00
43 61 74 61 6C 6F 67
20 33 2E 30 30 00
00 00 02 00 01 00 20
20
03 dat MapInfo Native Data Format
1A 52 54 53 20 43 4F
扩展名 文件头标识(HEX) 文件描述
55 72 6C 43 61 63 68
65 20 4D 4D 46 20 56
65 72 20
45 52 46 53 53 41 56
DAT 45 44 41 54 41 46 49
4C 45
49 6E 6E 6F 20 53 65
74 75 70 20 55 6E 69
6E 73 74 61 6C 6C 20
4C 6F 67 20 28 62 29
扩展名 文件头标识(HEX) 文件描述
dbx CF AD 12 FE
CF AD 12 FE C5 FD 74
6F
3C 21 64 6F 63 74 79
70
3A DE 68 B1 dcx DCX Graphic File
00 01 00 DDB
Outlook Express dbx
dci AOL HTML mail file
扩展名 文件头标识(HEX) 文件描述
ppa; pps; pot;
msi; sdw; db
doc; dot; xls;
xlt; xla; ppt;
apr ;ppa; pps;
pot; msi; sdw;
db
DPL 4D 5A 50
DRV 4D 5A 16
D0 CF 11 E0 A1 B1 1A MS Compound Document v1 or
扩展名 文件头标识(HEX) 文件描述
20 53 74 75 64 69 6F
dss 02 64 73 73
Digital Speech Standard
(Olympus, Grundig, & Phillips)
dtd DesignTools 2D Design file
07 64 74 32 64 64 74
64
3C 21 45 4E 54 49 54
59
44 56 44 DVR DVR-Studio stream file
扩展名 文件头标识(HEX) 文件描述
e-mail files. Signatures shown
here are for Netscape, Eudora,
and a generic signature,
respectively. EML is also used by
Outlook Express and QuickMail.
A commmon file extension for
e-mail files. Signatures shown
EML
46 72 6F 6D 20 3F 3F here are for Netscape, Eudora,
3F and a generic signature,
扩展名 文件头标识(HEX) 文件描述
[32 byte offset] 40 40
enl 40 20 00 00 40 40 40 EndNote Library File
40
eps 25 21 50 53 Adobe EPS File
25 21 50 53 2D 41 64
6F 62 65
eps Postscript
25 21 50 53 2D 41 64
6F 62 65 2D 33 2E 30
20 45 50 53 46 2D 33
扩展名 文件头标识(HEX) 文件描述
00
exe; dll; drv;
vxd; sys; ocx; 4D 5A Win32 Executable
vbx
exe; dll; drv;
vxd; sys; ocx; 4D 5A Win16 Executable
vbx
exe; com; 386;
ax; acm; sys;
dll; drv; flt;
扩展名 文件头标识(HEX) 文件描述
00
FLV 46 4C 56 01 Flash video file
3C 4D 61 6B 65 72 46
69 6C 65 20
00 00 1A 00 07 80 01
00
20 00 68 00 20 0 fmt Lotus 123 v4 FMT file
43 48 41 FNT
4D 5A FON Font file
87 F5 3E GBC
扩展名 文件头标识(HEX) 文件描述
Show Partner graphics file (not
confirmed)
Gzip Archive File gz; tar; tgz 1F 8B
GZ Compressed File gz; tgz 1F 8B 08
HAP Archive File hap 91 33 48 46
Windows heap dump file HDMP 4D 44 4D 50 93 A7
GX2 47 58 32
hdr
23 3F 52 41 44 49 41 adiance High Dynamic Range
4E 43 45 0A image file
扩展名 文件头标识(HEX) 文件描述
20 77 69 74 68 20 42
69 6E 48 65 78 20
HTM 3C 21 44
htm; html 3C 21 44 4F 43 54 HyperText Markup Language 3
htm; html 3C 48 54 4D 4C 3E HyperText Markup Language 2
htm; html 3C 68 74 6D 6C 3E HyperText Markup Language 1
html 68 74 6D 6C 3E HTML
ico 00 00 01 00 00 Icon File
00 00 01 00 01 00 20
20
扩展名 文件头标识(HEX) 文件描述
file ()
ISO-9660 CD Disc Image (This
ISO 43 44 30 30 31 signature usually occurs at byte
8001, 8801, or 9001.)
RealPlayer video file (V11 and
later)
JARCS compressed archive JAR 4A 41 52 43 53 00
JAR Archive File jar 5F 27 A8 89
ivr 2E 52 45 43
jpg; jpeg FF D8 FF
扩展名 文件头标识(HEX) 文件描述
LHP 3F 5F 03
lhp 3F 5F 03 00 Windows Help File
Unix archiver (ar) files and
lib
21 3C 61 72 63 68 3E Microsoft Program Library
0A Common Object File Format
(COFF)
LIB 2A 24 20
49 54 4F 4C 49 54 4C
扩展名 文件头标识(HEX) 文件描述
lwp 57 6F 72 64 50 72 6F Lotus WordPro v9
m3u 23 45 58
00 00 00 20 66 74 79
m4a 70 4D 34 41 20 00 00 Apple Lossless Audio Codec file
00 00
00 00 00 20 66 74 79
m4a; m4v 70 4D 34 41 20 00 00 QuickTime M4A/M4V file
00 00
3C 3F 78 6D 6C 20 76 Windows Visual Stylesheet XML
扩展名 文件头标识(HEX) 文件描述
MDF 00 FF FF
00 FF FF FF FF FF FF FF
mdf FF FF FF 00 00 02 00 Alcohol 120% CD image
01
mdf 01 0F 00 00
Microsoft SQL Server 2000
database
Microsoft Document Imaging file MDI 45 50
MDS 4D 45 44
扩展名 文件头标识(HEX) 文件描述
management and scheduling
software (Also see "MILES" and
"MV2C" signatures)
Milestones v2.1a project
management and scheduling
software (Also see "MILES" and
"MV214" signatures)
Yamaha Corp. Synthetic music
Mobile Application Format
MLS 4D 56 32 43
扩展名 文件头标识(HEX) 文件描述
Monochrome Picture TIFF bitmap
file (unconfirmed)
MPEG-1 Audio Layer 3 (MP3)
audio file
mp 0C ED
MP3 49 44 33
MP3 FF FB 50
00 00 00 18 66 74 79
70 33 67 70 35
00 00 01 MPA
扩展名 文件头标识(HEX) 文件描述
msi 23 20 Cerius2 file
MSV
4D 53 5F 56 4F 49 43 Sony Memory Stick Compressed
45 Voice file
4E 45 53 NES
C2 20 20 NLS
0E 4E 65 72 6F 49 53
4F
1A 00 00 ntf Lotus Notes database template
1A 00 00 03 00 00 nsf; ntf Lotus Notes Database/Template
扩展名 文件头标识(HEX) 文件描述
later/compatible processors
OCX 4D 5A ActiveX or OLE Custom Control
OCX 4D 5A 90
OLB 4D 5A OLE object library
OLB 4D 5A 90
41 4F 4C 56 4D 31 30
30
1A 0B pak Compressed archive file
扩展名 文件头标识(HEX) 文件描述
[11 byte offset] 00 00
00 00 00 00 00 00 00
pdb 00 00 00 00 00 00 00
00 00 00 00 00 00 00
00
Palmpilot Database/Document
File
PDF 25 50 44
Adobe Portable Document
扩展名 文件头标识(HEX) 文件描述
0A
PPC 52 65 63
PPT D0 CF 11
ppt
[512 byte offset] 00 6E PowerPoint presentation
1E F0 subheader (MS Office)
ppt
[512 byte offset] 0F 00 PowerPoint presentation
扩展名 文件头标识(HEX) 文件描述
pwl E3 82 85 96 Windows Password
qbb 45 86 00 00 06 00 Intuit QuickBooks Backup file
qdf AC 9E BD 8F Quicken
qph 03 00 00 00 Quicken price history file
qt 6D 64 61 74 Quicktime Movie File
qxd 00 00 4D 4D 58 50 52
2E 52 4D 46 00 00 00
12 00
2E 72 61 FD ra; ram Real Audio File
2E 72 61 FD 00 ra RealAudio streaming media file
扩展名 文件头标识(HEX) 文件描述
rpm ED AB EE DB RPM Archive File
43 23 2B 44 A4 43 4D
A5 48 64 72
7B 5C 72 RTF
7B 5C 72 74 66 rtf Rich Text Format File
24 46 4C 32 40 28 23
29 20 53 50 53 53 20
44 41 54 41 20 46 49
4C 45
RTD RagTime document file
扩展名 文件头标识(HEX) 文件描述
secure drive
sly; srt; slt 53 52 01 00 Sage
SMD 00 FF FF
snm
00 1E 84 90 00 00 00 Netscape Communicator (v4) mail
00 folder
Microsoft Access Snapshot Viewer
file
Adobe Flash shared object file
扩展名 文件头标识(HEX) 文件描述
sxm math OpenOffice Math
sxw writer OpenOffice Writer
syw 41 4D 59 4F Harvard Graphics symbol graphic
TAG 00 00 02
tar; cpio 30 37 30 37 30 37 CPIO Archive File
tar.z 1F 9D 90 Compressed tape archive file
tga 00 00 10 00 00 RLE压缩的前5字节
TGA 00 00 02
tga 00 00 02 00 00 未压缩的前5字节
TIF; TIFF 49 20 49 Tagged Image File Format file
tif; tiff 49 49 2A TIFF (Intel)
Tagged Image File Format file
tif; tiff 49 49 2A 00 (little endian, i.e., LSB first in the
byte; Intel)
Tagged Image File Format file (big
扩展名 文件头标识(HEX) 文件描述
BigTIFF files; Tagged Image File
Format files >4 GB
TIF; TIFF 4D 4D 00 2B
TLB
4D 53 46 54 02 00 01 OLE, SPSS, or Visual C++ type
00 library file
01 10 Novell LANalyzer capture file tr1
00 01 00 TST
00 01 00 TTF
55 46 41 ufa UFA Archive File
扩展名 文件头标识(HEX) 文件描述
wav 57 41 56 45 66 6D 74 Wave Files
wb2 00 00 02 00
QuattroPro for Windows
Spreadsheet file
wb3
[24 byte offset] 3E 00 Quatro Pro for Windows 7.0
03 00 FE FF 09 00 06 Notebook file
20 00 60 40 60 Lotus 123 v1 Worksheet wk1; wks
00 00 02 00 06 04 06
00 08 00 00 00 00 00
扩展名 文件头标识(HEX) 文件描述
WMV 30 26 B2
wp FF 57 50 43 WordPerfect v5 or v6
wpd FF 57 50 43 WordPerfect
wpg FF 57 50 47 WordPerfect Graphics
wri 31 BE Microsoft Write file
WRI 31 BE 00
wri 32 BE Microsoft Write file
WordStar Version 5.0/6.0
扩展名 文件头标识(HEX) 文件描述
xls
[512 byte offset] 09 08 Excel spreadsheet subheader (MS
10 00 00 06 05 00 Office)
3C 3F 78 XML
3C 3F 78 6D 6C xml XML Document
FF FE 3C 00 52 00 4F
xml 00 4F 00 54 00 53 00 XML Document (ROOTSTUB)
54 00 55 00 42 00
XMV 00 50 01
扩展名 文件头标识(HEX) 文件描述
zoo 5A 4F 4F 20 ZOO Archive File
有了这个表格,我们就可以通过检查文件的十六进制头来判断文件实际
的类型了。


发布评论