// Detect It Easy: detection rule file
// Author: anonymous

meta("compiler", "Oracle Solaris Studio");

function getOSSVersion() {
    var sResult = "";
    var nSection = ELF.getSectionNumber(".comment");

    if (nSection != -1) {
        var nSectionOffset = ELF.getSectionFileOffset(nSection);
        var nSectionSize = ELF.getSectionFileSize(nSection);
        var nOffset = ELF.findString(nSectionOffset, nSectionSize, "Sun WorkShop");
        if (nOffset != -1) {
            return ELF.getString(nOffset + 13, 100);
        }
        nOffset = ELF.findString(nSectionOffset, nSectionSize, "acomp: Sun C");
        if (nOffset != -1) {
            return ELF.getString(nOffset + 13, 100);
        }
        nOffset = ELF.findString(nSectionOffset, nSectionSize, "SUNWCC.h");
        if (nOffset != -1) {
            return "5.X";
        }
    }

    return sResult;
}

function detect() {
    if (ELF.compareEP("bc1020..e003....1300....e022....a203a0..1300....e222....1300....e222....a52c20..a404a0..a40440122700....e804....80a520"))
    // SPARC instruction set
    {
        if (ELF.isSectionNamePresent(".SUNW_version")) {
            bDetected = true;
        }
        var sOSSVersion = getOSSVersion();
        if (sOSSVersion) {
            bDetected = true;
            sVersion = sOSSVersion;
        }
    }

    sLang = "C/C++";

    return result();
}