Add configurable binfmt support#357
Open
GlitchedCode922 wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
namefield allows setting a human-readable name for the entry. Thetypefield accepts either E (extension) or M (magic number) and selects the way the rule is parsed.offsetis used only for magic number rules, and makes matching start from a specified byte. For extensions, it is ignored. Themagicfield takes either the magic number, or the extension. Themaskfield makes some bits of the magic number ignored. Every bit of value 0 in mask makes the corresponding bit in magic be ignored.interpretersets 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. Themagic,maskandinterpreterfields 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
prootusing the option--binfmt-rules <path>, with the host-space path of the file.Notes:
PATHis ignored.$1and its path in$0.