从DLL及其关联的导入库(VS8)中删除导出的符号 [英] Removing exported symbols from a DLL and its associated import library (VS8)

查看:136
本文介绍了从DLL及其关联的导入库(VS8)中删除导出的符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以对DLL及其.lib文件进行后处理,以删除不需要的符号?

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

背景:

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

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.

但是,我非常希望DLL的导出符号中没有增强的提示.

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.

推荐答案

我不知道执行此操作的工具,但这是您可以构建的一段C ++代码,可以更改DLL导出的名称.在这种情况下,您可以将不需要的名称设置为空字符串(0字符):

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.

这篇关于从DLL及其关联的导入库(VS8)中删除导出的符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