// Detect It Easy: detection rule file

// Author: DosX
// E-Mail: collab@kay-software.ru
// GitHub: https://github.com/DosX-dev
// Telegram: @DosX_dev

meta("library", "Direct3D");

function detect() {
    var maxVersion = 0,
        re = /d3dx?(\d{1,2})/i;

    for (var n = 0; n < PE.getNumberOfImports(); n++) {
        var m = PE.getImportLibraryName(n).match(re);
        if (m && /^\d+$/.test(m[1]) && Number(m[1]) > maxVersion) {
            maxVersion = Number(m[1]);
        }
    }

    for (var n = 0; n < PE.getNumberOfExportFunctions(); n++) {
        var m = PE.getExportFunctionName(n).match(re);
        if (m && /^\d+$/.test(m[1]) && Number(m[1]) > maxVersion) {
            maxVersion = Number(m[1]);
        }
    }

    if (maxVersion > 0 && maxVersion <= 13) {
        sVersion = String(maxVersion);
        bDetected = true;
    } else {
        sVersion = PE.isLibraryPresentExp(/^d3d(\d{1,2})/i);

        if (sVersion && sVersion.length > 1) {
            sVersion = sVersion[1];

            if (sVersion > 0 && sVersion <= 13) {
                bDetected = true;
            }
        }
    }

    return result();
}