Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

The test of intelligent tinkering is to save all the parts. -- Aldo Leopold


devel / comp.unix.shell / Check the hashbang (magic number) in a executable file.

SubjectAuthor
* Check the hashbang (magic number) in a executable file.hongy...@gmail.com
+- Re: Check the hashbang (magic number) in a executable file.Eli the Bearded
+* Re: Check the hashbang (magic number) in a executable file.Keith Thompson
|`* Re: Check the hashbang (magic number) in a executable file.Lew Pitcher
| +* Re: Check the hashbang (magic number) in a executable file.Lew Pitcher
| |+* Re: Check the hashbang (magic number) in a executable file.Ben Bacarisse
| ||`* Re: Check the hashbang (magic number) in a executable file.Lew Pitcher
| || `* Re: Check the hashbang (magic number) in a executable file.Ben Bacarisse
| ||  `* Re: Check the hashbang (magic number) in a executable file.Lew Pitcher
| ||   `* Re: Check the hashbang (magic number) in a executable file.Ben Bacarisse
| ||    `* Re: Check the hashbang (magic number) in a executable file.Lew Pitcher
| ||     +- Re: Check the hashbang (magic number) in a executable file.Lew Pitcher
| ||     `* Re: Check the hashbang (magic number) in a executable file.David W. Hodgins
| ||      `- Re: Check the hashbang (magic number) in a executable file.Janis Papanagnou
| |`* Re: Check the hashbang (magic number) in a executable file.hongy...@gmail.com
| | `- Re: Check the hashbang (magic number) in a executable file.Lew Pitcher
| `* Re: Check the hashbang (magic number) in a executable file.hongy...@gmail.com
|  `* Re: Check the hashbang (magic number) in a executable file.Lew Pitcher
|   +* Re: Check the hashbang (magic number) in a executable file.Chris Elvidge
|   |+- Re: Check the hashbang (magic number) in a executable file.David W. Hodgins
|   |`- Re: Check the hashbang (magic number) in a executable file.hongy...@gmail.com
|   +* Re: Check the hashbang (magic number) in a executable file.Spiros Bousbouras
|   |`- Re: Check the hashbang (magic number) in a executable file.Kenny McCormack
|   `- Re: Check the hashbang (magic number) in a executable file.hongy...@gmail.com
`* Re: Check the hashbang (magic number) in a executable file.David W. Hodgins
 `- Re: Check the hashbang (magic number) in a executable file.hongy...@gmail.com

Pages:12
Check the hashbang (magic number) in a executable file.

<6607ce2c-8820-4b22-9181-35cb829aa3e7n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4372&group=comp.unix.shell#4372

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:620a:81c:: with SMTP id s28mr12842897qks.45.1631922883103;
Fri, 17 Sep 2021 16:54:43 -0700 (PDT)
X-Received: by 2002:ac8:6145:: with SMTP id d5mr12621741qtm.197.1631922882849;
Fri, 17 Sep 2021 16:54:42 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Fri, 17 Sep 2021 16:54:42 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=8.210.184.1; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 8.210.184.1
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <6607ce2c-8820-4b22-9181-35cb829aa3e7n@googlegroups.com>
Subject: Check the hashbang (magic number) in a executable file.
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Fri, 17 Sep 2021 23:54:43 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 26
 by: hongy...@gmail.com - Fri, 17 Sep 2021 23:54 UTC

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?

Regards,
HZ

Re: Check the hashbang (magic number) in a executable file.

<eli$2109172047@qaz.wtf>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4373&group=comp.unix.shell#4373

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!panix!.POSTED.panix5.panix.com!qz!not-for-mail
From: *...@eli.users.panix.com (Eli the Bearded)
Newsgroups: comp.unix.shell
Subject: Re: Check the hashbang (magic number) in a executable file.
Date: Sat, 18 Sep 2021 00:47:47 -0000 (UTC)
Organization: Some absurd concept
Message-ID: <eli$2109172047@qaz.wtf>
References: <6607ce2c-8820-4b22-9181-35cb829aa3e7n@googlegroups.com>
Injection-Date: Sat, 18 Sep 2021 00:47:47 -0000 (UTC)
Injection-Info: reader1.panix.com; posting-host="panix5.panix.com:166.84.1.5";
logging-data="18487"; mail-complaints-to="abuse@panix.com"
User-Agent: Vectrex rn 2.1 (beta)
X-Liz: It's actually happened, the entire Internet is a massive game of Redcode
X-Motto: "Erosion of rights never seems to reverse itself." -- kenny@panix
X-US-Congress: Moronic Fucks.
X-Attribution: EtB
XFrom: is a real address
Encrypted: double rot-13
 by: Eli the Bearded - Sat, 18 Sep 2021 00:47 UTC

In comp.unix.shell, hongy...@gmail.com <hongyi.zhao@gmail.com> wrote:
> See the following testing:

man file
man magic

Maybe something like

https://openpreservation.org/blogs/magic-editing-and-creation-primer/

Or just find non-compiled version of the magic file.

Elijah
------
last attempted to edit a magic file twenty plus years ago

Re: Check the hashbang (magic number) in a executable file.

<87y27ud5xa.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4374&group=comp.unix.shell#4374

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.unix.shell
Subject: Re: Check the hashbang (magic number) in a executable file.
Date: Fri, 17 Sep 2021 18:32:49 -0700
Organization: None to speak of
Lines: 33
Message-ID: <87y27ud5xa.fsf@nosuchdomain.example.com>
References: <6607ce2c-8820-4b22-9181-35cb829aa3e7n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="1c0a1727ab10b2ea8ec5f4efe0f5dac1";
logging-data="14756"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ATaulpWX03HYslqb8C23L"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:Tqo7pTMr8VmBMPOIqV04BWX/F0o=
sha1:kYgoM8hMl3jc4u903r6lH9CHLRA=
 by: Keith Thompson - Sat, 18 Sep 2021 01:32 UTC

"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

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Re: Check the hashbang (magic number) in a executable file.

<op.09v4jtrxa3w0dxdave@hodgins.homeip.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4375&group=comp.unix.shell#4375

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: dwhodg...@nomail.afraid.org (David W. Hodgins)
Newsgroups: comp.unix.shell
Subject: Re: Check the hashbang (magic number) in a executable file.
Date: Fri, 17 Sep 2021 20:48:55 -0400
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <op.09v4jtrxa3w0dxdave@hodgins.homeip.net>
References: <6607ce2c-8820-4b22-9181-35cb829aa3e7n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes
Content-Transfer-Encoding: 8bit
Injection-Info: reader02.eternal-september.org; posting-host="4918f0e32381b84fc3637c9949dc99e9";
logging-data="14276"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX191+P7CImAOntN5ii9BYEiWC8ohD10EthE="
User-Agent: Opera Mail/12.16 (Linux)
Cancel-Lock: sha1:AqCO+FAx/4lsXvdcCnSKakKAHKI=
 by: David W. Hodgins - Sat, 18 Sep 2021 00:48 UTC

On Fri, 17 Sep 2021 19:54:42 -0400, hongy...@gmail.com <hongyi.zhao@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

Regards, Dave Hodgins

--
Change dwhodgins@nomail.afraid.org to davidwhodgins@teksavvy.com for
email replies.

Re: Check the hashbang (magic number) in a executable file.

<5c00f43a-c282-43db-b639-47d2399d20een@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4377&group=comp.unix.shell#4377

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:ac8:724c:: with SMTP id l12mr14046753qtp.131.1631955598798;
Sat, 18 Sep 2021 01:59:58 -0700 (PDT)
X-Received: by 2002:a05:620a:b95:: with SMTP id k21mr14346163qkh.459.1631955598612;
Sat, 18 Sep 2021 01:59:58 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Sat, 18 Sep 2021 01:59:58 -0700 (PDT)
In-Reply-To: <op.09v4jtrxa3w0dxdave@hodgins.homeip.net>
Injection-Info: google-groups.googlegroups.com; posting-host=60.249.28.133; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 60.249.28.133
References: <6607ce2c-8820-4b22-9181-35cb829aa3e7n@googlegroups.com> <op.09v4jtrxa3w0dxdave@hodgins.homeip.net>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <5c00f43a-c282-43db-b639-47d2399d20een@googlegroups.com>
Subject: Re: Check the hashbang (magic number) in a executable file.
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Sat, 18 Sep 2021 08:59:58 +0000
Content-Type: text/plain; charset="UTF-8"
 by: hongy...@gmail.com - Sat, 18 Sep 2021 08:59 UTC

On Saturday, September 18, 2021 at 11:04:42 AM UTC+8, David W. Hodgins wrote:
> 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

Thank you and all replies here. I rechecked and confirmed it as the following:

$ dd if=/usr/bin/find bs=1 count=4 2>/dev/null | hd -c
00000000 7f 45 4c 46 |.ELF|
0000000 177 E L F
0000004

$ man 5 elf | grep -i 'magic'
EI_MAG0 The first byte of the magic number. It must be filled with ELFMAG0. (0: 0x7f)
EI_MAG1 The second byte of the magic number. It must be filled with ELFMAG1. (1: 'E')
EI_MAG2 The third byte of the magic number. It must be filled with ELFMAG2. (2: 'L')
EI_MAG3 The fourth byte of the magic number. It must be filled with ELFMAG3. (3: 'F')

Best, HZ

Re: Check the hashbang (magic number) in a executable file.

<si511d$72b$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4379&group=comp.unix.shell#4379

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: lew.pitc...@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.unix.shell
Subject: Re: Check the hashbang (magic number) in a executable file.
Date: Sat, 18 Sep 2021 15:36:14 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 45
Message-ID: <si511d$72b$1@dont-email.me>
References: <6607ce2c-8820-4b22-9181-35cb829aa3e7n@googlegroups.com>
<87y27ud5xa.fsf@nosuchdomain.example.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 18 Sep 2021 15:36:14 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="79461ccc7bdc8834988ac80adab7ab32";
logging-data="7243"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ecl/7fZ1HaiinzVNuOnjUdw0V7Q+wZSY="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:GF2hN2Sa9aR/1It/mzp+xUQHsYU=
 by: Lew Pitcher - Sat, 18 Sep 2021 15:36 UTC

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
"In Skills, We Trust"

Re: Check the hashbang (magic number) in a executable file.

<si55qp$72b$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4380&group=comp.unix.shell#4380

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: lew.pitc...@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.unix.shell
Subject: Re: Check the hashbang (magic number) in a executable file.
Date: Sat, 18 Sep 2021 16:58:01 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 61
Message-ID: <si55qp$72b$2@dont-email.me>
References: <6607ce2c-8820-4b22-9181-35cb829aa3e7n@googlegroups.com>
<87y27ud5xa.fsf@nosuchdomain.example.com> <si511d$72b$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 18 Sep 2021 16:58:01 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="79461ccc7bdc8834988ac80adab7ab32";
logging-data="7243"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Ubb5skBWCztZxVIUlYGtqD/kc5pIjpVA="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:VcICRbzo/P3YtBE34X9Tz7sgS9A=
 by: Lew Pitcher - Sat, 18 Sep 2021 16:58 UTC

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" <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.

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"

Re: Check the hashbang (magic number) in a executable file.

<87y27ta69e.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4381&group=comp.unix.shell#4381

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.unix.shell
Subject: Re: Check the hashbang (magic number) in a executable file.
Date: Sat, 18 Sep 2021 23:06:05 +0100
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <87y27ta69e.fsf@bsb.me.uk>
References: <6607ce2c-8820-4b22-9181-35cb829aa3e7n@googlegroups.com>
<87y27ud5xa.fsf@nosuchdomain.example.com> <si511d$72b$1@dont-email.me>
<si55qp$72b$2@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="0c09f1be6dc9f9f9ec7a839caed35995";
logging-data="26641"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+29rRdSL5GzCVuTH7Z+8sFKHc4kOS5I4s="
Cancel-Lock: sha1:xGvW3QPdXc7rBik0aIF5kYpa0SU=
sha1:NdP8QslhVchNEk7EJx8M0jgR6Qc=
X-BSB-Auth: 1.f65fb4001729ac243d11.20210918230605BST.87y27ta69e.fsf@bsb.me.uk
 by: Ben Bacarisse - Sat, 18 Sep 2021 22:06 UTC

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!

--
Ben.

Re: Check the hashbang (magic number) in a executable file.

<si5oc6$f66$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4382&group=comp.unix.shell#4382

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: lew.pitc...@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.unix.shell
Subject: Re: Check the hashbang (magic number) in a executable file.
Date: Sat, 18 Sep 2021 22:14:30 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 42
Message-ID: <si5oc6$f66$1@dont-email.me>
References: <6607ce2c-8820-4b22-9181-35cb829aa3e7n@googlegroups.com>
<87y27ud5xa.fsf@nosuchdomain.example.com> <si511d$72b$1@dont-email.me>
<si55qp$72b$2@dont-email.me> <87y27ta69e.fsf@bsb.me.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 18 Sep 2021 22:14:30 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="cd232ac5b7354537c5fecfeff14abd66";
logging-data="15558"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+4YtjWqyHrLYR4FnYaWZ2OWXnK2j1WBdo="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:mUesv7+/iN1gke6stXHZgnuP1Wk=
 by: Lew Pitcher - Sat, 18 Sep 2021 22:14 UTC

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
"In Skills, We Trust"

Re: Check the hashbang (magic number) in a executable file.

<87mto9a55p.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4383&group=comp.unix.shell#4383

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.unix.shell
Subject: Re: Check the hashbang (magic number) in a executable file.
Date: Sat, 18 Sep 2021 23:29:54 +0100
Organization: A noiseless patient Spider
Lines: 52
Message-ID: <87mto9a55p.fsf@bsb.me.uk>
References: <6607ce2c-8820-4b22-9181-35cb829aa3e7n@googlegroups.com>
<87y27ud5xa.fsf@nosuchdomain.example.com> <si511d$72b$1@dont-email.me>
<si55qp$72b$2@dont-email.me> <87y27ta69e.fsf@bsb.me.uk>
<si5oc6$f66$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="0c09f1be6dc9f9f9ec7a839caed35995";
logging-data="26641"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/FdlJqD6syxH+M7SZNlOkENuDc8na9Cl0="
Cancel-Lock: sha1:5pfvGtMBz90r42pAAqjVzBZJesA=
sha1:flrj4Hc1bSr9M+UaBb0lO3V4qlk=
X-BSB-Auth: 1.b6e0d3573b9d46e4e667.20210918232954BST.87mto9a55p.fsf@bsb.me.uk
 by: Ben Bacarisse - Sat, 18 Sep 2021 22:29 UTC

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"
>>>> 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.

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.

--
Ben.

Re: Check the hashbang (magic number) in a executable file.

<si5qah$f66$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4384&group=comp.unix.shell#4384

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: lew.pitc...@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.unix.shell
Subject: Re: Check the hashbang (magic number) in a executable file.
Date: Sat, 18 Sep 2021 22:47:45 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 72
Message-ID: <si5qah$f66$2@dont-email.me>
References: <6607ce2c-8820-4b22-9181-35cb829aa3e7n@googlegroups.com>
<87y27ud5xa.fsf@nosuchdomain.example.com> <si511d$72b$1@dont-email.me>
<si55qp$72b$2@dont-email.me> <87y27ta69e.fsf@bsb.me.uk>
<si5oc6$f66$1@dont-email.me> <87mto9a55p.fsf@bsb.me.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 18 Sep 2021 22:47:45 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="cd232ac5b7354537c5fecfeff14abd66";
logging-data="15558"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18viVOimhE48VSqlJRszGbA150jbhql2Mo="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:WhxrwZJexZOxp8GuoQimI5ZwW5g=
 by: Lew Pitcher - Sat, 18 Sep 2021 22:47 UTC

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"
>>>>> 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.
>
> 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, perhaps /all/ executables are "scripts" of some sort.

--
Lew Pitcher
"In Skills, We Trust"

Re: Check the hashbang (magic number) in a executable file.

<a9739838-cfe8-4bad-ba77-9e0737f054c0n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4385&group=comp.unix.shell#4385

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a37:a60f:: with SMTP id p15mr1431245qke.114.1632009656688;
Sat, 18 Sep 2021 17:00:56 -0700 (PDT)
X-Received: by 2002:ad4:496d:: with SMTP id p13mr14897496qvy.52.1632009656417;
Sat, 18 Sep 2021 17:00:56 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Sat, 18 Sep 2021 17:00:56 -0700 (PDT)
In-Reply-To: <si511d$72b$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=161.117.83.59; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 161.117.83.59
References: <6607ce2c-8820-4b22-9181-35cb829aa3e7n@googlegroups.com>
<87y27ud5xa.fsf@nosuchdomain.example.com> <si511d$72b$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <a9739838-cfe8-4bad-ba77-9e0737f054c0n@googlegroups.com>
Subject: Re: Check the hashbang (magic number) in a executable file.
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Sun, 19 Sep 2021 00:00:56 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 49
 by: hongy...@gmail.com - Sun, 19 Sep 2021 00:00 UTC

On Saturday, September 18, 2021 at 11:36:19 PM UTC+8, 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,

$ 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.

HZ

Re: Check the hashbang (magic number) in a executable file.

<8e2a3818-ee78-497b-87d7-8afdb643ed05n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4386&group=comp.unix.shell#4386

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:ac8:6697:: with SMTP id d23mr17093284qtp.34.1632009830421; Sat, 18 Sep 2021 17:03:50 -0700 (PDT)
X-Received: by 2002:a05:620a:2298:: with SMTP id o24mr17999517qkh.235.1632009830288; Sat, 18 Sep 2021 17:03:50 -0700 (PDT)
Path: i2pn2.org!i2pn.org!aioe.org!feeder1.feed.usenet.farm!feed.usenet.farm!tr2.eu1.usenetexpress.com!feeder.usenetexpress.com!tr2.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Sat, 18 Sep 2021 17:03:50 -0700 (PDT)
In-Reply-To: <si55qp$72b$2@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=8.210.99.126; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 8.210.99.126
References: <6607ce2c-8820-4b22-9181-35cb829aa3e7n@googlegroups.com> <87y27ud5xa.fsf@nosuchdomain.example.com> <si511d$72b$1@dont-email.me> <si55qp$72b$2@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <8e2a3818-ee78-497b-87d7-8afdb643ed05n@googlegroups.com>
Subject: Re: Check the hashbang (magic number) in a executable file.
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Sun, 19 Sep 2021 00:03:50 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 62
 by: hongy...@gmail.com - Sun, 19 Sep 2021 00:03 UTC

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:
> >
> >> "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

$ sudo mount -t binfmt_misc none /proc/sys/fs/binfmt_misc
mount: /proc/sys/fs/binfmt_misc: none already mounted on /sys/fs/bpf.

>
> 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"

Re: Check the hashbang (magic number) in a executable file.

<si7i85$csu$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4387&group=comp.unix.shell#4387

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: lew.pitc...@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.unix.shell
Subject: Re: Check the hashbang (magic number) in a executable file.
Date: Sun, 19 Sep 2021 14:42:14 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <si7i85$csu$1@dont-email.me>
References: <6607ce2c-8820-4b22-9181-35cb829aa3e7n@googlegroups.com>
<87y27ud5xa.fsf@nosuchdomain.example.com> <si511d$72b$1@dont-email.me>
<a9739838-cfe8-4bad-ba77-9e0737f054c0n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 19 Sep 2021 14:42:14 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="cd232ac5b7354537c5fecfeff14abd66";
logging-data="13214"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18aNdzI7Hpji1t9vHz06U59zk4YMcuHY5E="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:JbaMaZ1pCFiFGbuuSnBvn0x8R1o=
 by: Lew Pitcher - Sun, 19 Sep 2021 14:42 UTC

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

--
Lew Pitcher
"In Skills, We Trust"

Re: Check the hashbang (magic number) in a executable file.

<si7idm$csu$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4388&group=comp.unix.shell#4388

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: lew.pitc...@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.unix.shell
Subject: Re: Check the hashbang (magic number) in a executable file.
Date: Sun, 19 Sep 2021 14:45:10 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 70
Message-ID: <si7idm$csu$2@dont-email.me>
References: <6607ce2c-8820-4b22-9181-35cb829aa3e7n@googlegroups.com>
<87y27ud5xa.fsf@nosuchdomain.example.com> <si511d$72b$1@dont-email.me>
<si55qp$72b$2@dont-email.me>
<8e2a3818-ee78-497b-87d7-8afdb643ed05n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 19 Sep 2021 14:45:10 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="cd232ac5b7354537c5fecfeff14abd66";
logging-data="13214"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+rI2GJV5NfkHSePWDz9pGT2H0P8qMaMRU="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:cMBZpQqI+o7vtyKZDs19o913ucE=
 by: Lew Pitcher - Sun, 19 Sep 2021 14:45 UTC

On Sat, 18 Sep 2021 17:03:50 -0700, hongy...@gmail.com wrote:

> 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:
>> >
>> >> "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
>
> $ sudo mount -t binfmt_misc none /proc/sys/fs/binfmt_misc
> mount: /proc/sys/fs/binfmt_misc: none already mounted on /sys/fs/bpf.

Try
mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc
as root

I don't often mount binfmt_misc manually. I automount it through
an /etc/fstab entry that looks like:

none /proc/sys/fs/binfmt_misc binfmt_misc defaults 0 0

[snip]

HTH
--
Lew Pitcher
"In Skills, We Trust"

Re: Check the hashbang (magic number) in a executable file.

<si7nj1$tri$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4389&group=comp.unix.shell#4389

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: chr...@mshome.net (Chris Elvidge)
Newsgroups: comp.unix.shell
Subject: Re: Check the hashbang (magic number) in a executable file.
Date: Sun, 19 Sep 2021 17:13:20 +0100
Organization: A noiseless patient Spider
Lines: 45
Message-ID: <si7nj1$tri$1@dont-email.me>
References: <6607ce2c-8820-4b22-9181-35cb829aa3e7n@googlegroups.com>
<87y27ud5xa.fsf@nosuchdomain.example.com> <si511d$72b$1@dont-email.me>
<a9739838-cfe8-4bad-ba77-9e0737f054c0n@googlegroups.com>
<si7i85$csu$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 19 Sep 2021 16:13:21 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="2ac5ffe6612a2245b7ffd56d7af16ed9";
logging-data="30578"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+fhRLOv4WHsWUBYV8lFsZEnZrQjaWf860="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101
Thunderbird/52.2.1 Lightning/5.4
Cancel-Lock: sha1:h/i/bQ4rsD/UbHTOKQGmtQ4YADs=
In-Reply-To: <si7i85$csu$1@dont-email.me>
Content-Language: en-GB
 by: Chris Elvidge - Sun, 19 Sep 2021 16:13 UTC

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

Re: Check the hashbang (magic number) in a executable file.

<op.09y66dr4a3w0dxdave@hodgins.homeip.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4390&group=comp.unix.shell#4390

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: dwhodg...@nomail.afraid.org (David W. Hodgins)
Newsgroups: comp.unix.shell
Subject: Re: Check the hashbang (magic number) in a executable file.
Date: Sun, 19 Sep 2021 12:38:27 -0400
Organization: A noiseless patient Spider
Lines: 28
Message-ID: <op.09y66dr4a3w0dxdave@hodgins.homeip.net>
References: <6607ce2c-8820-4b22-9181-35cb829aa3e7n@googlegroups.com>
<87y27ud5xa.fsf@nosuchdomain.example.com> <si511d$72b$1@dont-email.me>
<a9739838-cfe8-4bad-ba77-9e0737f054c0n@googlegroups.com>
<si7i85$csu$1@dont-email.me> <si7nj1$tri$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes
Content-Transfer-Encoding: 8bit
Injection-Info: reader02.eternal-september.org; posting-host="17d5019687e118323269e6e4314ab8b8";
logging-data="28677"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1889+uN4if19mI5WsbPoC0nc3jQPbREYRM="
User-Agent: Opera Mail/12.16 (Linux)
Cancel-Lock: sha1:ZVouH2uvyh+KcQJY8TzLULAKOeU=
 by: David W. Hodgins - Sun, 19 Sep 2021 16:38 UTC

The binfmt_misc directory in /sys is created when the kernel module binfmt_misc is
loaded.

https://github.com/torvalds/linux/blob/master/Documentation/admin-guide/binfmt-misc.rst

In systemd based systems, the module is loaded by systemd if systemd-binfmt.service
has been enabled.

https://www.man7.org/linux/man-pages/man5/binfmt.d.5.html

In non-systemd based systems it's done by the first service that needs it in
the initd startup script. For example wine normally has ...
if [ -e /proc/sys/fs/binfmt_misc/windows ]; then
failure
echo
gprintf "Wine Registration already enabled!\n"
exit 1
fi
/sbin/modprobe binfmt_misc &>/dev/null
RETVAL=$?
echo ':windows:M::MZ::/usr/bin/wine:' >/proc/sys/fs/binfmt_misc/register
echo ':windowsPE:M::PE::/usr/bin/wine:' >/proc/sys/fs/binfmt_misc/register

Regards, Dave Hodgins

--
Change dwhodgins@nomail.afraid.org to davidwhodgins@teksavvy.com for
email replies.

Re: Check the hashbang (magic number) in a executable file.

<0E1AooXb+1atPC9la@bongo-ra.co>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4391&group=comp.unix.shell#4391

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!NFyD4+LU+vfu+oVKTmfrbQ.user.46.165.242.91.POSTED!not-for-mail
From: spi...@gmail.com (Spiros Bousbouras)
Newsgroups: comp.unix.shell
Subject: Re: Check the hashbang (magic number) in a executable file.
Date: Sun, 19 Sep 2021 17:56:05 -0000 (UTC)
Organization: Aioe.org NNTP Server
Message-ID: <0E1AooXb+1atPC9la@bongo-ra.co>
References: <6607ce2c-8820-4b22-9181-35cb829aa3e7n@googlegroups.com> <87y27ud5xa.fsf@nosuchdomain.example.com> <si511d$72b$1@dont-email.me>
<a9739838-cfe8-4bad-ba77-9e0737f054c0n@googlegroups.com> <si7i85$csu$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="43279"; posting-host="NFyD4+LU+vfu+oVKTmfrbQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Server-Commands: nowebcancel
X-Notice: Filtered by postfilter v. 0.9.2
X-Organisation: Weyland-Yutani
 by: Spiros Bousbouras - Sun, 19 Sep 2021 17:56 UTC

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

Re: Check the hashbang (magic number) in a executable file.

<si827d$2a8ri$1@news.xmission.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4392&group=comp.unix.shell#4392

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.shell
Subject: Re: Check the hashbang (magic number) in a executable file.
Date: Sun, 19 Sep 2021 19:14:53 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <si827d$2a8ri$1@news.xmission.com>
References: <6607ce2c-8820-4b22-9181-35cb829aa3e7n@googlegroups.com> <a9739838-cfe8-4bad-ba77-9e0737f054c0n@googlegroups.com> <si7i85$csu$1@dont-email.me> <0E1AooXb+1atPC9la@bongo-ra.co>
Injection-Date: Sun, 19 Sep 2021 19:14:53 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="2433906"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Sun, 19 Sep 2021 19:14 UTC

In article <0E1AooXb+1atPC9la@bongo-ra.co>,
Spiros Bousbouras <spibou@gmail.com> wrote:
>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

I found it at:

https://www.kernel.org/doc/html/latest/admin-guide/binfmt-misc.html

--
The randomly chosen signature file that would have appeared here is more than 4
lines long. As such, it violates one or more Usenet RFCs. In order to remain
in compliance with said RFCs, the actual sig can be found at the following URL:
http://user.xmission.com/~gazelle/Sigs/Pedantic

Re: Check the hashbang (magic number) in a executable file.

<87mto86s6y.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4393&group=comp.unix.shell#4393

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.unix.shell
Subject: Re: Check the hashbang (magic number) in a executable file.
Date: Mon, 20 Sep 2021 00:50:29 +0100
Organization: A noiseless patient Spider
Lines: 75
Message-ID: <87mto86s6y.fsf@bsb.me.uk>
References: <6607ce2c-8820-4b22-9181-35cb829aa3e7n@googlegroups.com>
<87y27ud5xa.fsf@nosuchdomain.example.com> <si511d$72b$1@dont-email.me>
<si55qp$72b$2@dont-email.me> <87y27ta69e.fsf@bsb.me.uk>
<si5oc6$f66$1@dont-email.me> <87mto9a55p.fsf@bsb.me.uk>
<si5qah$f66$2@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="1f3951e377d36699f32bdc66edf3a8b5";
logging-data="26974"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+18pJVVvODNvs8FOszo9dCk5nO0CXfomQ="
Cancel-Lock: sha1:MaPcKYPJZ6cEcty1+Eu514JFcjA=
sha1:wVQQL4Fo1p4s56+RURf6iU4arRU=
X-BSB-Auth: 1.49201a256e6ff4c96e15.20210920005029BST.87mto86s6y.fsf@bsb.me.uk
 by: Ben Bacarisse - Sun, 19 Sep 2021 23:50 UTC

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" 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.
>>
>> 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?

--
Ben.

Re: Check the hashbang (magic number) in a executable file.

<si8o0u$7te$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4394&group=comp.unix.shell#4394

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: lew.pitc...@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.unix.shell
Subject: Re: Check the hashbang (magic number) in a executable file.
Date: Mon, 20 Sep 2021 01:26:54 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 84
Message-ID: <si8o0u$7te$1@dont-email.me>
References: <6607ce2c-8820-4b22-9181-35cb829aa3e7n@googlegroups.com>
<87y27ud5xa.fsf@nosuchdomain.example.com> <si511d$72b$1@dont-email.me>
<si55qp$72b$2@dont-email.me> <87y27ta69e.fsf@bsb.me.uk>
<si5oc6$f66$1@dont-email.me> <87mto9a55p.fsf@bsb.me.uk>
<si5qah$f66$2@dont-email.me> <87mto86s6y.fsf@bsb.me.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 20 Sep 2021 01:26:54 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="ee0d79b1a0a1c6d7adfaea1572272000";
logging-data="8110"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+9zdFjbYrawKO1b/S/NW9Td9JdGjYr4Bs="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:IrEI0T5JM3z1Ka1lgcWfrrhGgZY=
 by: Lew Pitcher - Mon, 20 Sep 2021 01:26 UTC

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" 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.
>>>
>>> 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
--
Lew Pitcher
"In Skills, We Trust"

Re: Check the hashbang (magic number) in a executable file.

<si8phg$7te$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4395&group=comp.unix.shell#4395

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: lew.pitc...@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.unix.shell
Subject: Re: Check the hashbang (magic number) in a executable file.
Date: Mon, 20 Sep 2021 01:52:48 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 100
Message-ID: <si8phg$7te$2@dont-email.me>
References: <6607ce2c-8820-4b22-9181-35cb829aa3e7n@googlegroups.com>
<87y27ud5xa.fsf@nosuchdomain.example.com> <si511d$72b$1@dont-email.me>
<si55qp$72b$2@dont-email.me> <87y27ta69e.fsf@bsb.me.uk>
<si5oc6$f66$1@dont-email.me> <87mto9a55p.fsf@bsb.me.uk>
<si5qah$f66$2@dont-email.me> <87mto86s6y.fsf@bsb.me.uk>
<si8o0u$7te$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 20 Sep 2021 01:52:48 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="ee0d79b1a0a1c6d7adfaea1572272000";
logging-data="8110"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+JT/cQMgeVvhTz+kFJOunARnJq2O+V/SI="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:X4VCSQgEO0qXN0F3JWusJmf3JhI=
 by: Lew Pitcher - Mon, 20 Sep 2021 01:52 UTC

On Mon, 20 Sep 2021 01:26:54 +0000, Lew Pitcher wrote:

> 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" 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.
>>>>
>>>> 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

I should point out that, in Linux, the kernel portion of the exec() syscall
is implemented in fs/exec.c. It invokes several fs/binfmt_*.c modules to handle
the executable exec() was passed. These binfmt_* modules include
binfmt_aout.c which handles the a.out format executables
binfmt_elf.c which handles ELF executables
binfmt_em86.c which handles X86 code execution on Alpha processors
binfmt_flat.c which handles uClinux FLAT format binaries
binfmt_elf_fdpic.c which handles uClinux FDPIC format binaries
binfmt_misc.c which handles user-defined executables
and
binfmt_script.c which handles "scripts starting with #!"

--
Lew Pitcher
"In Skills, We Trust"

Re: Check the hashbang (magic number) in a executable file.

<op.09zxhtyya3w0dxdave@hodgins.homeip.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4396&group=comp.unix.shell#4396

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: dwhodg...@nomail.afraid.org (David W. Hodgins)
Newsgroups: comp.unix.shell
Subject: Re: Check the hashbang (magic number) in a executable file.
Date: Sun, 19 Sep 2021 22:06:55 -0400
Organization: A noiseless patient Spider
Lines: 28
Message-ID: <op.09zxhtyya3w0dxdave@hodgins.homeip.net>
References: <6607ce2c-8820-4b22-9181-35cb829aa3e7n@googlegroups.com>
<87y27ud5xa.fsf@nosuchdomain.example.com> <si511d$72b$1@dont-email.me>
<si55qp$72b$2@dont-email.me> <87y27ta69e.fsf@bsb.me.uk>
<si5oc6$f66$1@dont-email.me> <87mto9a55p.fsf@bsb.me.uk>
<si5qah$f66$2@dont-email.me> <87mto86s6y.fsf@bsb.me.uk>
<si8o0u$7te$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes
Content-Transfer-Encoding: 8bit
Injection-Info: reader02.eternal-september.org; posting-host="a271bdcd63e7f60e6f751fac36350512";
logging-data="10229"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Jlx2THlenO0kpyMEkSXvGvAOZrmWIvZw="
User-Agent: Opera Mail/12.16 (Linux)
Cancel-Lock: sha1:UZtcBWkmj6HMwMRMlTYL5qBZKps=
 by: David W. Hodgins - Mon, 20 Sep 2021 02:06 UTC

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.

Regards, Dave Hodgins

--
Change dwhodgins@nomail.afraid.org to davidwhodgins@teksavvy.com for
email replies.

Re: Check the hashbang (magic number) in a executable file.

<si9fpq$1pen$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4397&group=comp.unix.shell#4397

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!LTi+xflewmQTbbz7H4hZOQ.user.46.165.242.75.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Check the hashbang (magic number) in a executable file.
Date: Mon, 20 Sep 2021 10:12:42 +0200
Organization: Aioe.org NNTP Server
Message-ID: <si9fpq$1pen$1@gioia.aioe.org>
References: <6607ce2c-8820-4b22-9181-35cb829aa3e7n@googlegroups.com>
<87y27ud5xa.fsf@nosuchdomain.example.com> <si511d$72b$1@dont-email.me>
<si55qp$72b$2@dont-email.me> <87y27ta69e.fsf@bsb.me.uk>
<si5oc6$f66$1@dont-email.me> <87mto9a55p.fsf@bsb.me.uk>
<si5qah$f66$2@dont-email.me> <87mto86s6y.fsf@bsb.me.uk>
<si8o0u$7te$1@dont-email.me> <op.09zxhtyya3w0dxdave@hodgins.homeip.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="58839"; posting-host="LTi+xflewmQTbbz7H4hZOQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Janis Papanagnou - Mon, 20 Sep 2021 08:12 UTC

On 20.09.21 04:06, David W. Hodgins wrote:
> 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.

I very much agree with what you've described here, but one detail;
'program' we called the textual "recipe"; we have C-programs (to be
compiled) or shell-programs (~"shell-Scripts") to be interpreted, we
have assembler-programs (the text, not the assembled machine code).

Janis

Re: Check the hashbang (magic number) in a executable file.

<534bd1e4-4ee3-43ea-8b7d-c93e929baf4cn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4398&group=comp.unix.shell#4398

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:ac8:4308:: with SMTP id z8mr11945906qtm.121.1632127032055;
Mon, 20 Sep 2021 01:37:12 -0700 (PDT)
X-Received: by 2002:a05:620a:2298:: with SMTP id o24mr23429959qkh.235.1632127031879;
Mon, 20 Sep 2021 01:37:11 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Mon, 20 Sep 2021 01:37:11 -0700 (PDT)
In-Reply-To: <si7i85$csu$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=54.180.135.214; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 54.180.135.214
References: <6607ce2c-8820-4b22-9181-35cb829aa3e7n@googlegroups.com>
<87y27ud5xa.fsf@nosuchdomain.example.com> <si511d$72b$1@dont-email.me>
<a9739838-cfe8-4bad-ba77-9e0737f054c0n@googlegroups.com> <si7i85$csu$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <534bd1e4-4ee3-43ea-8b7d-c93e929baf4cn@googlegroups.com>
Subject: Re: Check the hashbang (magic number) in a executable file.
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Mon, 20 Sep 2021 08:37:12 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 42
 by: hongy...@gmail.com - Mon, 20 Sep 2021 08:37 UTC

On Sunday, September 19, 2021 at 10:42:19 PM UTC+8, 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've installed the kernel source code, but still can't find this file:

werner@X10DAi-00:~$ dpkg --get-selections | grep linux-source
linux-source install
linux-source-5.4.0 install
werner@X10DAi-00:~$ dpkg -L linux-source-5.4.0 | grep -i binfmt_misc.txt
werner@X10DAi-00:~$
> 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"

Pages:12
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor