Beispiel #1
0
    def test_from_stream(self):
        ae = self.assertEqual

        stream = ByteIStream(bytes([x for x in range(17)]))
        uuid1 = CLSIDToUUID.from_stream(stream, byte_order=LITTLE_ENDIAN)
        uuid2 = CLSIDToUUID.from_stream(stream, 1, byte_order=LITTLE_ENDIAN)

        stream.seek(0, SEEK_SET)
        uuid3 = CLSIDToUUID.from_stream(stream, byte_order=BIG_ENDIAN)
        uuid4 = CLSIDToUUID.from_stream(stream, 1, byte_order=BIG_ENDIAN)

        ae(uuid1, UUID(bytes_le=bytes([x for x in range(16)])))
        ae(uuid2, UUID(bytes_le=bytes([x for x in range(1, 17)])))
        ae(uuid3, UUID(bytes=bytes([x for x in range(16)])))
        ae(uuid4, UUID(bytes=bytes([x for x in range(1, 17)])))
Beispiel #2
0
    def test_from_stream(self):
        ae = self.assertEqual

        stream = ByteIStream(bytes([x for x in range(17)]))
        uuid1 = CLSIDToUUID.from_stream(stream, byte_order=LITTLE_ENDIAN)
        uuid2 = CLSIDToUUID.from_stream(stream, 1, byte_order=LITTLE_ENDIAN)

        stream.seek(0, SEEK_SET)
        uuid3 = CLSIDToUUID.from_stream(stream, byte_order=BIG_ENDIAN)
        uuid4 = CLSIDToUUID.from_stream(stream, 1, byte_order=BIG_ENDIAN)

        ae(uuid1, UUID(bytes_le=bytes([x for x in range(16)])))
        ae(uuid2, UUID(bytes_le=bytes([x for x in range(1, 17)])))
        ae(uuid3, UUID(bytes=bytes([x for x in range(16)])))
        ae(uuid4, UUID(bytes=bytes([x for x in range(1, 17)])))
Beispiel #3
0
    def from_stream(cls, stream, offset=None):
        """Creates a :class:`Header` object from a stream.

        :type stream: :class:`lf.dec.IStream`
        :param stream: A stream that contains the compound file header.

        :type offset: ``int``
        :param offset: The start of the header in :attr:`stream`.

        :rtype: :class:`Header`
        :returns: The corresponding :class:`Header` object.

        """
        if offset is not None:
            stream.seek(offset, SEEK_SET)
        # end if

        head = header.from_buffer_copy(stream.read(512))

        clsid = head.clsid
        clsid = CLSIDToUUID.from_ctype(clsid)

        return Header((
            bytes(head.sig), clsid, head.ver_minor, head.ver_major,
            head.byte_order, head.sect_shift, head.mini_sect_shift,
            bytes(head.rsvd), head.dir_sect_count, head.fat_sect_count,
            head.dir_sect_offset, head.trans_num, head.mini_stream_cutoff,
            head.mini_fat_sect_offset, head.mini_fat_sect_count,
            head.di_fat_sect_offset, head.di_fat_sect_count, list(head.di_fat)
        ))
Beispiel #4
0
    def from_stream(cls, stream, offset=None):
        """Creates a :class:`Header` object from a stream.

        :type stream: :class:`lf.dec.IStream`
        :param stream: A stream that contains the compound file header.

        :type offset: ``int``
        :param offset: The start of the header in :attr:`stream`.

        :rtype: :class:`Header`
        :returns: The corresponding :class:`Header` object.

        """
        if offset is not None:
            stream.seek(offset, SEEK_SET)
        # end if

        head = header.from_buffer_copy(stream.read(512))

        clsid = head.clsid
        clsid = CLSIDToUUID.from_ctype(clsid)

        return Header(
            (bytes(head.sig), clsid, head.ver_minor, head.ver_major,
             head.byte_order, head.sect_shift, head.mini_sect_shift,
             bytes(head.rsvd), head.dir_sect_count, head.fat_sect_count,
             head.dir_sect_offset, head.trans_num, head.mini_stream_cutoff,
             head.mini_fat_sect_offset, head.mini_fat_sect_count,
             head.di_fat_sect_offset, head.di_fat_sect_count,
             list(head.di_fat)))
