Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>I know that the '@4' is the size of the stack but why is it needed?</p> </blockquote> <p>To enable the linker to report a fatal error if your compiler assumed the wrong calling convention for the function (this can happen if you forget to include header files in C and ignore all the compiler warnings or if a declaration doesn't exactly match the function in the shared library).</p> <blockquote> <p>Why don't C Functions need decorations?</p> </blockquote> <p>Functions that use the <code>cdecl</code> calling convention are decorated with a single leading (so it would actually be <code>_printf</code>). </p> <p>The reason why no parameter size is encoded into the decorated name is that the caller is responsible for both setting up and tearing down the stack, so an argument count mismatch will not be fatal for the stack setup (though the calling function might still crash if it isn't given the right arguments, of course). It might even be possible that the argument count is variable, like in the case of <code>printf</code>.</p> <blockquote> <p>When I looked in the kernel32.dll with a hex editor I only saw <code>ExitProcess</code> not <code>_ExitProcess@4</code>.</p> </blockquote> <p>The mangled names are usually mapped to the actual exported names of the DLL using definition files (<code>*.def</code>), which then get compiled to <code>*.lib</code> import library files that can be used in your linker invocation. An example of such a definition file for <code>kernel32.dll</code> is <a href="http://www.dsource.org/projects/bindings/wiki/DefFiles/Kernel32" rel="nofollow">this one</a>. The following line defines the mapping for <code>ExitProcess</code>:</p> <pre><code>_ExitProcess@4 = ExitProcess </code></pre> <blockquote> <p>Is this the way I should be using these functions?</p> </blockquote> <p>I don't know NASM very well, but the code I've seen so far usually specifies the decorated name, like in your example.</p> <p>You can find more information <a href="http://www.unixwiz.net/techtips/win32-callconv.html#decor" rel="nofollow">on this excellent page about Win32 calling conventions</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload