libmagic(文件)数据库“使用”和“清除”类型

libmagic(文件)数据库“使用”和“清除”类型

我目前正在为 libmagic 数据库(由 file 命令使用)编写解析器,但没有找到有关“use”和“clear”类型(魔术文件中的第二列)的任何信息。
有人可以向我解释一下这种类型应该做什么吗?

答案1

这些都是相当新的功能,记录在magic(5):

use
从当前偏移量开始递归调用指定的 magic。如果引用的名称以 ^然后魔法的字节顺序被切换;如果提到魔法leshort例如,它被视为 beshort 反之亦然。这对于避免重复不同字节顺序的规则很有用。

clear
该测试始终为真,并清除该延续级别的匹配标志。它旨在与默认测试一起使用。

通过“相当新”:

2014-11-27 18:40 克里斯托·祖拉斯

    * Allow setting more parameters from the command line.
    * Split name/use and indirect magic recursion limits.

2013-04-22 11:20 克里斯托·祖拉斯

    * The way "default" was implemented was not very useful
      because the "if something was printed at that level"
      was not easily controlled by the user, and the format
      was bound to a string which is too restrictive. Add
      a "clear" for that level keyword and make "default"
      void. This way one can do:            

            >>13    clear   x
            >>13    lelong  1       foo
            >>13    lelong  2       bar
            >>13    default x
            >>>13   lelong  x       unknown %x 

相关内容