当前位置:   article > 正文

利用文件头标志判断文件类型

vb 获取根据文件标识头文件类型

简介

我们都知道,文件的扩展名是用来识别文件类型的。通过给他指定扩展名,我们可以告诉自己,也告诉操作系统我们想用什么方式打开这个文件。比如我么会把.jpg的文件默认用图片显示软件打开,.zip 文件会默认用解压软件打开等等。

然而,扩展名完全是可以随便改改的。我们可以给文件设置一个任意的扩展名,当然也可以不设置扩展名。这样一来我们就不能了解到这个文件究竟是做什么的,究竟是个什么样的文件。我们或许也会疑惑,为什么一个软件,比如视频播放器,就能用正确的方式打开.mp4 .rmvb .wmv 等等的视频?

事实上,所有的文件都是以二进制的形式进行存储的,本质上没有差别。之所以使用的方法不同,只是因为我们理解他的方式不同。在每一个文件(包括图片,视频或其他的非ASCII文件)的开头(十六进制表示)实际上都有一片区域来显示这个文件的实际用法,这就是文件头标志。

Linux下我们可以用file命令直接查看文件的实际格式,但是他本质上也是利用文件头标志来进行文件类型判断的。下面就简要介绍下手动判断文件真实类型的方法。

表格

扩展名文件头标识(HEX)文件描述
12300 00 1A 00 05 10 04Lotus 1-2-3 spreadsheet (v9) file
3gg; 3gp; 3g200 00 00 nn 66 74 79 70 33 67 703rd Generation Partnership Project 3GPP (nn=0x14) and 3GPP2 (nn=0x20) multimedia files
7z37 7A BC AF 27 1C7-ZIP compressed file
aba00 01 42 41Palm Address Book Archive file
abi41 4F 4C 49 4E 44 45 58AOL address book index file
aby; idx41 4F 4C 44 42AOL database files: address book (ABY) and user configuration data (MAIN.IDX)
accdb00 01 00 00 53 74 61 6E 64 61 72 64 20 41 43 45 20 44 42Microsoft Access 2007 file
ACM4D 5AMS audio compression manager driver
ADF44 4F 53Amiga disk file
adx03 00 00 00 41 50 50 52Lotus Approach ADX file
AIFF46 4F 52 4D 00Audio Interchange File
ain21 12AIN Compressed Archive File
ami5B 76 65 72 5DLotus Ami Pro
amr23 21 41 4D 52Adaptive Multi-Rate ACELP (Algebraic Code Excited Linear Prediction) Codec, commonly audio format with GSM cell phones
ANI52 49 46 46 
API4D 5A 90 00 03 00 00 00Acrobat plug-in
arc1A 0xLH archive file, old version(where x = 0x2, 0x3, 0x4, 0x8 or 0x9 for types 1-5, respectively)
arc41 72 43 01FreeArc compressed file
arj60 EAARJ Compressed Archive
ARJ60 EA 27 
ART4A 47 03 0E 00 00 00AOL ART file
ART4A 47 04 0E 00 00 00AOL ART file
asf30 26 B2 75 8E 66 CF 11Windows Media
asf; wma; wmv30 26 B2 75 8E 66 CF 11 A6 D9 00 AA 00 62 CE 6CMicrosoft Windows Media Audio/Video File(Advanced Streaming Format)
asx3CAdvanced Stream redirector file
au2E 73 6E 64SoundMachine Audio File NeXT/Sun Microsystems μ-Law audio file
avi41 56 49 20Audio Video Interleave (AVI)
AX4D 5ALibrary cache file
AX4D 5A 90 00 03 00 00 00DirectShow filter
bag41 4F 4C 20 46 65 65 64 62 61 67AOL and AIM buddy list file
BAS20 20 20 
bin42 4C 49 32 32 33 51Thomson Speedtouch series WLAN router firmware
bmp42 4DWindows Bitmap
BMP42 4D 3E 
bz; bz242 5A 68BZIP Archive
BZ2; TAR.BZ2; TBZ2; TB242 5A 68bzip2 compressed archive
CAB49 53 63 
CAB; HDR49 53 63 28Install Shield v5.x or 6.x compressed file
CAB4D 53 43 46Microsoft CAB File Format
cat30Microsoft security catalog file
CBD43 42 46 49 4C 45WordPerfect dictionary file (unconfirmed)
CCD5B 43 6C 
cdrCDRCorel Draw
CDR45 4C 49 54 45 20 43 6F 6D 6D 61 6E 64 65 72 20Elite Plus Commander saved game file
CDR, DVF4D 53 5F 56 4F 49 43 45Sony Compressed Voice File
CHI; CHM49 54 53 46Microsoft Compiled HTML Help File
CHM49 54 53 
CLB43 4D 58 31Corel Binary metafile
CLB43 4F 4D 2BCOM+ Catalog file
cnt3A 42 61 73 65 
COM, DLL, DRV, EXE, PIF, QTS, QTX, SYS4D 5AWindows/DOS executable file
COM4D 5A EE 
COME9 3B 03 
CPE46 41 58 43 4F 56 45 52 2D 56 45 52Microsoft Fax Cover Sheet
CPL4D 5AControl panel application
CPT43 50 54 37 46 49 4C 45Corel Photopaint file
CPT43 50 54 46 49 4C 45Corel Photopaint file
CPX5B 57 69 
cru; crush43 52 55 53 48CRUSH Archive File
CRU43 52 55 53 48 20 76Crush compressed archive
CRW49 49 1A 00 00 00 48 45 41 50 43 43 44 52 02 00Canon digital camera RAW file
CTF43 61 74 61 6C 6F 67 20 33 2E 30 30 00WhereIsIt Catalog file
CUR00 00 02 00 01 00 20 20Windows cursor file
dat03MapInfo Native Data Format
dat1A 52 54 53 20 43 4F 4D 50 52 45 53 53 45 44 20 49 4D 41 47 45 20 56 31 2E 30 1ARuntime Software disk image
dat41 56 47 36 5F 49 6E 74 65 67 72 69 74 79 5F 44 61 74 61 62 61 73 65AVG6 Integrity database file
DAT43 52 45 47Windows 9x registry hive
DAT43 6C 69 65 6E 74 20 55 72 6C 43 61 63 68 65 20 4D 4D 46 20 56 65 72 20IE History DAT file
DAT45 52 46 53 53 41 56 45 44 41 54 41 46 49 4C 45Kroll EasyRecovery Saved Recovery State file
DAT49 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 29Inno Setup Uninstall Log file
db00 06 15 61 00 00 00 02 00 00 04 D2 00 00 10 00Netscape Navigator (v4) database file
DB44 42 46 48Palm Zire photo database
db08dBASE IV or dBFast configuration file
db303dBASE III file
db404dBASE IV data file
dba00 01 42 44Palm DateBook Archive file
dbxCF AD 12 FE 
dbxCF AD 12 FE C5 FD 74 6FOutlook Express
dci3C 21 64 6F 63 74 79 70AOL HTML mail file
dcx3A DE 68 B1DCX Graphic File
DDB00 01 00 
dib42 4Ddevice-independent bitmap image
DLL4D 5A 90 
DMP4D 44 4D 50 93 A7Windows minidump file
DMS44 4D 53 21Amiga DiskMasher compressed archive
doc0D 44 4F 43DeskMate Document file
doc12 34 56 78 90 FFMS Word 6.0
doc31 BE 00 00 00 AB 00 00MS Word for DOS 6.0
doc7F FE 34 0AMS Word
dot; ppt; xla; ppa; pps; pot; msi; sdw; dbD0 CF 11 E0MS Office/OLE2
doc; dot; xls; xlt; xla; ppt; apr ;ppa; pps; pot; msi; sdw; dbD0 CF 11 E0 A1 B1 1A E1MS Compound Document v1 or Lotus Approach APR file
DPL4D 5A 50 
DRV4D 5A 16 
drw07A common signature and file extension for many drawing programs.
drw01 FF 02 04 03 02Micrografx vector graphic file
ds44D 47 58 20 69 74 70 64Micrografix Designer 4
DSN4D 56CD Stomper Pro label file
dsp23 20 4D 69 63 72 6F 73 6F 66 74 20 44 65 76 6 56C 6F 70 65 72 20 53 74 75 64 69 6FMicrosoft Developer Studio project file
dss02 64 73 73Digital Speech Standard (Olympus, Grundig, & Phillips)
dtd07 64 74 32 64 64 74 64DesignTools 2D Design file
dtd3C 21 45 4E 54 49 54 59XML DTD
DVR44 56 44DVR-Studio stream file
dwg41 43 31 
Enn (where nn are numbers)45 56 46EnCase evidence file
ECO2A 50 52 
elf7F 45 4C 46 01 01 01 00ELF Executable
emf01 00 00 00 58 00 00 00Extended (Enhanced) Windows Metafile Format, printer spool file
eml44 65 6C 69 76 65 72 79 2D 64 61 74 65 3AEmail
EML46 72 6F 6D 20 20 20A commmon file extension for e-mail files. Signatures shown here are for Netscape, Eudora, and a generic signature, respectively. EML is also used by Outlook Express and QuickMail.
EML46 72 6F 6D 20 3F 3F 3FA commmon file extension for e-mail files. Signatures shown here are for Netscape, Eudora, and a generic signature, respectively. EML is also used by Outlook Express and QuickMail.
EML46 72 6F 6D 3A 20A commmon file extension for e-mail files. Signatures shown here are for Netscape, Eudora, and a generic signature, respectively. EML is also used by Outlook Express and QuickMail.
EML52 65 63 
enc00 5C 41 B1 FFMujahideen Secrets 2 encrypted file
enl[32 byte offset] 40 40 40 20 00 00 40 40 40 40EndNote Library File
eps25 21 50 53Adobe EPS File
eps25 21 50 53 2D 41 64 6F 62 65Postscript
eps25 21 50 53 2D 41 64 6F 62 65 2D 33 2E 30 20 45 50 53 46 2D 33 20 30Adobe encapsulated PostScript file (If this signature is not at the immediate beginning of the file, it will occur early in the file, commonly at byte offset 30)
EPSC5 D0 D3 
eth1A 35 01 00GN Nettest WinPharoah capture file
evt30 00 00 00 4C 66 4C 65Windows Event Viewer file
evt03 00 00 00 C4 66 C4 56 
EVTX45 6C 66 46 69 6C 65 00Windows Vista event log file
exe; dll; drv; vxd; sys; ocx; vbx4D 5AWin32 Executable
exe; dll; drv; vxd; sys; ocx; vbx4D 5AWin16 Executable
exe; com; 386; ax; acm; sys; dll; drv; flt; fon; ocx; scr; lrc; vxd; cpl; x324D 5AExecutable File
EXE, DLL, OCX, OLB, IMM, IME4D 5A 90 
fli00 11 AFFLIC Animation file
flt00 01 01OpenFlight 3D file
FLT4D 5A 90 00 03 00 00 00Audition graphic filter file (Adobe)
FLV46 4C 56 01Flash video file
fm3C 4D 61 6B 65 72 46 69 6C 65 20Adobe FrameMaker file
fm300 00 1A 00 07 80 01 00Lotus 123 v3 FMT file
fmt20 00 68 00 20 0Lotus 123 v4 FMT file
FNT43 48 41 
FON4D 5AFont file
GBC87 F5 3E 
gid3F 5F 03 00Windows Help Index File
GID4C 4E 02 00Windows Help index file
GIF47 49 46 38 
gif47 49 46 38 37 61Graphics interchange format file (GIF 87A)
gif47 49 46 38 39 61Graphics interchange format file (GIF89A)
GTD7B 50 72 
GX247 58 32Show Partner graphics file (not confirmed)
gz; tar; tgz1F 8BGzip Archive File
gz; tgz1F 8B 08GZ Compressed File
hap91 33 48 46HAP Archive File
HDMP4D 44 4D 50 93 A7Windows heap dump file
hdr23 3F 52 41 44 49 41 4E 43 45 0Aadiance High Dynamic Range image file
HLP3F 5F 03 
hlp3F 5F 03 00Windows Help file
HLP4C 4E 02 00Windows Help file
hlp[7 byte offset] 00 00 FF FF FF FFWindows Help file
hqx28 54 68 69 73 20 66 69 6C 65Macintosh BinHex 4 Compressed Archive
hqx28 54 68 69 73 20 66 69 6C 65 20 6D 75 73 74 20 62 65 20 63 6F 6E 76 65 72 74 65 64 20 77 69 74 68 20 42 69 6E 48 65 78 20Macintosh BinHex 4 Compressed Archive
HTM3C 21 44 
htm; html3C 21 44 4F 43 54HyperText Markup Language 3
htm; html3C 48 54 4D 4C 3EHyperText Markup Language 2
htm; html3C 68 74 6D 6C 3EHyperText Markup Language 1
html68 74 6D 6C 3EHTML
ico00 00 01 00 00Icon File
ico00 00 01 00 01 00 20 20Icon File
IFF46 4F 52 4D 
IFO44 56 44DVD info file
IME4D 5A 90 
img00 01 00 08 00 01 00 01 01Ventura Publisher/GEM VDI Image Format Bitmap file
IMG00 FF FF 
IMM4D 5A 90 
ind41 4F 4C 49 44 58AOL client preferences/settings file (MAIN.IND)
ISO43 44 30 30 31ISO-9660 CD Disc Image (This signature usually occurs at byte 8001, 8801, or 9001.)
ivr2E 52 45 43RealPlayer video file (V11 and later)
JAR4A 41 52 43 53 00JARCS compressed archive
jar5F 27 A8 89JAR Archive File
jpg; jpegFF D8 FF 
jpg; jpe; jpegFF D8 FF E0 00JPG Graphic File
jpg; jpe; jpegFF D8 FF FE 00JPG Graphic File
KGB4B 47 42 5F 61 72 63 68 20 2DKGB archive
KOZ49 44 33 03 00 00 00Sprint Music Store audio file (for mobile devices)
LDB42 49 4C 
lha2D 6C 68 35 2DLHA Compressed
lha; lzh[2 byte offset] 2D 6C 68Compressed archive file
LHP3F 5F 03 
lhp3F 5F 03 00Windows Help File
lib21 3C 61 72 63 68 3E 0AUnix archiver (ar) files and Microsoft Program Library Common Object File Format (COFF)
LIB2A 24 20 
LIT49 54 4F 4C 49 54 4C 53Microsoft Reader eBook file
LNK4C 00 00 
lnk4C 00 00 00Windows Shortcut (Link File)
lnk4C 00 00 00 01 14 02Windows Link File
LNK4C 00 00 00 01 14 02 00Windows shortcut file
log2A 2A 2A 20 20 49 6E 73 74 61 6C 6C 61 74 69 6F 6E 20 53 74 61 72 74 65 64 20Symantec Wise Installer log file
lzhlhLz compression file
lwp57 6F 72 64 50 72 6FLotus WordPro v9
m3u23 45 58 
m4a00 00 00 20 66 74 79 70 4D 34 41 20 00 00 00 00Apple Lossless Audio Codec file
m4a; m4v00 00 00 20 66 74 79 70 4D 34 41 20 00 00 00 00QuickTime M4A/M4V file
manifest3C 3F 78 6D 6C 20 76 65 72 73 69 6F 6E 3DWindows Visual Stylesheet XML file
MAR4D 41 52 31 00Mozilla archive
MAR4D 41 52 43Microsoft/MSN MARC archive
MAR4D 41 72 30 00MAr compressed archive
maxD0 CF 11 
mdb00 01 00 00 53 74 61 6E 64 61 72 64 20 4A 65 74 20 44 42Microsoft Access file
mdb; mda; mde; mdt53 74 61 6E 64 61 72 64 20 4AMS Access
MDF00 FF FF 
mdf00 FF FF FF FF FF FF FF FF FF FF 00 00 02 00 01Alcohol 120% CD image
mdf01 0F 00 00Microsoft SQL Server 2000 database
MDI45 50Microsoft Document Imaging file
MDS4D 45 44 
MID; MIDI4D 54 68 64Musical Instrument Digital Interface (MIDI) sound file
mkv1A 45 DF A3 93 42 82 88 6D 61 74 72 6F 73 6B 61Matroska stream file
MLS4D 49 4C 45 53Milestones v1.0 project management and scheduling software (Also see “MV2C” and “MV214” signatures)
MLS4D 4C 53 57Skype localization data file
MLS4D 56 32 31 34Milestones v2.1b project management and scheduling software (Also see “MILES” and “MV2C” signatures)
MLS4D 56 32 43Milestones v2.1a project management and scheduling software (Also see “MILES” and “MV214” signatures)
MMF4D 4D 4D 44 00 00Yamaha Corp. Synthetic music Mobile Application Format (SMAF) for multimedia files that can be played on hand-held devices.
mny00 01 00 00 4D 53 49 53 41 4D 20 44 61 74 61 62 61 73 65Microsoft Money file
MOV00 00 0F 
MOV00 00 77 
mov6D 6F 6F 76Quicktime
mov6D 64 61 74QuickTime Movie
mp0C EDMonochrome Picture TIFF bitmap file (unconfirmed)
MP349 44 33MPEG-1 Audio Layer 3 (MP3) audio file
MP3FF FB 50 
mp400 00 00 18 66 74 79 70 33 67 70 35MPEG-4 video files
MPA00 00 01 
mpg; mpeg00 00 01 B3MPEG Movie
mpg00 00 01 BAMPEG
MSC3C 3F 78 
msc3C 3F 78 6D 6C 20 76 65 72 73 69 6F 6E 3D 22 31 2E 30 22 3F 3E 0D 0A 3C 4D 4D 43 5F 43 6F 6E 73 6F 6C 65 46 69 6C 65 20 43 6F 6E 73 6F 6C 65 56 65 72 73 69 6F 6E 3D 22Microsoft Management Console Snap-in Control file
msi23 20Cerius2 file
MSV4D 53 5F 56 4F 49 43 45Sony Memory Stick Compressed Voice file
NES4E 45 53 
NLSC2 20 20 
nri0E 4E 65 72 6F 49 53 4FNero CD Compilation
ntf1A 00 00Lotus Notes database template
nsf; ntf1A 00 00 03 00 00Lotus Notes Database/Template
nsf1A 00 00 03 00 00 11 00Notes Database
nsf1A 00 00 04 00 00Lotus Notes database
ntf30 31 4F 52 44 4E 41 4E 43 45 20 53 55 52 56 45 59 20 20 20 20 20 20 20National Transfer Format Map File
obj4C 01Microsoft Common Object File Format (COFF) relocatable object code file for an Intel 386 or later/compatible processors
OCX4D 5AActiveX or OLE Custom Control
OCX4D 5A 90 
OLB4D 5AOLE object library
OLB4D 5A 90 
org; pfc41 4F 4C 56 4D 31 30 30AOL personal file cabinet (PFC) file
pak1A 0BCompressed archive file
PAT47 46 31 50 41 54 43 48Advanced Gravis Ultrasound patch file
PAT47 50 41 54GIMP (GNU Image Manipulation Program) pattern file
PBK5B 41 44 
PCB17 A1 50 
PCS0A 05 01 
pcx0A nn 01 01ZSOFT Paintbrush file(where nn = 0x02, 0x03, or 0x05)
pcx0A 05 01 08PC Paintbrush(often associated with Quake Engine games)
pdb[11 byte offset] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00Palmpilot Database/Document File
PDF25 50 44 
pdf; fdf25 50 44 46Adobe Portable Document Format and Forms Document file
pdf25 50 44 46 2D 31 2EAdobe Acrobat
PDG48 48 02 
pf11 00 00 00 53 43 43 41Windows prefetch file
pic01 00 00 00 01Unknown type picture file
PJT00 00 07 
PLL24 53 6F 
PNG89 50 4E 
PNG89 50 4E 47 
png89 50 4E 47 0D 0APNG Image File
png89 50 4E 47 0D 0A 1A 0APNG Image File
PPC52 65 63 
PPTD0 CF 11 
ppt[512 byte offset] 00 6E 1E F0PowerPoint presentation subheader (MS Office)
ppt[512 byte offset] 0F 00 E8 03PowerPoint presentation subheader (MS Office)
PPZ4D 53 43 46Powerpoint Packaged Presentation
prc42 4F 4F 4B 4D 4F 42 49Palmpilot resource file
PRG23 44 45 
ps25 21 50 53 2D 41 64 6F 62 65Postscript
PSD38 42 50 
psd38 42 50 53Adobe Photoshop image file
psp7E 42 4B 00PaintShop Pro Image File
pst21 42 44 4EMicrosoft Outlook Personal Folder file
pwlE3 82 85 96Windows Password
qbb45 86 00 00 06 00Intuit QuickBooks Backup file
qdfAC 9E BD 8FQuicken
qph03 00 00 00Quicken price history file
qt6D 64 61 74Quicktime Movie File
qxd00 00 4D 4D 58 50 52
ra2E 52 4D 46 00 00 00 12 00Real Audio file
ra; ram2E 72 61 FDReal Audio File
ra2E 72 61 FD 00RealAudio streaming media file
RAR52 61 72 
rar52 61 72 21RAR Archive File
RAW06 05 00 
reg52 45 47 45 44 49 54 34 
rgb01 DA 01 01 00 03Silicon Graphics RGB Bitmap
RM2E 52 4D 
rm; rmvb2E 52 4D 46Real Media streaming media file
rpmED AB EE DBRPM Archive File
RTD43 23 2B 44 A4 43 4D A5 48 64 72RagTime document file
RTF7B 5C 72 
rtf7B 5C 72 74 66Rich Text Format File
sav24 46 4C 32 40 28 23 29 20 53 50 53 53 20 44 41 54 41 20 46 49 4C 45SPSS Data file
SBV46 45 44 46(Unknown file type)
SCH2A 76 65 
scm80 53 43 
SH348 48 47 42 31Harvard Graphics presentation file
SHD4B 49 00 00Windows 9x printer spool file
sit53 49 54 21Stuffit v1 Archive File
sit53 74 75 66 66 49 74Stuffit v5 Archive File
sle3A 56 45 52 53 49 4F 4ESurfplan kite project file
sle41 43 76teganos Security Suite virtual secure drive
sly; srt; slt53 52 01 00Sage sly.or.srt.or.slt
SMD00 FF FF 
snm00 1E 84 90 00 00 00 00Netscape Communicator (v4) mail folder
SNP4D 53 43 46Microsoft Access Snapshot Viewer file
sol00 BFAdobe Flash shared object file (e.g., Flash cookies)
spl00 00 01 00Windows NT/2000/XP printer spool file
SCR4D 5AScreen saver
SUBFF FF FF 
SWF43 57 53Shockwave Flash file (v5+)
SWF46 57 53Macromedia Shockwave Flash player file
sxccalcOpenOffice Calc
sxddrawOpenOffice Draw
sxiimpressOpenOffice Impress
sxmmathOpenOffice Math
sxwwriterOpenOffice Writer
syw41 4D 59 4FHarvard Graphics symbol graphic
TAG00 00 02 
tar; cpio30 37 30 37 30 37CPIO Archive File
tar.z1F 9D 90Compressed tape archive file
tga00 00 10 00 00RLE压缩的前5字节
TGA00 00 02 
tga00 00 02 00 00未压缩的前5字节
TIF; TIFF49 20 49Tagged Image File Format file
tif; tiff49 49 2ATIFF (Intel)
tif; tiff49 49 2A 00Tagged Image File Format file (little endian, i.e., LSB first in the byte; Intel)
TIF; TIFF4D 4D 00 2ATagged Image File Format file (big endian, i.e., LSB last in the byte; Motorola)
tif; tiff4D 4D 2ATIFF (Motorola)
TIF; TIFF4D 4D 00 2BBigTIFF files; Tagged Image File Format files >4 GB
TLB4D 53 46 54 02 00 01 00OLE, SPSS, or Visual C++ type library file
tr101 10Novell LANalyzer capture file
TST00 01 00 
TTF00 01 00 
ufa55 46 41UFA Archive File
VBX4D 5AVisualBASIC application
VCD45 4E 54 52 59 56 43 44 02 00 00 01 02 00 18 58VideoVCD (GNU VCDImager) file
vcf42 45 47 49 4E 3A 56 43 41 52 44 0D 0AvCard file
vob00 00 01 BADVD Video Movie File (video/dvd, video/mpeg)
VXD, 3864D 5AWindows virtual device drivers
WAV52 49 46 
wav57 41 56 45Wave
wav57 41 56 45 66 6D 74Wave Files
wb200 00 02 00QuattroPro for Windows Spreadsheet file
wb3[24 byte offset] 3E 00 03 00 FE FF 09 00 06Quatro Pro for Windows 7.0 Notebook file
wk1; wks20 00 60 40 60Lotus 123 v1 Worksheet
wk100 00 02 00 06 04 06 00 08 00 00 00 00 00Lotus 1-2-3 spreadsheet (v1) file
wk300 00 1A 00 00 10 04 00Lotus 123 spreadsheet (v3) file
wk4; wk500 00 1A 00 02 10 04 00Lotus 1-2-3 spreadsheet (v4, v5) file
wks0E 57 4B 53DeskMate Worksheet
WMA30 26 B2 
wmf01 00 09 00Graphics Metafile
wmf01 00 09 00 00 03Windows Metadata file (Win 3.x format)
wmf02 00 09 00Graphics Metafile
wmfD7 CD C6 9AWindows Meta File
WMV30 26 B2 
wpFF 57 50 43WordPerfect v5 or v6
wpdFF 57 50 43WordPerfect
wpgFF 57 50 47WordPerfect Graphics
wri31 BEMicrosoft Write file
WRI31 BE 00 
wri32 BEMicrosoft Write file
ws1D 7DWordStar Version 5.0/6.0 document
XBE58 42 45 
xdr3CBizTalk XML-Data Reduced Schema file
xls09 02 06 00 00 00 10 00 B9 04 5C 00MS Excel v2
xls09 04 06 00 00 00 10 00 F6 05 5C 00MS Excel v4
XLSD0 CF 11 
xlsD0 CF 11 E0MS Excel
xls[512 byte offset] 09 08 10 00 00 06 05 00Excel spreadsheet subheader (MS Office)
XML3C 3F 78 
xml3C 3F 78 6D 6CXML Document
xmlFF FE 3C 00 52 00 4F 00 4F 00 54 00 53 00 54 00 55 00 42 00XML Document (ROOTSTUB)
XMV00 50 01 
XSLFF FE 3C 
xul72 73 69 6F 6E 3D 22 31 3C 3F 78 6D 6C 20 76 65 2E 30 22 3F 3EXML User Interface Language file
z1F 9DTAR Compressed Archive File
Z1F 9D 8C 
ZIP50 4B 03 
zip; jar; zipx50 4B 03 04ZIP Archive
zip50 4B 30 30ZIP Archive (outdated)
Zip50 4B 30 30 50 4B 03 04WINZIP Compressed
zoo5A 4F 4F 20ZOO Archive File

 

