See the following testing:
See the following testing:
$ dd if=/usr/bin/find bs=1 count=2 2>/dev/null |od -bc
0000000 177 105
177 E
0000002
$ dd if=/usr/bin/ls bs=1 count=2 2>/dev/null |od -bc
0000000 177 105
177 E
0000002
$ ascii -t \# \!
2/3 35 0x23 0o43 00100011
2/1 33 0x21 0o41 00100001
So, it seems that for a non-script executable file, the magic number is always the following sequence:
$ ascii -t o177 o105
7/15 127 0x7F 0o177 01111111
4/5 69 0x45 0o105 01000101
Amy I right?
So, it seems that for a non-script executable file, the magic number is always the following sequence:
$ ascii -t o177 o105
7/15 127 0x7F 0o177 01111111
4/5 69 0x45 0o105 01000101
Amy I right?
On Fri, 17 Sep 2021 19:54:42 -0400, hongy...@gmail.com <hongy...@gmail.com> wrote:
So, it seems that for a non-script executable file, the magic number is always the following sequence:
$ ascii -t o177 o105
7/15 127 0x7F 0o177 01111111
4/5 69 0x45 0o105 01000101
Amy I right?See https://wiki.osdev.org/ELF#Header
"hongy...@gmail.com" <hongyi.zhao@gmail.com> writes:
See the following testing:
$ dd if=/usr/bin/find bs=1 count=2 2>/dev/null |od -bc
0000000 177 105
177 E
0000002
$ dd if=/usr/bin/ls bs=1 count=2 2>/dev/null |od -bc
0000000 177 105
177 E
0000002
$ ascii -t \# \!
2/3 35 0x23 0o43 00100011
2/1 33 0x21 0o41 00100001
So, it seems that for a non-script executable file, the magic number is always
the following sequence:
$ ascii -t o177 o105
7/15 127 0x7F 0o177 01111111
4/5 69 0x45 0o105 01000101
Amy I right?
You seem to be assuming that a file's "magic number" is always 2 bytes.
man 5 elf
On Fri, 17 Sep 2021 18:32:49 -0700, Keith Thompson wrote:
"hongy...@gmail.com" <hongyi.zhao@gmail.com> writes:
See the following testing:
$ dd if=/usr/bin/find bs=1 count=2 2>/dev/null |od -bc
0000000 177 105
177 E
0000002
$ dd if=/usr/bin/ls bs=1 count=2 2>/dev/null |od -bc
0000000 177 105
177 E
0000002
$ ascii -t \# \!
2/3 35 0x23 0o43 00100011
2/1 33 0x21 0o41 00100001
So, it seems that for a non-script executable file, the magic number is always
the following sequence:
$ ascii -t o177 o105
7/15 127 0x7F 0o177 01111111
4/5 69 0x45 0o105 01000101
Amy I right?
You seem to be assuming that a file's "magic number" is always 2 bytes.
man 5 elf
Hongy also seems to be assuming that a "non-script executable file" only consists of an ELF executable. Under Linux, this is not true, as almost
/any/ file can be executed using the binfmt_misc facility. This facility allows the sysop to define new "magic numbers" for "non-script executable" files (such as a+x WAV files, or a+x pdf files) and the interpreter that
the kernel will automagically invoke to execute that sort of file.
See /usr/src/linux/Documentation/binfmt_misc.txt for details, or https://linuxgazette.net/118/lg_tips.html#tips.2 for my short summary.
Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:
On Sat, 18 Sep 2021 15:36:14 +0000, Lew Pitcher wrote:
Hongy also seems to be assuming that a "non-script executable file" only >>> consists of an ELF executable. Under Linux, this is not true, as almost
/any/ file can be executed using the binfmt_misc facility. This facility >>> allows the sysop to define new "magic numbers" for "non-script executable" >>> files (such as a+x WAV files, or a+x pdf files) and the interpreter that >>> the kernel will automagically invoke to execute that sort of file.
See /usr/src/linux/Documentation/binfmt_misc.txt for details, or
https://linuxgazette.net/118/lg_tips.html#tips.2 for my short summary.
Example of binfmt_misc use:
As root:
mount -t binfmt_misc none /proc/sys/fs/binfmt_misc
echo :audio:M::RIFF::/usr/bin/paplay: >/proc/sys/fs/binfmt_misc/register >>
As user:
12:56 $ ls -l HELLO.WAV
-rw-r--r-- 1 lpitcher users 25956 Feb 23 2020 HELLO.WAV
12:56 $ chmod a+x HELLO.WAV
12:56 $ ./HELLO.WAV
(audio file HELLO.WAV plays on speakers)
Some of the cases could be argued to be scripts and not "non-script executable files". Here, the audio player can be seen as an interpreter
for a sound script!
On Sat, 18 Sep 2021 15:36:14 +0000, Lew Pitcher wrote:
Hongy also seems to be assuming that a "non-script executable file" only
consists of an ELF executable. Under Linux, this is not true, as almost
/any/ file can be executed using the binfmt_misc facility. This facility
allows the sysop to define new "magic numbers" for "non-script executable" >> files (such as a+x WAV files, or a+x pdf files) and the interpreter that
the kernel will automagically invoke to execute that sort of file.
See /usr/src/linux/Documentation/binfmt_misc.txt for details, or
https://linuxgazette.net/118/lg_tips.html#tips.2 for my short summary.
Example of binfmt_misc use:
As root:
mount -t binfmt_misc none /proc/sys/fs/binfmt_misc
echo :audio:M::RIFF::/usr/bin/paplay: >/proc/sys/fs/binfmt_misc/register
As user:
12:56 $ ls -l HELLO.WAV
-rw-r--r-- 1 lpitcher users 25956 Feb 23 2020 HELLO.WAV
12:56 $ chmod a+x HELLO.WAV
12:56 $ ./HELLO.WAV
(audio file HELLO.WAV plays on speakers)
On Sat, 18 Sep 2021 23:06:05 +0100, Ben Bacarisse wrote:
Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:
On Sat, 18 Sep 2021 15:36:14 +0000, Lew Pitcher wrote:
Hongy also seems to be assuming that a "non-script executable file" only >>>> consists of an ELF executable. Under Linux, this is not true, as almost >>>> /any/ file can be executed using the binfmt_misc facility. This facility >>>> allows the sysop to define new "magic numbers" for "non-script executable" >>>> files (such as a+x WAV files, or a+x pdf files) and the interpreter that >>>> the kernel will automagically invoke to execute that sort of file.
See /usr/src/linux/Documentation/binfmt_misc.txt for details, or
https://linuxgazette.net/118/lg_tips.html#tips.2 for my short summary.
Example of binfmt_misc use:
As root:
mount -t binfmt_misc none /proc/sys/fs/binfmt_misc
echo :audio:M::RIFF::/usr/bin/paplay: >/proc/sys/fs/binfmt_misc/register
As user:
12:56 $ ls -l HELLO.WAV
-rw-r--r-- 1 lpitcher users 25956 Feb 23 2020 HELLO.WAV
12:56 $ chmod a+x HELLO.WAV
12:56 $ ./HELLO.WAV
(audio file HELLO.WAV plays on speakers)
Some of the cases could be argued to be scripts and not "non-script
executable files". Here, the audio player can be seen as an interpreter
for a sound script!
Ahhh, but not a script in the usual Unix sense of the word.
Given your proposed interpretation, then even ELF files become scripts, "interpreted" by ld.so. After all, the binfmt_misc process is exactly
what happens under the (kernel) covers when exec() invokes an ELF
file.
So, perhaps /all/ executables are "scripts" of some sort.
Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:
On Sat, 18 Sep 2021 23:06:05 +0100, Ben Bacarisse wrote:
Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:
On Sat, 18 Sep 2021 15:36:14 +0000, Lew Pitcher wrote:
Hongy also seems to be assuming that a "non-script executable file" only >>>>> consists of an ELF executable. Under Linux, this is not true, as almost >>>>> /any/ file can be executed using the binfmt_misc facility. This facility >>>>> allows the sysop to define new "magic numbers" for "non-script executable"Example of binfmt_misc use:
files (such as a+x WAV files, or a+x pdf files) and the interpreter that >>>>> the kernel will automagically invoke to execute that sort of file.
See /usr/src/linux/Documentation/binfmt_misc.txt for details, or
https://linuxgazette.net/118/lg_tips.html#tips.2 for my short summary. >>>>
As root:
mount -t binfmt_misc none /proc/sys/fs/binfmt_misc
echo :audio:M::RIFF::/usr/bin/paplay: >/proc/sys/fs/binfmt_misc/register
As user:
12:56 $ ls -l HELLO.WAV
-rw-r--r-- 1 lpitcher users 25956 Feb 23 2020 HELLO.WAV
12:56 $ chmod a+x HELLO.WAV
12:56 $ ./HELLO.WAV
(audio file HELLO.WAV plays on speakers)
Some of the cases could be argued to be scripts and not "non-script
executable files". Here, the audio player can be seen as an interpreter >>> for a sound script!
Ahhh, but not a script in the usual Unix sense of the word.
Oh, sure. I was stretching the term, but I do think "data interpreted
by some other running program" is a reasonable extension to the idea.
Given your proposed interpretation, then even ELF files become scripts,
"interpreted" by ld.so. After all, the binfmt_misc process is exactly
what happens under the (kernel) covers when exec() invokes an ELF
file.
Surely control eventually transfers to the code?
The "data", once
loaded and resolved, are executable by the hardware. That's the core distinction, isn't it?
So, perhaps /all/ executables are "scripts" of some sort.
On Fri, 17 Sep 2021 18:32:49 -0700, Keith Thompson wrote:
"hongy...@gmail.com" <hongy...@gmail.com> writes:
See the following testing:
$ dd if=/usr/bin/find bs=1 count=2 2>/dev/null |od -bc
0000000 177 105
177 E
0000002
$ dd if=/usr/bin/ls bs=1 count=2 2>/dev/null |od -bc
0000000 177 105
177 E
0000002
$ ascii -t \# \!
2/3 35 0x23 0o43 00100011
2/1 33 0x21 0o41 00100001
So, it seems that for a non-script executable file, the magic number is always
the following sequence:
$ ascii -t o177 o105
7/15 127 0x7F 0o177 01111111
4/5 69 0x45 0o105 01000101
Amy I right?
You seem to be assuming that a file's "magic number" is always 2 bytes.
man 5 elfHongy also seems to be assuming that a "non-script executable file" only consists of an ELF executable. Under Linux, this is not true, as almost
/any/ file can be executed using the binfmt_misc facility. This facility allows the sysop to define new "magic numbers" for "non-script executable" files (such as a+x WAV files, or a+x pdf files) and the interpreter that
the kernel will automagically invoke to execute that sort of file.
See /usr/src/linux/Documentation/binfmt_misc.txt for details,
or
https://linuxgazette.net/118/lg_tips.html#tips.2 for my short summary.
On Sat, 18 Sep 2021 15:36:14 +0000, Lew Pitcher wrote:
On Fri, 17 Sep 2021 18:32:49 -0700, Keith Thompson wrote:
"hongy...@gmail.com" <hongy...@gmail.com> writes:
See the following testing:
$ dd if=/usr/bin/find bs=1 count=2 2>/dev/null |od -bc
0000000 177 105
177 E
0000002
$ dd if=/usr/bin/ls bs=1 count=2 2>/dev/null |od -bc
0000000 177 105
177 E
0000002
$ ascii -t \# \!
2/3 35 0x23 0o43 00100011
2/1 33 0x21 0o41 00100001
So, it seems that for a non-script executable file, the magic number is always
the following sequence:
$ ascii -t o177 o105
7/15 127 0x7F 0o177 01111111
4/5 69 0x45 0o105 01000101
Amy I right?
You seem to be assuming that a file's "magic number" is always 2 bytes.
man 5 elf
Hongy also seems to be assuming that a "non-script executable file" only consists of an ELF executable. Under Linux, this is not true, as almost /any/ file can be executed using the binfmt_misc facility. This facility allows the sysop to define new "magic numbers" for "non-script executable" files (such as a+x WAV files, or a+x pdf files) and the interpreter that the kernel will automagically invoke to execute that sort of file.
See /usr/src/linux/Documentation/binfmt_misc.txt for details, or https://linuxgazette.net/118/lg_tips.html#tips.2 for my short summary.Example of binfmt_misc use:
As root:
mount -t binfmt_misc none /proc/sys/fs/binfmt_misc
echo :audio:M::RIFF::/usr/bin/paplay: >/proc/sys/fs/binfmt_misc/register
As user:
12:56 $ ls -l HELLO.WAV
-rw-r--r-- 1 lpitcher users 25956 Feb 23 2020 HELLO.WAV
12:56 $ chmod a+x HELLO.WAV
12:56 $ ./HELLO.WAV
(audio file HELLO.WAV plays on speakers)
--
Lew Pitcher
"In Skills, We Trust"
On Saturday, September 18, 2021 at 11:36:19 PM UTC+8, Lew Pitcher wrote:[snip]
Hongy also seems to be assuming that a "non-script executable file" only
consists of an ELF executable. Under Linux, this is not true, as almost
/any/ file can be executed using the binfmt_misc facility. This facility
allows the sysop to define new "magic numbers" for "non-script executable" >> files (such as a+x WAV files, or a+x pdf files) and the interpreter that
the kernel will automagically invoke to execute that sort of file.
See /usr/src/linux/Documentation/binfmt_misc.txt for details,
$ ls /usr/src/linux/Documentation/binfmt_misc.txt
ls: cannot access '/usr/src/linux/Documentation/binfmt_misc.txt': No such file or directory
or
https://linuxgazette.net/118/lg_tips.html#tips.2 for my short summary.
Thank you for your wonderful and elaborate tips.
On Sunday, September 19, 2021 at 12:58:06 AM UTC+8, Lew Pitcher wrote:
On Sat, 18 Sep 2021 15:36:14 +0000, Lew Pitcher wrote:
On Fri, 17 Sep 2021 18:32:49 -0700, Keith Thompson wrote:Example of binfmt_misc use:
"hongy...@gmail.com" <hongy...@gmail.com> writes:
See the following testing:
$ dd if=/usr/bin/find bs=1 count=2 2>/dev/null |od -bc
0000000 177 105
177 E
0000002
$ dd if=/usr/bin/ls bs=1 count=2 2>/dev/null |od -bc
0000000 177 105
177 E
0000002
$ ascii -t \# \!
2/3 35 0x23 0o43 00100011
2/1 33 0x21 0o41 00100001
So, it seems that for a non-script executable file, the magic number is always
the following sequence:
$ ascii -t o177 o105
7/15 127 0x7F 0o177 01111111
4/5 69 0x45 0o105 01000101
Amy I right?
You seem to be assuming that a file's "magic number" is always 2 bytes. >> >>
man 5 elf
Hongy also seems to be assuming that a "non-script executable file" only >> > consists of an ELF executable. Under Linux, this is not true, as almost
/any/ file can be executed using the binfmt_misc facility. This facility >> > allows the sysop to define new "magic numbers" for "non-script executable" >> > files (such as a+x WAV files, or a+x pdf files) and the interpreter that >> > the kernel will automagically invoke to execute that sort of file.
See /usr/src/linux/Documentation/binfmt_misc.txt for details, or
https://linuxgazette.net/118/lg_tips.html#tips.2 for my short summary.
As root:
mount -t binfmt_misc none /proc/sys/fs/binfmt_misc
echo :audio:M::RIFF::/usr/bin/paplay: >/proc/sys/fs/binfmt_misc/register
$ sudo mount -t binfmt_misc none /proc/sys/fs/binfmt_misc
mount: /proc/sys/fs/binfmt_misc: none already mounted on /sys/fs/bpf.
On Sat, 18 Sep 2021 17:00:56 -0700, hongy...@gmail.com wrote:
On Saturday, September 18, 2021 at 11:36:19 PM UTC+8, Lew Pitcher wrote:[snip]
Hongy also seems to be assuming that a "non-script executable file" only >>> consists of an ELF executable. Under Linux, this is not true, as almost
/any/ file can be executed using the binfmt_misc facility. This facility >>> allows the sysop to define new "magic numbers" for "non-script executable" >>> files (such as a+x WAV files, or a+x pdf files) and the interpreter that >>> the kernel will automagically invoke to execute that sort of file.
See /usr/src/linux/Documentation/binfmt_misc.txt for details,
$ ls /usr/src/linux/Documentation/binfmt_misc.txt
ls: cannot access '/usr/src/linux/Documentation/binfmt_misc.txt': No such file or directory
Did you install the appropriate kernel source code?
/usr/src/linux usually symlinks to the Linux kernel source code (which is named with the full kernel version, something like /usr/src/linux-4.4.276) and the Documentation subdirectory of that source code directory contains
the binfmt_misc.txt file.
If you don't want to install the kernel source code, you might look at
https://lwn.net/Articles/679310/
which contains a version of the binfmt_misc.txt file
or
https://linuxgazette.net/118/lg_tips.html#tips.2 for my short summary.
Thank you for your wonderful and elaborate tips.
You're welcome
If you don't want to install the kernel source code, you might look at
https://lwn.net/Articles/679310/
which contains a version of the binfmt_misc.txt file
On Sun, 19 Sep 2021 14:42:14 -0000 (UTC)
Lew Pitcher <lew.pitcher@digitalfreehold.ca> wrote:
If you don't want to install the kernel source code, you might look at
https://lwn.net/Articles/679310/
which contains a version of the binfmt_misc.txt file
There is also man update-binfmts
On Sat, 18 Sep 2021 23:29:54 +0100, Ben Bacarisse wrote:
Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:
On Sat, 18 Sep 2021 23:06:05 +0100, Ben Bacarisse wrote:
Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:
On Sat, 18 Sep 2021 15:36:14 +0000, Lew Pitcher wrote:
Hongy also seems to be assuming that a "non-script executable file" only >>>>>> consists of an ELF executable. Under Linux, this is not true, as almost >>>>>> /any/ file can be executed using the binfmt_misc facility. This facility >>>>>> allows the sysop to define new "magic numbers" for "non-script executable"Example of binfmt_misc use:
files (such as a+x WAV files, or a+x pdf files) and the interpreter that >>>>>> the kernel will automagically invoke to execute that sort of file. >>>>>>
See /usr/src/linux/Documentation/binfmt_misc.txt for details, or
https://linuxgazette.net/118/lg_tips.html#tips.2 for my short summary. >>>>>
As root:
mount -t binfmt_misc none /proc/sys/fs/binfmt_misc
echo :audio:M::RIFF::/usr/bin/paplay: >/proc/sys/fs/binfmt_misc/register
As user:
12:56 $ ls -l HELLO.WAV
-rw-r--r-- 1 lpitcher users 25956 Feb 23 2020 HELLO.WAV
12:56 $ chmod a+x HELLO.WAV
12:56 $ ./HELLO.WAV
(audio file HELLO.WAV plays on speakers)
Some of the cases could be argued to be scripts and not "non-script
executable files". Here, the audio player can be seen as an interpreter >>>> for a sound script!
Ahhh, but not a script in the usual Unix sense of the word.
Oh, sure. I was stretching the term, but I do think "data interpreted
by some other running program" is a reasonable extension to the idea.
Given your proposed interpretation, then even ELF files become scripts,
"interpreted" by ld.so. After all, the binfmt_misc process is exactly
what happens under the (kernel) covers when exec() invokes an ELF
file.
Surely control eventually transfers to the code?
With ld.so, yes. But that's not a /requirement/.
The "data", once
loaded and resolved, are executable by the hardware. That's the core
distinction, isn't it?
ELF files aren't binary images; they contain a large number of data
elements that need external processing to resolve into executable
binary data. ld.so provides that external processing, interpreting
elements (such as relocation and external linkage tables) in order
to prepare an executable binary. Even then, the whole "program"
isn't loaded directly into memory; ld.so handles page-fault requests, providing binary image data for pages to be demand-loaded. Even the
error messages from ld.so ("Bad ELF interpreter") call ld.so an "interpreter".
On Mon, 20 Sep 2021 00:50:29 +0100, Ben Bacarisse wrote:
Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:
On Sat, 18 Sep 2021 23:29:54 +0100, Ben Bacarisse wrote:
Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:
On Sat, 18 Sep 2021 23:06:05 +0100, Ben Bacarisse wrote:
Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:
On Sat, 18 Sep 2021 15:36:14 +0000, Lew Pitcher wrote:
Hongy also seems to be assuming that a "non-script executable file" onlyExample of binfmt_misc use:
consists of an ELF executable. Under Linux, this is not true, as almost
/any/ file can be executed using the binfmt_misc facility. This facility
allows the sysop to define new "magic numbers" for "non-script executable"
files (such as a+x WAV files, or a+x pdf files) and the interpreter that
the kernel will automagically invoke to execute that sort of file. >>>>>>>>
See /usr/src/linux/Documentation/binfmt_misc.txt for details, or >>>>>>>> https://linuxgazette.net/118/lg_tips.html#tips.2 for my short summary. >>>>>>>
As root:
mount -t binfmt_misc none /proc/sys/fs/binfmt_misc
echo :audio:M::RIFF::/usr/bin/paplay: >/proc/sys/fs/binfmt_misc/register
As user:
12:56 $ ls -l HELLO.WAV
-rw-r--r-- 1 lpitcher users 25956 Feb 23 2020 HELLO.WAV
12:56 $ chmod a+x HELLO.WAV
12:56 $ ./HELLO.WAV
(audio file HELLO.WAV plays on speakers)
Some of the cases could be argued to be scripts and not "non-script >>>>>> executable files". Here, the audio player can be seen as an interpreter >>>>>> for a sound script!
Ahhh, but not a script in the usual Unix sense of the word.
Oh, sure. I was stretching the term, but I do think "data interpreted >>>> by some other running program" is a reasonable extension to the idea.
Given your proposed interpretation, then even ELF files become scripts, >>>>> "interpreted" by ld.so. After all, the binfmt_misc process is exactly >>>>> what happens under the (kernel) covers when exec() invokes an ELF
file.
Surely control eventually transfers to the code?
With ld.so, yes. But that's not a /requirement/.
The "data", once
loaded and resolved, are executable by the hardware. That's the core
distinction, isn't it?
ELF files aren't binary images; they contain a large number of data
elements that need external processing to resolve into executable
binary data. ld.so provides that external processing, interpreting
elements (such as relocation and external linkage tables) in order
to prepare an executable binary. Even then, the whole "program"
isn't loaded directly into memory; ld.so handles page-fault requests,
providing binary image data for pages to be demand-loaded. Even the
error messages from ld.so ("Bad ELF interpreter") call ld.so an
"interpreter".
So what characterises the distinction you were using between script and
non-script executable files when you proposed sound files as an example
of the latter?
I agree it's woolly, but if you don't like my take on it, where is your
line?
TBH, I don't really /have/ a line. If I were pressed, I might say that I
make a distinction between executables that use the "shebang", and executables that do not. To me (my personal opinion) a "shebang" clearly indicates a "script".
Just my (friendly) 2 cents worth
TBH, I don't really /have/ a line. If I were pressed, I might say that I
make a distinction between executables that use the "shebang", and executables that do not. To me (my personal opinion) a "shebang" clearly indicates a "script".
Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:
On Sat, 18 Sep 2021 23:29:54 +0100, Ben Bacarisse wrote:
Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:
On Sat, 18 Sep 2021 23:06:05 +0100, Ben Bacarisse wrote:
Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:
On Sat, 18 Sep 2021 15:36:14 +0000, Lew Pitcher wrote:
Hongy also seems to be assuming that a "non-script executable file" onlyExample of binfmt_misc use:
consists of an ELF executable. Under Linux, this is not true, as almost >>>>>>> /any/ file can be executed using the binfmt_misc facility. This facility
allows the sysop to define new "magic numbers" for "non-script executable"
files (such as a+x WAV files, or a+x pdf files) and the interpreter that
the kernel will automagically invoke to execute that sort of file. >>>>>>>
See /usr/src/linux/Documentation/binfmt_misc.txt for details, or >>>>>>> https://linuxgazette.net/118/lg_tips.html#tips.2 for my short summary. >>>>>>
As root:
mount -t binfmt_misc none /proc/sys/fs/binfmt_misc
echo :audio:M::RIFF::/usr/bin/paplay: >/proc/sys/fs/binfmt_misc/register
As user:
12:56 $ ls -l HELLO.WAV
-rw-r--r-- 1 lpitcher users 25956 Feb 23 2020 HELLO.WAV
12:56 $ chmod a+x HELLO.WAV
12:56 $ ./HELLO.WAV
(audio file HELLO.WAV plays on speakers)
Some of the cases could be argued to be scripts and not "non-script
executable files". Here, the audio player can be seen as an interpreter >>>>> for a sound script!
Ahhh, but not a script in the usual Unix sense of the word.
Oh, sure. I was stretching the term, but I do think "data interpreted
by some other running program" is a reasonable extension to the idea.
Given your proposed interpretation, then even ELF files become scripts, >>>> "interpreted" by ld.so. After all, the binfmt_misc process is exactly
what happens under the (kernel) covers when exec() invokes an ELF
file.
Surely control eventually transfers to the code?
With ld.so, yes. But that's not a /requirement/.
The "data", once
loaded and resolved, are executable by the hardware. That's the core
distinction, isn't it?
ELF files aren't binary images; they contain a large number of data
elements that need external processing to resolve into executable
binary data. ld.so provides that external processing, interpreting
elements (such as relocation and external linkage tables) in order
to prepare an executable binary. Even then, the whole "program"
isn't loaded directly into memory; ld.so handles page-fault requests,
providing binary image data for pages to be demand-loaded. Even the
error messages from ld.so ("Bad ELF interpreter") call ld.so an
"interpreter".
So what characterises the distinction you were using between script and non-script executable files when you proposed sound files as an example
of the latter?
I agree it's woolly, but if you don't like my take on it, where is your
line?
On Sun, 19 Sep 2021 21:26:54 -0400, Lew Pitcher <lew.pitcher@digitalfreehold.ca> wrote:
TBH, I don't really /have/ a line. If I were pressed, I might say that I
make a distinction between executables that use the "shebang", and
executables that do not. To me (my personal opinion) a "shebang" clearly
indicates a "script".
Based on what I've been taught ...
A program contains machine language instructions (and some data),
usually created by
an assembler, and if needed, a compiler. It usually uses a dynamic
linker to patch
in addresses needed for relocation and handle segment loading, but
otherwise is
processed directly by the cpu.
A script is interpreted as it's executed. The interpreter generates the machine
language instructions dynamically, based on the contents of the script.
The hashbang
just allows automatic selection of the interpreter to use when selecting
the file for
processing. Some interpreters allow the generated machine language to
be stored for
later execution. Those compiled scripts are now programs.
While binfmt allows a data file to include automatic resolution of what program or
interpreter to use allowing clicking on the file, the data file does not contain
any machine instructions. It's still just data.
On Sat, 18 Sep 2021 17:00:56 -0700, hongy...@gmail.com wrote:
On Saturday, September 18, 2021 at 11:36:19 PM UTC+8, Lew Pitcher wrote:[snip]
Hongy also seems to be assuming that a "non-script executable file" only >> consists of an ELF executable. Under Linux, this is not true, as almost
/any/ file can be executed using the binfmt_misc facility. This facility >> allows the sysop to define new "magic numbers" for "non-script executable" >> files (such as a+x WAV files, or a+x pdf files) and the interpreter that >> the kernel will automagically invoke to execute that sort of file.
See /usr/src/linux/Documentation/binfmt_misc.txt for details,
$ ls /usr/src/linux/Documentation/binfmt_misc.txtDid you install the appropriate kernel source code?
ls: cannot access '/usr/src/linux/Documentation/binfmt_misc.txt': No such file or directory
/usr/src/linux usually symlinks to the Linux kernel source code (which is named with the full kernel version, something like /usr/src/linux-4.4.276) and the Documentation subdirectory of that source code directory contains
the binfmt_misc.txt file.
If you don't want to install the kernel source code, you might look at https://lwn.net/Articles/679310/
which contains a version of the binfmt_misc.txt file
or
https://linuxgazette.net/118/lg_tips.html#tips.2 for my short summary.
Thank you for your wonderful and elaborate tips.You're welcome
--
Lew Pitcher
"In Skills, We Trust"
On 19/09/2021 03:42 pm, Lew Pitcher wrote:
On Sat, 18 Sep 2021 17:00:56 -0700, hongy...@gmail.com wrote:
On Saturday, September 18, 2021 at 11:36:19 PM UTC+8, Lew Pitcher wrote:[snip]
Hongy also seems to be assuming that a "non-script executable file" only >>> consists of an ELF executable. Under Linux, this is not true, as almost >>> /any/ file can be executed using the binfmt_misc facility. This facility >>> allows the sysop to define new "magic numbers" for "non-script executable"
files (such as a+x WAV files, or a+x pdf files) and the interpreter that >>> the kernel will automagically invoke to execute that sort of file.
See /usr/src/linux/Documentation/binfmt_misc.txt for details,
$ ls /usr/src/linux/Documentation/binfmt_misc.txt
ls: cannot access '/usr/src/linux/Documentation/binfmt_misc.txt': No such file or directory
Did you install the appropriate kernel source code?
/usr/src/linux usually symlinks to the Linux kernel source code (which is named with the full kernel version, something like /usr/src/linux-4.4.276) and the Documentation subdirectory of that source code directory contains the binfmt_misc.txt file.I found :
/usr/src/linux-5.13.13/Documentation/admin-guide/binfmt-misc.rst
If you don't want to install the kernel source code, you might look at https://lwn.net/Articles/679310/
which contains a version of the binfmt_misc.txt file
or
https://linuxgazette.net/118/lg_tips.html#tips.2 for my short summary.
Thank you for your wonderful and elaborate tips.
You're welcome
--
Chris Elvidge
England
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 296 |
Nodes: | 16 (2 / 14) |
Uptime: | 50:34:08 |
Calls: | 6,649 |
Calls today: | 1 |
Files: | 12,200 |
Messages: | 5,330,212 |