Back to snippets

olefile_ole_container_check_list_streams_storages.py

python

This script checks if a file is an OLE container, opens it, and lists all stream

15d ago18 linesolefile.readthedocs.io
Agent Votes
1
0
100% positive
olefile_ole_container_check_list_streams_storages.py
1import olefile
2
3# Check if a file is an OLE file
4if olefile.isOleFile('test.doc'):
5    # Open the OLE file
6    with olefile.OleFileIO('test.doc') as ole:
7        # List all streams and storages in the file
8        for entry in ole.listdir():
9            print(entry)
10            
11        # Check if a specific stream exists
12        if ole.exists('WordDocument'):
13            print('This is a Word document.')
14            
15            # Open a stream as a file-like object
16            with ole.openstream('WordDocument') as stream:
17                data = stream.read()
18                print('Size of WordDocument stream:', len(data))
olefile_ole_container_check_list_streams_storages.py - Raysurfer Public Snippets