Пример #1
0
    def encode_command(self, encoder, offset, address, relocations_offset):
        import peachpy.encoder
        assert isinstance(encoder, peachpy.encoder.Encoder)

        if len(self.relocations) == 0:
            relocations_offset = 0
        if encoder.bitness == 32:
            return encoder.fixed_string(self.section_name, 16) + \
                encoder.fixed_string(self.segment_name, 16) + \
                encoder.uint32(address) + \
                encoder.uint32(self.content_size) + \
                encoder.uint32(offset) + \
                encoder.uint32(self.log2_alignment) + \
                encoder.uint32(relocations_offset) + \
                encoder.uint32(self.relocations_count) + \
                encoder.uint32(self.type | self.attributes) + \
                bytearray(8)
        else:
            return encoder.fixed_string(self.section_name, 16) + \
                encoder.fixed_string(self.segment_name, 16) + \
                encoder.uint64(address) + \
                encoder.uint64(self.content_size) + \
                encoder.uint32(offset) + \
                encoder.uint32(self.log2_alignment) + \
                encoder.uint32(relocations_offset) + \
                encoder.uint32(self.relocations_count) + \
                encoder.uint32(self.type | self.attributes) + \
                bytearray(12)
Пример #2
0
    def as_bytearray(self):
        import peachpy.encoder

        encoder = peachpy.encoder.Encoder(self.abi.endianness)

        if self.abi.pointer_size == 4:
            return encoder.fixed_string(self.name, 16) + \
                encoder.fixed_string(self.segment_name, 16) + \
                encoder.uint32(self.address or 0) + \
                encoder.uint32(self.content_size) + \
                encoder.uint32(self.offset) + \
                encoder.uint32(self.alignment) + \
                encoder.uint32(self.relocation_offset or 0) + \
                encoder.uint32(self.relocation_count) + \
                encoder.uint32(self.type | self.attributes) + \
                bytearray(8)
        else:
            return encoder.fixed_string(self.name, 16) + \
                encoder.fixed_string(self.segment_name, 16) + \
                encoder.uint64(self.address or 0) + \
                encoder.uint64(self.content_size) + \
                encoder.uint32(self.offset) + \
                encoder.uint32(self.alignment) + \
                encoder.uint32(self.relocation_offset or 0) + \
                encoder.uint32(self.relocation_count) + \
                encoder.uint32(self.type | self.attributes) + \
                bytearray(12)
Пример #3
0
    def as_bytearray(self):
        import peachpy.encoder

        encoder = peachpy.encoder.Encoder(self.abi.endianness)

        if self.abi.pointer_size == 4:
            return (
                encoder.fixed_string(self.name, 16)
                + encoder.fixed_string(self.segment_name, 16)
                + encoder.uint32(self.address or 0)
                + encoder.uint32(self.content_size)
                + encoder.uint32(self.offset)
                + encoder.uint32(self.alignment)
                + encoder.uint32(self.relocation_offset or 0)
                + encoder.uint32(self.relocation_count)
                + encoder.uint32(self.type | self.attributes)
                + bytearray(8)
            )
        else:
            return (
                encoder.fixed_string(self.name, 16)
                + encoder.fixed_string(self.segment_name, 16)
                + encoder.uint64(self.address or 0)
                + encoder.uint64(self.content_size)
                + encoder.uint32(self.offset)
                + encoder.uint32(self.alignment)
                + encoder.uint32(self.relocation_offset or 0)
                + encoder.uint32(self.relocation_count)
                + encoder.uint32(self.type | self.attributes)
                + bytearray(12)
            )
Пример #4
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.id) + \
                   encoder.uint32(self.size) + \
                   encoder.fixed_string(self.name, 16) + \
                   encoder.uint32(self.address or 0) + \
                   encoder.uint32(self.memory_size) + \
                   encoder.uint32(self.offset) + \
                   encoder.uint32(self.file_size) + \
                   encoder.uint32(MemoryProtection.Default) + \
                   encoder.uint32(MemoryProtection.Default) + \
                   encoder.uint32(self.section_count) + \
                   encoder.uint32(self.flags)
        else:
            return encoder.uint32(self.id) + \
                   encoder.uint32(self.size) + \
                   encoder.fixed_string(self.name, 16) + \
                   encoder.uint64(self.address or 0) + \
                   encoder.uint64(self.memory_size) + \
                   encoder.uint64(self.offset) + \
                   encoder.uint64(self.file_size) + \
                   encoder.uint32(MemoryProtection.Default) + \
                   encoder.uint32(MemoryProtection.Default) + \
                   encoder.uint32(self.section_count) + \
                   encoder.uint32(self.flags)