Beispiel #5
0
    def test_from_ctype(self):
        ae = self.assertEqual

        stream = ByteIStream(bytes([x for x in range(16)]))
        uuid1 = guid_be.from_buffer_copy(stream.read(16))
        uuid1 = CLSIDToUUID.from_ctype(uuid1)

        ae(uuid1, UUID(bytes=bytes([x for x in range(16)])))
Beispiel #6
0
    def test_from_ctype(self):
        ae = self.assertEqual

        stream = ByteIStream(bytes([x for x in range(16)]))
        uuid1 = guid_be.from_buffer_copy(stream.read(16))
        uuid1 = CLSIDToUUID.from_ctype(uuid1)

        ae(uuid1, UUID(bytes=bytes([x for x in range(16)])))
Beispiel #7
0
    def from_stream(cls, stream, offset=None):
        """Creates a :class:`DirEntry` object from a stream.

        :type stream: :class:`lf.dec.IStream`
        :param stream: A stream that contains the directory entry.

        :type offset: ``int``
        :param offset: The start of the directory entry in :attr:`stream`.

        :rtype: :class:`DirEntry`
        :returns: The corresponding :class:`DirEntry` object.

        """
        if offset is not None:
            stream.seek(offset, SEEK_SET)
        # end if

        values = dir_entry.from_buffer_copy(stream.read(128))

        name = bytes(values.name)
        if values.name_size <= 64:
            name = name[:values.name_size]
        # end if

        new_name = name.decode("utf_16_le", "ignore")
        if new_name:
            name = new_name.split("\x00", 1)[0]
        # end if

        clsid = CLSIDToUUID.from_ctype(values.clsid)

        btime = values.btime
        try:
            btime = FILETIMETodatetime.from_ctype(btime)
        except (ValueError, TypeError):
            btime = (btime.hi << 32) | btime.lo
        # end try

        mtime = values.mtime
        try:
            mtime = FILETIMETodatetime.from_ctype(mtime)
        except (ValueError, TypeError):
            mtime = (mtime.hi << 32) | mtime.lo
        # end try

        return DirEntry((
            name, values.name_size, values.type, values.color, values.left_sid,
            values.right_sid, values.child_sid, clsid, values.state, btime,
            mtime, values.stream_sect_offset, values.stream_size
        ))
Beispiel #8
0
    def from_stream(cls, stream, offset=None):
        """Creates a :class:`DirEntry` object from a stream.

        :type stream: :class:`lf.dec.IStream`
        :param stream: A stream that contains the directory entry.

        :type offset: ``int``
        :param offset: The start of the directory entry in :attr:`stream`.

        :rtype: :class:`DirEntry`
        :returns: The corresponding :class:`DirEntry` object.

        """
        if offset is not None:
            stream.seek(offset, SEEK_SET)
        # end if

        values = dir_entry.from_buffer_copy(stream.read(128))

        name = bytes(values.name)
        if values.name_size <= 64:
            name = name[:values.name_size]
        # end if

        new_name = name.decode("utf_16_le", "ignore")
        if new_name:
            name = new_name.split("\x00", 1)[0]
        # end if

        clsid = CLSIDToUUID.from_ctype(values.clsid)

        btime = values.btime
        try:
            btime = FILETIMETodatetime.from_ctype(btime)
        except (ValueError, TypeError):
            btime = (btime.hi << 32) | btime.lo
        # end try

        mtime = values.mtime
        try:
            mtime = FILETIMETodatetime.from_ctype(mtime)
        except (ValueError, TypeError):
            mtime = (mtime.hi << 32) | mtime.lo
        # end try

        return DirEntry((name, values.name_size, values.type, values.color,
                         values.left_sid, values.right_sid, values.child_sid,
                         clsid, values.state, btime, mtime,
                         values.stream_sect_offset, values.stream_size))