// Detect It Easy: detection rule file
// Author: horsicq <horsicq@gmail.com>

meta("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() {
    if (ELF.isStringInTablePresent(".dynstr", "SDL_Init")) {
        bDetected = true;
    }

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

    return result();
}