Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #395737

Re: is_binary_file()

From Michael S <already5chosen@yahoo.com>
Newsgroups comp.lang.c
Subject Re: is_binary_file()
Date 2025-12-09 17:31 +0200
Organization A noiseless patient Spider
Message-ID <20251209173109.00000a32@yahoo.com> (permalink)
References (1 earlier) <10h0om3$280lv$1@dont-email.me> <10h73ga$9q1e$4@dont-email.me> <UmGZQ.359811$KTdf.303682@fx16.iad> <10h8l4o$m3nh$1@dont-email.me> <10h91o9$pkgv$1@dont-email.me>

Show all headers | View raw


On Tue, 9 Dec 2025 06:38:47 -0500
Paul <nospam@needed.invalid> wrote:

> On Tue, 12/9/2025 3:03 AM, David Brown wrote:
> > On 08/12/2025 21:16, Scott Lurndal wrote:  
> >> Michael Sanders <porkchop@invalid.foo> writes:  
> >>> On Sat, 6 Dec 2025 03:14:55 -0500, Paul wrote:
> >>>  
> >>>> It is the year 2025.
> >>>>
> >>>> How many times do you suppose someone has considered this
> >>>> question ?
> >>>>
> >>>> I'm not trying to be a smart ass by saying this, just that the
> >>>> question is bound to be nuanced. You can do a fast and totally
> >>>> inaccurate determination. You can do a computationally expensive
> >>>> or I/O expensive determination.  
> >>>
> >>> I get it Paul, but as with all things, there's lots of opinions
> >>> on this. 
> >>>> There has to be a reason for doing this, and a damn good reason.
> >>>>
> >>>> *******
> >>>>
> >>>> There is the "file" command.
> >>>>
> >>>> It was invented in 1973.
> >>>>
> >>>>     https://en.wikipedia.org/wiki/File_%28command%29
> >>>>
> >>>> The beauty of this command, is it has some sort of ordered
> >>>> approach to file determination.  
> >>>
> >>> And... is not generally available on Windows  
> >>
> >> It is open source and could be built for windows.
> >>
> >> It's also included in any linux distribution running
> >> under WSL.
> >>  
> > 
> > It is available anywhere you find Windows ports of common *nix
> > utilities, such as the msys2 project.  (And while an msys2
> > installation can be quite large, it's possible to pull out
> > individual utilities if you need to.)  Still, it's fair to say that
> > most Windows installations don't have it.
> > 
> > But surely on Windows you can just look at the file extension - if
> > it is ".txt", it's a text file, otherwise it's a binary file.  
> 
> There are a couple ways to get it.
> 
> The problem with this one, is /etc/magic is as old as the hills
> and does not have nearly as much capability. On the plus side,
> it's not going to burn your house down either.
> 
>    https://gnuwin32.sourceforge.net/packages/file.htm
> 
> A second source, is Cygwin, but again, it might depend on
> when the port was done. Doing it this way has to be better
> than the previous link, just because the previous one is
> so old.
> 
>    https://cygwin.com/packages/summary/file.html
> 
> And the Wiki on msys2 says this:
> 
>    "MSYS2 ("minimal system 2") is a software distribution and a
>     development platform for Microsoft Windows, based on Mingw-w64
> and Cygwin "
> 
> It still means when the release was done, could matter.
> 
> I started with Cygwin64. This is an example of an executable, but
> it relies on other dependencies.
> 
> https://mirror.csclub.uwaterloo.ca/cygwin/x86_64/release/file/file-5.46-1-x86_64.tar.xz
> 
> The installer is here.
> 
> https://cygwin.com/setup-x86_64.exe
> 
> # After installation, I checked the dependencies. This does not
> # help you find the /etc/magic file for its usage.
> 
> $ cygcheck /usr/bin/file.exe
> C:\cygwin64\bin\file.exe
>   C:\cygwin64\bin\cygmagic-1.dll
>     C:\cygwin64\bin\cygbz2-1.dll
>       C:\cygwin64\bin\cygwin1.dll
>         C:\WINDOWS\system32\KERNEL32.dll
>           C:\WINDOWS\system32\ntdll.dll
>           C:\WINDOWS\system32\KERNELBASE.dll
>     C:\cygwin64\bin\cyglzma-5.dll
>     C:\cygwin64\bin\cygz.dll
>     C:\cygwin64\bin\cygzstd-1.dll
> 
> Testing did not go well. I tested the "find.exe" in Cygwin64
> and it did not finish. I used Process Monitor to see what it
> was doing, and there was a lot of registry activity. (There
> should not be registry activity by find.exe or file.exe )
> 
> I tried the file.exe command and it didn't provide output
> and the machine hung. My machine never hangs. It's a model
> citizen. Windows Defender did not trip. An offline scan
> with Windows Defender did not find anything. This is possibly
> Process Monitor using all RAM, but that does not normally
> happen until 20 minutes or more have passed, and I was only
> running tracing for a minute or two.
> 
> Cygwin materials are held on mirror sites, and I was using
> a mirror (University of Waterloo). For the time being, I would
> recommend some isolation while you test that.
> 
> *******
> 
> On to msys2.
> 
> https://www.msys2.org/
> 
> Name: msys2-x86_64-20250830.exe
> Size: 93,680,251 bytes (89 MiB)
> SHA256:
> B54705073678D32686A2CC356BB552363429E6CCBABBFECCB6D3CB7EC101E73B
> 
> "Last analysis 22 hours ago", so it is likely someone in this thread
> triggered a retest.
> 
> https://www.virustotal.com/gui/file/b54705073678d32686a2cc356bb552363429e6ccbabbfeccb6d3cb7ec101e73b
>   [Clean]
> 
> Install on disk is 350MB in C:\msys64
> 
> https://www.msys2.org/docs/installer/
> 
> C:/msys64/msys2_shell.cmd -defterm -here -no-start -ucrt64   # Do not
> run elevated (use the unelevated terminal) # Windows Terminal prompt
> changes color
> 
> $ cd /c/msys64/usr/bin
> $ file.exe file.exe
> file.exe: PE32+ executable for MS Windows 5.02 (console), x86-64
> (stripped to external PDB), 10 sections $ cd /s/disktype
> $ file disktype.exe
> disktype.exe: PE32 executable for MS Windows 4.00 (console), Intel
> i386, 16 sections     # cygwin32 executable? # I change directory to
> the corrupted Sent file and check it with the msys2 version. $ file
> Sent Sent: Mailbox text, 1st line "From - Wed Nov 26 06:13:35 2008"
> # I compare to the WSL file command
> $ file Sent
> Sent: Non-ISO extended-ASCII text, with very long lines, with CRLF,
> NEL line terminators   # The corruption detection...
> 

