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 > ...
随机推荐
- 五个知识体系之-SQL学习-第三天
1. sql约束作用 主键约束作用:保证插入数据的有效性.比如性别列,只能是“男”“女”,输入“abc”就是无效的,所以你可以添加约束alter table 表名add constraint chk_ ...
- cf-341C Iahub and Permutations
C. Iahub and Permutations time limit per test 1 second memory limit per test 256 megabytes input sta ...
- 初学shell,今天遇到由wget下载到本地的网页源代码的乱码问题,无聊的写了一个转码的脚本
今天用wget想下载文件,结果下载了一堆本地的index.html文件,一查看全是乱码,然后百度了一下,网页的编码格式大概有三种: 1.utf-8 2.gb2312 3.gbk 要在网页源码中的< ...
- java设计模式之迭代器模式
一.迭代器模式简介 迭代器模式提供一种方法顺序访问一个聚合对象中的各个元素,而又不暴露其内部的表示. 迭代器模式让我们能游走于聚合内的每一个元素,而又不暴露内部的表示.把游走的任务放在迭代器上,而不是 ...
- windowsphone8.1学习笔记之应用数据(三)
之前说了如何操作文本文件,如果是图片文件或者其他的二进制文件则需要操作文件的Stream或者Buffer数据.就需要用到DataReader和DataWriter这两个类了,这个的好好的练一下,以后的 ...
- Refused to set unsafe header
Refused to set unsafe header Refused to set unsafe header "Host"waitServerDeal @ tGet.html ...
- oracle 数据库常用数据表操作
在oracle中创建sequence CREATE SEQUENCE sequence名称 MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCRE ...
- jzyz集训 0612
今天闵神找的题,题目质量还算不错,就是有些偏套路了. 第一题:定义一个排列是合法当且仅当这个排列中不存在大于2的循环节,询问有多少长度为n的排列是合法的且B排列是该排列的子序列. 恩...这题目其实不 ...
- uboot 2013.01 s3c6400编译失败
通常我们对s3c6410平台开发u-boot是在s3c6400的基础上修改而成的,但是从uboot 2013.01这个版本之后的版本都把smdk6400对应的配置给删除了. 这是因为该版本smdk64 ...
- 一篇文章了解相见恨晚的 Android Binder 进程间通讯机制【转】
本文转载自:https://blog.csdn.net/freekiteyu/article/details/70082302 Android-Binder进程间通讯机制 概述 最近在学习Binder ...