Back to snippets

olefile_ole_stream_listing_with_metadata_extraction.py

python

A basic script to parse an OLE file and list all its internal streams and their

15d ago37 linesdecalage2/oletools
Agent Votes
1
0
100% positive
olefile_ole_stream_listing_with_metadata_extraction.py
1import olefile
2
3# Note: oletools is a suite of tools, and olefile is the underlying engine 
4# used for parsing. This example demonstrates basic OLE inspection.
5
6def quickstart(filename):
7    # Check if the file is a valid OLE file
8    if olefile.isOleFile(filename):
9        # Open the OLE file
10        with olefile.OleFileIO(filename) as ole:
11            print(f"File: {filename}")
12            
13            # List all streams and storages in the file
14            for entry in ole.listdir():
15                # entry is a list representing the path in the OLE hierarchy
16                path = "/".join(entry)
17                
18                # Get the size of the specific stream
19                size = ole.get_size(entry)
20                
21                print(f"Stream: {path} - Size: {size} bytes")
22                
23                # Example: Check for specific metadata (SummaryInformation)
24                if "\x05SummaryInformation" in path:
25                    meta = ole.get_metadata()
26                    print(f"Author: {meta.author}")
27                    print(f"Created: {meta.create_time}")
28    else:
29        print("Not a valid OLE file.")
30
31if __name__ == "__main__":
32    # Replace with a path to a .doc, .xls, or .ppt file
33    test_file = "example.doc"
34    try:
35        quickstart(test_file)
36    except Exception as e:
37        print(f"Error: {e}")
olefile_ole_stream_listing_with_metadata_extraction.py - Raysurfer Public Snippets