cutter/src/AnalTask.cpp

114 lines
2.9 KiB
C++
Raw Normal View History

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/InitialOptionsDialog.h"
#include <QJsonArray>
2018-05-05 13:20:14 +00:00
#include <QDebug>
#include <QCheckBox>
2018-05-28 14:19:04 +00:00
AnalTask::AnalTask() :
AsyncTask()
{
}
2018-05-26 18:09:20 +00:00
AnalTask::~AnalTask()
{
}
2018-05-26 18:09:20 +00:00
void AnalTask::interrupt()
{
2018-05-26 18:09:20 +00:00
AsyncTask::interrupt();
2018-06-23 12:01:11 +00:00
r_cons_singleton()->context->breaked = true;
2018-05-26 18:09:20 +00:00
}
2018-05-26 18:09:20 +00:00
void AnalTask::runTask()
{
log(tr("Loading the file...\n"));
openFailed = false;
2018-09-22 16:00:21 +00:00
int perms = R_PERM_RX;
if (options.writeEnabled)
2018-09-22 16:00:21 +00:00
perms |= R_PERM_W;
2018-05-05 13:20:14 +00:00
// Demangle (must be before file Core()->loadFile)
Core()->setConfig("bin.demangle", options.demangle);
2018-05-05 13:20:14 +00:00
// Do not reload the file if already loaded
QJsonArray openedFiles = Core()->getOpenedFiles();
2018-07-06 21:23:51 +00:00
if (!openedFiles.size() && options.filename.length()) {
bool fileLoaded = Core()->loadFile(options.filename,
options.binLoadAddr,
options.mapAddr,
perms,
options.useVA,
options.loadBinInfo,
options.forceBinPlugin);
if (!fileLoaded) {
// Something wrong happened, fallback to open dialog
openFailed = true;
emit openFileFailed();
2018-07-06 21:23:51 +00:00
interrupt();
return;
}
}
// r_core_bin_load might change asm.bits, so let's set that after the bin is loaded
Core()->setCPU(options.arch, options.cpu, options.bits);
2018-05-27 19:49:14 +00:00
if (isInterrupted()) {
return;
}
if (!options.os.isNull()) {
Core()->cmd("e asm.os=" + options.os);
}
if (!options.pdbFile.isNull()) {
2018-07-06 21:23:51 +00:00
log(tr("Loading PDB file...\n"));
Core()->loadPDB(options.pdbFile);
}
2018-05-27 19:49:14 +00:00
if (isInterrupted()) {
return;
}
if (!options.shellcode.isNull() && options.shellcode.size() / 2 > 0) {
log(tr("Loading shellcode...\n"));
Core()->cmd("wx " + options.shellcode);
}
2018-07-24 17:50:55 +00:00
if (options.endian != InitialOptions::Endianness::Auto) {
Core()->setEndianness(options.endian == InitialOptions::Endianness::Big);
}
Core()->setBBSize(options.bbsize);
Core()->cmd("fs *");
if (!options.script.isNull()) {
2018-07-06 21:23:51 +00:00
log(tr("Executing script...\n"));
Core()->loadScript(options.script);
}
2018-05-27 19:49:14 +00:00
if (isInterrupted()) {
return;
}
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"));
}
}