tags:

views:

185

answers:

3

Is there any way to manually decorate function names in MS C++? I'm going to guess any solution would be Microsoft-specific, and I'm cool with that.

Alternatively, is there a way to declare the function "??_M@YGXPAXIHP6EX0@Z@Z" so the compiler can understand it? FYI, undname lists it as:

void _ _ stdcall `eh vector destructor iterator'(void * , unsigned int, int, void (_ _thiscall * )(void * ))

Obviously, the compiler is not happy with apostrophes in my identifers.

EDIT:
The solution was actually extremely simple. I complied the obj's, and hexedited the desired decorated names right over my placeholder names, padding them with nulls. The linker ate it right up, no questions asked. The functions are stubs, calling external functions so I don't have to keep hexediting every time I make a small change.

Thanks for the ideas everyone.

A: 

`eh vector destructor iterator'

You sure the apostrophes[sic] are part of the identifier? Did you try to use the function without them? Looks like they exist to improve readability.

Alternatively, is there a way to declare the function "??_M@YGXPAXIHP6EX0@Z@Z"

I seriously doubt if you can 'declare' a mangled name if we mean the same thing by declaration. Declaration is pre-compliation, mangling occurs much later.

??_M@YGXPAXIHP6EX0@Z@Z

This is a mangled name. All symbols with C++ linkage are mangled. This is sort of a hash of the signature, return type and calling convention information. Read more on MSDN.

dirkgently
Yeah, the apostrophes are part of the name -- it's a special compiler function named internally. Other undecorated names don't have them. I tried all kinds of ways to declare this, and no luck.
zildjohn01
A: 

I'll assume you know what the vector destructor iterator is, and only want to know how to mimic its name in your code.

One way might be to write your code in assembly, which might (but then again, might not) let you use almost any name for a function.

Another way might be to put your code in a DLL and override the name in your DLL's *.def file, using the optional entryname[=internalname] syntax which is allowed in a *.def file's EXPORTS section (which lets you rename what's being exported).

ChrisW
A: 

If you declare your function as extern "C" and use the linker option that disables underscore prefix, the name you give in the code is the name you'll have in the .obj file. But this won't solve all your problems, since the compiler will balk when you try to declare a function with special characters in the name.

I guess the solution (which is a lot of work IMO) is to give to the desired functions unique names in the source code (like PLACEHOLDER_01) and then replace these in the .obj file. You'll need somehow to parse the object file and change the symbol names.

Notice also that `eh vector destructor iterator' is a mangled name, the real (symbol) name shouldn't have apostrophes or spaces in it. When dumping the .obj/.dll, you'll have to disable name-mangling.

Fabio Ceconello