none
How to preserve user-defined section in Release configuration(怎样在发行配置中保留用户自定义的段) RRS feed

  • 问题

  • In a situation which I need to locating some string in an image file easily, I can alter or patching the executable later (though UltraEdit or PE Tools and so on). So I decide to put the string in a section defined by me in the source file. However in the Debug configuration I can figure out everything is OK. But in Release build the section is gone. I examine the command line of the Linker, and got no hint about such a behavior. I really need to preserve the user-defined section, so can any one give a help? I list the detailed procedure I took as follows:

    在一个应用中我需要方便定位可执行映像中的一个字符串,以便我可以随后进行更改(使用UE或PE Tools等)。因此在源文件中我将其放到了自定义的段中。奇怪的是在调试版本中,这个段存在;在发行版本中,这个段没了。我检查了链接器的命令行,但是得不到为什么会有这种行为的启发。我确实需要保留自定义段,请问有人能给予帮助吗?我在下面详列了我的做法:

    The following content coming from StdAfx.h, please notice the user-defined section I added:

    下面的内容来自StdAfx.h文件,请注意其中的自定义段:

    #pragma once

    #include "targetver.h"

    #include <stdio.h>
    #include <tchar.h>

    #pragma const_seg(".udata")
    const char* test = "mingyurui";
    #pragma const_seg("")

     

    One can build a very simple test project with the above header file, and check the Debug version with dumpbin, and following is my way:

    your directory comes here>dumpbin /rawdata:1 /section:.udata mytest.exe

    you will not difficult observe the string “mingyurui” from the output.

    可以用上面头文件建立一个很简单的测试工程,然后用dumpbin工具检查Debug版本的可执行文件,我的方法如下:

    正确路径>dumpbin /rawdata:1 /section:.udata mytest.exe

    不难从输出中找到字符串"mingyurui"

    But if one switch to Release build, the .udata section was gone! you can also check that though dumpbin with option /summay. Can any one point that to me?

    但是在发行版本中,段.udata没了,可以用dumpbin指定选项/summary验证这一点。请问有人能指点我一下吗?

     

    2010年7月7日 5:19

答案

全部回复