def extendSection(self, sectionIndex, data):
        """
        Extends an existing section in the L{PE} instance.
        
        @type sectionIndex: int
        @param sectionIndex: The index for the section to be extended.
        
        @type data: str
        @param data: The data to include in the section.
        
        @raise IndexError: If an invalid C{sectionIndex} was specified.
        @raise SectionHeadersException: If there is not section to extend.
        """
        
        fa = self.ntHeaders.optionalHeader.fileAlignment.value
        sa = self.ntHeaders.optionalHeader.sectionAlignment.value 
        
        if len(self.sectionHeaders):
            if len(self.sectionHeaders) == sectionIndex:
                try:
                    # we are in the last section or self.sectionHeaders has only 1 sectionHeader instance
                    vzLastSection = self.sectionHeaders[-1].misc.value 
                    rzLastSection = self.sectionHeaders[-1].sizeOfRawData.value
                    
                    self.sectionHeaders[-1].misc.value = self._adjustSectionAlignment(vzLastSection + len(data), fa,  sa)
                    self.sectionHeaders[-1].sizeOfRawData.value = self._adjustFileAlignment(rzLastSection + len(data),  fa)
                    
                    vz = self.sectionHeaders[-1].misc.value 
                    rz = self.sectionHeaders[-1].sizeOfRawData.value
                    
                except IndexError:
                    raise IndexError("list index out of range.")
                    
                if vz < rz:
                    print "WARNING: VirtualSize (%x) is less than SizeOfRawData (%x)" % (vz,  rz)
                    
                if len(data) % fa == 0:
                    self.sections[-1] += data
                else:
                    self.sections[-1] += data + "\xcc" * (fa - len(data) % fa)
                
            else:
                # if it is not the last section ...
                try:
                    # adjust data of the section the user wants to extend
                    counter = sectionIndex - 1
                    
                    vzCurrentSection = self.sectionHeaders[counter].misc.value
                    rzCurrentSection = self.sectionHeaders[counter].sizeOfRawData.value
                    
                    self.sectionHeaders[counter].misc.value = self._adjustSectionAlignment(vzCurrentSection + len(data),  fa,  sa)
                    self.sectionHeaders[counter].sizeOfRawData.value = self._adjustFileAlignment(rzCurrentSection + len(data),  fa)

                    if len(data) % fa == 0:
                        self.sections[counter] += data
                    else:
                        self.sections[counter] += data + "\xcc" * (fa - len(data) % fa)
                         
                    counter += 1
                    
                    while(counter != len(self.sectionHeaders)):
                        vzPreviousSection = self.sectionHeaders[counter - 1].misc.value
                        vaPreviousSection = self.sectionHeaders[counter - 1].virtualAddress.value
                        rzPreviousSection = self.sectionHeaders[counter - 1].sizeOfRawData.value
                        roPreviousSection = self.sectionHeaders[counter - 1].pointerToRawData.value
                        
                        # adjust VA and RO of the next section
                        self.sectionHeaders[counter].virtualAddress.value = self._adjustSectionAlignment(vzPreviousSection + vaPreviousSection,  fa,  sa)
                        self.sectionHeaders[counter].pointerToRawData.value = self._adjustFileAlignment(rzPreviousSection + roPreviousSection,  fa)
                        
                        vz = self.sectionHeaders[counter].virtualAddress.value 
                        rz = self.sectionHeaders[counter].pointerToRawData.value
                        
                        if vz < rz:
                            print "WARNING: VirtualSize (%x) is less than SizeOfRawData (%x)" % (vz,  rz)
                            
                        counter += 1
                    
                except IndexError:
                    raise IndexError("list index out of range.")
                
        else:
            raise excep.SectionHeadersException("There is no section to extend.")
def extendSection ( self , sectionIndex , data ) : fa = self . ntHeaders . optionalHeader . fileAlignment . value sa = self . ntHeaders . optionalHeader . sectionAlignment . value if len ( self . sectionHeaders ) : if len ( self . sectionHeaders ) == sectionIndex : try : vzLastSection = self . sectionHeaders [ - 1 ] . misc . value rzLastSection = self . sectionHeaders [ - 1 ] . sizeOfRawData . value self . sectionHeaders [ - 1 ] . misc . value = self . _adjustSectionAlignment ( vzLastSection + len ( data ) , fa , sa ) self . sectionHeaders [ - 1 ] . sizeOfRawData . value = self . _adjustFileAlignment ( rzLastSection + len ( data ) , fa ) vz = self . sectionHeaders [ - 1 ] . misc . value rz = self . sectionHeaders [ - 1 ] . sizeOfRawData . value except IndexError : raise IndexError ( "list index out of range." ) if vz < rz : print "WARNING: VirtualSize (%x) is less than SizeOfRawData (%x)" % ( vz , rz ) if len ( data ) % fa == 0 : self . sections [ - 1 ] += data else : self . sections [ - 1 ] += data + "\xcc" * ( fa - len ( data ) % fa ) else : try : counter = sectionIndex - 1 vzCurrentSection = self . sectionHeaders [ counter ] . misc . value rzCurrentSection = self . sectionHeaders [ counter ] . sizeOfRawData . value self . sectionHeaders [ counter ] . misc . value = self . _adjustSectionAlignment ( vzCurrentSection + len ( data ) , fa , sa ) self . sectionHeaders [ counter ] . sizeOfRawData . value = self . _adjustFileAlignment ( rzCurrentSection + len ( data ) , fa ) if len ( data ) % fa == 0 : self . sections [ counter ] += data else : self . sections [ counter ] += data + "\xcc" * ( fa - len ( data ) % fa ) counter += 1 while ( counter != len ( self . sectionHeaders ) ) : vzPreviousSection = self . sectionHeaders [ counter - 1 ] . misc . value vaPreviousSection = self . sectionHeaders [ counter - 1 ] . virtualAddress . value rzPreviousSection = self . sectionHeaders [ counter - 1 ] . sizeOfRawData . value roPreviousSection = self . sectionHeaders [ counter - 1 ] . pointerToRawData . value self . sectionHeaders [ counter ] . virtualAddress . value = self . _adjustSectionAlignment ( vzPreviousSection + vaPreviousSection , fa , sa ) self . sectionHeaders [ counter ] . pointerToRawData . value = self . _adjustFileAlignment ( rzPreviousSection + roPreviousSection , fa ) vz = self . sectionHeaders [ counter ] . virtualAddress . value rz = self . sectionHeaders [ counter ] . pointerToRawData . value if vz < rz : print "WARNING: VirtualSize (%x) is less than SizeOfRawData (%x)" % ( vz , rz ) counter += 1 except IndexError : raise IndexError ( "list index out of range." ) else : raise excep . SectionHeadersException ( "There is no section to extend." )
Extends an existing section in the L{PE} instance.
        
        @type sectionIndex: int
        @param sectionIndex: The index for the section to be extended.
        
        @type data: str
        @param data: The data to include in the section.
        
        @raise IndexError: If an invalid C{sectionIndex} was specified.
        @raise SectionHeadersException: If there is not section to extend.