binfmt.d - Linux
Overview
binfmt.d is a configuration directory for setting up support for different binary file formats in Linux. It allows you to register interpreters and handlers for specific binary file types, enabling seamless execution of executables from various platforms or architectures.
Syntax
/proc/sys/fs/binfmt_misc/register
or
echo 'interpreter :flags :magic' > /proc/sys/fs/binfmt_misc/register
Options/Flags
- interpreter: Path to the interpreter binary for the specific file format.
- flags: Optional flags to modify the interpreter’s behavior (e.g.,
S
for setting uid/gid). - magic: Hexadecimal value representing the magic number or identifier for the file format.
Examples
Example 1: Registering an interpreter for ELF executables
echo '/usr/bin/qemu-arm-static :S 0x7f454c4602010100' > /proc/sys/fs/binfmt_misc/register
Example 2: Unregistering an interpreter
echo -n '' > /proc/sys/fs/binfmt_misc/register
Common Issues
- Missing interpreter: Ensure the path to the interpreter binary is correct in the registration file.
- Incorrect magic number: Verify that the magic number specified in the registration matches the target file format.
- Permissions: Ensure that the registration file has the correct permissions to be written to by the system.
Integration
binfmt.d integrates with the Linux kernel’s file system support. It enables the execution of foreign binaries by modifying the kernel’s execve system call.
Related Commands
- file: Determine the type of a file.
- strings: Extract strings from binary files.
- objdump: Display the contents of object files.