示例#1
0
文件: symbol.py 项目: Rinoahu/PeachPy
    def encode(self, encoder, name_index_map, section_index_map):
        import peachpy.encoder
        assert isinstance(encoder, peachpy.encoder.Encoder)
        assert encoder.bitness in [32, 64]
        assert self.name in name_index_map
        from peachpy.formats.elf.section import SectionIndex
        assert self.section is None or isinstance(self.section, SectionIndex) or self.section in section_index_map

        name_index = name_index_map[self.name]
        section_index = SectionIndex.absolute
        if self.section is not None:
            if isinstance(self.section, SectionIndex):
                section_index = self.section
            else:
                section_index = section_index_map[self.section]
        if encoder.bitness == 32:
            return encoder.uint32(name_index) + \
                encoder.uint32(self.value) + \
                encoder.uint32(self.size) + \
                encoder.uint8((self.binding << 4) | (self.type & 0xF)) + \
                encoder.uint8(0) + \
                encoder.uint16(section_index)
        else:
            return encoder.uint32(name_index) + \
                encoder.uint8((self.binding << 4) | (self.type & 0xF)) + \
                encoder.uint8(0) + \
                encoder.uint16(section_index) + \
                encoder.uint64(self.value) + \
                encoder.uint64(self.size)
示例#2
0
文件: symbol.py 项目: pwaller/PeachPy
    def encode(self, encoder, name_index_map, section_index_map):
        import peachpy.encoder
        assert isinstance(encoder, peachpy.encoder.Encoder)
        assert encoder.bitness in [32, 64]
        assert self.name in name_index_map
        from peachpy.formats.elf.section import SectionIndex
        assert self.section is None or isinstance(
            self.section, SectionIndex) or self.section in section_index_map

        name_index = name_index_map[self.name]
        section_index = SectionIndex.absolute
        if self.section is not None:
            if isinstance(self.section, SectionIndex):
                section_index = self.section
            else:
                section_index = section_index_map[self.section]
        if encoder.bitness == 32:
            return encoder.uint32(name_index) + \
                encoder.uint32(self.value) + \
                encoder.uint32(self.size) + \
                encoder.uint8((self.binding << 4) | (self.type & 0xF)) + \
                encoder.uint8(0) + \
                encoder.uint16(section_index)
        else:
            return encoder.uint32(name_index) + \
                encoder.uint8((self.binding << 4) | (self.type & 0xF)) + \
                encoder.uint8(0) + \
                encoder.uint16(section_index) + \
                encoder.uint64(self.value) + \
                encoder.uint64(self.size)
示例#3
0
    def as_bytearray(self):
        import peachpy.encoder
        encoder = peachpy.encoder.Encoder(self.abi.endianness)

        if self.abi.pointer_size == 4:
            return encoder.uint32(self.string_index) + \
                encoder.uint8(self.type | self.visibility) + \
                encoder.uint8(self.section_index) + \
                encoder.uint16(self.description | self.flags) + \
                encoder.uint32(self.value)
        else:
            return encoder.uint32(self.string_index) + \
                encoder.uint8(self.type | self.visibility) + \
                encoder.uint8(self.section_index) + \
                encoder.uint16(self.description | self.flags) + \
                encoder.uint64(self.value)
示例#4
0
文件: symbol.py 项目: GaZ3ll3/PeachPy
 def as_bytearray(self):
     import peachpy.encoder
     encoder = peachpy.encoder.Encoder(self.abi.endianness)
     if self.abi.elf_class == ElfClass.Class32:
         return encoder.uint32(self.name_index) + \
             encoder.uint32(self.value) + \
             encoder.uint32(self.content_size) + \
             encoder.uint8((self.binding << 4) | (self.type & 0xF)) + \
             encoder.uint8(0) + \
             encoder.uint16(self.section_index)
     else:
         return encoder.uint32(self.name_index) + \
             encoder.uint8((self.binding << 4) | (self.type & 0xF)) + \
             encoder.uint8(0) + \
             encoder.uint16(self.section_index) + \
             encoder.uint64(self.value) + \
             encoder.uint64(self.content_size)
示例#5
0
    def encode(self, encoder, name_index_map, section_index_map, section_address_map):
        import peachpy.encoder
        assert isinstance(encoder, peachpy.encoder.Encoder)
        assert self.name in name_index_map
        assert self.section is None or self.section in section_index_map

        name_index = name_index_map[self.name]
        section_index = 0
        if self.section is not None:
            section_index = section_index_map[self.section]
        if encoder.bitness == 32:
            return encoder.uint32(name_index) + \
                encoder.uint8(self.type | self.visibility) + \
                encoder.uint8(section_index) + \
                encoder.uint16(self.description | self.flags) + \
                encoder.uint32(self.value)
        else:
            return encoder.uint32(name_index) + \
                encoder.uint8(self.type | self.visibility) + \
                encoder.uint8(section_index) + \
                encoder.uint16(self.description | self.flags) + \
                encoder.uint64(self.value + section_address_map[self.section])