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

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

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

    if (nSection != -1) {
        var nSectionOffset = ELF.getSectionFileOffset(nSection),
            nSectionSize = ELF.getSectionFileSize(nSection),
            nOffset = ELF.findString(nSectionOffset, nSectionSize, "Sun WorkShop");

        if (nOffset != -1) {
            return File.cleanString(ELF.getString(nOffset + 13, 100));
        }

        nOffset = ELF.findString(nSectionOffset, nSectionSize, "acomp: Sun C");
        if (nOffset != -1) {
            return File.cleanString(ELF.getString(nOffset + 13, 100));
        }

        nOffset = ELF.findString(nSectionOffset, nSectionSize, "SUNWCC.h");
        if (nOffset != -1) {
            return "5.X";
        }
    }

    return sResult;
}

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

        var sOSSVersion = getOSSVersion();
        if (sOSSVersion) {
            sVersion = sOSSVersion;
            bDetected = true;
        }
    }

    sLang = "C/C++";

    return result();
}