PE File .text Section Size

醉酒当歌 提交于 2021-01-29 06:02:18

问题


I wrote code and compiled it to exe, now the .text section need to be larger , If I have the code and I want to allocate more space in the .text section from code before compiling it , how to do so ? Allocate some buffers ?

I'm trying to alter the code or compiling option to result with a binary file with LARGER .TEXT section

my compiler VisualStudio2010 or cl.exe

Patching the binary file is more complicated


回答1:


Assuming it's really what you want, you may use inline assembly. E.g. for gcc+gas: void unused_global() { __asm(".space 10000"); }

For Visual Studio's cl.exe, it seems to be more tricky: there is no directives in inline asm, even REPT is unavailable. I would compile a bunch of nops separately with masm; otherwise we have to do something like this:

#define NOP __asm { NOP } ;
#define NOP8 NOP NOP NOP NOP NOP NOP NOP NOP
#define NOP64 NOP8 NOP8 NOP8 NOP8 NOP8 NOP8 NOP8 NOP8 
#define NOP512 NOP64 NOP64 NOP64 NOP64 NOP64 NOP64 NOP64 NOP64
#define NOP4096 NOP512 NOP512 NOP512 NOP512 NOP512 NOP512 NOP512 NOP512
#define NOP32768 NOP4096 NOP4096 NOP4096 NOP4096 NOP4096 NOP4096 NOP4096 NOP4096
void unused_global() { NOP32768 }


来源:https://stackoverflow.com/questions/14170748/pe-file-text-section-size

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!