parameters: (self)
docstring: Adds a resource section to the file containing the resources that
          were previously added via add_icon et al.  Assumes the file does not
          contain a resource section yet.
docstring_summary: Adds a resource section to the file containing the resources that
          were previously added via add_icon et al.  Assumes the file does not
          contain a resource section yet.
docstring_tokens: Adds a resource section to the file containing the resources that were previously added via add_icon et al . Assumes the file does not contain a resource section yet .
function: def add_resource_section(self):
          """ Adds a resource section to the file containing the resources that
          were previously added via add_icon et al.  Assumes the file does not
          contain a resource section yet. """
  
          # Calculate how much space to reserve.
          tables = [self.resources] + list(self.resources.get_nested_tables())
          table_size = 0
          string_size = 0
          desc_size = 16 * self.resources.count_resources()
  
          for table in tables:
              table._offset = table_size
              table_size += 16 + 8 * len(table)
              string_size += table._strings_size
              desc_size += table._descs_size
  
          # Now write the actual data.
          tbl_offs = 0
          str_offs = table_size
          desc_offs = str_offs + string_size
          data_offs = desc_offs + desc_size
          data = bytearray(data_offs)
          data_addr = _padded(len(self.vmem), self.section_alignment) + data_offs
  
          for table in tables:
              table.pack_header(data, tbl_offs)
  
              tbl_offs += 16
  
              for name, leaf in table._name_leaves:
                  if isinstance(leaf, ResourceTable):
                      pack_into('<II', data, tbl_offs, str_offs | 0x80000000, leaf._offset | 0x80000000)
                  else:
                      pack_into('<II', data, tbl_offs, str_offs | 0x80000000, desc_offs)
                      resdata = leaf.get_data()
                      pack_into('<IIII', data, desc_offs, data_addr, len(resdata), leaf.code_page, 0)
                      data += resdata
                      desc_offs += 16
                      data_addr += len(resdata)
                      align = len(resdata) & 3
                      if align:
                          data += bytearray(4 - align)
                          data_addr += 4 - align
                  tbl_offs += 8
  
                  # Pack the name into the string table.
                  pack_into('<H', data, str_offs, len(name))
                  str_offs += 2
                  for c in name:
                      pack_into('<H', data, str_offs, ord(c))
                      str_offs += 2
                  str_offs = _padded(str_offs, 4)
  
              for id, leaf in table._id_leaves:
                  if isinstance(leaf, ResourceTable):
                      pack_into('<II', data, tbl_offs, id, leaf._offset | 0x80000000)
                  else:
                      pack_into('<II', data, tbl_offs, id, desc_offs)
                      resdata = leaf.get_data()
                      pack_into('<IIII', data, desc_offs, data_addr, len(resdata), leaf.code_page, 0)
                      data += resdata
                      desc_offs += 16
                      data_addr += len(resdata)
                      align = len(resdata) & 3
                      if align:
                          data += bytearray(4 - align)
                          data_addr += 4 - align
                  tbl_offs += 8
  
          flags = 0x40000040 # readable, contains initialized data
          section = self.add_section('.rsrc', flags, data)
          self.res_rva = RVASize(section.vaddr, section.vsize)
function_tokens: def add_resource_section ( self ) : # Calculate how much space to reserve. tables = [ self . resources ] + list ( self . resources . get_nested_tables ( ) ) table_size = 0 string_size = 0 desc_size = 16 * self . resources . count_resources ( ) for table in tables : table . _offset = table_size table_size += 16 + 8 * len ( table ) string_size += table . _strings_size desc_size += table . _descs_size # Now write the actual data. tbl_offs = 0 str_offs = table_size desc_offs = str_offs + string_size data_offs = desc_offs + desc_size data = bytearray ( data_offs ) data_addr = _padded ( len ( self . vmem ) , self . section_alignment ) + data_offs for table in tables : table . pack_header ( data , tbl_offs ) tbl_offs += 16 for name , leaf in table . _name_leaves : if isinstance ( leaf , ResourceTable ) : pack_into ( '<II' , data , tbl_offs , str_offs | 0x80000000 , leaf . _offset | 0x80000000 ) else : pack_into ( '<II' , data , tbl_offs , str_offs | 0x80000000 , desc_offs ) resdata = leaf . get_data ( ) pack_into ( '<IIII' , data , desc_offs , data_addr , len ( resdata ) , leaf . code_page , 0 ) data += resdata desc_offs += 16 data_addr += len ( resdata ) align = len ( resdata ) & 3 if align : data += bytearray ( 4 - align ) data_addr += 4 - align tbl_offs += 8 # Pack the name into the string table. pack_into ( '<H' , data , str_offs , len ( name ) ) str_offs += 2 for c in name : pack_into ( '<H' , data , str_offs , ord ( c ) ) str_offs += 2 str_offs = _padded ( str_offs , 4 ) for id , leaf in table . _id_leaves : if isinstance ( leaf , ResourceTable ) : pack_into ( '<II' , data , tbl_offs , id , leaf . _offset | 0x80000000 ) else : pack_into ( '<II' , data , tbl_offs , id , desc_offs ) resdata = leaf . get_data ( ) pack_into ( '<IIII' , data , desc_offs , data_addr , len ( resdata ) , leaf . code_page , 0 ) data += resdata desc_offs += 16 data_addr += len ( resdata ) align = len ( resdata ) & 3 if align : data += bytearray ( 4 - align ) data_addr += 4 - align tbl_offs += 8 flags = 0x40000040 # readable, contains initialized data section = self . add_section ( '.rsrc' , flags , data ) self . res_rva = RVASize ( section . vaddr , section . vsize )