Page 1 of 1

PE executable problem

Posted: Sat Jan 31, 2009 4:01 pm
by neon
Hey everyone,

I am not quite sure where the problem might be here. I am trying to properly execute a PE executable. I have the file loaded into memory, and have gotten both the image base and entry point address from the loaded file. The image base + entry point address also is the same as what I expect it to be (According to the linker map.) I have verified all of this to be true using the bochs debugger and my compiliers linker map.

Everything is fine...except the entry point is actually not there at the expected address thus it crashes. I have verified this using the bochs debugger. When I checked the real location in memory of the address point using the debugger, it was at base + 0x400 which I find odd.

Does this have to do with alignment in some way? Where do you think the problem might be at? I have been stuck on this for a few days and just cannot seem to find the cause of it. Because I don't know the cause I don't know where to begin looking for a solution.

Any help is appreciated. I am also willing to post code if needed if you let me know what code you want to see.

Re: PE executable problem

Posted: Sun Feb 01, 2009 6:43 am
by ru2aqare
neon wrote:Does this have to do with alignment in some way? Where do you think the problem might be at? I have been stuck on this for a few days and just cannot seem to find the cause of it. Because I don't know the cause I don't know where to begin looking for a solution.
Are you sure you take section alignment and file alignment into account? Something similar happened to me in the past, and the workaround was to make the linker use the same alignment for sections and sectors (effectively creating a 1:1 mapping of the image to the file). After that I implemented paging in the boot loader and this workaround wasn't needed anymore.

Re: PE executable problem

Posted: Sun Feb 01, 2009 12:24 pm
by neon
Are you sure you take section alignment and file alignment into account? Something similar happened to me in the past, and the workaround was to make the linker use the same alignment for sections and sectors (effectively creating a 1:1 mapping of the image to the file).
Wow, I cannot believe I forgot about that! I added /ALIGN:512 to MSVC++'s linker command line and it works like a charm right now :D
After that I implemented paging in the boot loader and this workaround wasn't needed anymore.
My boot loader actually does have paging implemented; the only feature being used though is to insure we don't go beyond 4MB. Its more of a bug check feature for me.

Although I might be needing to fully impliment paging when loading boot time modules...This I have no clue and will be my next problem. At the moment by boot loaders main program passes control to OSInit.exe (Thanks to you ;) ). OSInit.exe is responsible for loading the boot time device drivers and the kernel. The problem I have is how should I proceed with this.

Thanks for your great help! :D