예제 #1
0
 def elfMagicBytes(self):
     # Obviously, there is a need for refactoring...
     if PYTHON_VERSION.major == 3:
         return str(b' '.join(
             slicer(binascii.b2a_hex(self.magicBytes[:16]), 2)),
                    encoding="ascii")
     else:
         return ' '.join(slicer(binascii.b2a_hex(self.magicBytes[:16]), 2))
예제 #2
0
    def dumps(self, image, rowLength=16, **kws):
        result = []
        self.rowLength = rowLength

        if not image.sections:
            return ''

        if self.calculateAddressBits(image) > self.MAX_ADDRESS_BITS:
            raise AddressRangeToLargeError('could not encode image.')

        params = self.setParameters(**kws)

        self.preProcessing(image)

        header = self.composeHeader(image.meta)
        if header:
            result.append(header)
        for section in image:
            address = section.address
            rows = slicer(section.data, rowLength,
                          lambda x: [int(y) for y in x])
            for row in rows:
                length = len(row)
                result.append(self.composeRow(address, length, row))
                address += rowLength
        footer = self.composeFooter(image.meta)
        if footer:
            result.append(footer)
        return self.postProcess('\n'.join(result))
예제 #3
0
    def dumps(self, image, row_length=16, **kws):
        result = []
        self.row_length = row_length

        if hasattr(image, "sections") and not image.sections:
            return b''

        if self.calculate_address_bits(image) > self.MAX_ADDRESS_BITS:
            raise AddressRangeToLargeError('could not encode image.')

        params = self.set_parameters(**kws)

        self.pre_processing(image)

        header = self.compose_header(
            image.meta if hasattr(image, 'meta') else {})
        if header:
            result.append(header)
        for section in image:
            address = section.start_address
            rows = slicer(section.data, row_length,
                          lambda x: [int(y) for y in x])
            for row in rows:
                length = len(row)
                result.append(self.compose_row(address, length, row))
                address += row_length
        footer = self.compose_footer(
            image.meta if hasattr(image, 'meta') else {})
        if footer:
            result.append(footer)
        if PYTHON_VERSION.major == 3:
            return self.post_processing(bytes('\n'.join(result), "ascii"))
        else:
            return self.post_processing(bytes('\n'.join(result)))
예제 #4
0
파일: fpc.py 프로젝트: yang123vc/objutils
 def postProcess(self, data):
     result = []
     for line in data.splitlines():
         if len(line) % 4:
             self.error("Size of line must be a multiple of 4.")
             continue
         res = []
         for item in slicer(line, 8, atoi16):
             item = self.convertQuintuple(item)
             res.append(item)
         result.append("{0}{1}".format(PREFIX, ''.join(res)))
     return '\n'.join(result)
예제 #5
0
 def post_processing(self, data):
     result = []
     for line in data.splitlines():
         if len(line) % 4:
             self.error("Size of line must be a multiple of 4.")
             continue
         res = []
         for item in slicer(line, 8, atoi16):
             item = self.convert_quintuple(item)
             res.append(item)
         result.append("{0}{1}".format(PREFIX, ''.join(res)))
     if PYTHON_VERSION.major == 3:
         return bytes('\n'.join(result), "ascii")
     else:
         return bytes('\n'.join(result))