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 基础 1.5 python数据类型(二)--列表常用方法示例
#/usr/bin/python #coding=utf-8 #@Time :2017/10/12 23:30 #@Auther :liuzhenchuan #@File :列表.py lis ...
- 查看远程分支的log
1 将远程分支的commit fetch到本地 git fetch 2 查看远程分支的log git log <remote-branch>
- plus.os.name 无法正确执行的问题
使用HTML5+开发App的时候, 如果碰到正确的代码却无法出现预期的执行效果, 请检查模块权限配置是否OK? 比如plus.os.name, 需要Device权限 ;
- Grunt学习笔记【3】---- filter使用方式和实现原理详解
本文主要讲配置任务中的filter,包括使用默认fs.Stats方法名和自定义过滤函数,以及filter的实现原理. 通过设置filter属性可以实现一些特殊处理逻辑.例如:要清理某个文件夹下的所有空 ...
- JavaScript 如何创建search字段
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 微信小程序配置详解
在之前已经通过微信公众平台的官方网站https://mp.weixin.qq.com/debug/wxadoc/dev/devtools/devtools.html,注册好小程序并且登录成功后(这里主 ...
- Java for LeetCode 100 Same Tree
Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ...
- EF异常捕捉
try{// 写数据库}catch (DbEntityValidationException dbEx){ }
- HDU4529 郑厂长系列故事——N骑士问题 —— 状压DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4529 郑厂长系列故事——N骑士问题 Time Limit: 6000/3000 MS (Java/Ot ...
- WCF异常处理
[读书笔记] 在进行分布式应用的异常处理时需要解决和考虑的基本要素: 异常的封装:服务端抛出的异常如何序列化传递到客户端 敏感信息的屏蔽:抛出的异常往往包含一些敏感的信息,直接将服务操作执行过程抛出的 ...