Loading A .exe File

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
JoeTheProgrammer
Member
Member
Posts: 48
Joined: Mon Aug 13, 2007 2:30 pm

Loading A .exe File

Post by JoeTheProgrammer »

Does anyone know where I can get any information on loading a .exe file into memory and executing it in c++ or c?

Thanks,
Joseph
LordMage
Member
Member
Posts: 115
Joined: Sat Sep 22, 2007 7:26 am
Contact:

Post by LordMage »

What EXE, there are more than several formats, do you mean strictly a DOS EXE, Win16 EXE, Win32 EXE, or do you simply mean any executable format file?? what are you using to compile your c++/c program? Your EXE depends on your compiler and will determine what format you are speaking of.
Getting back in the game.
JoeTheProgrammer
Member
Member
Posts: 48
Joined: Mon Aug 13, 2007 2:30 pm

Post by JoeTheProgrammer »

LordMage wrote:What EXE, there are more than several formats, do you mean strictly a DOS EXE, Win16 EXE, Win32 EXE, or do you simply mean any executable format file?? what are you using to compile your c++/c program? Your EXE depends on your compiler and will determine what format you are speaking of.
I want to load a DOS EXE.
LordMage
Member
Member
Posts: 115
Joined: Sat Sep 22, 2007 7:26 am
Contact:

Post by LordMage »

Well, as far as actually loading one I have not done it before. but I do know that you first have to make sure that your kernel is going to support the calls within the program. If you are planning on having your kernel as a DOS EXE then I don't suppose that would be a problem. Now, the main thing you need to do is get past the header information and look for the start of the binary execution statements inside. this website has information of the header http://www.delorie.com/djgpp/doc/exe/

Hopefully that will help

By the By, what compiler are you using?
Getting back in the game.
JoeTheProgrammer
Member
Member
Posts: 48
Joined: Mon Aug 13, 2007 2:30 pm

Post by JoeTheProgrammer »

LordMage wrote:Well, as far as actually loading one I have not done it before. but I do know that you first have to make sure that your kernel is going to support the calls within the program. If you are planning on having your kernel as a DOS EXE then I don't suppose that would be a problem. Now, the main thing you need to do is get past the header information and look for the start of the binary execution statements inside. this website has information of the header http://www.delorie.com/djgpp/doc/exe/

Hopefully that will help

By the By, what compiler are you using?
Also I wanted to know how to load a Win32 EXE as well. The compiler I am using is gcc on Mac.
LordMage
Member
Member
Posts: 115
Joined: Sat Sep 22, 2007 7:26 am
Contact:

Post by LordMage »

have you setup gcc for cross compiling to those formats??? Okay, a common Win32 EXE is the PE or Portable Executable. I am using this type and you can get actualy code and a good explaination of how to load them in asm at Neon's OS Development Tutorial site. here is the address http://www.mt2002.sitesled.com/OSDevIndex.html

again hope this helps.
Getting back in the game.
JoeTheProgrammer
Member
Member
Posts: 48
Joined: Mon Aug 13, 2007 2:30 pm

Post by JoeTheProgrammer »

LordMage wrote:have you setup gcc for cross compiling to those formats??? Okay, a common Win32 EXE is the PE or Portable Executable. I am using this type and you can get actualy code and a good explaination of how to load them in asm at Neon's OS Development Tutorial site. here is the address http://www.mt2002.sitesled.com/OSDevIndex.html

again hope this helps.
For some reason that url is not working for me. Also how do you set up cross compiling for the exe format, since I am new to programming on Mac.
LordMage
Member
Member
Posts: 115
Joined: Sat Sep 22, 2007 7:26 am
Contact:

Post by LordMage »

you got me, I don't use gcc or Mac. I am a windows junkie. why have you chosen to load microsoft formats anyway. most Mac/Unix/Linux users load ELF which is I think the native compile format for gcc. I could be wrong though.

I think the site mite be undergoing an update or something check it out later. I found it very informative
Getting back in the game.
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Post by Brynet-Inc »

Most modern Unix systems use ELF, Mac OSX does not.. ;)

http://en.wikipedia.org/wiki/Mach-O
http://en.wikipedia.org/wiki/Executable ... ble_Format

As for the "PE" cross-compiler, Try visiting our friend.. "Google".
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Post by Colonel Kernel »

There is a tutorial on the OS-Dev wiki for creating a GCC cross-compiler. The example target format in the tutorial is elf, but you could probably use whatever target you want. I've followed the tutorial successfully to create a gcc cross-compiler on Mac OS X that targets elf.
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!
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post by Dex »

You can get C code for loading a MZ exe here: http://alexfru.chat.ru/epm.html#los4d
I also have code for loading a PE file, but its in asm.
JoeTheProgrammer
Member
Member
Posts: 48
Joined: Mon Aug 13, 2007 2:30 pm

Post by JoeTheProgrammer »

Thanks all for all of the information.
Post Reply