简体   繁体   English

添加了pe可执行节损坏.text节

[英]Added pe executable section corrupting .text section

I am trying to add a section to pe executable, when I add the section it is corrupting the memory of the first 40 bytes of the .text section. 我正在尝试向pe可执行文件添加一个节,当我添加该节时,它破坏了.text节的前40个字节的内存。 I wanted to know if anyone knows why my function is corrupting the .text section? 我想知道是否有人知道为什么我的函数损坏了.text节?

When I check in CFF explorer all the offsets are correct including the new sections. 当我签入CFF资源管理器时,所有偏移都正确,包括新部分。 This has happened repeatedly with different files. 对于不同的文件,这种情况反复发生。

Here is the code to create the added section: 这是创建添加的部分的代码:

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

I've found the solution there is not enough space at the end of section headers to add another section header so its overwriting the section straight after which is .text. 我发现解决方案在节标题的末尾没有足够的空间来添加另一个节标题,因此它直接覆盖了.text之后的节。 Now I need to find out how to increase header space in file so I can add a section header without overflow. 现在,我需要找出如何增加文件头的空间,以便可以添加节头而不会溢出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM