Пример #1
0
static DWORD PluginLoadGenericMultiple(
    _Inout_ LPTSTR names,
    _Inout_ PBYTE pluginsArray,
    _In_ DWORD max,
    _In_ PLUGIN_TYPE const * const type
    ) {
    DWORD count = 0;
    DWORD i = 0;
    LPTSTR pluginName = NULL;
    LPTSTR ctx = NULL;
    PPLUGIN_HEAD plugin = NULL;

    while (StrNextToken(names, _T(","), &ctx, &pluginName)) {
        LOG(Info, SUB_LOG(_T("Loading %s <%s>")), type->name, pluginName);

        if (count >= max) {
            FATAL(_T("Cannot load more than <%u> %ss"), max, type->name);
        }

        for (i = 0; i < count; i++) {
            if (STR_EQ(pluginName, PLUGIN_GET_NAME((PPLUGIN_HEAD)(pluginsArray + (i * type->size))))) {
                FATAL(_T("%s <%s> is already loaded"), type->name, pluginName);
            }
        }

        plugin = (PPLUGIN_HEAD)(pluginsArray + (count * type->size));
        PLUGIN_SET_NAME(plugin, pluginName);
        PLUGIN_SET_TYPE(plugin, type);
        PluginLoadGenericSingle(plugin);

        count++;
    }

    return count;
}
Пример #2
0
static void ParseOptions(
    _In_ PACE_FILTER_OPTIONS opt,
    _In_ int argc,
    _In_ TCHAR * argv[]
    ) {

    const static struct option long_options[] = {
        { _T("list-plugins"), no_argument, 0, _T('L') },
        { _T("list-importers"), no_argument, 0, _T('I') },
        { _T("list-filters"), no_argument, 0, _T('F') },
        { _T("list-writers"), no_argument, 0, _T('W') },

        { _T("importers"), required_argument, 0, _T('i') },
        { _T("filters"), required_argument, 0, _T('f') },
        { _T("writers"), required_argument, 0, _T('w') },
        { _T("invert-filters"), required_argument, 0, _T('r') },

        { _T("progression"), required_argument, 0, _T('p') },
        { _T("logfile"), required_argument, 0, _T('l') },
        { _T("dbglvl"), required_argument, 0, _T('d') },
        { _T("loglvl"), required_argument, 0, _T('d') },
        { _T("help"), no_argument, 0, _T('h') },
        { _T("usage"), no_argument, 0, _T('h') },

        { 0, 0, 0, 0 }
    };

    int curropt = 0;
    BOOL bExitAfterOpt = FALSE;
    LPTSTR filter = NULL;
    LPTSTR ctx = NULL;

    //
    // Default options
    //
    SetLogLevel(DEFAULT_OPT_DEBUGLEVEL);
    opt->misc.progression = DEFAULT_OPT_PROGRESSION;

    //
    // Parsing
    //
    while ((curropt = getopt_long_only(argc, argv, EMPTY_STR, long_options, NULL)) != -1) {
        switch (curropt) {
            //
            // List
            //
        case _T('L'):
            SetLogLevel(_T("NONE"));
            ListImporters();
            ListFilters();
            ListWriters();
            ExitProcess(EXIT_SUCCESS);
            break;

        case _T('I'):
            SetLogLevel(_T("NONE"));
            ListImporters();
            bExitAfterOpt = TRUE;
            break;

        case _T('F'):
            SetLogLevel(_T("NONE"));
            ListFilters();
            bExitAfterOpt = TRUE;
            break;

        case _T('W'):
            SetLogLevel(_T("NONE"));
            ListWriters();
            bExitAfterOpt = TRUE;
            break;

            //
            // Plugins
            //
        case _T('i'):
            opt->names.importers = optarg;
            opt->plugins.numberOfImporters = PluginLoadImporters(opt->names.importers, opt->plugins.importers, PLUGIN_MAX_IMPORTERS);
            break;

        case _T('f'):
            opt->names.filters = optarg;
            opt->plugins.numberOfFilters = PluginLoadFilters(opt->names.filters, opt->plugins.filters, PLUGIN_MAX_FILTERS);
            break;

        case _T('w'):
            opt->names.writers = optarg;
            opt->plugins.numberOfWriters = PluginLoadWriters(opt->names.writers, opt->plugins.writers, PLUGIN_MAX_WRITERS);
            break;

        case _T('r'):
            opt->names.inverted = optarg;

            DWORD i = 0;
            filter = NULL;
            ctx = NULL;

            // TODO : invert after filters (numOfF == 0)

            while (StrNextToken(opt->names.inverted, ",", &ctx, &filter)) {
                for (i = 0; i < PLUGIN_MAX_FILTERS; i++) {
                    if (PLUGIN_IS_LOADED(&opt->plugins.filters[i])) {
                        if (STR_EQ(filter, PLUGIN_GET_NAME(&opt->plugins.filters[i]))) {
                            LOG(Info, SUB_LOG(_T("Inverting filter <%s>")), filter);
                            opt->plugins.filters[i].inverted = TRUE;
                            break;
                        }
                    }
                }
                if (i == PLUGIN_MAX_FILTERS) {
                    FATAL(_T("Trying to invert a non-loaded filter : <%s>"), filter);
                }
            }
            break;

            //
            // Misc
            //
        case _T('p'):
            opt->misc.progression = _tstoi(optarg);
            LOG(Info, SUB_LOG(_T("Printing progression every <%u> ACE")), opt->misc.progression);
            break;

        case _T('l'):
            opt->misc.logfile = optarg;
            SetLogFile(opt->misc.logfile);
            break;

        case _T('d'):
            opt->misc.loglvl = optarg;
            SetLogLevel(opt->misc.loglvl);
            break;

        case _T('h'):
            opt->misc.showHelp = TRUE;
            break;

        default:
            FATAL(_T("Unknown option"));
            break;
        }
    }


    LPTSTR optname = NULL;
    LPTSTR optval = NULL;
    int i = 0;

    for (i = optind; i < argc; i++) {
        ctx = NULL;

        StrNextToken(argv[i], "=", &ctx, &optname);
        optval = ctx; //We do not use StrNextToken here because optval can contain an equal sign.

        if (!optname || !optval) {
            FATAL(_T("Cannot parse plugin option <%s> (must be in format name=value)"), argv[i]);
        }
        else {
            LOG(Dbg, _T("Adding plugin option <%s : %s>"), optname, optval);
            AddStrPair(&gs_PluginOptions.end, optname, optval);
            if (!gs_PluginOptions.head) {
                gs_PluginOptions.head = gs_PluginOptions.end;
            }
        }
    }

    if (bExitAfterOpt) {
        ExitProcess(EXIT_SUCCESS);
    }
}