예제 #1
0
bool SelfTest::checkInjector(const QString &injectorType)
{
    AbstractInjector::Ptr injector = InjectorFactory::createInjector(injectorType);
    if (!injector) {
        emit error(tr("Unable to create instance of injector %1.").arg(injectorType));
        return false;
    }
    if (!injector->selfTest()) {
        emit error(tr("Injector %1 failed to pass its self-test: %2.").arg(injectorType,
                                                                           injector->errorString()));
        return false;
    }

    emit information(tr("Injector %1 successfully passed its self-test.").arg(injectorType));
    return true;
}
예제 #2
0
파일: main.cpp 프로젝트: krf/GammaRay
int main(int argc, char **argv)
{
    QApplication::setOrganizationName("KDAB");
    QApplication::setOrganizationDomain("kdab.com");
    QApplication::setApplicationName("GammaRay");

    QStringList args;
    for (int i = 1; i < argc; ++i) {
        args.push_back(QString::fromLocal8Bit(argv[i]));
    }
    QApplication app(argc, argv);

    QStringList builtInArgs = QStringList() << QLatin1String("-style")
                              << QLatin1String("-stylesheet")
                              << QLatin1String("-graphicssystem");

    QString injectorType;
    int pid = -1;
    while (!args.isEmpty() && args.first().startsWith('-')) {
        const QString arg = args.takeFirst();
        if ((arg == QLatin1String("-i") || arg == QLatin1String("--injector")) && !args.isEmpty()) {
            injectorType = args.takeFirst();
            continue;
        }
        if ((arg == QLatin1String("-p") || arg == QLatin1String("--pid")) && !args.isEmpty()) {
            pid = args.takeFirst().toInt();
            continue;
        }
        if (arg == QLatin1String("-h") || arg == QLatin1String("--help")) {
            usage(argv[0]);
            return 0;
        }
        if (arg == QLatin1String("-v") || arg == QLatin1String("--version")) {
            out << PROGRAM_NAME << " version " << GAMMARAY_VERSION_STRING << endl;
            out << "Copyright (C) 2010-2013 Klaralvdalens Datakonsult AB, "
                << "a KDAB Group company, [email protected]" << endl;
            return 0;
        }
        if (arg == QLatin1String("-filtertest")) {
            qputenv("GAMMARAY_TEST_FILTER", "1");
        }
        if (arg == QLatin1String("-unittest")) {
            qputenv("GAMMARAY_UNITTEST", "1");
        }
        if (arg == QLatin1String("-modeltest")) {
            qputenv("GAMMARAY_MODELTEST", "1");
        }
        // built-in arguments of QApp, could be meant for us if we are showing the launcher window
        foreach (const QString &builtInArg, builtInArgs) {
            if (arg == builtInArg && !args.isEmpty()) {
                args.takeFirst();
            }
        }
    }

    if (args.isEmpty() && pid <= 0) {
        LauncherWindow dialog;
        if (dialog.exec() == QDialog::Accepted) {
            args = dialog.launchArguments();
            bool ok;
            pid = dialog.pid().toInt(&ok);
            if (!ok && args.isEmpty()) {
                return 0;
            }
        } else {
            return 0;
        }
    }

    const QString probeDll = ProbeFinder::findProbe(QLatin1String("gammaray_probe"));
    qputenv("GAMMARAY_PROBE_PATH", QFileInfo(probeDll).absolutePath().toLocal8Bit());

    AbstractInjector::Ptr injector;
    if (injectorType.isEmpty()) {
        if (pid > 0) {
            injector = InjectorFactory::defaultInjectorForAttach();
        } else {
            injector = InjectorFactory::defaultInjectorForLaunch();
        }
    } else {
        injector = InjectorFactory::createInjector(injectorType);
    }

    if (injector) {
        if (pid > 0) {
            if (!injector->attach(pid, probeDll, QLatin1String("gammaray_probe_inject"))) {
                err << "Unable to attach injector " << injector->name() << endl;
                err << "Exit code: " << injector->exitCode() << endl;
                if (!injector->errorString().isEmpty()) {
                    err << "Error: " << injector->errorString() << endl;
                }
                return 1;
            } else {
                return 0;
            }
        } else {
            if (!injector->launch(args, probeDll, QLatin1String("gammaray_probe_inject"))) {
                err << "Failed to launch injector " << injector->name() << endl;
                err << "Exit code: " << injector->exitCode() << endl;
                if (!injector->errorString().isEmpty()) {
                    err << "Error: " << injector->errorString() << endl;
                }
                return 1;
            }
            return injector->exitCode();
        }
        return 1;
    }

    if (injectorType.isEmpty()) {
        if (pid > 0) {
#if defined(Q_OS_WIN)
            err << "Sorry, but at this time there is no attach injector on the Windows platform" << endl;
            err << "Only the launch injector windll is available on Windows" << endl;
#else
            err << "Uh-oh, there is no default attach injector" << endl;
#endif
        } else {
            err << "Uh-oh, there is no default launch injector" << endl;
        }
    } else {
        err << "Injector " << injectorType << " not found." << endl;
    }
    return 1;
}