Dynamic Link Libraries¶
The Microsoft docs describe a DLL
as "a library that contains code and data that can be used by more than one program at the same time
."
Reading up on COM objects might clear up things if you're wondering about the history behind DLL's and how they came to be what they are today.
DLLs are used as one of the core functionalities behind application execution in Windows. From the Windows documentation, "The use of DLLs helps promote modularization of code, code reuse, efficient memory usage, and reduced disk space. So, the operating system and the programs load faster, run faster, and take less disk space on the computer."
When a DLL is loaded as a function in a program, the DLL is assigned as a dependency
. Since a program is dependent on a DLL, attackers can target the DLLs rather than the applications to control some aspect of execution or functionality.
DLLs are created no different than any other project/application; they only require slight syntax modification to work. Below is an example of a DLL from the Visual C++ Win32 Dynamic-Link Library project
:
Below is the header file
for the DLL; it will define what functions are imported and exported:
How are they used by an application?¶
load-time dynamic linking:¶
When loaded using load-time dynamic linking, explicit calls to the DLL functions are made from the application
. You can only achieve this type of linking by providing a header (.h) and import library (.lib) file
. Below is an example of calling an exported DLL function from an application.
run-time dynamic linking:¶
When loaded using run-time dynamic linking, a separate function
(LoadLibrary
or LoadLibraryEx
) is used to load the DLL at run time
. Once loaded, you need to use GetProcAddress to identify the exported DLL function to call
. Below is an example of loading and importing a DLL function in an application.