// Detect It Easy: detection rule file format

init("linker", "unknown", PE.getCompilerVersion(), PE.getGeneralOptionsEx());

includeScript("FASM");
includeScript("RosASM");
includeScript("SpASM");
includeScript("FPC");

function detect(bShowType, bShowVersion, bShowOptions) {
    if (PE.compare("'MZ'90000300000004000000FFFF0000B800000000000000400000000000000000000000000000000000000000000000000000000000000000000000800000000E1FBA0E00B409CD21B8014CCD21'This program cannot be run in DOS mode.\r\r\n$'00000000000000'PE'0000")) {
        var nMajor = PE.getMajorLinkerVersion();
        var nMinor = PE.getMinorLinkerVersion();
        if (nMajor == 2) {
            if (nMinor == 55) {
                sName = "LCC Linker";
                sVersion += "*";
                bDetected = true;
            } else if (nMinor <= 40 || nMinor == 56) {
                sName = "GNU Linker ld (GNU Binutils)";
                if (nMinor == 56) {
                    sVersion += "*";
                }
                bDetected = true;
            } else if (nMinor == 50) {
                sName = "Polink";
                sVersion += "*";
                bDetected = true;
            }
        } else if (nMajor == 1) {
            if (nMinor == 3) {
                sName = "LCC Linker";
                bDetected = true;
            }
        }
    } else if (PE.compare("'This program must be run under Win'....0D0A24..00", 0x50)) {
        sName = "Turbo Linker";
        if (sVersion == "2.25") {
            sVersion += "*,Delphi";
        }
        bDetected = true;
    } else if (PE.compare("FB..'jr'", 0x1e)) {
        sName = "Turbo Linker";
        sVersion = (PE.readByte(0x1f) / 16).toFixed(1);
        if (PE.compare("'32STUB'", 0x200)) {
            sOptions = sOptions.append("RTM32");
        }
        bDetected = true;
    } else if (PE.compare( /*[Tt]*/ "'his is a Windows '" /*(?:95|NT)*/ , 0x4f)) {
        sName = "Watcom Linker";
        sVersion += "*";
        bDetected = true;
    } else if (PE.compare("'MZ'6c000100000002000000ffff000000000000110000004000000000000000'Win'....' Program!\r\n$'b409ba0001cd21b44ccd2160000000'GoLink, GoAsm www.GoDevTool.com'00")) {
        sName = "GoLink";
        bDetected = true;
    }
    var nMajor = PE.getMajorLinkerVersion();
    var nMinor = PE.getMinorLinkerVersion();
    if ((nMajor == 2) && (nMinor == 18)) {
        sName = "Watcom Linker";
        bDetected = true;
    } else if ((nMajor == 2) && (nMinor == 52)) {
        sName = "PowerBASIC Linker";
        bDetected = true;
    }
    // Correct version
    if (sName == "Borland Linker") {
        if (PE.getMajorLinkerVersion() > 15) {
            sVersion += "*";
        }
    }

    /* if(!bDetected&&(bShowVersion||bShowOptions))
    {
        if(!bShowType)
        {
            sName+=" "+sType;
        }
        bDetected=1;
    } */

    if (bFASM) {
        // FASM doesn't have a linker.
        bDetected = false;
    }
    if (bRosASM) {
        // RosASM doesn't have a linker.
        bDetected = false;
    }
    if (bSpASM) {
        // SpASM doesn't have a linker.
        bDetected = false;
    }
    if (bFPC) {
        // Free Pascal doesn't have a linker.
        bDetected = false;
    }

    return result(bShowType, bShowVersion, bShowOptions);
}