cutter/src/main.cpp

97 lines
3.0 KiB
C++
Raw Normal View History

2017-04-01 11:20:13 +00:00
#include "mainwindow.h"
#include "newfiledialog.h"
2017-04-01 11:20:13 +00:00
#include "optionsdialog.h"
#include <QApplication>
2017-04-01 11:20:13 +00:00
#include <QCommandLineParser>
#include <QTextCodec>
#include <QMessageBox>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
a.setOrganizationName("iaito");
a.setApplicationName("iaito");
a.setApplicationVersion(APP_VERSION);
// Set QString codec to UTF-8
QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
#endif
2017-04-01 11:20:13 +00:00
QCommandLineParser cmdParser;
cmdParser.setApplicationDescription("A Qt and C++ GUI for radare2 reverse engineering framework");
cmdParser.addHelpOption();
cmdParser.addVersionOption();
cmdParser.addPositionalArgument("filename", QObject::tr("Filename to open."));
QCommandLineOption analOption({"A", "anal"},
2017-05-04 16:05:24 +00:00
QObject::tr("Automatically start analysis. Needs filename to be specified. May be a value between 0 and 4."),
QObject::tr("level"));
cmdParser.addOption(analOption);
2017-04-01 11:20:13 +00:00
cmdParser.process(a);
QStringList args = cmdParser.positionalArguments();
// Check r2 version
QString r2version = r_core_version();
QString localVersion = "" R2_GITTAP;
2017-04-09 19:55:06 +00:00
if (r2version != localVersion)
{
QMessageBox msg;
msg.setIcon(QMessageBox::Critical);
msg.setWindowIcon(QIcon(":/new/prefix1/img/logo-small.png"));
msg.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
msg.setWindowTitle("Version mismatch!");
msg.setText(QString("The version used to compile iaito (%1) does not match the binary version of radare2 (%2). This could result in unexpected behaviour. Are you sure you want to continue?").arg(localVersion, r2version));
2017-04-09 19:55:06 +00:00
if (msg.exec() == QMessageBox::No)
return 1;
}
bool analLevelSpecified = false;
int analLevel = 0;
if (cmdParser.isSet(analOption))
{
analLevel = cmdParser.value(analOption).toInt(&analLevelSpecified);
if (!analLevelSpecified || analLevel < 0 || analLevel > 4)
{
printf("%s\n", QObject::tr("Invalid Analysis Level. May be a value between 0 and 4.").toLocal8Bit().constData());
return 1;
}
}
2017-04-09 19:55:06 +00:00
if (args.empty())
2017-04-01 11:20:13 +00:00
{
if (analLevelSpecified)
{
printf("%s\n", QObject::tr("Filename must be specified to start analysis automatically.").toLocal8Bit().constData());
return 1;
}
2017-04-01 11:20:13 +00:00
NewFileDialog *n = new NewFileDialog();
n->setAttribute(Qt::WA_DeleteOnClose);
2017-04-01 11:33:16 +00:00
n->show();
2017-04-01 11:20:13 +00:00
}
else // filename specified as positional argument
{
OptionsDialog *o = new OptionsDialog(args[0]);
o->setAttribute(Qt::WA_DeleteOnClose);
2017-04-01 11:33:16 +00:00
o->show();
if (analLevelSpecified)
o->setupAndStartAnalysis(analLevel);
2017-04-01 11:20:13 +00:00
}
return a.exec();
}