gcc 4.8.5 :centos
struct stat st;
stat 获取文件信息
open O_RDONLY
read(fd,buffer,st.st_size);
前四个字节获取unsigned int len =
((unsigned char)buffer[0] << 24) | ((unsigned char)buffer[1] << 16) | ((unsigned char)buffer[2] << 8) | ((unsigned char)buffer[3] )
通过或来把四个字节转为16进制连接起来(或:| 有1既是1)
疑问:文件的字节数(st.st_size 和 len 比较有什么意义吗??)
Maxlen = len - 262144 -4 ; 是啥意义? 2^18 == 262144 == 256 * 1024
od -N4 -t x1
test
.txt|
head
-1|
sed
-e
's/0000000//g'
-e
's/ //g'
|
tr
-d
'
'
od -N4 -t x1
test
.txt|
head
-1|
sed
-e
's/0000000//g'
-e
's/ //g'
下面编码和文件类型对比来自参考路径,不确定准确性;
JPEG (jpg),文件头:FFD8FF
PNG (png),文件头:89504E47
GIF (gif),文件头:47494638
TIFF (tif),文件头:49492A00
Windows Bitmap (bmp),文件头:424D
CAD (dwg),文件头:41433130
Adobe Photoshop (psd),文件头:38425053
Rich Text Format (rtf),文件头:7B5C727466
XML (xml),文件头:3C3F786D6C
HTML (html),文件头:68746D6C3E
Email [thorough only] (eml),文件头:44656C69766572792D646174653A
Outlook Express (dbx),文件头:CFAD12FEC5FD746F
Outlook (pst),文件头:2142444E
MS Word/Excel (xls.or.doc),文件头:D0CF11E0
MS Access (mdb),文件头:5374616E64617264204A
WordPerfect (wpd),文件头:FF575043
Postscript (eps.or.ps),文件头:252150532D41646F6265
Adobe Acrobat (pdf),文件头:255044462D312E
Quicken (qdf),文件头:AC9EBD8F
Windows Password (pwl),文件头:E3828596
ZIP Archive (zip),文件头:504B0304
RAR Archive (rar),文件头:52617221
Wave (wav),文件头:57415645
AVI (avi),文件头:41564920
Real Audio (ram),文件头:2E7261FD
Real Media (rm),文件头:2E524D46
MPEG (mpg),文件头:000001BA
MPEG (mpg),文件头:000001B3
Quicktime (mov),文件头:6D6F6F76
Windows Media (asf),文件头:3026B2758E66CF11
MIDI (mid),文件头:4D546864
常用文件的文件头如下:
1. MIDI (mid),文件头:4D546864
2. JPEG (jpg),文件头:FFD8FF
3. PNG (png),文件头:89504E47
4. GIF (gif),文件头:47494638
5. TIFF (tif),文件头:49492A00
6. Windows Bitmap (bmp),文件头:424D
7. CAD (dwg),文件头:41433130
8. Adobe Photoshop (psd),文件头:38425053
9. Rich Text Format (rtf),文件头:7B5C727466
10. XML (xml),文件头:3C3F786D6C
11. HTML (html),文件头:68746D6C3E
12. Email [thorough only] (eml),文件头:44656C69766572792D646174653A
13. Outlook Express (dbx),文件头:CFAD12FEC5FD746F
14. Outlook (pst),文件头:2142444E
15. MS Word/Excel (xls.or.doc),文件头:D0CF11E0
16. MS Access (mdb),文件头:5374616E64617264204A
17. WordPerfect (wpd),文件头:FF575043
18. Postscript (eps.or.ps),文件头:252150532D41646F6265
19. Adobe Acrobat (pdf),文件头:255044462D312E
20. Quicken (qdf),文件头:AC9EBD8F
21. Windows Password (pwl),文件头:E3828596
22. ZIP Archive (zip),文件头:504B0304
23. RAR Archive (rar),文件头:52617221
24. Wave (wav),文件头:57415645
25. AVI (avi),文件头:52494646
26. Real Audio (ram),文件头:2E7261FD
27. Real Media (rm),文件头:2E524D46
28. Windows Media Audio(wma)(asf),文件头:3026b2758e66cf
29. wrf, 文件头:574f5446000600
29. MPEG (mpg),文件头:000001BA
30. MPEG (mpg),文件头:000001B3
31. Quicktime (mov),文件头:6D6F6F76
32. Windows Media (asf),文件头:3026B2758E66CF11
参考路径:
http://suiwnet.blog.51cto.com/2492370/1419491
http://www.oschina.net/code/snippet_128697_39191#57989
http://blog.csdn.net/gagapencil/article/details/40392363
http://www.oschina.net/question/1033955_2148033