How to open and run .EXE, .*NIX, and apple programs

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Fixitnow

How to open and run .EXE, .*NIX, and apple programs

Post by Fixitnow »

I would love to learn how to do this.
Anton

Re:How to open and run .EXE, .*NIX, and apple programs

Post by Anton »

This would be generally done by first loading the header of the executable into memory. The header will indicate which parts of the executable need to be loaded, how they need to be modified, and where they are located in the file. The header also indicates the address of the entry point in the image of the file. After loading and mapping the file into memory as required, have some control flow jump to the entry point. The executable is now being executed.

Windows, Unix, and Apple executables tend to have different formats. The modern Windows format is PE. Most current versions of Apple and Unix (and clones) use ELF or a variant of a.out. There are advantages and disadvantages to each, but the general outline of the loading procedure is the same for all.

One thing to note is that you would very likely be unable to run an Apple executable on a PC. Even though you might be able to load the header and the necessary sections of the file into memory, any code would be in a format not understandable by x86 machines. This also holds for Unix executables not intended to run on Intel machines. The header will usually specify the type of processor the executable is targeted for.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:How to open and run .EXE, .*NIX, and apple programs

Post by Candy »

Fixitnow wrote: I would love to learn how to do this.
Option 1. Buy a PC and a Mac and use Windows, Unix and MacOS to run the programs.

Option 2. Install Windows, Unix and MacOS in emulators on your current PC and run the programs.

Option 3. Create an operating system with all hardware support you need, add binary loader (that loads certain binaries and relocates them), add PPC or X86 (or both) emulator and run.

If you're not specifically out for option 3, I'd recommend 1 or 2.
JoeKayzA

Re:How to open and run .EXE, .*NIX, and apple programs

Post by JoeKayzA »

Fixitnow wrote: I would love to learn how to do this.
What are .*NIX programs? ;)

Well, for .exe, you are looking for the so-called PE executable file format. Don't know if there is information on the FAQ, but I can remember some people on this forum which talked about it (or even use it regularly).

Linux, Solaris and some other unices use the ELF format instead. Don't know about MacOS, a google search mentioned a format called Mach-O. Maybe this is the default for MacOSX...

btw, using google is probably the best tip I can give you for the future.. ;)


cheers Joe
Fixthestar248

Re:How to open and run .EXE, .*NIX, and apple programs

Post by Fixthestar248 »

*NIX files are UNIX files.
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Re:How to open and run .EXE, .*NIX, and apple programs

Post by Colonel Kernel »

Anton wrote: One thing to note is that you would very likely be unable to run an Apple executable on a PC. Even though you might be able to load the header and the necessary sections of the file into memory, any code would be in a format not understandable by x86 machines.
This will not be true for much longer:

http://www.apple.com/pr/library/2005/jun/06intel.html
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
Cjmovie

Re:How to open and run .EXE, .*NIX, and apple programs

Post by Cjmovie »

Haven't you guys ever heard of wotsit?
http://www.wotsit.org/search.asp?s=binary

;D
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:How to open and run .EXE, .*NIX, and apple programs

Post by Solar »

Ts, ts, ts... *shakinghishead*

None of you so far mentioned that each type of executable will expect a different set of API functions to be available at runtime...

An Apple executable, e.g. when trying to open a window, will try to call an OS function APPLE_OpenWindow(). A Windows executable will try to call WINDOWS_OpenWindow(). Where those functions reside, how exactly they are called etc. is very much system-specific. So, your loader not only would have to handle the different binary executable formats, but the OS you're running would have to provide all the applicable APIs.

Under Linux, there's Wine providing (parts of) the Windows API. Under Windows, there's Cygwin (although that requires a recompilation). I know of no such API "simulator" for MacOS.

Not to speak of how very different the applications themselves are functioning. DOS tools give help on "/?", Unix tools on "-h" or "--help". Apple GUI is rendered to Postscript IIRC, Unix tools go through toolkits to access X Window, Windows does it different yet again.

I strongly second Candy's recommendation: Go for 1) or 2), 3) won't happen.
Every good solution is obvious once you've found it.
Cjmovie

Re:How to open and run .EXE, .*NIX, and apple programs

Post by Cjmovie »

I assumed he wanted to know how to compile _his_ code into one of those formats and get his OS to load it. (as in, possibly, a bootloader)
Actual programs from the net in those formats, yeah, lots of problems if you want to run those, mainly the architecture difference (on MACS, PowerPC vs x86, or even x86-64 ;D) and the API difference, as solar noted.
Post Reply