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 基础 5.2 类的继承
一. 类的继承 继承,顾名思议就知道是它的意思,举个例子说明,你现在有一个现有的A类,现在需要写一个B类,但是B类是A类的特殊版,我们就可以使用继承,B类继承A类时,B类会自动获得A类的所有属性和方法 ...
- 用nvm管理windows nodejs时用npm全局安装的插件无法调用的解决方案
在环境变量中啊新建变量NODE_PATH赋值为prefix设置的地址即 prefix=D:\Users\xxx\AppData\Roaming\nodejs\npm-global 然后把%NODE_P ...
- EasyPlayer windows RTSP播放器OCX插件使用说明
鉴于大家对于EasyPlayer插件的使用还不太熟悉,特此写一篇插件的使用文档,供大家参考:EasyPlayer插件有两种,一种是基于IE的ActiveX控件,一种是基于FireFox(也支持多浏览器 ...
- yarn_action
https://maprdocs.mapr.com/home/AdministratorGuide/ResourceAllocation-YARNContainer.html yarn.schedul ...
- 我的Java开发学习之旅------>工具类:Java获取字符串和文件进行MD5值
ps:这几天本人用百度云盘秒传了几部大片到云盘上,几个G的文件瞬秒竟然显示"上传成功"!这真让我目瞪口呆,要是这样的话,那得多快的网速,这绝对是不可能的,也许这仅是个假象.百度了一 ...
- Android Weekly Notes Issue #320
Android Weekly Issue #320 July 29th, 2018 Android Weekly Issue #320 本期内容包括: Firebase的MLKit; 关于写Andro ...
- SPOJ - REPEATS —— 后缀数组 重复次数最多的连续重复子串
题目链接:https://vjudge.net/problem/SPOJ-REPEATS REPEATS - Repeats no tags A string s is called an (k,l ...
- Linux- 恢复.swp文件
当我们对Linux文件系统下的文件编辑时,很多新手老手都有可能出现一些失误,在对一个文件编辑或者改动,甚至是不小心按到键盘并没有发现改动到某处时,没有强制退出(:q!)就直接退出,导致文件变成了.sw ...
- jQuery蓝色修边tab标签切换
jQuery蓝色修边tab标签切换,jQuery,tab选项卡,标签切换,jQuery蓝色修边tab标签广告代码切换是一款非常简单实用tab选项卡切换效果,自己定义好相关的html标签即可,选项卡切换 ...
- 分享知识-快乐自己:SpringMvc中的四种数据源及相关配置(整合快速集成开发)
数据库连接: jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://39.105.105.186:3306/SpringMybatis?us ...