Hi Guys,

There's a little question for you. PE Explorer is capable of reading the number and sizes of parameters of decorated functions in DLLs. Can we use decoration in MASM, so that any of our dlls can export the decorations as well?

According to the MSDN documentation:



?a@@YAHD@Z


is the equivalent of:



int a(char){int i=3;return i;};


If we can use decorations, would someone please show me an example of how we can?
Any literature on decorations is also welcome.

Thanks.

Regards,
Art
Posted on 2003-11-25 06:25:50 by art_sands
I can't see much point in using them as they seem to be used internally and I could find nothing that suggested they could be used externally. The asm reference appears to be for in-line assembly.

The function and class names are encoded in the decorated name. The rest of the decorated name is a code that has internal meaning only for the compiler and the linker


For C decorations, @4 pushes 4 bytes onto the stack, since almost every parameter is a dword you can safely assume that the value devided by 4 gives you the number of parameters. We already use these in libraries and such, the PROTO directive tells the linker how to decorate the name.
Posted on 2003-11-25 06:45:28 by donkey
Hi Donkey,

Well there's lots of info in the C++/C Build Tools reference in MSDN. Check it out.

Yeah you're right about the decorations not being necessary. But I want my dll to export the entire decorated symbol name (C decoration). that way, any tool or program can easily determine the number and the sizes of parameters of my functions. generating inc files of small dlls can be done manually but it becomes a pain for large ones.

Btw, the above decorations i spoke about were those produced by the C++ compilation.

C decorations are very simple.

Regards,
Art
Posted on 2003-11-25 06:55:51 by art_sands
oh,

and there's also this tool called

undname [-f] decorated_name

which undecorates names for you. It simply calls the UnDecorateSymbolName api in imagehlp.dll.

Regards,
Art
Posted on 2003-11-25 06:57:28 by art_sands
Hi Art,

Whenever I build a lib with MASM32 it always exports the fully decorated C name. Since DLLs do not export the decorated names the only place this is useful is in library files and masm does this already.
Posted on 2003-11-25 07:05:04 by donkey
well

this came as a surprise to me too, but dlls do export decorated names.

I've seen some myself using PE Explorer.

Regards,
Art
Posted on 2003-11-25 07:09:42 by art_sands
Mmmm,

I've never seen one, I've been through most of the API and that doesn't use them. At any rate no option in MASM exists to generate them that I can find. They are in the lib file that is generated when you build a dll however.
Posted on 2003-11-25 07:22:43 by donkey
Originally posted by donkey
Mmmm,

I've never seen one, I've been through most of the API and that doesn't use them. At any rate no option in MASM exists to generate them that I can find. They are in the lib file that is generated when you build a dll however.
Hmmmm.... ;)

decorated.asm:
.386

.model flat,stdcall
option casemap:none
include windows.inc
include kernel32.inc
includelib kernel32.lib

.code
MyDummyDecoratedFunction proc export MyDummyParamOne:DWORD, MyDummyParamTwo:DWORD
ret
MyDummyDecoratedFunction endp

start:
invoke ExitProcess,0
end start
ml /c /coff decorated.asm
link /subsystem:windows decorated.obj

link /dump /exports decorated.exe
Dump of file decorated.exe



File Type: EXECUTABLE IMAGE

Section contains the following exports for decorated.exe

0 characteristics
3FC360FD time date stamp Tue Nov 25 15:02:37 2003
0.00 version
1 ordinal base
1 number of functions
1 number of names

ordinal hint RVA name

1 0 00001000 _MyDummyDecoratedFunction@8
Posted on 2003-11-25 07:57:38 by Morris
Decoration changes from compiler to compiler. Most of the time, external interfaces are left mostly undocumented - in C++ source, this would be via a block like the following:


extern "C" {
// function prototypes go here
}


however, when exporting classes or objects, you really do need the C++ name decoration.
Somebody on irc found this link the other day.
Posted on 2003-11-25 08:36:10 by f0dder
hi morris,

that works. thanks for the solution. now that makes my job a little easier.

hey, you don't need .def files no more. or am i gone nuts? :grin:

Regards,
Art:alright:
Posted on 2003-11-25 08:49:47 by art_sands
Or you can read the book of pcasm in the part of interaction with C/C++, there you can see for what is used decoration ;) and for what is necesary ;) http://www.drpaulcarter.com/pcasm/ and maybe you can use some C++ classes in asm ;)...., I think that can be done.....


Nice day or night.
Posted on 2003-11-26 23:32:17 by rea
Hi hgb,

check out the microprocessor chapter and tell me if you find something inaccurate or missing.

oh by the way you said something about using "C++ classes" in asm. can you show me an example or was that a typo.

Regards,
Art
Posted on 2003-11-27 03:02:55 by art_sands
yet another FAQ contender.
Posted on 2003-12-16 19:01:25 by evil__donkey
I will try.

and sorry for not answer before... I am now in vacations, but I think I put myself to work, reading proving writing testing learning organizating I am doing some masive movements at my house, but I see that I am happy.


Nice day or night.
Posted on 2003-12-17 00:12:49 by rea