Ejemplo n.º 1
0
    def encode(self, encoder, symbol_index_map):
        import peachpy.encoder
        assert isinstance(encoder, peachpy.encoder.Encoder)
        assert encoder.bitness in [32, 64]
        assert self.symbol in symbol_index_map

        symbol_index = symbol_index_map[self.symbol]
        info = (symbol_index << 32) | self.type

        return encoder.unsigned_offset(self.offset) + \
            encoder.unsigned_offset(info) + \
            encoder.signed_offset(self.addend)
Ejemplo n.º 2
0
    def encode(self, encoder, symbol_index_map):
        import peachpy.encoder
        assert isinstance(encoder, peachpy.encoder.Encoder)
        assert encoder.bitness in [32, 64]
        assert self.symbol in symbol_index_map

        symbol_index = symbol_index_map[self.symbol]
        info = (symbol_index << 32) | self.type

        return encoder.unsigned_offset(self.offset) + \
            encoder.unsigned_offset(info) + \
            encoder.signed_offset(self.addend)
Ejemplo n.º 3
0
    def as_bytearray(self):
        import peachpy.encoder
        encoder = peachpy.encoder.Encoder(self.abi.endianness, self.abi.elf_bitness)

        return self.identification.as_bytearray + \
            encoder.uint16(self.file_type) + \
            encoder.uint16(self.abi.elf_machine_type) + \
            encoder.uint32(self.file_version) + \
            encoder.unsigned_offset(self.entry_address or 0) + \
            encoder.unsigned_offset(self.program_header_table_offset or 0) + \
            encoder.unsigned_offset(self.section_header_table_offset or 0) + \
            encoder.uint32(self.flags) + \
            encoder.uint16(self.file_header_size) + \
            encoder.uint16(self.program_header_entry_size) + \
            encoder.uint16(self.program_header_entries_count) + \
            encoder.uint16(self.section_header_entry_size) + \
            encoder.uint16(self.section_header_entries_count) + \
            encoder.uint16(self.section_name_string_table_index)
Ejemplo n.º 4
0
    def as_bytearray(self):
        import peachpy.encoder
        encoder = peachpy.encoder.Encoder(self.abi.endianness, self.abi.elf_bitness)

        return self.identification.as_bytearray + \
            encoder.uint16(self.file_type) + \
            encoder.uint16(self.abi.elf_machine_type) + \
            encoder.uint32(self.file_version) + \
            encoder.unsigned_offset(self.entry_address or 0) + \
            encoder.unsigned_offset(self.program_header_table_offset or 0) + \
            encoder.unsigned_offset(self.section_header_table_offset or 0) + \
            encoder.uint32(self.flags) + \
            encoder.uint16(self.file_header_size) + \
            encoder.uint16(self.program_header_entry_size) + \
            encoder.uint16(self.program_header_entries_count) + \
            encoder.uint16(self.section_header_entry_size) + \
            encoder.uint16(self.section_header_entries_count) + \
            encoder.uint16(self.section_name_string_table_index)
Ejemplo n.º 5
0
    def encode_header(self,
                      encoder,
                      name_index_map,
                      section_index_map,
                      offset,
                      address=None,
                      link_section=None,
                      info=None,
                      content_size=0,
                      entry_size=0):
        import peachpy.encoder
        from peachpy.util import is_uint64, is_uint32
        assert isinstance(encoder, peachpy.encoder.Encoder)
        assert isinstance(name_index_map, dict)
        assert section_index_map is None or isinstance(section_index_map, dict)
        assert offset is None or is_uint64(offset)
        assert address is None or is_uint64(address)
        assert link_section is None or isinstance(link_section, Section)
        assert info is None or is_uint64(info)
        assert is_uint64(content_size)
        assert is_uint32(entry_size)

        assert encoder.bitness in [32, 64]
        if encoder.bitness == 32:
            assert offset is None or is_uint32(offset)
            assert address is None or is_uint32(address)
        assert self.name is None or self.name in name_index_map
        assert section_index_map is not None or link_section is None

        name_index = name_index_map.get(self.name, 0)
        if address is None:
            address = 0
        if offset is None:
            offset = 0
        link = 0
        if link_section is not None:
            link = section_index_map[link_section]
        if info is None:
            info = 0
        return encoder.uint32(name_index) + \
            encoder.uint32(self.type) + \
            encoder.unsigned_offset(self.flags) + \
            encoder.unsigned_offset(address) + \
            encoder.unsigned_offset(offset) + \
            encoder.unsigned_offset(content_size) + \
            encoder.uint32(link) + \
            encoder.uint32(info) + \
            encoder.unsigned_offset(self.alignment) + \
            encoder.unsigned_offset(entry_size)
Ejemplo n.º 6
0
    def encode_header(self, encoder, name_index_map, section_index_map, offset,
                      address=None, link_section=None, info=None,
                      content_size=0, entry_size=0):
        import peachpy.encoder
        from peachpy.util import is_uint64, is_uint32
        assert isinstance(encoder, peachpy.encoder.Encoder)
        assert isinstance(name_index_map, dict)
        assert section_index_map is None or isinstance(section_index_map, dict)
        assert offset is None or is_uint64(offset)
        assert address is None or is_uint64(address)
        assert link_section is None or isinstance(link_section, Section)
        assert info is None or is_uint64(info)
        assert is_uint64(content_size)
        assert is_uint32(entry_size)

        assert encoder.bitness in [32, 64]
        if encoder.bitness == 32:
            assert offset is None or is_uint32(offset)
            assert address is None or is_uint32(address)
        assert self.name is None or self.name in name_index_map
        assert section_index_map is not None or link_section is None

        name_index = name_index_map.get(self.name, 0)
        if address is None:
            address = 0
        if offset is None:
            offset = 0
        link = 0
        if link_section is not None:
            link = section_index_map[link_section]
        if info is None:
            info = 0
        return encoder.uint32(name_index) + \
            encoder.uint32(self.type) + \
            encoder.unsigned_offset(self.flags) + \
            encoder.unsigned_offset(address) + \
            encoder.unsigned_offset(offset) + \
            encoder.unsigned_offset(content_size) + \
            encoder.uint32(link) + \
            encoder.uint32(info) + \
            encoder.unsigned_offset(self.alignment) + \
            encoder.unsigned_offset(entry_size)