2018-03-04 17:42:02 +00:00
|
|
|
#include "Cutter.h"
|
2018-05-26 18:09:20 +00:00
|
|
|
#include "AnalTask.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>
|
2018-05-05 13:20:14 +00:00
|
|
|
#include <QDebug>
|
|
|
|
#include <QCheckBox>
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2018-05-27 16:03:29 +00:00
|
|
|
AnalTask::AnalTask(QObject *parent) :
|
|
|
|
AsyncTask(parent)
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
2017-03-31 22:43:12 +00:00
|
|
|
}
|
|
|
|
|
2018-05-26 18:09:20 +00:00
|
|
|
AnalTask::~AnalTask()
|
2017-03-31 22:43:12 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-05-26 18:09:20 +00:00
|
|
|
void AnalTask::interrupt()
|
2018-03-09 12:57:57 +00:00
|
|
|
{
|
2018-05-26 18:09:20 +00:00
|
|
|
AsyncTask::interrupt();
|
|
|
|
r_cons_singleton()->breaked = true;
|
|
|
|
}
|
2018-03-09 12:57:57 +00:00
|
|
|
|
2018-05-26 18:09:20 +00:00
|
|
|
void AnalTask::runTask()
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
2018-05-26 18:49:57 +00:00
|
|
|
log(tr("Loading Binary...\n"));
|
2018-03-09 12:57:57 +00:00
|
|
|
|
2018-05-27 16:03:29 +00:00
|
|
|
Core()->setCPU(options.arch, options.cpu, options.bits);
|
2017-09-28 22:04:57 +00:00
|
|
|
|
2018-02-27 10:20:48 +00:00
|
|
|
int perms = R_IO_READ | R_IO_EXEC;
|
2018-05-27 16:03:29 +00:00
|
|
|
if (options.writeEnabled)
|
2018-02-27 10:20:48 +00:00
|
|
|
perms |= R_IO_WRITE;
|
2017-09-28 22:04:57 +00:00
|
|
|
|
2018-05-05 13:20:14 +00:00
|
|
|
// Demangle (must be before file Core()->loadFile)
|
2018-05-27 16:03:29 +00:00
|
|
|
Core()->setConfig("bin.demangle", options.demangle);
|
2017-10-01 16:03:06 +00:00
|
|
|
|
2018-05-05 13:20:14 +00:00
|
|
|
// Do not reload the file if already loaded
|
2018-01-27 10:40:26 +00:00
|
|
|
QJsonArray openedFiles = Core()->getOpenedFiles();
|
2018-03-21 20:32:32 +00:00
|
|
|
if (!openedFiles.size()) {
|
2018-05-27 16:03:29 +00:00
|
|
|
bool fileLoaded = Core()->loadFile(options.filename,
|
|
|
|
options.binLoadAddr,
|
|
|
|
options.mapAddr,
|
|
|
|
perms,
|
|
|
|
options.useVA,
|
|
|
|
options.loadBinInfo,
|
|
|
|
options.forceBinPlugin);
|
2018-05-08 20:44:53 +00:00
|
|
|
if (!fileLoaded) {
|
|
|
|
// Something wrong happened, fallback to open dialog
|
|
|
|
emit openFileFailed();
|
2018-05-26 18:09:20 +00:00
|
|
|
AsyncTask::interrupt();
|
2018-05-08 20:44:53 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-01-27 10:40:26 +00:00
|
|
|
}
|
2017-09-28 22:04:57 +00:00
|
|
|
|
2018-05-27 19:49:14 +00:00
|
|
|
if (isInterrupted()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-27 16:03:29 +00:00
|
|
|
if (!options.os.isNull()) {
|
|
|
|
Core()->cmd("e asm.os=" + options.os);
|
2017-09-28 22:04:57 +00:00
|
|
|
}
|
|
|
|
|
2018-05-05 13:20:14 +00:00
|
|
|
// Load PDB and/or scripts
|
2018-05-27 16:03:29 +00:00
|
|
|
if (!options.pdbFile.isNull()) {
|
|
|
|
Core()->loadPDB(options.pdbFile);
|
2017-09-28 22:04:57 +00:00
|
|
|
}
|
2018-05-27 16:03:29 +00:00
|
|
|
|
2018-05-27 19:49:14 +00:00
|
|
|
if (isInterrupted()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-27 16:03:29 +00:00
|
|
|
if (!options.script.isNull()) {
|
|
|
|
Core()->loadScript(options.script);
|
2018-04-30 06:39:48 +00:00
|
|
|
}
|
|
|
|
|
2018-05-27 19:49:14 +00:00
|
|
|
if (isInterrupted()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-27 16:03:29 +00:00
|
|
|
if (options.endian != InitialOptions::Endianness::Auto) {
|
|
|
|
Core()->setEndianness(options.endian == InitialOptions::Endianness::Big);
|
2018-01-27 10:40:26 +00:00
|
|
|
}
|
2018-05-27 16:03:29 +00:00
|
|
|
|
|
|
|
Core()->setBBSize(options.bbsize);
|
|
|
|
|
2018-05-05 13:20:14 +00:00
|
|
|
// Use prj.simple as default as long as regular projects are broken
|
|
|
|
Core()->setConfig("prj.simple", true);
|
|
|
|
|
2018-05-27 19:38:19 +00:00
|
|
|
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"));
|
|
|
|
}
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|