cutter/src/AnalThread.cpp

124 lines
3.2 KiB
C++
Raw Normal View History

#include <QDebug>
2018-03-04 17:42:02 +00:00
#include "Cutter.h"
#include "AnalThread.h"
2017-10-01 19:09:42 +00:00
#include "MainWindow.h"
#include "dialogs/OptionsDialog.h"
#include <QJsonArray>
AnalThread::AnalThread(OptionsDialog *parent) :
QThread(parent),
level(2),
2017-10-09 18:08:35 +00:00
main(nullptr),
2018-04-12 06:33:30 +00:00
core(Core()),
interrupted(false)
{
}
AnalThread::~AnalThread()
{
2018-03-21 20:32:32 +00:00
if (isRunning()) {
quit();
wait();
}
}
void AnalThread::start(MainWindow *main, int level, QList<QString> advanced)
{
this->level = level;
this->advanced = advanced;
this->main = main;
QThread::start();
}
void AnalThread::interruptAndWait()
{
interrupted = true;
2018-03-21 20:32:32 +00:00
while (isRunning()) {
r_cons_singleton()->breaked = true;
r_sys_usleep(10000);
}
}
// run() will be called when a thread starts
void AnalThread::run()
{
const auto optionsDialog = dynamic_cast<OptionsDialog *>(parent());
const auto &ui = optionsDialog->ui;
int va = ui->vaCheckBox->isChecked();
ut64 loadaddr = 0LL;
ut64 mapaddr = 0LL;
interrupted = false;
//
// Advanced Options
//
2018-03-21 20:32:32 +00:00
core->setCPU(optionsDialog->getSelectedArch(), optionsDialog->getSelectedCPU(),
optionsDialog->getSelectedBits());
2018-02-27 10:20:48 +00:00
int perms = R_IO_READ | R_IO_EXEC;
if (ui->writeCheckBox->isChecked())
perms |= R_IO_WRITE;
bool loadBinInfo = !ui->binCheckBox->isChecked();
2018-03-21 20:32:32 +00:00
if (loadBinInfo) {
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);
mapaddr = 0;
}
2018-03-21 20:32:32 +00:00
} else {
Core()->setConfig("file.info", "false");
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
QString forceBinPlugin = nullptr;
QVariant forceBinPluginData = ui->formatComboBox->currentData();
2018-03-21 20:32:32 +00:00
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());
QJsonArray openedFiles = Core()->getOpenedFiles();
2018-03-21 20:32:32 +00:00
if (!openedFiles.size()) {
core->loadFile(main->getFilename(), loadaddr, mapaddr, perms, va, binidx, loadBinInfo,
forceBinPlugin);
}
emit updateProgress("Analysis in progress.");
QString os = optionsDialog->getSelectedOS();
2018-03-21 20:32:32 +00:00
if (!os.isNull()) {
2017-10-09 18:08:35 +00:00
core->cmd("e asm.os=" + os);
}
2018-03-21 20:32:32 +00:00
if (ui->pdbCheckBox->isChecked()) {
2017-10-09 18:08:35 +00:00
core->loadPDB(ui->pdbLineEdit->text());
}
if (ui->scriptCheckBox->isChecked()) {
core->loadScript(ui->scriptLineEdit->text());
}
2018-03-21 20:32:32 +00:00
if (optionsDialog->getSelectedEndianness() != OptionsDialog::Endianness::Auto) {
core->setEndianness(optionsDialog->getSelectedEndianness() == OptionsDialog::Endianness::Big);
}
2018-01-20 10:35:31 +00:00
core->setBBSize(optionsDialog->getSelectedBBSize());
// 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);
}