C程序新段声明

C program new segment declaration

我有这个简单的代码测试代码:

#include <Windows.h>
#include <stdio.h>

/* Declare new sections to store encrypted code and shellcode data */
#pragma section(".code", execute, read, write)
#pragma comment(linker,"/SECTION:.code,ERW")

// From here executable code will go in .code section
#pragma code_seg(".code")


int test()
{
    printf("prova");
    return 0;
}

// .stub SECTION
#pragma section(".stub", execute, read, write)
#pragma code_seg(".stub")

int main(int argc, char *argv[]){
    test(); /* Call function which executes shellcode now that it is decrypted */
    return 0;
}

谁能告诉我为什么如果我转储这个文件我只有这个默认部分:

未生成的.code 段。我想我曾经在一些以前的项目中这样做过,我做错了什么吗?

-- 进一步测试--

使用以下指令,我能够将所有 code/variable/costant 限制在使用 dumbin 命令可见的 .code 段中。

#pragma section(".code", execute, read)
#pragma section(".codedata", read, write)
#pragma comment(linker,"/SECTION:.code,ERW")
#pragma comment(linker,"/SECTION:.codedata,ERW")
#pragma comment(linker, "/MERGE:.codedata=.code")

#pragma code_seg(".code")
#pragma data_seg(".codedata")
#pragma const_seg(".codedata")