pefile.py 文件源码

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

项目:post_pre 作者: coruws 项目源码 文件源码
def dump(self, indentation=0):
        """Returns a string representation of the structure."""

        dump = []

        dump.append('[{0}]'.format(self.name))

        printable_bytes = [ord(i) for i in string.printable if i not in string.whitespace]

        # Refer to the __set_format__ method for an explanation
        # of the following construct.
        for keys in self.__keys__:
            for key in keys:

                val = getattr(self, key)
                if isinstance(val, (int, long)):
                    val_str = '0x%-8X' % (val)
                    if key == 'TimeDateStamp' or key == 'dwTimeStamp':
                        try:
                            val_str += ' [%s UTC]' % time.asctime(time.gmtime(val))
                        except exceptions.ValueError as e:
                            val_str += ' [INVALID TIME]'
                else:
                    val_str = val
                    try:
                        val_str = val_str.encode('ascii', 'backslashreplace')
                    except:
                        pass
                    if isinstance(val_str[0], int):
                        val_str = ''.join(
                                [chr(i) if (i in printable_bytes) else
                                 '\\x{0:02x}'.format(i) for i in val_str.rstrip(b'\x00')])
                    else:
                        val_str = ''.join(
                                [i if (ord(i) in printable_bytes) else
                                 '\\x{0:02x}'.format(ord(i)) for i in val_str.rstrip(b'\x00')])

                dump.append('0x%-8X 0x%-3X %-30s %s' % (
                    self.__field_offsets__[key] + self.__file_offset__,
                    self.__field_offsets__[key], key+':', val_str))

        return dump
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号