MSVC C++ 名称在运行时从字符串修改 [英] MSVC C++ Name Mangling From String On Runtime
问题描述
首先,我将从我需要在运行时进行名称修改的原因开始.
First i will start with the reason i need name mangling on runtime.
我需要在 dll 和它的包装器之间建立一个桥梁
I need to create a bridge between dll and its wrapper
namespace Wrapper
{
class __declspec(dllexport) Token
{
public:
virtual void release() {}
};
}
class __declspec(dllexport) Token
{
public:
virtual void release(){}
};
这个想法是使用 dumpin 生成所有包含类令牌的 dll 的重整名称,然后再将它们解散.
The idea is to use dumpin to generate all the mangled names of the dll holding class token and than demangled them.
?release@Token@@UAEXXZ --> void Token::release(void)
?release@Token@@UAEXXZ --> void Token::release(void)
之后我想转换的是匹配Wrapper,所以我需要更改函数名称
after that i want to convert is to match the Wrapper so i will need to change the function name
void Token::release(void) --> void Wrapper::Token::release(void)
void Token::release(void) --> void Wrapper::Token::release(void)
然后我需要再次对其进行处理,以便我可以创建一个 def 文件,将旧函数指向新函数.
and then i need to mangle it again so i can create a def file that direct the old function to the new one.
?release@Token@@UAEXXZ = ?release@Token@Wrapper@@UAEXXZ
?release@Token@@UAEXXZ = ?release@Token@Wrapper@@UAEXXZ
所有这些过程都需要在运行时进行.
all this process needs to be on run time.
首先也是最简单的解决方案是找到一个处理字符串的函数,但我找不到任何......
First and the easiest solution is to find a function that mangle strings but i couldn't find any...
还有其他解决方案吗?
推荐答案
Clang 编译器与 MSVC 的 ABI 兼容,包括名称修改.底层基础设施是LLVM项目的一部分,我发现llvm-undname 破坏 MSVC 名称.也许您可以重新设计它以将 Wrapper::
命名空间添加到符号并重新整理.
The Clang compiler is ABI-compatible with MSVC, including name mangling.
The underlying infrastructure is part of the LLVM project, and I found llvm-undname which demangles MSVC names. Perhaps you can rework it to add the Wrapper::
namespace to symbols and re-mangle.
您可以在 这个测试代码.
这篇关于MSVC C++ 名称在运行时从字符串修改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!