在链接上添加可执行文件部分

问题描述 投票:0回答:1

我目前正在使用Visual Studio 2017,并尝试使我的应用程序更具防篡改性。现在我想要保护的关键代码函数将在运行时被解密,为此我试图将它们添加到文件中的自定义部分,这将被称为.foobar作为示例。我正在使用#pragma指令添加该部分,稍后指定应该链接哪个函数,但是当我分析PE文件时,没有.foobar部分。

我正在尝试添加该函数的代码如下:

#pragma section(".foobar",execute, read, write)
#pragma comment(linker,"/SECTION:.foobar,ERW")
...
Main() function and others...
...
#pragma code_seg(".foobar")
int IWantThisToBeInFoobar() {...}

我也试过以下内容:

int IWantThisToBeInFoobar();
...
#pragma alloc_text(".foobar", IWantThisToBeInFoobar)
...
int IWantThisToBeInFoobar() {...}

到目前为止,这些都没有工作,我使用ExeInfo PE查看部分,并且没有.foobar的任何迹象。

任何帮助或指导表示赞赏。

c visual-studio linker portable-executable pragma
1个回答
0
投票

弄清楚,必须使用/ OPT:NOREF和/ LTCG进行编译。

希望这对将来的某些人有用。

© www.soinside.com 2019 - 2024. All rights reserved.