I don’t know how to ask this better but why does this:
call ExitProcess
do the same as this?:
mov eax, ExitProcess
mov eax, [eax]
call eax
I would think that these would be equivalent:
call ExitProcess
mov eax, ExitProcess
call eax
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
When importing the code from a DLL, the symbol
ExitProcessisn’t actually the address of the code that exits your process (it’s the address of the address). So, in that case, you have to dereference it to get the actual code address.That means that you must use:
to call it.
For example, there’s some code at this location containing the following:
However, importing the DLL directly in user code is not the only way to get at the function. I’ll explain why you’re seeing both ways below.
The "normal" means of calling a DLL function is to mark it
externthenimportit from the DLL:Because that sets up the symbol to be an indirect reference to the code, you need to call it indirectly.
After some searching, it appears there is code in the wild that uses the naked form:
From what I can tell, this all seems to use the
alinklinker, which links with thewin32.liblibrary file. It’s possible that this library provides the stub for calling the actual DLL code, something like:In
nasm, this would import the address ofExitProcessfrom the DLL and call itExitProcessActual, keeping in mind that this address is an indirect reference to the code, not the address of the code itself.It would then export the
ExitProcessentry point (the one in this LIB file, not the one in the DLL) so that others could use it.Then someone could simply write:
to exit the process – the library would jump to the actual DLL code.
In fact, with a little more research, this is exactly what’s happening. From the
alink.txtfile which comes with thealinkdownload:(
__imp_MessageBoxAis the symbol imported from the DLL, equivalent to myExitProcessActualabove).