帮助识别文件类型: Magic Number/File Signature

文件类型一般是通过扩展名来识别的,但这个并不靠谱,因为扩展名可以瞎改

另一种作法是查看文件中特定位置(文件开头或少量偏移)的几个字节,因为大家有约定,一些特定的字节代表特定的类型. 这些字节就是 Magic Number,或称 File Signature

常见的Magic Number有:

  
http://en.wikipedia.org/wiki/List_of_file_signatures

  50 4B 03 04        zip

  CA FE BA BE      java class

  FF FE              Byte-order mark for 16-bit Unicode text file

 

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.