Search code examples
visual-c++dllreverse-engineeringportable-executable

prevent VC++ DLL rebasing by PE header editing


I need to set the flag /FIXED to prevent the rebasing of my VC++ dll without recompiling. (http://msdn.microsoft.com/en-us/library/w368ysh2.aspx). Where is this flag in the PE header?

thank you, Riccardo


Solution

  • The /FIXED linker switch does not correspond to a flag in the PE header, it actually specifies whether a relocation section is added to the PE file by the linker.

    The DYNAMIC_BASE flag Hans Passant talks about specifies whether the OS is allowed to relocate the image in memory when it is loaded (if ASLR is on).

    • Linking with /FIXED is fine for a .exe as long as you don't need ASLR for securiy (Web browser etc)
    • Linking with /FIXED for a .dll is not a good idea, if the dll cannot be loaded at its preferred address (some other dll might already be loaded there) the dll loading will fail!