// Detect It Easy: detection rule file format

init("library", "Qt");

function getQTVersion() {
    var sResult = "";
    var nSize = ELF.getSize();
    var nOffset = ELF.findString(0, nSize, "/usr/local/Trolltech/Qt-");
    if (nOffset != -1) {
        sResult = ELF.getString(nOffset + 24);
        var aVersion = sResult.match(/(.*)\//);
        if (aVersion) {
            sResult = aVersion[1];
        }
    }

    return sResult;
}

function detect(bShowType, bShowVersion, bShowOptions) {

    if (ELF.isStringInTablePresent(".dynstr", "libQtCore.so.4")) {
        sVersion = "4.X";
        bDetected = true;
    } else if (ELF.isStringInTablePresent(".dynstr", "libQt5Core.so.5")) {
        sVersion = "5.X";
        bDetected = true;
    } else if (ELF.isStringInTablePresent(".dynstr", "libQt6Core_x86.so")) {
        sVersion = "6.X";
        bDetected = true;
    }

    if (bDetected) {
        var sQTVersion = getQTVersion();
        if (sQTVersion != "") {
            sVersion = sQTVersion;
        }
    }

    return result(bShowType, bShowVersion, bShowOptions);
}