2017-03-29 10:18:37 +00:00
|
|
|
#include <QDebug>
|
2017-09-25 12:55:41 +00:00
|
|
|
#include "cutter.h"
|
2017-10-02 16:18:40 +00:00
|
|
|
#include "AnalThread.h"
|
2017-10-01 19:09:42 +00:00
|
|
|
#include "MainWindow.h"
|
|
|
|
#include "dialogs/OptionsDialog.h"
|
2018-01-27 10:40:26 +00:00
|
|
|
#include <QJsonArray>
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2017-09-28 22:04:57 +00:00
|
|
|
AnalThread::AnalThread(OptionsDialog *parent) :
|
2017-03-31 22:43:12 +00:00
|
|
|
QThread(parent),
|
2017-09-29 11:32:53 +00:00
|
|
|
level(2),
|
2017-10-09 18:08:35 +00:00
|
|
|
main(nullptr),
|
|
|
|
core(CutterCore::getInstance())
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
2017-03-31 22:43:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AnalThread::~AnalThread()
|
|
|
|
{
|
2017-04-09 19:55:06 +00:00
|
|
|
if (isRunning())
|
|
|
|
{
|
2017-03-31 22:43:12 +00:00
|
|
|
quit();
|
|
|
|
wait();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-28 22:04:57 +00:00
|
|
|
void AnalThread::start(MainWindow *main, int level, QList<QString> advanced)
|
2017-03-31 22:43:12 +00:00
|
|
|
{
|
|
|
|
this->level = level;
|
2017-07-24 11:05:28 +00:00
|
|
|
this->advanced = advanced;
|
2017-09-28 22:04:57 +00:00
|
|
|
this->main = main;
|
2017-03-31 22:43:12 +00:00
|
|
|
|
|
|
|
QThread::start();
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// run() will be called when a thread starts
|
|
|
|
void AnalThread::run()
|
|
|
|
{
|
2017-09-28 22:04:57 +00:00
|
|
|
const auto optionsDialog = dynamic_cast<OptionsDialog *>(parent());
|
2017-11-03 17:22:54 +00:00
|
|
|
const auto &ui = optionsDialog->ui;
|
2017-09-28 22:04:57 +00:00
|
|
|
int va = ui->vaCheckBox->isChecked();
|
|
|
|
ut64 loadaddr = 0LL;
|
|
|
|
ut64 mapaddr = 0LL;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Advanced Options
|
|
|
|
//
|
|
|
|
|
2017-10-09 18:08:35 +00:00
|
|
|
core->setCPU(optionsDialog->getSelectedArch(), optionsDialog->getSelectedCPU(), optionsDialog->getSelectedBits());
|
2017-09-28 22:04:57 +00:00
|
|
|
|
|
|
|
bool rw = false;
|
2018-01-27 10:40:26 +00:00
|
|
|
bool loadBinInfo = ui->binCheckBox->isChecked();
|
2017-09-28 22:04:57 +00:00
|
|
|
|
2018-01-27 10:40:26 +00:00
|
|
|
if (loadBinInfo)
|
2017-09-28 22:04:57 +00:00
|
|
|
{
|
|
|
|
if (!va)
|
|
|
|
{
|
|
|
|
va = 2;
|
|
|
|
loadaddr = UT64_MAX;
|
2017-10-09 18:08:35 +00:00
|
|
|
r_config_set_i(core->core()->config, "bin.laddr", loadaddr);
|
2017-09-28 22:04:57 +00:00
|
|
|
mapaddr = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
va = false;
|
|
|
|
loadaddr = mapaddr = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
emit updateProgress(tr("Loading binary"));
|
|
|
|
// options dialog should show the list of archs inside the given fatbin
|
|
|
|
int binidx = 0; // index of subbin
|
|
|
|
|
2017-09-29 11:32:53 +00:00
|
|
|
QString forceBinPlugin = nullptr;
|
|
|
|
QVariant forceBinPluginData = ui->formatComboBox->currentData();
|
|
|
|
if (!forceBinPluginData.isNull())
|
|
|
|
{
|
|
|
|
RBinPluginDescription pluginDesc = forceBinPluginData.value<RBinPluginDescription>();
|
|
|
|
forceBinPlugin = pluginDesc.name;
|
|
|
|
}
|
|
|
|
|
2017-10-09 18:08:35 +00:00
|
|
|
core->setConfig("bin.demangle", ui->demangleCheckBox->isChecked());
|
2017-10-01 16:03:06 +00:00
|
|
|
|
2018-01-27 10:40:26 +00:00
|
|
|
QJsonArray openedFiles = Core()->getOpenedFiles();
|
|
|
|
qDebug() << openedFiles << openedFiles.size();
|
|
|
|
if (!openedFiles.size())
|
|
|
|
{
|
|
|
|
core->loadFile(main->getFilename(), loadaddr, mapaddr, rw, va, binidx, loadBinInfo, forceBinPlugin);
|
|
|
|
}
|
2017-09-28 22:04:57 +00:00
|
|
|
emit updateProgress("Analysis in progress.");
|
|
|
|
|
|
|
|
QString os = optionsDialog->getSelectedOS();
|
|
|
|
if (!os.isNull())
|
|
|
|
{
|
2017-10-09 18:08:35 +00:00
|
|
|
core->cmd("e asm.os=" + os);
|
2017-09-28 22:04:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ui->pdbCheckBox->isChecked())
|
|
|
|
{
|
2017-10-09 18:08:35 +00:00
|
|
|
core->loadPDB(ui->pdbLineEdit->text());
|
2017-09-28 22:04:57 +00:00
|
|
|
}
|
2017-11-26 13:17:16 +00:00
|
|
|
|
2018-01-27 10:40:26 +00:00
|
|
|
if (optionsDialog->getSelectedEndianness() != OptionsDialog::Endianness::Auto)
|
|
|
|
{
|
|
|
|
core->setEndianness(optionsDialog->getSelectedEndianness() == OptionsDialog::Endianness::Big);
|
|
|
|
}
|
2018-01-20 10:35:31 +00:00
|
|
|
|
2017-11-26 13:17:16 +00:00
|
|
|
// use prj.simple as default as long as regular projects are broken
|
|
|
|
core->setConfig("prj.simple", true);
|
|
|
|
|
2017-10-09 18:08:35 +00:00
|
|
|
core->analyze(this->level, this->advanced);
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|