Knowledge Review section of the New PE PE

Dian Why a new section . Step and the new section

    For example, a few speak before our PE file in a blank area to add the code, but this is a drawback, because you blank section area may be read-only attribute can not be executed. If you modify the attributes. So the program may appear problems. so a new section can achieve our code.

and many more.

  1. Step New Day

    1. Add in the last section of a section position. If there is no empty space. I need to expand the extension header. And offset correction section of their own.

    2. The number of the section header modify the file.

    3. Add a new section table to modify the properties of the section of the table. Section .VirtualAddress. The members specified in this section expand the memory where it is. So you need to modify.

    4. Modify the section table file offset section .PointerToRawData we specify where to expand the memory section. This section then also need to specify where in the document launched

    Size. .SizeofRawData section after section of the data in the table in Section 5. Modify the alignment of our new section. I need to add some sections in the PE file data according to the size of the data file is aligned Add. And fill to the members.

    6. Modify extension headers PE image size. SizeofImage. This member is the key. If you do not modify the image size in accordance with the alignment of memory. So we just will not be mapped into memory. PE file or impossible to perform.

The new section Dian two steps . Combat manually add a section .

    1. Add a table section

        Add section table of the time. Needs to be added after the last section. For example just what a PE file

  Because the extension header SizeofHeaders marked head + size + NT DOS first section of the table. Align stored by file, so the data section 400 is the beginning. So we figure shown in the last section table .rsrc. We below there is enough space to add a new section table, so we copy the section table. paste behind him. .rsrc paste a new section table.

  We rename this section AAAA

   2. Modify the number of the section table . In the attribute header .

  There is a file header attribute records the number of our section of the table. We've added a section. Then you need to add in the original header record number 1. Find the number of the section table position. And add a can.

    Originally 7, 8 can now be changed.

    3. The offset correction section table .

  We've added a section table. So we have to specify memory location, commenced this section of the table. File deployed position. As well as the size of the data section.

  Corresponding to the three members are:

    Section .VirtualAddress

    节.SizeOfRawData

    节.PointerToRawData

   3.1 Jie .VirtuallAddress modification

  First, the first member of Section .virtuallAddress. We are aligned according to the file. With a section on the table to align storage.

    For example deployed position after a section of the table aligned 0x1c000 then we changed to 0x1d000

  3.2 Jie .sizeofRawData modification

  This member is the section in accordance with the size of the data file alignment. We depend on how much data is added to this section. We can add 0x1000 bytes behind PE file.

The new section of the starting position into FFFFF facilitate our view.

   We added a section of data 0x1000. Then the members on the amendment to 0x1000

  3.3 Section .PointerRawToData file offset Change

  The last section is modified in the file where to expand. We need this fancy file a section offset. And a section data size. Counted out.

例如上一个节 偏移位置为10. 那么节数据为100.  那么节数据就是从10 ~ 100都是上一个节. 我们的节展开就要从100位置展开.

  例如下图:

   上一个节开始位置是8400 节数据对齐后的大小是0x600 他俩相加则是 0x8A00. 所以我们的偏移位置在0x8A00开始.

  4.修改扩展头中PE的镜像大小 SizeofImage

我们新增了0x1000节数据大小.那么我们的镜像大小也要加0x1000大小进行映射.注意.要按照内存对齐.

我们的原镜像大小以及按照内存对齐的方式存放了. 就是0x1D000. 那么我们加了0x1000的数据就是 0x1E000大小.我们修改为0x1E000

保存文件

  5.保存文件内存中查看是否映射.

首先运行一下:

可以成功运行.

  去内存中查看.节表是否映射. 我们节在内存中展开的偏移是 0x1D000 加上我们的ImageBase 就是 0x41D000位置.

跳转过去之后发现就是我们刚才填写FFFF的数据.已经成功映射了.至此我们就为这个PE文件新增了一个节.

 

三丶总结

   根据上面实战添加节.进行一个总结.

    1.一个节表0x28个字节.在最后一个节表位置添加.如果SizeofHeaders 有足够空间的情况下.

    2.修改文件头中节表个数. 文件.SectionNumber = 原有节个数 + 你新增节的个数. 例如: 原为7.你增加了一个节.就为8

    3.修改节属性:

      节.VirtuallAddress 内存中展开的位置.按照内存对齐.   可以参照上一个节.virtuallAddress位置.我们进行修改.

      节.SizeofRawData 节数据按照文件对齐后的大小.      节.SizeofRawData = 你添加的节数据大小. 按照文件对齐存放. 例如添加了0x1000.那么大小就是0x1000

      节.PointerToRawData 文件中的偏移.  节.PointerToRawData = ()上一个节.PointerToRawData + 上一个节.SizeofRawData. )

    4.修改扩展头SizeofImage PE镜像大小.  扩展头.SizeofImage = 内存对齐(原SizeofImage值 + 你行增节数据大小 按照内存对齐)

 

Guess you like

Origin www.cnblogs.com/gd-luojialin/p/11306293.html
Recommended