<commit_before>#!/usr/bin/env python3
"""
Parse MSI file for info

Related:
- https://github.com/decalage2/oletools/blob/master/oletools/olemeta.py
- https://github.com/ralphje/signify/issues/24#issuecomment-1148320566
"""
import olefile
import os
import sys


def main(pathname):
    # Check file exists:
    if not os.path.exists(pathname):
        raise FileNotFoundError(pathname)

    ole = olefile.OleFileIO(pathname)

    meta = ole.get_metadata()

    for prop in meta.SUMMARY_ATTRIBS:
        value = getattr(meta, prop)
        print((prop, value))

    if not ole.exists("\x05DigitalSignature"):
        print("WARNING: File not signed!")
    else:
        with ole.openstream("\x05DigitalSignature") as fh:
            b_data = fh.read()
            # print(b_data)

    # end:
    ole.close()


# if called directly, then run this example:
if __name__ == "__main__":
    try:
        sys.exit(main(sys.argv[1]))
    except IndexError:<commit_msg>tweak info output<commit_after>#!/usr/bin/env python3
"""
Parse MSI file for info

Related:
- https://github.com/decalage2/oletools/blob/master/oletools/olemeta.py
- https://github.com/ralphje/signify/issues/24#issuecomment-1148320566
"""
import olefile
import os
import sys


def main(pathname):
    # Check file exists:
    if not os.path.exists(pathname):
        raise FileNotFoundError(pathname)

    ole = olefile.OleFileIO(pathname)

    meta = ole.get_metadata()

    for prop in meta.SUMMARY_ATTRIBS:
        value = getattr(meta, prop)
        print((prop, value))

    # get raw info:
    # other_props = ole.getproperties("\x05SummaryInformation")
    # for item in other_props.values():
    #     print(item)

    if not ole.exists("\x05DigitalSignature"):
        print("WARNING: File not signed!")
    else:
        with ole.openstream("\x05DigitalSignature") as fh:
            b_data = fh.read()
            print(f"DigitalSignature: {len(b_data)} bytes")

    # end:
    ole.close()


# if called directly, then run this example:
if __name__ == "__main__":
    try:
        sys.exit(main(sys.argv[1]))
    except IndexError:
{'fraction_non_alphanumeric': 0.1256544502617801, 'fraction_numerical': 0.01903855306996668, 'mean_word_length': 2.958568738229755, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1983259', 'n_tokens_mistral': 743, 'n_tokens_neox': 686, 'n_words': 153}