Refactor Analysis Options

This commit is contained in:
Florian Märkl 2018-05-27 21:38:19 +02:00
parent f09d32bd3d
commit 4ce04c4f95
4 changed files with 80 additions and 60 deletions

View File

@ -21,13 +21,6 @@ void AnalTask::interrupt()
r_cons_singleton()->breaked = true;
}
void AnalTask::interruptAndWait()
{
do {
interrupt();
} while(!wait(10));
}
void AnalTask::runTask()
{
log(tr("Loading Binary...\n"));
@ -81,10 +74,17 @@ void AnalTask::runTask()
// Use prj.simple as default as long as regular projects are broken
Core()->setConfig("prj.simple", true);
// Start analysis
log(tr("Analysis in progress...\n"));
Core()->analyze(options.analLevel, options.analAdvanced);
log(tr("Analysis complete!"));
if (!options.analCmd.empty()) {
log(tr("Analyzing...\n"));
for (QString cmd : options.analCmd) {
if (isInterrupted()) {
return;
}
log(" " + tr("Running") + " " + cmd + "\n");
Core()->cmd(cmd);
}
log(tr("Analysis complete!\n"));
} else {
log(tr("Skipping Analysis.\n"));
}
}

View File

@ -36,8 +36,7 @@ struct InitialOptions
int bbsize = 0;
int analLevel = 1;
QList<QString> analAdvanced;
QList<QString> analCmd;
};
class AnalTask : public AsyncTask
@ -53,7 +52,6 @@ public:
void setOptions(const InitialOptions &options) { this->options = options; }
void interrupt() override;
void interruptAndWait();
protected:
void runTask() override;

View File

@ -145,6 +145,53 @@ QString OptionsDialog::getSelectedOS()
return os.isValid() ? os.toString() : nullptr;
}
QList<QString> OptionsDialog::getSelectedAdvancedAnalCmds()
{
QList<QString> advanced = QList<QString>();
if (ui->analSlider->value() == 3) {
if (ui->aa_symbols->isChecked()) {
advanced << "aa";
}
if (ui->aar_references->isChecked()) {
advanced << "aar";
}
if (ui->aac_calls->isChecked()) {
advanced << "aac";
}
if (ui->aab_basicblocks->isChecked()) {
advanced << "aab";
}
if (ui->aan_rename->isChecked()) {
advanced << "aan";
}
if (ui->aae_emulate->isChecked()) {
advanced << "aae";
}
if (ui->aat_consecutive->isChecked()) {
advanced << "aat";
}
if (ui->afta_typeargument->isChecked()) {
advanced << "afta";
}
if (ui->aaT_aftertrap->isChecked()) {
advanced << "aaT";
}
if (ui->aap_preludes->isChecked()) {
advanced << "aap";
}
if (ui->jmptbl->isChecked()) {
advanced << "e! anal.jmptbl";
}
if (ui->pushret->isChecked()) {
advanced << "e! anal.pushret";
}
if (ui->hasnext->isChecked()) {
advanced << "e! anal.hasnext";
}
}
return advanced;
}
void OptionsDialog::setupAndStartAnalysis(int level, QList<QString> advanced)
{
ui->analSlider->setValue(level);
@ -191,6 +238,22 @@ void OptionsDialog::setupAndStartAnalysis(int level, QList<QString> advanced)
options.endian = getSelectedEndianness();
options.bbsize = getSelectedBBSize();
switch(level) {
case 1:
options.analCmd = { "aaa" };
break;
case 2:
options.analCmd = { "aaaa" };
break;
case 3:
options.analCmd = advanced;
break;
default:
options.analCmd = {};
break;
}
AnalTask *analTask = new AnalTask(main);
analTask->setOptions(options);
@ -214,50 +277,7 @@ void OptionsDialog::updateProgress(const QString &status)
void OptionsDialog::on_okButton_clicked()
{
QList<QString> advanced = QList<QString>();
if (ui->analSlider->value() == 3) {
if (ui->aa_symbols->isChecked()) {
advanced << "aa";
}
if (ui->aar_references->isChecked()) {
advanced << "aar";
}
if (ui->aac_calls->isChecked()) {
advanced << "aac";
}
if (ui->aab_basicblocks->isChecked()) {
advanced << "aab";
}
if (ui->aan_rename->isChecked()) {
advanced << "aan";
}
if (ui->aae_emulate->isChecked()) {
advanced << "aae";
}
if (ui->aat_consecutive->isChecked()) {
advanced << "aat";
}
if (ui->afta_typeargument->isChecked()) {
advanced << "afta";
}
if (ui->aaT_aftertrap->isChecked()) {
advanced << "aaT";
}
if (ui->aap_preludes->isChecked()) {
advanced << "aap";
}
if (ui->jmptbl->isChecked()) {
advanced << "e! anal.jmptbl";
}
if (ui->pushret->isChecked()) {
advanced << "e! anal.pushret";
}
if (ui->hasnext->isChecked()) {
advanced << "e! anal.hasnext";
}
}
setupAndStartAnalysis(ui->analSlider->value(), advanced);
setupAndStartAnalysis(ui->analSlider->value(), getSelectedAdvancedAnalCmds());
}
void OptionsDialog::analysisFinished()

View File

@ -26,6 +26,7 @@ public:
public slots:
void updateProgress(const QString &str);
private slots:
void on_okButton_clicked();
void on_analSlider_valueChanged(int value);
@ -63,6 +64,7 @@ public:
int getSelectedBBSize();
InitialOptions::Endianness getSelectedEndianness();
QString getSelectedOS();
QList<QString> getSelectedAdvancedAnalCmds();
void reject() override;
};