import re


def rule(event):
    if all(
        [
            event.deep_get("Image", default="").endswith("\\csc.exe"),
            any(
                [
                    any(
                        [
                            ":\\Perflogs\\" in event.deep_get("CommandLine", default=""),
                            ":\\Users\\Public\\" in event.deep_get("CommandLine", default=""),
                            "\\AppData\\Local\\Temp\\" in event.deep_get("CommandLine", default=""),
                            "\\Temporary Internet" in event.deep_get("CommandLine", default=""),
                            "\\Windows\\Temp\\" in event.deep_get("CommandLine", default=""),
                        ]
                    ),
                    any(
                        [
                            all(
                                [
                                    ":\\Users\\" in event.deep_get("CommandLine", default=""),
                                    "\\Favorites\\" in event.deep_get("CommandLine", default=""),
                                ]
                            ),
                            all(
                                [
                                    ":\\Users\\" in event.deep_get("CommandLine", default=""),
                                    "\\Favourites\\" in event.deep_get("CommandLine", default=""),
                                ]
                            ),
                            all(
                                [
                                    ":\\Users\\" in event.deep_get("CommandLine", default=""),
                                    "\\Contacts\\" in event.deep_get("CommandLine", default=""),
                                ]
                            ),
                            all(
                                [
                                    ":\\Users\\" in event.deep_get("CommandLine", default=""),
                                    "\\Pictures\\" in event.deep_get("CommandLine", default=""),
                                ]
                            ),
                        ]
                    ),
                    re.match(
                        r"(?:[Pp]rogram[Dd]ata|%(?:[Ll]ocal)?[Aa]pp[Dd]ata%|\\\\[Aa]pp[Dd]ata\\\\(?:[Ll]ocal(?:[Ll]ow)?|[Rr]oaming))\\\\[^\\\\]{1,256}$",
                        event.deep_get("CommandLine", default=""),
                    ),
                ]
            ),
            not any(
                [
                    any(
                        [
                            event.deep_get("ParentImage", default="").startswith(
                                "C:\\Program Files (x86)\\"
                            ),
                            event.deep_get("ParentImage", default="").startswith(
                                "C:\\Program Files\\"
                            ),
                        ]
                    ),
                    event.deep_get("ParentImage", default="")
                    == "C:\\Windows\\System32\\sdiagnhost.exe",
                    event.deep_get("ParentImage", default="")
                    == "C:\\Windows\\System32\\inetsrv\\w3wp.exe",
                ]
            ),
            not any(
                [
                    event.deep_get("ParentImage", default="")
                    in [
                        "C:\\ProgramData\\chocolatey\\choco.exe",
                        "C:\\ProgramData\\chocolatey\\tools\\shimgen.exe",
                    ],
                    "\\ProgramData\\Microsoft\\Windows Defender Advanced Threat Protection"
                    in event.deep_get("ParentCommandLine", default=""),
                    any(
                        [
                            "JwB7ACIAZgBhAGkAbABlAGQAIgA6AHQAcgB1AGUALAAiAG0AcwBnACIAOgAiAEEAbgBzAGkAYgBsAGUAIAByAGUAcQB1AGkAcgBlAHMAIABQAG8AdwBlAHIAUwBoAGUAbABsACAAdgAzAC4AMAAgAG8AcgAgAG4AZQB3AGUAcgAiAH0AJw"
                            in event.deep_get("ParentCommandLine", default=""),
                            "cAewAiAGYAYQBpAGwAZQBkACIAOgB0AHIAdQBlACwAIgBtAHMAZwAiADoAIgBBAG4AcwBpAGIAbABlACAAcgBlAHEAdQBpAHIAZQBzACAAUABvAHcAZQByAFMAaABlAGwAbAAgAHYAMwAuADAAIABvAHIAIABuAGUAdwBlAHIAIgB9ACcA"
                            in event.deep_get("ParentCommandLine", default=""),
                            "nAHsAIgBmAGEAaQBsAGUAZAAiADoAdAByAHUAZQAsACIAbQBzAGcAIgA6ACIAQQBuAHMAaQBiAGwAZQAgAHIAZQBxAHUAaQByAGUAcwAgAFAAbwB3AGUAcgBTAGgAZQBsAGwAIAB2ADMALgAwACAAbwByACAAbgBlAHcAZQByACIAfQAnA"
                            in event.deep_get("ParentCommandLine", default=""),
                        ]
                    ),
                ]
            ),
        ]
    ):
        return True
    return False
