从 DLL 及其关联的导入库中删除导出的符号 (VS8)

发布于 2024-12-04 15:50:50 字数 283 浏览 1 评论 0原文

有没有办法对 DLL 及其 .lib 文件进行后处理,以删除我不想要的符号?

背景:

DLL 的代码使用 boost::serialization,它可以导出(很多很多)符号。显然,这是为了使链接器不会忽略未引用但在初始化时具有重要副作用的静态对象。

然而,我非常希望 DLL 的导出符号中没有任何提升的提示。

我的原因是,由于链接步骤已完成,因此可以安全地删除由库引起的符号表中的混乱。

因此,我想知道是否有一些工具可以完成此任务。

Is there any way to postprocess a DLL and its .lib file to remove symbols that I do not want within them?

Background:

The DLL's code uses boost::serialization, which dllexports (many many) symbols. Apparently this is so as to cause the linker not to omit static objects that are unreferenced but have important side effects when initialized.

However, I'd very much prefer that there be no hint of boost within the DLL's exported symbols.

I reason that since the link step has completed that it would be safe to remove the mess in the symbol table caused by the library.

Hence, I am wondering if there exists some tool to accomplish this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心如狂蝶 2024-12-11 15:50:50

我不知道有什么工具可以执行此操作,但您可以构建一段 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
}

这更多的是某种混淆,但完全删除名称更复杂,因为它需要对导出部分进行完全一致的重写。

I don't know a tool that does this, but here is a piece of C++ code you can build that can change a DLL exported names. In this case, you can set the names you don't want to an empty string (the 0 character):

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
}

It's more some kind of obfuscation but removing names completely is more complex since it requires a full consistent rewrite of the exports section.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文