lij*_*jie 5 visual-studio-2005 visual-studio
有什么方法可以对 DLL 及其 .lib 文件进行后处理以删除我不想要的符号?
背景:
DLL 的代码使用 boost::serialization,它 dllexports(很多)符号。显然,这是为了使链接器不会省略未引用但在初始化时具有重要副作用的静态对象。
但是,我非常希望 DLL 的导出符号中没有任何提升的提示。
我的理由是,既然链接步骤已经完成,那么删除由库引起的符号表中的混乱是安全的。
因此,我想知道是否存在一些工具来实现这一点。
我不知道有什么工具可以执行此操作,但您可以构建一段 C++ 代码,它可以更改 DLL 导出的名称。在这种情况下,您可以将不需要的名称设置为空字符串(0 字符):
void RemoveUnwantedExports(PSTR ImageName)
{
LOADED_IMAGE image;
// load dll in memory for r/w access
// you'll need Imagehlp.h and Imagehlp.lib to compile successfully
if (MapAndLoad(ImageName, NULL, &image, TRUE, FALSE))
{
// get the export table
ULONG size;
PIMAGE_EXPORT_DIRECTORY exports = (PIMAGE_EXPORT_DIRECTORY)ImageDirectoryEntryToData(image.MappedAddress, FALSE, IMAGE_DIRECTORY_ENTRY_EXPORT, &size);
PIMAGE_SECTION_HEADER *pHeader = new PIMAGE_SECTION_HEADER();
// get the names address
PULONG names = (PULONG)ImageRvaToVa(image.FileHeader, image.MappedAddress, exports->AddressOfNames, pHeader);
for (ULONG i = 0; i < exports->NumberOfNames; i++)
{
// get a given name
PSTR name = (PSTR)ImageRvaToVa(image.FileHeader, image.MappedAddress, names[i] , pHeader);
// printf("%s\n", name); // debug info
if (IsUnwanted(name))
{
name[0] = 0; // set it to an empty string
}
}
UnMapAndLoad(&image); // commit & write
}
}
BOOL IsUnwanted(PSTR name)
{
// implement this
}
Run Code Online (Sandbox Code Playgroud)
这更像是某种混淆,但完全删除名称更复杂,因为它需要对导出部分进行完全一致的重写。
| 归档时间: |
|
| 查看次数: |
2375 次 |
| 最近记录: |