Below is the list of files that I needed to run copy of file.exe
taken from msys2 on bare Windows:
 Directory of C:\tmp\tst

12/09/2025  05:00 PM    <DIR>          .
12/09/2025  04:53 PM    <DIR>          ..
12/09/2025  04:54 PM            24,225 file.exe
12/09/2025  05:00 PM        10,357,200 magic.mgc
12/09/2025  04:57 PM         3,358,337 msys-2.0.dll
12/09/2025  04:58 PM            67,277 msys-bz2-1.dll
12/09/2025  04:58 PM           176,762 msys-lzma-5.dll
12/09/2025  04:57 PM           160,362 msys-magic-1.dll
12/09/2025  04:59 PM            88,576 msys-z.dll
12/09/2025  04:58 PM         1,136,580 msys-zstd-1.dll
               8 File(s)     15,369,319 bytes
               2 Dir(s)  760,461,594,624 bytes free

It's still less convenient than running from msys2 prompt, because
by default file.exe does not look for magic.mgc in the current
directory. So I had to run it as 
'file.exe --magic-file magic.mgc my-files'
Can be "solved" by small envelop batch file, unless it creates some
other inconvenience.

> This tells me the msys2 has an older version of magic determination
> on the file.exe command .
> 
> And for the cygwin64, use the rubber gloves on it.
> It did not work as expected. Use your SafeHex handling
> techniques, until it proves in for you.
> 
>    Paul

I never tried cygwin64. For what I do, the level of compatibility
provided by msys2 is sufficient.

I do have misfortune of using old cygwin, because it's how
Altera (then Intel then again Altera) packages their Nios2 SDK. During
the years it (cygwin) suffered from multiple issues caused by usual
malware that IT of our company stubbornly confuses for anti-malware.
The most recent example is Trend Micro virus that they call "antivirus"
that on few installations (but not on all of them) silently deletes some
vital components of cygwin.

Recently I was glad to discover that all components of said SDK that I
care about actually don't need cygwin. They are either proper Windows
exe, or bash, perl and python scripts. They work fine from msys2 prompt
and are actually faster that way than from within cygwin shell.
So now I have grand plan to gradually stop using old cygwin altogether.










Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

is_binary_file() Michael Sanders <porkchop@invalid.foo> - 2025-12-06 01:05 +0000
  Re: is_binary_file() Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2025-12-06 01:41 +0000
    Re: is_binary_file() Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2025-12-06 02:00 +0000
      Re: is_binary_file() Michael Sanders <porkchop@invalid.foo> - 2025-12-08 17:40 +0000
      Re: is_binary_file() Michael Sanders <porkchop@invalid.foo> - 2025-12-10 11:35 +0000
        Re: is_binary_file() scott@slp53.sl.home (Scott Lurndal) - 2025-12-10 15:07 +0000
          Re: is_binary_file() Michael S <already5chosen@yahoo.com> - 2025-12-10 19:00 +0200
            Re: is_binary_file() scott@slp53.sl.home (Scott Lurndal) - 2025-12-10 17:18 +0000
              Re: is_binary_file() Richard Heathfield <rjh@cpax.org.uk> - 2025-12-10 19:42 +0000
                Re: is_binary_file() bart <bc@freeuk.com> - 2025-12-10 22:37 +0000
                Re: is_binary_file() Paul <nospam@needed.invalid> - 2025-12-10 22:35 -0500
                Re: is_binary_file() bart <bc@freeuk.com> - 2025-12-11 11:46 +0000
                Re: is_binary_file() Bonita Montero <Bonita.Montero@gmail.com> - 2025-12-11 12:53 +0100
          Re: is_binary_file() Michael Sanders <porkchop@invalid.foo> - 2025-12-10 18:42 +0000
        Re: is_binary_file() Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2025-12-10 15:58 +0000
          Re: is_binary_file() Michael Sanders <porkchop@invalid.foo> - 2025-12-10 18:44 +0000
        Re: is_binary_file() James Kuyper <jameskuyper@alumni.caltech.edu> - 2025-12-10 12:46 -0500
          Re: is_binary_file() Michael Sanders <porkchop@invalid.foo> - 2025-12-10 18:45 +0000
        Re: is_binary_file() Michael Sanders <porkchop@invalid.foo> - 2025-12-10 18:41 +0000
          Re: is_binary_file() Michael Sanders <porkchop@invalid.foo> - 2025-12-10 20:57 +0000
            Re: is_binary_file() scott@slp53.sl.home (Scott Lurndal) - 2025-12-10 22:07 +0000
              Re: is_binary_file() Michael Sanders <porkchop@invalid.foo> - 2025-12-11 01:09 +0000
                Re: is_binary_file() Michael Sanders <porkchop@invalid.foo> - 2025-12-11 12:33 +0000
                Re: is_binary_file() Michael Sanders <porkchop@invalid.foo> - 2025-12-12 19:25 +0000
                Re: is_binary_file() Michael Sanders <porkchop@invalid.foo> - 2025-12-12 22:54 +0000
                Re: is_binary_file() "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2025-12-12 15:33 -0800
                Re: is_binary_file() Michael Sanders <porkchop@invalid.foo> - 2025-12-13 00:20 +0000
                Re: is_binary_file() Michael Sanders <porkchop@invalid.foo> - 2025-12-13 02:32 +0000
                Re: is_binary_file() Michael Sanders <porkchop@invalid.foo> - 2025-12-16 00:26 +0000
                Re: is_binary_file() Bonita Montero <Bonita.Montero@gmail.com> - 2025-12-16 17:24 +0100
                Re: is_binary_file() Michael Sanders <porkchop@invalid.foo> - 2025-12-17 03:19 +0000
                Re: is_binary_file() Bonita Montero <Bonita.Montero@gmail.com> - 2025-12-17 07:57 +0100
                Re: is_binary_file() Michael Sanders <porkchop@invalid.foo> - 2025-12-17 19:35 +0000
                Re: is_binary_file() Bonita Montero <Bonita.Montero@gmail.com> - 2025-12-18 08:44 +0100
                Re: is_binary_file() bart <bc@freeuk.com> - 2025-12-18 12:49 +0000
                Re: is_binary_file() Bonita Montero <Bonita.Montero@gmail.com> - 2025-12-18 14:06 +0100
                Re: is_binary_file() gazelle@shell.xmission.com (Kenny McCormack) - 2025-12-18 13:17 +0000
                Re: is_binary_file() Bonita Montero <Bonita.Montero@gmail.com> - 2025-12-18 16:03 +0100
  Re: is_binary_file() Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-12-05 17:42 -0800
    Re: is_binary_file() scott@slp53.sl.home (Scott Lurndal) - 2025-12-06 17:37 +0000
      Re: is_binary_file() Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-12-06 16:05 -0800
      Re: is_binary_file() Louis Krupp <lkrupp@invalid.pssw.com.invalid> - 2025-12-07 03:43 -0700
        Re: is_binary_file() scott@slp53.sl.home (Scott Lurndal) - 2025-12-07 16:47 +0000
        Re: is_binary_file() Lawrence D’Oliveiro <ldo@nz.invalid> - 2025-12-27 03:18 +0000
    Re: is_binary_file() Michael Sanders <porkchop@invalid.foo> - 2025-12-08 17:46 +0000
  Re: is_binary_file() Kaz Kylheku <046-301-5902@kylheku.com> - 2025-12-06 02:42 +0000
    Re: is_binary_file() bart <bc@freeuk.com> - 2025-12-06 12:42 +0000
    Re: is_binary_file() scott@slp53.sl.home (Scott Lurndal) - 2025-12-06 17:40 +0000
      Re: is_binary_file() Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2025-12-06 18:04 +0000
        Re: is_binary_file() scott@slp53.sl.home (Scott Lurndal) - 2025-12-06 19:06 +0000
          Re: is_binary_file() Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2025-12-06 21:16 +0000
    Re: is_binary_file() Michael Sanders <porkchop@invalid.foo> - 2025-12-08 17:48 +0000
      Re: is_binary_file() Kaz Kylheku <046-301-5902@kylheku.com> - 2025-12-08 19:26 +0000
        Re: is_binary_file() Richard Heathfield <rjh@cpax.org.uk> - 2025-12-08 19:42 +0000
        Re: is_binary_file() Michael Sanders <porkchop@invalid.foo> - 2025-12-09 21:49 +0000
  Re: is_binary_file() Paul <nospam@needed.invalid> - 2025-12-06 03:14 -0500
    Re: is_binary_file() Michael Sanders <porkchop@invalid.foo> - 2025-12-08 17:56 +0000
      Re: is_binary_file() scott@slp53.sl.home (Scott Lurndal) - 2025-12-08 20:16 +0000
        Re: is_binary_file() David Brown <david.brown@hesbynett.no> - 2025-12-09 09:03 +0100
          Re: is_binary_file() Richard Heathfield <rjh@cpax.org.uk> - 2025-12-09 09:43 +0000
            Re: is_binary_file() Richard Harnden <richard.nospam@gmail.invalid> - 2025-12-09 10:17 +0000
              Re: is_binary_file() Kaz Kylheku <046-301-5902@kylheku.com> - 2025-12-09 20:15 +0000
          Re: is_binary_file() tTh <tth@none.invalid> - 2025-12-09 12:22 +0100
            Re: is_binary_file() Paul <nospam@needed.invalid> - 2025-12-09 20:26 -0500
          Re: is_binary_file() Paul <nospam@needed.invalid> - 2025-12-09 06:38 -0500
            Re: is_binary_file() Michael S <already5chosen@yahoo.com> - 2025-12-09 17:31 +0200
            Re: is_binary_file() Lawrence D’Oliveiro <ldo@nz.invalid> - 2025-12-28 02:49 +0000
    Re: is_binary_file() Lawrence D’Oliveiro <ldo@nz.invalid> - 2025-12-28 00:12 +0000
      Re: is_binary_file() richard@cogsci.ed.ac.uk (Richard Tobin) - 2025-12-28 00:43 +0000
  Re: is_binary_file() scott@slp53.sl.home (Scott Lurndal) - 2025-12-06 17:33 +0000
    Re: is_binary_file() Bonita Montero <Bonita.Montero@gmail.com> - 2025-12-07 19:04 +0100
  Re: is_binary_file() James Kuyper <jameskuyper@alumni.caltech.edu> - 2025-12-06 20:37 -0500
    Re: is_binary_file() Michael Sanders <porkchop@invalid.foo> - 2025-12-08 18:02 +0000
    Re: is_binary_file() James Kuyper <jameskuyper@alumni.caltech.edu> - 2025-12-09 16:29 -0500
      Re: is_binary_file() Michael S <already5chosen@yahoo.com> - 2025-12-10 11:21 +0200
        Re: is_binary_file() James Kuyper <jameskuyper@alumni.caltech.edu> - 2025-12-10 12:48 -0500
      Re: is_binary_file() Michael Sanders <porkchop@invalid.foo> - 2025-12-10 11:38 +0000
  Re: is_binary_file() antispam@fricas.org (Waldek Hebisch) - 2025-12-07 03:43 +0000
    Re: is_binary_file() Michael Sanders <porkchop@invalid.foo> - 2025-12-08 18:04 +0000
      Re: is_binary_file() bart <bc@freeuk.com> - 2025-12-08 18:44 +0000
        Re: is_binary_file() Michael Sanders <porkchop@invalid.foo> - 2025-12-09 19:53 +0000
          Re: is_binary_file() Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-12-09 15:42 -0800
            Re: is_binary_file() Michael Sanders <porkchop@invalid.foo> - 2025-12-10 11:41 +0000
              Re: is_binary_file() Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-12-10 15:20 -0800
                Re: is_binary_file() Michael Sanders <porkchop@invalid.foo> - 2025-12-10 23:59 +0000
        Re: is_binary_file() James Kuyper <jameskuyper@alumni.caltech.edu> - 2025-12-09 16:23 -0500
  Re: is_binary_file() Richard Harnden <richard.nospam@gmail.invalid> - 2025-12-07 19:01 +0000
    Re: is_binary_file() Richard Heathfield <rjh@cpax.org.uk> - 2025-12-07 21:51 +0000
      Re: is_binary_file() Richard Harnden <richard.nospam@gmail.invalid> - 2025-12-07 22:49 +0000
      Re: is_binary_file() Bonita Montero <Bonita.Montero@gmail.com> - 2025-12-08 13:51 +0100
        Re: is_binary_file() scott@slp53.sl.home (Scott Lurndal) - 2025-12-08 16:04 +0000
          Re: is_binary_file() Bonita Montero <Bonita.Montero@gmail.com> - 2025-12-08 19:27 +0100
        Re: is_binary_file() Lawrence D’Oliveiro <ldo@nz.invalid> - 2025-12-27 05:51 +0000
          Re: is_binary_file() Bonita Montero <Bonita.Montero@gmail.com> - 2025-12-29 16:06 +0100
            Re: is_binary_file() mjos_examine <m6502x64@gmail.com> - 2025-12-29 11:49 -0500
              Re: is_binary_file() Bonita Montero <Bonita.Montero@gmail.com> - 2025-12-29 20:49 +0100
            Re: is_binary_file() Lawrence D’Oliveiro <ldo@nz.invalid> - 2025-12-30 01:52 +0000
      Re: is_binary_file() scott@slp53.sl.home (Scott Lurndal) - 2025-12-08 16:02 +0000
    Re: is_binary_file() Michael Sanders <porkchop@invalid.foo> - 2025-12-08 18:07 +0000
    Re: is_binary_file() Lawrence D’Oliveiro <ldo@nz.invalid> - 2025-12-27 03:13 +0000
      Re: is_binary_file() Paul <nospam@needed.invalid> - 2025-12-27 01:28 -0500
        Re: is_binary_file() Lawrence D’Oliveiro <ldo@nz.invalid> - 2025-12-27 21:27 +0000
        Re: is_binary_file() antispam@fricas.org (Waldek Hebisch) - 2025-12-28 05:46 +0000
  Re: is_binary_file() "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2025-12-07 14:42 -0800
    Re: is_binary_file() Michael Sanders <porkchop@invalid.foo> - 2025-12-08 18:09 +0000
      Re: is_binary_file() "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2025-12-09 12:45 -0800
  Re: is_binary_file() Bonita Montero <Bonita.Montero@gmail.com> - 2025-12-08 20:36 +0100
    Re: is_binary_file() Bonita Montero <Bonita.Montero@gmail.com> - 2025-12-08 20:50 +0100
      Re: is_binary_file() Bonita Montero <Bonita.Montero@gmail.com> - 2025-12-09 15:09 +0100
    Re: is_binary_file() Bonita Montero <Bonita.Montero@gmail.com> - 2025-12-10 09:18 +0100
  Re: is_binary_file() Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-12-08 14:43 -0800
    Re: is_binary_file() Michael Sanders <porkchop@invalid.foo> - 2025-12-09 21:38 +0000
  Re: is_binary_file() Kaz Kylheku <046-301-5902@kylheku.com> - 2025-12-11 17:33 +0000
    Re: is_binary_file() Bonita Montero <Bonita.Montero@gmail.com> - 2025-12-11 19:10 +0100
    Re: is_binary_file() "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2025-12-11 14:56 -0800
    Re: is_binary_file() James Kuyper <jameskuyper@alumni.caltech.edu> - 2025-12-11 18:15 -0500
    Re: is_binary_file() Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-12-12 02:19 +0100
    Re: is_binary_file() Michael Sanders <porkchop@invalid.foo> - 2025-12-14 08:27 +0000
    Re: is_binary_file() Lynn McGuire <lynnmcguire5@gmail.com> - 2025-12-17 00:52 -0600

csiph-web