【问题标题】:Added pe executable section corrupting .text section添加了破坏 .text 部分的 pe 可执行部分
【发布时间】: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;

}

【问题讨论】:

    标签: c++ portable-executable


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 2014-09-25
        • 2018-11-19
        • 1970-01-01
        • 2012-12-16
        • 2012-12-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-04-04
        相关资源
        最近更新 更多