1

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 ?

Gilles 'SO- stop being evil'
865k204 gold badges1.8k silver badges2.3k bronze badges
asked Dec 12, 2015 at 16:49

1 Answer 1

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 mentioned leshort for example, it is treated as beshort 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 
answered Dec 12, 2015 at 20:26
1
  • I checked the source (was curious...), saw it was documented as quoted, and found an up-to-date copy. Commented Dec 12, 2015 at 20:45

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.