flat assembler
Message board for the users of flat assembler.

Index > Windows > Name decorators when declaring EXTERNALS

Author
Thread Post new topic Reply to topic
wyvern



Joined: 08 Dec 2011
Posts: 27
wyvern
Hi guys Smile, can somebody explain me what are the differences between:

1. EXTRN '__imp__ExitProcess@4' as ExitProcess:dword
2. EXTRN _ExitProcess@4
3. EXTRN ExitProcess

This thing about "name mangling" is confusing me, is neccesary to prefix mi labels with the "_" decorator (for example "_start:") to make Windows happy? (the MASM assembler seems to prefix everything with "_").

If someone can explain or guide me with this i would appreciat it, i want to know how relevant this can be when developing applications for Windows, or if it is important in other systems too.

_________________
Thanks
Post 28 Dec 2011, 20:18
View user's profile Send private message Reply with quote
majidkamali1370



Joined: 31 Oct 2010
Posts: 50
Location: Iran
majidkamali1370
I don't know your answer but, about underline, it is for stdcall declaration.
As MSDN:
Quote:
An underscore (_) is prefixed to the name. The name is followed by the at sign (@) followed by the number of bytes (in decimal) in the argument list. Therefore, the function declared as int func( int a, double b ) is decorated as follows: _func@12

http://msdn.microsoft.com/en-us/library/zxk0tw93%28v=vs.71%29.aspx
Post 28 Dec 2011, 21:54
View user's profile Send private message Send e-mail Yahoo Messenger ICQ Number Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1408
Location: Toronto, Canada
AsmGuru62
@wyvern: so are you asking for MASM coding or FASM coding?
Because, I have never had to use the underscores or these EXTRN things in FASM.
Post 28 Dec 2011, 22:19
View user's profile Send private message Send e-mail Reply with quote
wyvern



Joined: 08 Dec 2011
Posts: 27
wyvern
@AsmGuru62 If you use FORMAT PE in FASM im pretty sure you will never use decorators. Even if you work with some linkers like GOLINK or ALINK you can ignore decorators. I think im not asking for a particular assembler coding, but mi most used assembler is FASM. For example look the FASM example at C:\FASM\EXAMPLES\MSCOFF\MSCOFF.ASM, it is using decoratos, like if it was good practice, good habit or whatever

From what i understand, name mangling is a C++ thing for linkers and is used by some vendors like Micrsooft or Borland, if im not wrong it was originally designed for "function overloading", so the linker can recognize diferent functions with the same name.

Im in doubt if this is important or not for ASM development on Windows. FASM doesnt add the "_" prefix to functions (like MASM/TASM or GOASM with /ms), i should add this myself for some propposit?, or i can foget about this if mi linker of choice doesnt care?.

And the "'__imp__ExitProcess@4'" thing is alien for me, its equivalent to "_ExitProcess@4" ?
Post 28 Dec 2011, 22:38
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1408
Location: Toronto, Canada
AsmGuru62
I see... I write my whole programs in FASM only, so I am not using any linkers at all. But, I think, yes, you need decorations to interface FASM with other components, written not in FASM, but with some other type of language.

If I am not mistaken "_imp__xxxx" is some kind of a JMP to a real function. I have seen this often - in HLL when code calls an API -- the CALL itself come to a some kind of JMP table and from there it goes to a real API function imported from Windows DLLs. FASM, however, calls API straight by an address inside import table -- no additional jumps. Very cool!
Post 29 Dec 2011, 00:18
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17253
Location: In your JS exploiting you and your system
revolution
Name decoration is not a fasm thing, or a Windows thing. It is a C/C++ thing. If you are linking to the C/C++ library then you have to match the names that C/C++ used when it made the library.

Also note that some C/C++ compilers have even worse looking name mangling that what you show above.
Post 29 Dec 2011, 00:42
View user's profile Send private message Visit poster's website Reply with quote
wyvern



Joined: 08 Dec 2011
Posts: 27
wyvern
So, calling a entry point like this "_start:" or even adding the "_" to var labels is unnecessary or absurd. I wonder why a lot of asm code out there is writenn like that.
Post 29 Dec 2011, 01:08
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17253
Location: In your JS exploiting you and your system
revolution
wyvern wrote:
So, calling a entry point like this "_start:" or even adding the "_" to var labels is unnecessary or absurd.
If you are using the "public" directive and linking with C code then you may have to add the underscore so that the C code can find your function.

If you are using "extrn" directive then you will have to match the function name to whatever the other compiler has named the function.

If you are using just the Windows API and your own asm code then you can name things in any way you please.
Post 29 Dec 2011, 02:15
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.