Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/146.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 添加了pe可执行文件部分损坏。文本部分_C++_Portable Executable - Fatal编程技术网

C++ 添加了pe可执行文件部分损坏。文本部分

C++ 添加了pe可执行文件部分损坏。文本部分,c++,portable-executable,C++,Portable Executable,我正在尝试向pe可执行文件添加一个节,当我添加该节时,它正在破坏.text节的前40个字节的内存。我想知道是否有人知道为什么我的函数会破坏.text部分 当我签入CFF浏览器时,所有偏移都是正确的,包括新的部分。这在不同的文件中反复发生 以下是创建添加节的代码: int addSection(char* sectionName, DWORD size){ int pos = ntHeader->FileHeader.NumberOfSections; firstSection[pos].V

我正在尝试向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;

}

我发现解决方案是在节标题的末尾没有足够的空间添加另一个节标题,因此它会直接覆盖该节,后面是.text。现在,我需要了解如何增加文件中的标题空间,以便在不溢出的情况下添加节标题。

在可移植可执行文件中添加节: