Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is DLL always have the same Base Address?

Tags:

c

windows

I'm studying about windows and DLL stuffs and I have some question about it. :)

I made a simple program that loads my own DLL. This DLL has just simple functions, plus, minus.

This is the question : if I load some DLL (for example, text.dll), is this DLL always have the same Base Address? or it changes when I restart it? and can I hold the DLL's Base Address?

When I test it, it always have same Base Address, but I think when I need to do about this, I have to make some exception about the DLL Base Address.

like image 866
Nagi Avatar asked Jan 03 '12 17:01

Nagi


2 Answers

The operating system will load your DLL in whatever base address it pleases. You can specify a "preferred" base address, but if that does not happen to be available, (for whatever reason, which may well be completely out of your control,) your DLL will be relocated by the operating system to whatever address the operating system sees fit.

like image 169
Mike Nakis Avatar answered Oct 03 '22 02:10

Mike Nakis


i load some DLL(for example, text.dll), is this DLL always have the same Base Address?

No. It is a preferred base address. If something is already loaded at that address, the loader will rebase it and fixup all of the addresses.

Other things, like Address Space Layout Randomization could cause it to be different every time the process starts.

like image 36
vcsjones Avatar answered Oct 03 '22 02:10

vcsjones