I am currently writing a parser for the libmagic database (used by the file command) and i don't found any information on the 'use' and 'clear' type (second column in the magic file).
Can someone explain to me what this types should do ?
1 Answer 1
Those are fairly new features, documented in magic(5)
:
use
Recursively call the named magic starting from the current offset. If the name of the referenced begins with a^
then the endianness of the magic is switched; if the magic mentionedleshort
for example, it is treated asbeshort
and vice versa. This is useful to avoid duplicating the rules for different endianness.
clear
This test is always true and clears the match flag for that continuation level. It is intended to be used with the default test.
By "fairly new":
2014年11月27日 18:40 Christos Zoulas
* Allow setting more parameters from the command line.
* Split name/use and indirect magic recursion limits.
2013年04月22日 11:20 Christos Zoulas
* 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
-
I checked the source (was curious...), saw it was documented as quoted, and found an up-to-date copy.Thomas Dickey– Thomas Dickey2015年12月12日 20:45:01 +00:00Commented Dec 12, 2015 at 20:45