views:

72

answers:

3

I remember a few years ago(2002) there was a multipartite virus that could be run natively on linux and windows. I don't know if a compiler could be specially craft an executable so that it could be read as both ELF and PE, so that the os would start executing at different entry points. Or a program that could merge two programs, one compiled using mingw, one compiled in native linux, to one program.

I don't know if such a program exists, or could it exist, and I'm know this could be implemented in Java or some scripting language, but that's not a native program.

Imagine the possibilities, I could deploy a program with linux and window (and perhaps os/x)libraries, and one main executable that could be run on any os. The cross-platform support would compensate the bigger size.

+2  A: 

No.

Windows and Linux use vastly different binary file formats. See Portable Executable (Windows) and Executable and Linkable Format (Linux).

Something like WINE will run Windows executables on Linux but that's not the same thing.

cletus
I know that, but I was thinking if there was a way to tweak the parameters(even if it meant some unimportant ones being wrong) so that we could have a runnable executable where we could have different entry points, thus we could put code for linux and window in different segments. Maybe using the coff format?
TiansHUo
The answer is still no. The formats are incompatible.
cletus
http://www.symantec.com/security_response/writeup.jsp?docid=2002-052915-3340-99
TiansHUo
A: 

This is actually a really terrible idea for multiple reasons.

  1. Cross-compiling across operating system boundaries is extremely difficult to do properly.
  2. If you go for the second route (building separate PE binaries on Windows and ELF on Linux, and then somehow merging them) you have to maintain two machines, each running a different OS and the full build stack, and you'd have to make sure that you tested both versions separately before gluing them together.
  3. Dynamic linking is already a pain to properly manage, on Windows and on Linux; static linking can generate binaries that are much more inconvenient to deal with than whatever imaginary benefits you get from providing one single file type to your end-user.

If you want to run the same binary executable file on multiple OSes, your options are Java, Mono, and potentially NativeClient, the browser plug-in Google's developing to work around the "webapps are too slow" problem.

clee
So you are saying some kind of virtualization (JVM,etc) between the os and the app is much better. But you haven't answered the question, I was asking whether it is possible, not whether it was difficult, or worth. Going for the second route seems possible, you still had to maintain cross-platform binaries. But the question is there a program to glue these programs together?
TiansHUo
+1  A: 

Windows programs have a DOS stub in the beginning, and I just ran an ELF executable through debug.com, which said that the first instruction of this exe was JG 0x147. Just maybe something could be done with this...

Arthur Kalliokoski
The problem is that windows ignores this dos stub in pe files. But that is interesting, because we could maybe even implement support for dos. Consider this, an interpretor for a scripting language that is multi-platform supported. Then we could deploy using one binary, several libraries and user scripts.
TiansHUo
But if it was named to have a .com extension, and didn't have the MZ signature, Windows (32 bit) would try to run it as a 16 bit DOS program.
Arthur Kalliokoski