// 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+)/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) {
        sVersion = String(maxVersion);
        bDetected = true;
    } else if (PE.isLibraryPresentExp(/^d3d/i)) {
        bDetected = true;
    }

    return result();
}