0

I have two files, both of them are exe. One for 32bit, and one for 64bit. I'd like to create a small program(a third exe) in C, which contains these two files. When i start my third exe, it should do some work, and execute one of them. Is this somehow possible?

Thanks in advance!

kampi
  • 2,362
  • 12
  • 52
  • 91
  • It is called [Fat binary](https://en.wikipedia.org/wiki/Fat_binary) and AFAIK Windows don't support them. You could play dirty tricks. Why not install both binaries + your launcher and choose (at runtime) which you would run. – Basile Starynkevitch Aug 28 '14 at 19:52
  • @BasileStarynkevitch: Windows doesn't support it? I seen such things on Windows. For example ProcessExlorer from Sysinternals works on the same way. Or i misunderstood something? – kampi Aug 28 '14 at 20:01
  • 2
    @kampi - what he means is Windows doesn't support this feature at the OS level, unlike Mac OS X for example. But you can make your own executable packer/unpacker to do this. I asked a similar question [here](http://stackoverflow.com/questions/1170643/any-tools-available-for-packing-32bit-64bit-executables-together) and there are some useful responses. – snowcrash09 Aug 28 '14 at 20:07

1 Answers1

1

Doing it yourself in C

There are ways to implement this kind of thing in C/C++ described here and here. Basically you do the following:

  1. Add your 32-bit and 64-bit executables as binary PE resources to a 32-bit bootstrapper executable. You can do this using any PE resource editor including Visual Studio if that's what you're using.
  2. The bootstrapper uses the IsWow64Process API to decide whether it is running on a 64bit system or not.
  3. The bootstrapper extracts the correct executable file from its resources using the resource APIs
  4. The bootstrapper writes the executable file to a temporary file and executes it.

This is pretty much what I had to do for an old project, and offers you the most control and flexibility. But if you just want quick and dirty...

Making AutoIT do it for you!

I also found this guide to compiling an AutoIT script which basically does all of the above for you! Neat, eh?

I will reproduce the AutoIT script here in case the link disappears:

; Check if we’re on 64-bit OS…
If EnvGet(“PROCESSOR_ARCHITEW6432″)=”” Then
    ; No we’re not – run x86 version…
    FileInstall(“D:\Support\ETrustCheck_x86.exe”,@TempDir & “\ETrustCheck_x86.exe”)
    RunWait(“D:\Support\ETrustCheck_x86.exe”,@TempDir & “\ETrustCheck_x86.exe”)
    FileDelete(@TempDir & “\ETrustCheck_x86.exe”)
Else
    ; Yes we are – run x64 version..
    FileInstall(“D:\Support\ETrustCheck_x64.exe”,@TempDir & “\ETrustCheck_x64.exe”)
    RunWait(“D:\Support\ETrustCheck_x86.exe”,@TempDir & “\ETrustCheck_x64.exe”)
    FileDelete(@TempDir & “\ETrustCheck_x64.exe”)
EndIf

; The END

This script can be wrapped by the AutoIT script editor into 32bit launcher with your two executables packed into it.

snowcrash09
  • 4,694
  • 27
  • 45