首页 文章

添加了pe可执行部分损坏的.text部分

提问于
浏览
1

我试图在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;

}

2 回答

  • 0

    在可移植可执行文件中添加部分:https://github.com/Ge0/PeTools/tree/master/PeAddSection

  • 1

    我发现解决方案在节 Headers 末尾没有足够的空间来添加另一个节 Headers ,因此它会直接覆盖该节之后的.text文件 . 现在我需要找出如何增加文件中的 Headers 空间,这样我就可以添加一个没有溢出的节头 .

相关问题