【发布时间】:2015-01-26 00:16:32
【问题描述】:
我正在尝试向 pe 可执行文件添加一个部分,当我添加该部分时,它会破坏 .text 部分的前 40 个字节的内存。我想知道是否有人知道为什么我的函数会破坏 .text 部分?
当我签入 CFF 资源管理器时,所有偏移量都是正确的,包括新部分。这在不同的文件中反复发生。
这是创建添加部分的代码:
int addSection(char* sectionName, DWORD size){
int pos = ntHeader->FileHeader.NumberOfSections;
firstSection[pos].VirtualAddress = align((firstSection[pos - 1].VirtualAddress + firstSection[pos - 1].Misc.VirtualSize), ntHeader->OptionalHeader.SectionAlignment);
firstSection[pos].Misc.VirtualSize = (size);
firstSection[pos].PointerToRawData = align((firstSection[pos - 1].PointerToRawData + firstSection[pos - 1].SizeOfRawData), ntHeader->OptionalHeader.FileAlignment);
firstSection[pos].SizeOfRawData = align(size, ntHeader->OptionalHeader.FileAlignment);
firstSection[pos].NumberOfLinenumbers = 0;
firstSection[pos].NumberOfRelocations = 0;
firstSection[pos].PointerToLinenumbers = 0;
firstSection[pos].PointerToRelocations = 0;
ntHeader->FileHeader.NumberOfSections++;
ntHeader->OptionalHeader.SizeOfImage += align(firstSection[ntHeader->FileHeader.NumberOfSections-1].Misc.VirtualSize, ntHeader->OptionalHeader.SectionAlignment);
return 0;
}
【问题讨论】: