linux系统下file使用的magic文件格式说明
bestring16 一个两个字节unicode(UCS16)字符串以大端字节序表示
!:apple
!:mime MIMETYPE
!:strength OP VALUE
#在开始位置找到MZ
string MZ >0x18 leshort <0x40 MS-DOS executable
>0x18 leshort >0x3f extended PC executable (e.g., MS Windows)
# MS Windows executables are also valid MS-DOS executables
string MZ
>0x18 leshort <0x40 MZ executable (MS-DOS)
# skip the whole block below if it is not an extended executable
>0x18 leshort >0x3f
>>(0x3c.l) string PE\\ PE executable (MS-Windows)
>>(0x3c.l) string LX\\ LX executable (OS/)
(0x3c.l):读取从开始偏移0x3c个字节位置的long长度的值(l的含义)用该值和PE\0\0做字符串的比较,如果相等就匹配
这种检测的方法有一个缺点,你必须确保你最终打印一些东西,或者用户可以获得空的输出(例如:上面的例子中当既不是PE\0\0 也不是LE\0\0)
圆括号内允许一个去修改从文件中读取的值在他被用作一个偏移量之前。
# MS Windows executables are also valid MS-DOS executables
string MZ
# sometimes, the value at 0x18 is less that 0x40 but there's still an
# extended executable, simply appended to the file
>0x18 leshort <0x40
>>(.s*) leshort 0x014c COFF executable (MS-DOS, DJGPP)
>>(.s*) leshort !0x014c MZ executable (MS-DOS)
有时候你不知道前面字段确切的偏移,它取决于长度或者位置(当间接被使用之前)。你可以指定一个相对偏移最后高等级范围的末尾使用&作为一个前缀给偏移量
string MZ
>0x18 leshort >0x3f
>>(0x3c.l) string PE\\ PE executable (MS-Windows)
# immediately following the PE signature is the CPU type
>>>& leshort 0x14c for Intel
>>>& leshort 0x184 for DEC Alpha
相对位置偏移0字节(&0)
间接和直接偏移可以结合使用
string MZ
>0x18 leshort <0x40
>>(.s*) leshort !0x014c MZ executable (MS-DOS)
# if it's not COFF, go back 512 bytes and add the offset taken
# from byte /, which is yet another way of finding the start
# of the extended executable
>>>&(.s-) string LE LE executable (MS Windows VxD driver)
或者其他方法:
string MZ
>0x18 leshort >0x3f
>>(0x3c.l) string LE\\ LE executable (MS-Windows)
# at offset 0x80 (-, since relative offsets start at the end
# of the up-level match) inside the LE header, we find the absolute
# offset to the code area, where we look for a specific signature
>>>(&0x7c.l+0x26) string UPX \b, UPX compressed
string MZ
>0x18 leshort >0x3f
>>(0x3c.l) string LE\\ LE executable (MS-Windows)
# at offset 0x58 inside the LE header, we find the relative offset
# to a data area where we look for a specific signature
>>>&(&0x54.l-) string UNACE \b, ACE self-extracting archive
最后如果你不得不解决偏移/长度 组合在你的文件中,甚至第二个值在
string MZ
>0x18 leshort >0x3f
>>(0x3c.l) string PE\\ PE executable (MS-Windows)
# search for the PE section called ".idata"...
>>>&0xf4 search/0x140 .idata
# ...and go to the end of it, calculated from start+length;
# these are located and bytes after the section name
>>>>(&0xe.l+(-)) string PK\\ \b, ZIP self-extracting archive
匹配MP3文件的一个示例:
# MP3, M1A
# modified by Joerg Jenderek
# GRR the original test are too common for many DOS files
# so don't accept as MP3 until we've tested the rate
beshort&0xFFFE 0xFFFA
# rates
> byte&0xF0 0x10 MPEG ADTS, layer III, v1, kbps
!:mime audio/mpeg
> byte&0xF0 0x20 MPEG ADTS, layer III, v1, kbps
!:mime audio/mpeg
> byte&0xF0 0x30 MPEG ADTS, layer III, v1, kbps
!:mime audio/mpeg> byte&0xF0 0xA0 MPEG ADTS, layer III, v1, kbps
!:mime audio/mpeg
> byte&0xF0 0xB0 MPEG ADTS, layer III, v1, kbps
用开始位置的数值的二进制值&(与)0xFFFE结果如果是0XFFFA就匹配,简化后可以这样
beshort&0xFE 0xFA
(>2 byte&0xF0 0x10):偏移2个字节的值&0xF0的值是对应0x10、0x20、0x30。。。任意一个都算匹配
linux系统下file使用的magic文件格式说明的更多相关文章
- 深入理解linux系统下proc文件系统内容
深入理解linux系统下proc文件系统内容 内容摘要:Linux系统上的/proc目录是一种文件系统,即proc文件系统. Linux系统上的/proc目录是一种文件系统,即proc文件系统.与其它 ...
- 在Linux系统下运行微信Web开发者工具
微信Web开发者工具只有window版本和mac版本,如果想要在Linux系统下运行微信Web开发者工具,需要花费很大周折. 注:带 * 的步骤或文件为不确定是否管用的步骤或文件.本人系统为Linux ...
- linux系统下的权限知识梳理
下面对linux系统下的有关权限操作命令进行了梳理总结,并配合简单实例进行说明.linux中除了常见的读(r).写(w).执行(x)权限以外,还有其他的一些特殊或隐藏权限,熟练掌握这些权限知识的使用, ...
- Linux系统下Apache2.4.17的安装过程
Linux系统下安装Apache Server2.4.17.还是先声明一下,Linux命令我不进行讲解,因为我不是讲Linux命令的.有需要注意的地方,我会上图,没什么值得的注意的地方,我就不上图了. ...
- Linux系统下fd分配的方法
最近几天在公司里写网络通讯的代码比较多,自然就会涉及到IO事件监测方法的问题.我惊奇的发现select轮训的方法在那里居然还大行其道.我告诉他们现在无论在Linux系统下,还是windows系统下,s ...
- Linux系统下ssh的相关配置详细解析
Linux系统下ssh的相关配置进行了详细的分析介绍. ssh是大家常用的登录linux服务器的方式,但是为了安全考虑,有时候我们需要针对ssh做一些特殊处理,本文记录笔者曾经做过的一些修改,供大家参 ...
- 在Linux系统下安装大于mysql5.5版本的数据库
linux下mysql 5.5的安装方法: 1.安装所需要系统库相关库文件 gcc等开发包,在安装linux系统的时候安装. 2.创建mysql安装目录 # mkdir -p /usr/lo ...
- Linux系统下查看某文件修改的时间戳
Linux系统下查看某文件修改的时间戳查看文件时间戳命令:stat awk.txt File: `awk.txt' Size: 20 Blocks: 8 I ...
- linux系统下svn服务器操作命令
linux系统下svn服务器操作命令 .输出指定文件或URL的内容. svncat 目标[@版本]…如果指定了版本,将从指定的版本开始查找. svncat -r PREV filename > ...
随机推荐
- php字符串中 转义字符 “ ’‘ ” ’ “” ‘ " \’ ' ' \‘ " " \" '' \ " " 使用
<?php echo $str_string1='甲问:"你在哪里学的PHP?"'; echo "<br />"; echo $str_str ...
- maven依赖本地非repository中的jar包【转】
今天在使用maven编译打包一个web应用的时候,碰到一个问题: 项目在开发是引入了依赖jar包,放在了WEB-INF/lib目录下,并通过buildpath中将web libariary导入. 在e ...
- 题解 P1387 【最大正方形】
传送门 搞不清楚为什么这一题要DP . . . . . . 思路: \(n\le100\),考虑暴力. 要求一大块区间内都是1,考虑前缀和. 在矩阵中求一个符合条件的子矩阵,考虑\(n^3\)的&qu ...
- 我的Java开发学习之旅------>Java使用Fork/Join框架来并行执行任务
现代的计算机已经向多CPU方向发展,即使是普通的PC,甚至现在的智能手机.多核处理器已被广泛应用.在未来,处理器的核心数将会发展的越来越多. 虽然硬件上的多核CPU已经十分成熟,但是很多应用程序并未这 ...
- python 的print 用法
print(x,y) 等价于 import sys sys.stdout.write(str(x) + ' ' +str(y) + '\n') 从语法上讲,调用python3.0 的print 函数有 ...
- JSP中的内容布局
参考 :https://stackoverflow.com/questions/10529963/what-is-the-best-way-to-create-jsp-layout-template ...
- bind(),live(),delegate(),on()绑定事件方式
1.bind():向匹配元素添加一个或多个事件处理器. 适用所有版本,但是自从jquery1.7版本以后bind()函数推荐用on()来代替. $(selector).bind(event,data, ...
- 3D焦点图插件
在线演示 本地下载
- smokeping 报警配置
摘自: http://blog.csdn.net/achejq/article/details/51556494 smokeping 默认用sendmail 发邮件告警,也可以直接调用外部程序进行报警 ...
- python类初探
class human: is_alive=True is_man=True def __init__(self,age): print('this is __init__() method, whi ...