Skip to content

Add configurable binfmt support#357

Open
GlitchedCode922 wants to merge 1 commit into
termux:masterfrom
GlitchedCode922:binfmt
Open

Add configurable binfmt support#357
GlitchedCode922 wants to merge 1 commit into
termux:masterfrom
GlitchedCode922:binfmt

Conversation

@GlitchedCode922
Copy link
Copy Markdown

@GlitchedCode922 GlitchedCode922 commented May 20, 2026

This PR adds support for registering and executing custom binary formats, similar to Linux's binfmt_misc.
Adding formats is done using a configuration file, accepting entries of this format:
:name:type:offset:magic:mask:interpreter:
The name field allows setting a human-readable name for the entry. The type field accepts either E (extension) or M (magic number) and selects the way the rule is parsed. offset is used only for magic number rules, and makes matching start from a specified byte. For extensions, it is ignored. The magic field takes either the magic number, or the extension. The mask field makes some bits of the magic number ignored. Every bit of value 0 in mask makes the corresponding bit in magic be ignored. interpreter sets the path of the program to be called when a matching file is executed. Options are not supported, and any spaces will be parsed as part of the interpreter path. To use options, other arguments etc, use a wrapper script or binary. The magic, mask and interpreter fields support those escape sequences: \n: newline, \t: tab, \r: carriage return, \x: hex byte (followed by 2 characters 0-F), \\: backslash.
Here is an example for each entry type:
Extension: :java-jar:E:0:.jar:0:/usr/bin/java-jar:
Magic number: :x86-elf:M:0:\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x3e\x00:\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff:/usr/local/bin/box64:
The configuration file is passed to proot using the option --binfmt-rules <path>, with the host-space path of the file.
Notes:

  • Shebangs will take precedence over binfmt formats. - Full paths to the interpreter in proot-space are required, PATH is ignored.
  • The interpreter will be called with the binary path in $1 and its path in $0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant