Page 2 of 2

Re: not a valid Win32 application

PostPosted: 1. Aug 2010, 13:41
by Sasquatch
mpack wrote:A question for Wine experts if you please: if you were to take a Linux executable and run it on Windows then you would get a "Not a Win32 executable" message. What would happen if you ran the same executable under Wine? Wine obviously has the capacity to recognize and run that file, but would it?

This is the result:
wine /usr/bin/leafpad
wine: Bad EXE format for Z:\usr\bin\leafpad.

So, it really does look for a .exe format. It can't run Linux native executables, because there are no file extensions on Linux. To give you some more information, this is the difference between a Linux executable and a Windows executable:
file /usr/bin/leafpad
/usr/bin/leafpad: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, stripped

file /media/programs/Installed\ Programs/NewsLeecher/newsLeecher.exe
/media/programs/Installed Programs/NewsLeecher/newsLeecher.exe: PE32 executable for MS Windows (GUI) Intel 80386 32-bit

When you open a .exe file in a text editor like Notepad, you will clearly see a piece of plain text on the first line:
This program must be run under Win32

If this does not exist, it's not a valid Windows executable I reckon. Wine's own executables, like notepad, will not run on Windows because of that. Though it won't give an error at all.

Re: not a valid Win32 application

PostPosted: 2. Aug 2010, 10:30
by mpack
Sasquatch wrote:This is the result:

Thanks for that, that blows my idea that this might be a Linux executable (e.g. compiled with gcc) even though it has a .exe name.

Sasquatch wrote:When you open a .exe file in a text editor like Notepad, you will clearly see a piece of plain text on the first line:
This program must be run under Win32

If this does not exist, it's not a valid Windows executable I reckon.

Actually, not quite. Every PE32 executable has a stub 16bit DOS executable preceding it, and that string you see is just a string embedded in the most common 16bit executable stub that people use. The idea of that particular stub is that if you run this .exe in a DOS shell it will print out that message. But there is no requirement that every 32bit app use that particular stub. It could use a stub with a different message, or a stub that does something else entirely. [EDIT] Mind you, you are probably correct to say that if you don't see this string then it probably isn't a valid Win32 executable. Another thing to look for is the start of the true Win32 PE header, marked with the characters 'PE', usually at offset 100h (256 decimal). You may see this followed (after a gap) with the words "CODE", "DATA" and "INIT".

Also, that error message only shows in DOS (*) - it is totally distinct from the OPs error message, which is issued by Windows when it tries and fails to load a Win32 image for execution.

(*) ps, the Cmd shell is not DOS. The message does not show up there.

Re: not a valid Win32 application

PostPosted: 2. Aug 2010, 23:34
by Okie2003
mpack wrote:
Okie2003 wrote:. . . Did you do the check I suggested? It would settle the matter in minutes, and remove the need for speculation.

OK, I hope I did what you suggested. I got Frhed - Free hex editor and did a partial open on a BW file that works and one of the recent ones that does not. I am not sure what i am looking at. The first line is identical (I think), the second is different, the third is identical and then my eyes crossed ;-) kudos to you programmers. AnywayI copied a few lines of each into notepad:
MZ<bh:90><bh:00><bh:03><bh:00><bh:00><bh:00><bh:04><bh:00><bh:00><bh:00><bh:ff><bh:ff><bh:00><bh:00><bh:b8><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00>@<bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00>0<bh:01><bh:00><bh:00><bh:0e><bh:1f><bh:ba><bh:0e><bh:00><bh:b4><bh:09><bh:cd>!<bh:b8><bh:01>L<bh:cd>!This program cannot be run in DOS mode.


Above from a file that won't work

Below from a file that will

MZ<bh:90><bh:00><bh:03><bh:00><bh:00><bh:00><bh:04><bh:00><bh:00><bh:00><bh:ff><bh:ff><bh:00><bh:00><bh:b8><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00>@<bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00><bh:00>@<bh:01><bh:00><bh:00><bh:0e><bh:1f><bh:ba><bh:0e><bh:00><bh:b4><bh:09><bh:cd>!<bh:b8><bh:01>L<bh:cd>!This program cannot be run in DOS mode.


Does this tell us anything or should I do something else. If I did not do what you ask, please try again and I will try again.

Re: not a valid Win32 application

PostPosted: 3. Aug 2010, 05:40
by Okie2003
I have created a new virtual hard-drive and installed a test copy of Win XP. I then did a minimal install of BibleWorks and updated. The update DID work. I have asked on the BW forum if anyone is still running a native install of Win 2000.

Re: not a valid Win32 application

PostPosted: 3. Aug 2010, 09:23
by mpack
Hmm. Without going through it byte by byte it the two do look the same, no obvious signs of corruption: the non-working one is definitely intended to be a PE32 and not a Linux executable, garbage, all zeros etc. In which case I must accept the idea that it's a Windows version thing. Now I know that the PE32 format has not fundamentally changed since Win9x days (since I still use a Win9x era C compiler for most of my work!), so the only thing I can think of is that the PE header sets a new flag that Win2K doesn't recognize. If that is true then you ought to get the same error in native Win2K.

I do have a question for the BW developers: is Win2K a supported host OS?

Re: not a valid Win32 application

PostPosted: 5. Aug 2010, 00:24
by Okie2003
Just a follow up: First, thanks to all who took time to think about and reply to this thread. Second, the problem is that BibleWorks no longer works right with Win2k. BibleWorks does not know why. I suspect that very few, if any are using Win2k so it is not worth the effort to look into it. I just assumed since it had worked with Win2k and it worked in wine that it should work in Win2k. That's what I get for assuming.

Thanks again to all.

Re: [SOLVED] not a valid Win32 application

PostPosted: 8. Nov 2015, 16:51
by __Vano
The "not a valid Win32 application" error in this case must be triggered by the fields in the .exe's IMAGE_OPTIONAL_HEADER: Major/MinorOperatingSystemVersion and Major/MinorSubsystemVersion . They are typically set to the same value that corresponds to a Windows internal version number.

If those in your app are set to "5.1", it will run on XP (5.1) but not 2000 (5.0). You can hack the values in all the executable modules of the app to circumvent this, but the app may still fail due to API changes between the OS versions.