// DIE's signature file
// 27.12.2023 @DosX_dev add strings

// TODO: Rewrite this script

init("compiler", "DMD");

function detect(bShowType, bShowVersion, bShowOptions) {
    if (!PE.isNET() && PE.isSectionNamePresent(".minfo") && PE.isSectionNamePresent("._deh")) {
        bDetected = true;
    }

    if (!bDetected) {
        if ((PE.section[".rdata"]) && (PE.isDeepScan())) {
            var nOffset = PE.section[".rdata"].FileOffset;
            var nSize = PE.section[".rdata"].FileSize;
            if (
                PE.findSignature(nOffset, nSize, "'core.sys.windows.dll'") != -1 &&
                PE.findSignature(nOffset, nSize, "'string.d'") != -1
            ) {
                bDetected = true;
            }
        }
    }

    if (bDetected && PE.section[".rdata"]) {
        var nOffset = PE.section[".rdata"].FileOffset;
        var nSize = PE.section[".rdata"].FileSize;

        var strOffset = PE.findString(nOffset, nSize, "This program will continue, but will not operate when using DMD ");

        if (strOffset != -1) {
            sVersion = PE.getString(strOffset - 7, 5);

            if (sVersion.indexOf(".") == -1 || sVersion.split(".")[0].length != 1) {
                sVersion = "";
            }
        }
    }

    _setLang("D", bDetected);
    return result(bShowType, bShowVersion, bShowOptions);
}