hwfw.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:hwfw-tool 作者: LeeXiaolan 项目源码 文件源码
def toString(self, noItemData=True):
    self.header.fileLength = (
        self.header._FORMAT.size 
        + self.header.itemCount * HuaweiFirmwareItem._FORMAT.size
        - 0x4c # FIXME: Can not find where does this bias come from.
    )
    strs = [
      self.header.toString()[20:], # Partial header used for calculate CRC32 value.
    ]
    if self.header.extraHeaderLength:
      strs.append(self.extraHeader)
      self.header.fileLength += len(self.extraHeader)
    data = []
    for item in self.items:
      strs.append(item.toString())
      data.append(item.data)
      self.header.fileLength += item.size
    # Convert to big endian.
    self.header.fileLength = socket.htonl(self.header.fileLength)

    # Update header CRC32 value.
    self.header.headerCrc = seqCrc32(strs)

    if not noItemData:
      strs.extend(data)
      # All data are present, now update file CRC32 value.
      strs[0] = self.header.toString()[12:]
      self.header.fileCrc = seqCrc32(strs)

    # Using the latest header with correct CRC32 value and file length.
    strs[0] = self.header.toString()
    return ''.join(strs)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号