Need Simple Way To Determine If File Is Executable

Sebastian 'lunar' Wiesner basti.wiesner at gmx.net
Wed Dec 20 07:28:59 EST 2006


Marc 'BlackJack' Rintsch <bj_666 at gmx.net> schrieb

> In <emav7p$e5f$03$1 at news.t-online.com>, Sebastian 'lunar' Wiesner
> wrote:
> 
>> Gabriel Genellina <gagsl-py at yahoo.com.ar> schrieb
>>> A similar function exists on Linux too. But even if a file has the
>>> right file format, if it does not have the execute bit set, won't
>>> run. And you could set that bit on a JPG image too - and nothing
>>> good would happen, I presume.
>> 
>> Really? I don't think so. Afaik on Linux executable binary files need
>> an ELF header.
> 
> There are other executable loaders for `a.out` and `COFF` in the
> kernel, and with the `binfmt_misc` module you can make anything with a
> "magic" header executable, including Python scripts/bytecode and even
> JPEG images.

Yes, I know...
But ELF is actually the most common linker format on Linux systems.
a.out is a legacy format, that is afaik not used by any modern
distribution. Concerning COFF I'm not sure, if there is really a COFF
loader in the kernel. At least I did not find any information about
such a loader in the kernel configuration. It just lists elf, a.out and
binfmt_misc.

But basically you're right. One could even write a loader for JPEG
files. 
But as long as such an loader is not part of a standard linux
distribution, nothing bad happens when you try to execute a JPEG file,
and that's what I wanted to point out.

Sebastian

-- 
Freedom is always the freedom of dissenters.
        (Rosa Luxemburg)



More information about the Python-list mailing list