def rule(event):
    if all(
        [
            any(
                [
                    event.deep_get("TargetFilename", default="").endswith(".docm"),
                    event.deep_get("TargetFilename", default="").endswith(".dotm"),
                    event.deep_get("TargetFilename", default="").endswith(".xlsm"),
                    event.deep_get("TargetFilename", default="").endswith(".xltm"),
                    event.deep_get("TargetFilename", default="").endswith(".potm"),
                    event.deep_get("TargetFilename", default="").endswith(".pptm"),
                ]
            ),
            not all(
                [
                    any(
                        [
                            event.deep_get("Image", default="").startswith(
                                "C:\\Program Files\\Microsoft Office\\"
                            ),
                            event.deep_get("Image", default="").startswith(
                                "C:\\Program Files (x86)\\Microsoft Office\\"
                            ),
                        ]
                    ),
                    any(
                        [
                            event.deep_get("Image", default="").endswith("\\WINWORD.EXE"),
                            event.deep_get("Image", default="").endswith("\\EXCEL.EXE"),
                            event.deep_get("Image", default="").endswith("\\POWERPNT.EXE"),
                        ]
                    ),
                    "\\~$" in event.deep_get("TargetFilename", default=""),
                ]
            ),
        ]
    ):
        return True
    return False
