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 > ...
随机推荐
- python 基础 7.7 json--上
一. 文件json ...
- GS给客户单发包以及m_queGcWait(所有GC共享)
GS给客户单发包以及m_queGcWait(所有GC共享) send_stat BaseChannel::SendCmd(int nCmd, void* pData, int nLen) { Prot ...
- Webpack探索【12】--- externals详解
本文主要讲externals相关内容. https://segmentfault.com/a/1190000012113011
- Java使用到的常用类总结
基本类型 常用:int.long.double.boolean. 不常用:byte.float.char.short
- 在cocos2d-x中使用LUA
在cocos2d-x中使用LUA 1.注冊LUA脚本引擎 CCLuaEngine* pEngine = CCLuaEngine::defaultEngine(); CCScriptEngineMana ...
- SAP采购寄售业务操作步骤
[转自 http://blog.sina.com.cn/s/blog_6466e5f70100jghg.html] 这里所示的是比较完整的步骤,包含了:信息记录.采购合同.货源清单.采购申请.采购订单 ...
- 协程与IO多路复用
IO多路复用 I/O多路复用 : 通过一种机制,可以监视多个描述符,一旦某个描述符就绪(一般是读就绪或者写就绪),能够通知程序进行相应的读写操作. Python Python中有一个select模块, ...
- 细说后端模板渲染、客户端渲染、node 中间层、服务器端渲染(ssr)
细说后端模板渲染.客户端渲染.node 中间层.服务器端渲染(ssr) 前端与后端渲染方式的发展大致经历了这样几个阶段:后端模板渲染.客户端渲染.node 中间层.服务器端渲染(ssr). 1. 后端 ...
- HTML5_CSS3可切换注册登录表单
在线演示 本地下载
- media server died的解决方法【转】
本文转载自:https://blog.csdn.net/class_brick/article/details/78086261 在对MediaRecord进行初始化时添加上 mMediaRecord ...