有了这个表格,我们就可以通过检查文件的十六进制头来判断文件实际的类型了。

方法

windows下

我们可以通过ultraedit之类的文本编辑器检查文件的十六进制表示,很方便。

Linux下

我们有hexdump命令来查看文件的十六进制形式,用这种方法查看png文件的结果大概是这样的:

1
2
3
4
5
6
0000000 5089 474e 0a0d 0a1a 0000 0d00 4849 5244
0000010 0000 dc00 0000 3200 0608 0000 3700 b514
0000020 0073 0000 7009 5948 0073 0b00 0013 0b00
0000030 0113 9a00 189c 0000 4d0a 4369 5043 6850
0000040 746f 736f 6f68 2070 4349 2043 7270 666f
.......

然而,这个只能查看不能修改,而且实际上,他的高低位是反着的,实际上他应该表示为:

1
2
0000000 8050 4e47 0d0a 1a0a 0000 000d 4948 4452
.......

这样才是标准的png文件的头。

当然,我们有更方便强大的vim,用这个可以查看和修改文件的十六进制表示形式。我们用vim打开刚才的png文件,会的到以下的ascii表示形式:

1
2
3
4
5
6
7
8
<89>PNG^M                                                                   
^Z
^@^@^@^MIHDR^@^@^@Ü^@^@^@2^H^F^@^@^@7^Tµs^@^@^@ pHYs^@^@^K^S^@^@^K^S^A^@<9a> <9c>^X^@^@
MiCCPPhotoshop ICC profile^@^@xÚ<9d>SwX<93>÷^V>ß÷e^OVBØð±<97>l<81>^@"#¬^HÈ^P Y¢^P<92>^@a<84>^P^R@Å<85><88>
V^T^U^Q<9c>HUÄ<82>Õ
H<9d><88>â (¸gA<8a><88>Z<8b>U\8î^_ܧµ}zïííû×û¼ç<9c>çüÎyÏ^O<80>^Q^R&<91>æ¢j^@ 9R<85><:Ø^_<8f>OHÄɽ<80>^B^UHà^D ^PæËÂg^EÅ^@^@ð^Cyx~t°?ü^A¯o^@^B^@pÕ.$^RÇáÿ< 83>ºP&W^@ <91>^@à"^Rç^K^A<90>R^@È.TÈ^T^@È^X^@°S³d
^@<94>^@^@ly|B"^@ª^M^@ìôI>^E^@Ø©<93>Ü^W^@Ø¢^\©^H^@<8d>^A^@<99>(G$^B@»^@`U<81 >R,^BÀÂ^@ ¬@".^DÀ®^A<80>Y¶2G^B<80>½^E^@v<8e>X<90>^O@`^@<80><99>B,Ì^@ 8^B^@C^ ^^SÍ^C L^C 0Ò¿à©_p<85>¸H^A^@ÀË<95>Í<97>KÒ3^T¸<95>Ð^Zwòðàâ!âÂl±Ba^W)^Pf ä"<9
..........

接下来我们需要在命令模式下输入 :%!xxd 这样会得到以下的样子:

1
2
3
4
5
6
7
8
9
0000000: 8950 4e47 0d0a 1a0a 0000 000d 4948 4452  .PNG........IHDR   
0000010: 0000 00dc 0000 0032 0806 0000 0037 14b5 .......2.....7..
0000020: 7300 0000 0970 4859 7300 000b 1300 000b s....pHYs.......
0000030: 1301 009a 9c18 0000 0a4d 6943 4350 5068 .........MiCCPPh
0000040: 6f74 6f73 686f 7020 4943 4320 7072 6f66 otoshop ICC prof
0000050: 696c 6500 0078 da9d 5377 5893 f716 3edf ile..x..SwX...>.
0000060: f765 0f56 42d8 f0b1 976c 8100 2223 ac08 .e.VB....l.."#..
0000070: c810 59a2 1092 0061 8410 1240 c585 880a ..Y....a...@....
.......

这就对了,而且高低位的位置与一般的表示一致。

当我们需要调回ascii模式的时候,我们只要输入 :%!xxd -r 就可以回到之前的模式了。

这里要注意的是,在十六进制里我们可以通过编辑十六进制码来修改值,但是不要修改后面对应的ascii码和前面的地址,而且模式转换过去后一定要记得转换回来。

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号