// Detect It Easy: detection rule file format

init("library", "SDL");

function getSDLVersion() {
    var sResult = "";
    var nSection = ELF.getSectionNumber(".dynstr");
    if (nSection != -1) {
        var nOffset = ELF.getSectionFileOffset(nSection);
        var nSize = ELF.getSectionFileSize(nSection);

        var nVersionOffset = ELF.findString(nOffset, nSize, "libSDL-");
        if (nVersionOffset != -1) {
            var sSDLVersion = ELF.getString(nVersionOffset);
            var aVersion = sSDLVersion.match(/libSDL-(.*).so/);
            if (aVersion) {
                sResult = aVersion[1];
            }
        }
    }

    return sResult;
}

function detect(bShowType, bShowVersion, bShowOptions) {
    if (ELF.isStringInTablePresent(".dynstr", "SDL_Init")) {
        bDetected = true;
    }

    if (bDetected) {
        sVersion = getSDLVersion();
    }

    return result(bShowType, bShowVersion, bShowOptions);
}