我正在尝试向 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;
最佳答案
在可移植可执行文件中添加部分:https://github.com/Ge0/PeTools/tree/master/PeAddSection
关于c++ - 添加了破坏 .text 部分的 pe 可执行部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26283438/