#!/usr/bin/env python3
"""Primary compiler signatures."""

from .compiler_signature_constants import SECTION_EH_FRAME, SECTION_RDATA, SECTION_TEXT

CORE_COMPILER_SIGNATURES = {
    "MSVC": {
        "strings": [
            r"Microsoft.*Visual.*C\+\+",
            r"MSVCR\d+\.dll",
            r"MSVCP\d+\.dll",
            r"VCRUNTIME\d+\.dll",
            r"api-ms-win-crt",
            r"__security_cookie",
            r"__security_check_cookie",
        ],
        "imports": [
            "MSVCR80.dll",
            "MSVCR90.dll",
            "MSVCR100.dll",
            "MSVCR110.dll",
            "MSVCR120.dll",
            "MSVCR140.dll",
            "MSVCP80.dll",
            "MSVCP90.dll",
            "MSVCP100.dll",
            "MSVCP110.dll",
            "MSVCP120.dll",
            "MSVCP140.dll",
            "VCRUNTIME140.dll",
            "VCRUNTIME140_1.dll",
        ],
        "sections": [SECTION_RDATA, ".idata"],
        "rich_header": True,
    },
    "GCC": {
        "strings": [
            r"GCC:.*\d+\.\d+",
            r"GNU.*\d+\.\d+",
            r"__gxx_personality_v0",
            r"__cxa_finalize",
            r"__stack_chk_fail",
            r"_GLOBAL_OFFSET_TABLE_",
        ],
        "imports": ["libgcc_s.so", "libstdc++.so", "libc.so.6", "libm.so.6"],
        "sections": [SECTION_EH_FRAME, ".eh_frame_hdr", ".gcc_except_table"],
        "symbols": ["__gmon_start__", "__libc_start_main"],
    },
    "Clang": {
        "strings": [
            r"clang.*\d+\.\d+",
            r"LLVM.*\d+\.\d+",
            r"__clang_version__",
            r"Apple.*clang",
        ],
        "imports": ["libc++.so", "libc++abi.so"],
        "sections": [SECTION_EH_FRAME, ".debug_info"],
        "symbols": ["__cxa_atexit"],
    },
    "ICC": {
        "strings": [r"Intel.*C\+\+.*Compiler", r"libiomp5\.dll", r"libmmd\.dll"],
        "imports": ["libiomp5.dll", "libmmd.dll"],
        "sections": [],
        "symbols": [],
    },
    "Borland": {
        "strings": [r"Borland.*C\+\+", r"Embarcadero", r"CodeGear", r"__fastcall"],
        "imports": ["CC3250MT.DLL", "RTL250.BPL"],
        "sections": [".tls"],
        "symbols": [],
    },
    "MinGW": {
        "strings": [r"mingw", r"MinGW.*\d+\.\d+", r"__mingw_"],
        "imports": [
            "mingwm10.dll",
            "libgcc_s_dw2-1.dll",
            "libstdc++-6.dll",
            "libwinpthread-1.dll",
        ],
        "sections": [SECTION_EH_FRAME],
        "symbols": [],
    },
    "Delphi": {
        "strings": [r"Delphi", r"Borland.*Delphi"],
        "imports": ["rtl*.bpl"],
        "sections": [".itext", ".bss"],
        "symbols": [],
    },
    "Go": {
        "strings": [r"Go build", r"go\.buildid", r"runtime\."],
        "imports": [],
        "sections": [".gosymtab", ".gopclntab"],
        "symbols": ["runtime.main"],
    },
    "Rust": {
        "strings": [r"rustc", r"\.rustc"],
        "imports": [],
        "sections": [".rustc"],
        "symbols": ["_ZN"],
    },
    "VB": {
        "strings": [r"Visual Basic", r"VB\d+"],
        "imports": ["msvbvm60.dll", "msvbvm50.dll"],
        "sections": [],
        "symbols": [],
    },
    "AutoIt": {"strings": [r"AutoIt", r"AU3!"], "imports": [], "sections": [], "symbols": []},
    "PyInstaller": {
        "strings": [r"PyInstaller", r"pyi_\w+"],
        "imports": [],
        "sections": [],
        "symbols": [],
    },
    "DotNet": {
        "strings": [r"\.NETFramework", r"mscorlib"],
        "imports": ["mscoree.dll"],
        "sections": [SECTION_TEXT],
        "symbols": [],
    },
    "Lua": {"strings": [r"Lua", r"luaL_"], "imports": [], "sections": [], "symbols": []},
    "PHP": {"strings": [r"PHP", r"php_\w+"], "imports": [], "sections": [], "symbols": []},
    "Perl": {"strings": [r"Perl", r"perl_\w+"], "imports": [], "sections": [], "symbols": []},
    "Java": {"strings": [r"Java", r"JVM"], "imports": [], "sections": [], "symbols": []},
    "UPX": {
        "strings": [r"UPX", r"UPX!"],
        "imports": [],
        "sections": ["UPX0", "UPX1"],
        "symbols": [],
    },
    "Delphi (VCL)": {"strings": [r"VCL"], "imports": [], "sections": [], "symbols": []},
    "FASM": {"strings": [r"fasm"], "imports": [], "sections": [], "symbols": []},
    "MASM": {"strings": [r"masm"], "imports": [], "sections": [], "symbols": []},
    "Watcom": {"strings": [r"Watcom"], "imports": [], "sections": [], "symbols": []},
    "Intel": {"strings": [r"Intel"], "imports": [], "sections": [], "symbols": []},
    "Qt": {"strings": [r"Qt\d+"], "imports": [], "sections": [], "symbols": []},
    "QT": {"strings": [r"QT\d+"], "imports": [], "sections": [], "symbols": []},
    "Turbo C": {"strings": [r"Turbo C"], "imports": [], "sections": [], "symbols": []},
    "Microsoft Basic": {
        "strings": [r"Microsoft Basic"],
        "imports": [],
        "sections": [],
        "symbols": [],
    },
    "Microsoft Fortran": {
        "strings": [r"Microsoft Fortran"],
        "imports": [],
        "sections": [],
        "symbols": [],
    },
    "Visual Studio": {
        "strings": [r"Visual Studio"],
        "imports": [],
        "sections": [],
        "symbols": [],
    },
    "Borland C++": {
        "strings": [r"Borland C\+\+"],
        "imports": [],
        "sections": [],
        "symbols": [],
    },
    "Embarcadero": {"strings": [r"Embarcadero"], "imports": [], "sections": [], "symbols": []},
    "Delphi XE": {"strings": [r"Delphi XE"], "imports": [], "sections": [], "symbols": []},
    "C#": {"strings": [r"C#"], "imports": [], "sections": [], "symbols": []},
    "F#": {"strings": [r"F#"], "imports": [], "sections": [], "symbols": []},
}
