cutter/src/AnalThread.cpp

110 lines
3.3 KiB
C++
Raw Normal View History

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>
2018-05-05 13:20:14 +00:00
#include <QDebug>
#include <QCheckBox>
AnalThread::AnalThread(OptionsDialog *parent) :
QThread(parent),
level(2),
2017-10-09 18:08:35 +00:00
main(nullptr),
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;
2018-05-05 13:20:14 +00:00
bool va = ui->vaCheckBox->isChecked();
ut64 binLoadAddr = Core()->math(ui->entry_loadOffset->text()); // Where the bin header is located in the file (-B)
ut64 mapAddr = Core()->math(ui->entry_mapOffset->text()); // Where to map the file once loaded (-m)
interrupted = false;
2018-05-05 13:20:14 +00:00
emit updateProgress(tr("Loading binary..."));
2018-05-05 13:20:14 +00:00
// Set the CPU details (handle auto)
Core()->setCPU(optionsDialog->getSelectedArch(), optionsDialog->getSelectedCPU(),
2018-03-21 20:32:32 +00:00
optionsDialog->getSelectedBits());
2018-05-05 13:20:14 +00:00
// Binary opening permissions (read/write/execute)
2018-02-27 10:20:48 +00:00
int perms = R_IO_READ | R_IO_EXEC;
if (ui->writeCheckBox->isChecked())
perms |= R_IO_WRITE;
2018-05-05 13:20:14 +00:00
// Check if we must load and parse binary header (ELF, PE, ...)
bool loadBinInfo = !ui->binCheckBox->isChecked();
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;
}
2018-05-05 13:20:14 +00:00
// Demangle (must be before file Core()->loadFile)
Core()->setConfig("bin.demangle", ui->demangleCheckBox->isChecked());
2018-05-05 13:20:14 +00:00
// Do not reload the file if already loaded
QJsonArray openedFiles = Core()->getOpenedFiles();
2018-03-21 20:32:32 +00:00
if (!openedFiles.size()) {
2018-05-05 13:20:14 +00:00
Core()->loadFile(main->getFilename(), binLoadAddr, mapAddr, perms, va, loadBinInfo,
2018-03-21 20:32:32 +00:00
forceBinPlugin);
}
2018-05-05 13:20:14 +00:00
// Set asm OS configuration
QString os = optionsDialog->getSelectedOS();
2018-03-21 20:32:32 +00:00
if (!os.isNull()) {
2018-05-05 13:20:14 +00:00
Core()->cmd("e asm.os=" + os);
}
2018-05-05 13:20:14 +00:00
// Load PDB and/or scripts
2018-03-21 20:32:32 +00:00
if (ui->pdbCheckBox->isChecked()) {
2018-05-05 13:20:14 +00:00
Core()->loadPDB(ui->pdbLineEdit->text());
}
if (ui->scriptCheckBox->isChecked()) {
2018-05-05 13:20:14 +00:00
Core()->loadScript(ui->scriptLineEdit->text());
}
2018-05-05 13:20:14 +00:00
// Set various options
2018-03-21 20:32:32 +00:00
if (optionsDialog->getSelectedEndianness() != OptionsDialog::Endianness::Auto) {
2018-05-05 13:20:14 +00:00
Core()->setEndianness(optionsDialog->getSelectedEndianness() == OptionsDialog::Endianness::Big);
}
2018-05-05 13:20:14 +00:00
Core()->setBBSize(optionsDialog->getSelectedBBSize());
// Use prj.simple as default as long as regular projects are broken
Core()->setConfig("prj.simple", true);
// Start analysis
emit updateProgress(tr("Analysis in progress..."));
Core()->analyze(this->level, this->advanced);
emit updateProgress(tr("Analysis complete!"));
}