To actually register a new binary type, we have to set up a string like:
:name:type:offset:magic:mask:interpreter:
and echo it to /proc/sys/fs/binfmt_misc/register. We can choose
the : character upon our needs and we can omit a field by simply
using an empty string; for example if we omit the offset and the mask
fields:
:name:type::magic::interpreter:
Fields description follows.
nametypeM activates first
bytes recognition (also known as “magic” recognition); if set to
E activates file name extension recognition.
offsetmagicbinfmt_misc will look for file
recognition.
The magic string may contain hex–encoded characters like \x0a or
\xA4. When echoing the record from a shell environment, we will
have to quote the backslash: \\x0a.
If we chose filename extension matching, this is the extension to be
recognised (without the ., the \x0a specials are not
allowed). Extension matching is case sensitive.
maskmagic. The mask is ANDed with the
byte sequence from the file. It defaults to 0xff.
interpreterThere are some restrictions:
offset+size(magic) has to be less than 128.