'file' Command Giving False Positives
freebsd at edvax.de
Fri Jul 2 18:43:00 UTC 2010
On Fri, 02 Jul 2010 14:23:24 -0400, Lowell Gilbert <freebsd-questions-local at be-well.ilk.org> wrote:
> Apparently, your memory is better than mine, because that was indeed
> what I was thinking of. Which leads to the question of why magic(5)
> lists LZ as representing "MS-DOS executable (built-in)". I'd be
> hesitant to change that unless we knew for sure it was wrong.
As it has been mentioned before, .EXE is *one* of the formats
executable in DOS. .COM executables do not have specific headers
(as they are loaded directly). Also, .BAT are executable, allthough
they are text files, and finally .BTM are also text file executables,
specific to NDOS. As far as I also remember, there's .EXE on OS/2,
too. One could argue if "Windows" .PIF are also executables. Of
course, VMS also has .COM... but I see I'm making a digression... :-)
> Even if it _is_ wrong, the "problem" still remains for "MZ" at least:
> Any file starting with those letters is going to be identified as an
> MS-DOS executable, and there's no clear way to distinguish it from a
> text file that happens to start with those letters.
Well, there's a solution that is not *that* complicated: If the
file contains characters that don't match isprint(), i. e. those
outside the ASCII set used in real text files, it's likely to be
A scriptable solution might be to diff <filename> vs. `strings
<filename>`. If they differ, it's not a text, so it might be an
I'm not sure if the magic identification string starting with MZ
could be enlarged with other specific characters immediately
following MZ that are *only* present in executables...
The problem is that "MZ itself is completely sufficient:
% echo "MZ" > foo
% file foo
foo: MS-DOS executable
Of course, that's not correct.
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...
More information about the freebsd-questions