binfmt_misc

from Wikipedia, the free encyclopedia

binfmt_misc is a capability of the Linux kernel to recognize any executable files and to transfer them to a specific program in user mode , such as an interpreter or a program starter that loads the program into the main memory.

It is an optional kernel module through which in principle any file can be executed as a program. This sets it apart from other techniques, for example the shebang mechanism.

The executable formats are stored in a central database- like form in a virtual file system , the so-called registry , which works in a similar way to devfs , procfs or sysfs . By default, this file system is at / proc / sys / fs / binfmt_misc involved .

Differentiation from other techniques

An alternative possibility that has a similar goal as binfmt_misc is the shebang mechanism. The interpreter with the character combination is #!specified in the first line of the file to be executed . This technique is very widespread on Unix derivatives , especially for scripts , but is also only suitable for text files .

The binfmt_misc technology, on the other hand, does not require any special identification in the file, so it does not (necessarily) have to be a pure text file. Because the association between files and interpreters is recorded in a system-wide central database, the problem of the storage location with the shebang mechanism could, for example, be solved.

Registration

The location of the association between file types and interpreters is the file register that directly in the root directory of the virtual binfmt_misc - file system is must. Since the binfmt_misc file system is usually mounted under / proc / sys / fs / binfmt_misc , the name of the file on most Linux systems is / proc / sys / fs / binfmt_misc / register . It is a text file in which each line is an entry that defines how executable files should be treated. Each line has the following form:

:name:type:offset:magic:mask:interpreter:

The fields are there

  • name for the file-wide unique name of the format, which is specified in this line
  • type for the way the file should be recognized. This field has a value of either E or M . If E is set, the executable file is recognized by its file extension , offset and mask are then ignored. The file extension of the file format must then be specifiedin the magic field. Conversely, if M is set, the executable file is recognized by bytes at the beginning of the file. magic is then the magic number that identifies the file and offset is the position at which the magic number can be found in the file. On mask is the bitwise AND with the characteristic string (in hex), the magic string used from the file: Unseeded bits are ignored in comparison to the magic .
  • interpreter for the path to a program . The path to the file to be executed is passed as an argument .

For each registered file type, binfmt_misc creates a file in the virtual file system. This file can be read later for information about the file format.

use

Thanks to binfmt_misc, CLI and Java applications can be passed directly to the correct interpreter and thus started directly via the shell or by other programs.

It is also common practice to run Portable Executable files (files with the extensions .exe and .dll that have been compiled for MS-DOS or Microsoft Windows ) in Wine this way . The following line would then be noted in the registration file :

:DOSWin:M::MZ::/usr/bin/wine:

The file type of a portable executable is recognized by the magic string MZ in the type_code and the file is executed with the Windows runtime environment.

Web links