I've been noticing this for a while. Functions like IsDebuggerPresent
and GetModuleHandle
are always present in a binary's import directory structure. I assume is the Window's dynamic linker, but where do I find information about it? Below is a screenshot of the "default" functions I'm talking about which are always imported.
2 Answers
At a guess (since you don't provide much detail), the binaries you're looking at were compiled using a recent version of Microsoft Visual C++. The listed APIs are used by its CRT (C runtime) library in functions referenced by the startup or essential runtime code which is linked into every executable by default. You can find (most of) the CRT sources installed with Visual Studio and check yourself how these APIs are used. For example, IsDebuggerPresent
is used by the __raise_securityfailure
function which is called when the security cookie check fails (and in some other cases).
Since there are other compilers besides Visual C++ as well as its older versions, there are definitely binaries out there which do not import all or even any of these APIs. In fact, you can make a program which does not link to kernel32
at all (for example, by using only native APIs from ntdll.dll
or by loading the DLL dynamically shellcode style).
-
Thank you! Sorry for not providing much detail, I wasn't exactly sure how to phrase the question. But you provided me all the answers that I needed. Cheers– unc4nnyCommented Sep 25, 2021 at 21:52
IsDebuggerPresent is use to determine if the program is being debugged while GetModuleHandle is use to retrieve the handle on a specific module (Imagebase address) that exist in the current process context. These APIs can be not exist both in any program and does not have any relation with the windows dynamic linker.
There are other programs that don't have imported libraries and will resolved dynamically without the use of those APIs.
-
1I'm already acquainted with their behaviour. I was just wondering why they are present in the import table even tho I'm not using them in my code.– unc4nnyCommented Sep 25, 2021 at 17:42
main()
function in a C or C++ is rarely ever identical to the entry point of the binary file. And the part that runs before (and "around") themain()
function (aka the runtime) is what influences stuff that seems to be always there.