Пример #5
0
    def encode_command(self, encoder, offset, address, relocations_offset):
        import peachpy.encoder
        assert isinstance(encoder, peachpy.encoder.Encoder)

        if len(self.relocations) == 0:
            relocations_offset = 0
        if encoder.bitness == 32:
            return encoder.fixed_string(self.section_name, 16) + \
                encoder.fixed_string(self.segment_name, 16) + \
                encoder.uint32(address) + \
                encoder.uint32(self.content_size) + \
                encoder.uint32(offset) + \
                encoder.uint32(self.log2_alignment) + \
                encoder.uint32(relocations_offset) + \
                encoder.uint32(self.relocations_count) + \
                encoder.uint32(self.type | self.attributes) + \
                bytearray(8)
        else:
            return encoder.fixed_string(self.section_name, 16) + \
                encoder.fixed_string(self.segment_name, 16) + \
                encoder.uint64(address) + \
                encoder.uint64(self.content_size) + \
                encoder.uint32(offset) + \
                encoder.uint32(self.log2_alignment) + \
                encoder.uint32(relocations_offset) + \
                encoder.uint32(self.relocations_count) + \
                encoder.uint32(self.type | self.attributes) + \
                bytearray(12)
Пример #6
0
    def encode_command(self, encoder, section_offset_map, section_address_map,
                       section_relocations_map):
        import peachpy.encoder
        assert isinstance(encoder, peachpy.encoder.Encoder)

        offset = section_offset_map[self.sections[0]]
        memory_size = section_address_map[
            self.sections[-1]] + self.sections[-1].content_size
        file_size = sum(section.content_size for section in self.sections)

        address = 0
        if self.sections:
            address = section_address_map[self.sections[0]]
        # TODO: combine the two cases
        if encoder.bitness == 32:
            command_id = 0x1
            command_size = 56 + len(self.sections) * 68
            command = encoder.uint32(command_id) + \
                encoder.uint32(command_size) + \
                encoder.fixed_string(self.name, 16) + \
                encoder.uint32(address) + \
                encoder.uint32(memory_size) + \
                encoder.uint32(offset) + \
                encoder.uint32(file_size) + \
                encoder.uint32(MemoryProtection.default) + \
                encoder.uint32(MemoryProtection.default) + \
                encoder.uint32(len(self.sections)) + \
                encoder.uint32(self.flags)
        else:
            command_id = 0x19
            command_size = 72 + len(self.sections) * 80
            command = encoder.uint32(command_id) + \
                encoder.uint32(command_size) + \
                encoder.fixed_string(self.name, 16) + \
                encoder.uint64(address) + \
                encoder.uint64(memory_size) + \
                encoder.uint64(offset) + \
                encoder.uint64(file_size) + \
                encoder.uint32(MemoryProtection.default) + \
                encoder.uint32(MemoryProtection.default) + \
                encoder.uint32(len(self.sections)) + \
                encoder.uint32(self.flags)
        for section in self.sections:
            command += section.encode_command(
                encoder, section_offset_map[section],
                section_address_map[section],
                section_relocations_map.get(section))
        from peachpy.x86_64.abi import system_v_x86_64_abi
        return command
Пример #7
0
    def encode_command(self, encoder, section_offset_map, section_address_map, section_relocations_map):
        import peachpy.encoder
        assert isinstance(encoder, peachpy.encoder.Encoder)

        offset = section_offset_map[self.sections[0]]
        memory_size = sum(section.content_size for section in self.sections)
        file_size = sum(section.content_size for section in self.sections)

        address = 0
        if self.sections:
            address = section_address_map[self.sections[0]]
        # TODO: combine the two cases
        if encoder.bitness == 32:
            command_id = 0x1
            command_size = 56 + len(self.sections) * 68
            command = encoder.uint32(command_id) + \
                encoder.uint32(command_size) + \
                encoder.fixed_string(self.name, 16) + \
                encoder.uint32(address) + \
                encoder.uint32(memory_size) + \
                encoder.uint32(offset) + \
                encoder.uint32(file_size) + \
                encoder.uint32(MemoryProtection.default) + \
                encoder.uint32(MemoryProtection.default) + \
                encoder.uint32(len(self.sections)) + \
                encoder.uint32(self.flags)
        else:
            command_id = 0x19
            command_size = 72 + len(self.sections) * 80
            command = encoder.uint32(command_id) + \
                encoder.uint32(command_size) + \
                encoder.fixed_string(self.name, 16) + \
                encoder.uint64(address) + \
                encoder.uint64(memory_size) + \
                encoder.uint64(offset) + \
                encoder.uint64(file_size) + \
                encoder.uint32(MemoryProtection.default) + \
                encoder.uint32(MemoryProtection.default) + \
                encoder.uint32(len(self.sections)) + \
                encoder.uint32(self.flags)
        for section in self.sections:
            command += section.encode_command(encoder,
                                              section_offset_map[section],
                                              section_address_map[section],
                                              section_relocations_map.get(section))
        from peachpy.x86_64.abi import system_v_x86_64_abi
        return command