Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bind 64-bit and 32-bit executable into one?

Alright so my idea was some way to bind both 64-bit and 32-bit Windows executables into one application so if it doesn't run the 64-bit version it would then try the 32-bit one.

I was reading up about PE's and learned a little about MS-DOS Real Mode Stub and it says how it invokes an application (usually an error message). But every time I tried to do research about MS-DOS Real Mode Stub it seemed to only show error messages. So my idea was to overwrite the STUB with my 32-bit application.

My self being naive figured when the 32-bit operating system would run the the 64-bit executable it would fail and then run the stub file.

Is there any way to make my executable 32-bit/64-bit independent?

like image 285
Trevin Corkery Avatar asked Aug 04 '16 06:08

Trevin Corkery


2 Answers

You could not create a single executable file, containing both x86 and x64 code. However you could create separate 32bit and 64bit applications, pack x64 app into the x86 app resources. On the program start you could check, that you are running x64 environment using IsWow64Process then if needed, unpack your x64 version and run it instead

like image 155
Ari0nhh Avatar answered Nov 09 '22 22:11

Ari0nhh


There are fat binaries in MacOS, Linux and DOS (or hybrid DOS-Windows) but not 32 and 64-bit Windows

You can simply compile separate versions of the program, distribute both and then select the required version at run time by a script or another executable

Another way is installing only the desired version at install time. This is used by many programs like CCleaner. The installer is a 32-bit app or a universal one like .NET so that it can run anywhere. If it detects 64-bit Windows then it only installs the 64-bit version, and in the other case only the 32-bit version.

Read more:

  • Universal binary
  • Windows 8 fat binary (exe for x86 & ARM)
  • Windows NT has always been a multi-platform OS, but the binaries are not
like image 32
phuclv Avatar answered Nov 09 '22 23:11

phuclv