Continued from Page 1
Registering a binary format
The kernel has two ways of identifying a file as being of a particular binary format:
Magic numbers
A sequence of bytes that occur near the beginning of a binary file, and is unique for
every binary format. To identify a binary using this method, you must know the offset from
the beginning of the file from where the magic number begins, and what exactly the magic
number is. A good place to find out is "/usr/share/magic" and the
"magic" man page.
File name extensions
A simpler alternative is to identify a file format by its filename extension. While
this saves you from the hassle of finding out magic numbers, using magic numbers for
identification has the advantage that a file will be recognized even if it doesn’t
have the proper extension.
Every binary format that you want to use must be registered with the kernel, that is,
the kernel must be told how to identify the file format, and what interpreter to use for
it. This is done using the "/proc/sys/fs/binfmt_misc/register" file.
To register a file format, echo a string of the form:
:name:type:offset:magic:mask:
interpreter: to /proc/sys/fs/binfmt_ misc/register.
The fields are:
name The name by which this format will be identified.
type The method to use for recognizing the file format. This is "M"
for magic number, or "E" for extension.
offset Offset in bytes from the beginning of the file to the position where the
magic pattern begins.
magic The magic number, if you’re using magic numbers for recognition, or
the file extension otherwise.
mask Mask with which the magic number is bitwise ended. This defaults to all 1s.
interpreter The full path name of the program which should be invoked with the
name of the binary as the first argument.
Page(s) 1 2 3 |
|