Search code examples
portable-executable

Position code independant executable on windows


Is it possible to build a position independant code for windows ? I am not talking about a dll, i am talking about an executable (PE).

What i want to do is that functions (main for example) which are in the program should be mapped at a different memory address between 2 executions.

Thanks


Solution

  • You should read up on the image base relocation directory in a PE file. I was wondering the same thing you are asking now a while back. From the research I had done I couldn't find any compiler that generates completely base independent code. I ended up writing my program entirely in x86 asm with some tricks to load strings etc independent form the address. I can tell you its not worth the trouble. Just remap all the addresses to your target location.

    I suggest you start reading this https://msdn.microsoft.com/en-us/library/ms809762.aspx

    You should also check out Icezilon's (not sure how you spell his name) tutorials. They're very helpful