4.2. lf.win.ole.cfb — OLE structured storage (compound file binary)
This package provides support to work with OLE structured storage files. More
information about this file format can be found at:
http://msdn.microsoft.com/en-us/library/dd942138(PROT.10).aspx
-
class lf.win.ole.cfb.CompoundFile(stream, offset=None)
Represents an OLE structured storage file (compound file binary).
Parameters: |
- stream (IStream) – A stream covering the contents of the compound file.
- offset (int) – The start of the compound file in the stream.
|
- A Header object containing information from the compound file
header.
-
sect_size
- The number of bytes in a sector.
-
mini_sect_size
- The number of bytes in a mini sector.
-
mini_stream_cutoff
- The maximum size of a file (in bytes) in the mini stream.
-
ver_major
- The major version number. (from the header)
-
ver_minor
- The minor version number. (from the header)
-
di_fat
- A list of entries from the double indirect FAT.
-
fat
- A list of entries from the FAT.
-
mini_fat
- A list of entries from the mini FAT.
-
mini_stream
- A stream covering the contents of the mini stream. None if there is no
mini stream.
-
dir_stream
- A stream covering the contents of the directory stream. None if there
is no directory stream.
-
root_dir_entry
- A DirEntry object for the root directory entry. None if there is no
root directory.
-
dir_entries
- A dictionary of directory entries, found by traversing the RB tree.
-
cfb_stream
- A stream covering the contents of the file.
-
byte_offset(sect_num)
Calculates the byte offset of a sector number.
Parameter: | sect_num (int) – The sector number. |
Return type: | int |
Returns: | The byte offset in the file of the sector. |
-
mini_byte_offset(mini_sect_num)
Calculates the byte offset of a mini sector number.
Parameter: | mini_sect_num (int) – The mini sector number. |
Return type: | int |
Returns: | The byte offset in the mini stream of the mini sector number. |
-
get_fat_chain(first_sect)
Retrieves a chain from the FAT.
Parameter: | first_sect (int) – The sector number of the first sector in the chain. |
Raises IndexError: |
| If first_sect is beyond the size of the
file. |
Return type: | list |
Returns: | The sector chain from the FAT. |
-
get_mini_fat_chain(first_mini_sect)
Retrieves a chain from the mini FAT.
Parameter: | first_mini_sect (int) – The sector number of the first sector in the
chain. |
Raises IndexError: |
| If first_mini_sect is beyond the size of
the mini FAT. |
Return type: | list |
Returns: | The sector chain from the mini FAT. |
-
get_dir_entry(sid)
Retrieves a directory entry
Parameter: | sid (int) – The stream identifier of the directory entry. |
Raises IndexError: |
| If sid is out of range. |
Return type: | DirEntry |
Returns: | The directory entry. |
-
classmethod is_valid_dir_entry(entry)
Determines if a DirEntry object is valid.
If entry matches any of the following tests, it is
considered invalid:
- if entry.name is empty
- if entry.name contains invalid characters
- if entry.type is not 0x0, 0x1, 0x2, or 0x5
- if entry.color is not 0x0 or 0x1
- if entry.left_sid, entry.right_sid, or
entry.child_sid is not between STREAM_ID_MIN
and STREAM_ID_MAX, and is not STREAM_ID_NONE
Parameter: | entry (DirEntry) – The DirEntry object to examine |
Return type: | bool |
Returns: | True if entry is a valid directory entry. |
-
get_stream(sid, slack=False)
Retrieves the contents of a stream.
Parameters: |
- sid (int) – The stream identifier for the directory entry associated
with the stream.
- slack (bool) – If True, the contents of the entire stream are
returned. Otherwise the stream is truncated at the size
specified by the associated directory entry.
|
Raises IndexError: |
| If sid is out of range.
|
Return type: | IStream
|
Returns: | An IStream covering the contents of the
stream.
|
Represents the header from a compound file binary.
- The signature value.
- The class ID value.
- The minor version number.
- The major version number.
- The byte order mark value.
- The size of a sector, as a power of 2.
- The size of a sector in the mini stream, as a power of 2.
- The reserved value.
- The number of sectors that contain directory entries.
- The number of sectors that contain FAT entries.
- The sector offset of the first directory entry.
- The transaction signature number.
- The maximum size of a user-defined data stream that can be allocated in
the mini FAT.
- The sector offset of the first mini FAT entry.
- The number of sectors in the mini FAT.
- The sector offset of the first DIFAT entry (beyond the header).
- The number of sectors in the DIFAT.
- The first 109 DIFAT entries.
Creates a Header object from a stream.
Parameters: |
- stream (IStream) – A stream that contains the compound file header.
- offset (int) – The start of the header in stream.
|
Return type: | Header
|
Returns: | The corresponding Header object.
|
-
class lf.win.ole.cfb.DirEntry
Represents a directory entry in a compound file.
-
name
- The name of the directory entry.
-
name_size
- The length of the name field (in bytes).
-
type
- The type of directory entry.
-
color
- The color of the directory entry.
-
left_sid
- The stream identifier of the left sibling directory entry.
-
right_sid
- The stream identifier of the right sibling directory entry.
-
child_sid
- The stream identifier of the child directory entry.
-
clsid
- The CLSID of the directory entry.
-
state
- The user defined state bits.
-
btime
- The creation time of the directory entry.
-
mtime
- The last modification time of the directory entry.
-
stream_sect_offset
- The first sector of the stream.
-
stream_size
The size in bytes of the stream.
Note
Per the spec. if ver_major is 0x3, the high 4 bytes of this value
may be invalid, and must be ignored. This is a responsibility of
the calling function.
-
classmethod from_stream(stream, offset=None)
Creates a DirEntry object from a stream.
Parameters: |
- stream (IStream) – A stream that contains the directory entry.
- offset (int) – The start of the directory entry in stream.
|
Return type: | DirEntry
|
Returns: | The corresponding DirEntry object.
|