2019-02-22 16:50:45 +00:00
|
|
|
#include "core/Cutter.h"
|
|
|
|
#include "common/AnalTask.h"
|
|
|
|
#include "core/MainWindow.h"
|
2018-08-18 10:51:11 +00:00
|
|
|
#include "dialogs/InitialOptionsDialog.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-28 14:19:04 +00:00
|
|
|
AnalTask::AnalTask() :
|
|
|
|
AsyncTask()
|
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();
|
2020-10-28 12:28:04 +00:00
|
|
|
rz_cons_singleton()->context->breaked = true;
|
2018-05-26 18:09:20 +00:00
|
|
|
}
|
2018-03-09 12:57:57 +00:00
|
|
|
|
2020-08-10 16:12:38 +00:00
|
|
|
QString AnalTask::getTitle() {
|
|
|
|
// If no file is loaded we consider it's Initial Analysis
|
|
|
|
QJsonArray openedFiles = Core()->getOpenedFiles();
|
|
|
|
if (!openedFiles.size()) {
|
|
|
|
return tr("Initial Analysis");
|
|
|
|
}
|
|
|
|
return tr("Analyzing Program");
|
|
|
|
}
|
|
|
|
|
2018-05-26 18:09:20 +00:00
|
|
|
void AnalTask::runTask()
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
2020-10-28 12:28:04 +00:00
|
|
|
int perms = RZ_PERM_RX;
|
2020-05-23 11:41:12 +00:00
|
|
|
if (options.writeEnabled) {
|
2020-10-28 12:28:04 +00:00
|
|
|
perms |= RZ_PERM_W;
|
2020-05-23 11:41:12 +00:00
|
|
|
emit Core()->ioModeChanged();
|
|
|
|
|
|
|
|
}
|
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-07-06 21:23:51 +00:00
|
|
|
if (!openedFiles.size() && options.filename.length()) {
|
2020-08-10 16:12:38 +00:00
|
|
|
log(tr("Loading the file..."));
|
|
|
|
openFailed = false;
|
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
|
2018-07-07 10:39:28 +00:00
|
|
|
openFailed = true;
|
2018-05-08 20:44:53 +00:00
|
|
|
emit openFileFailed();
|
2018-07-06 21:23:51 +00:00
|
|
|
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
|
|
|
|
2020-10-28 12:28:04 +00:00
|
|
|
// rz_core_bin_load might change asm.bits, so let's set that after the bin is loaded
|
2018-08-14 15:07:52 +00:00
|
|
|
Core()->setCPU(options.arch, options.cpu, options.bits);
|
|
|
|
|
2018-05-27 19:49:14 +00:00
|
|
|
if (isInterrupted()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-27 16:03:29 +00:00
|
|
|
if (!options.os.isNull()) {
|
2020-03-20 18:11:30 +00:00
|
|
|
Core()->cmdRaw("e asm.os=" + options.os);
|
2017-09-28 22:04:57 +00:00
|
|
|
}
|
|
|
|
|
2018-05-27 16:03:29 +00:00
|
|
|
if (!options.pdbFile.isNull()) {
|
2018-10-30 07:42:43 +00:00
|
|
|
log(tr("Loading PDB file..."));
|
2018-05-27 16:03:29 +00:00
|
|
|
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-08-10 17:12:00 +00:00
|
|
|
if (!options.shellcode.isNull() && options.shellcode.size() / 2 > 0) {
|
2018-10-30 07:42:43 +00:00
|
|
|
log(tr("Loading shellcode..."));
|
2020-03-20 18:11:30 +00:00
|
|
|
Core()->cmdRaw("wx " + options.shellcode);
|
2018-08-10 17:12:00 +00:00
|
|
|
}
|
|
|
|
|
2018-07-24 17:50:55 +00:00
|
|
|
if (options.endian != InitialOptions::Endianness::Auto) {
|
|
|
|
Core()->setEndianness(options.endian == InitialOptions::Endianness::Big);
|
|
|
|
}
|
|
|
|
|
2020-03-20 18:11:30 +00:00
|
|
|
Core()->cmdRaw("fs *");
|
2018-07-24 17:50:55 +00:00
|
|
|
|
2018-05-27 16:03:29 +00:00
|
|
|
if (!options.script.isNull()) {
|
2018-10-30 07:42:43 +00:00
|
|
|
log(tr("Executing script..."));
|
2018-05-27 16:03:29 +00:00
|
|
|
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 19:38:19 +00:00
|
|
|
if (!options.analCmd.empty()) {
|
2019-08-03 21:58:41 +00:00
|
|
|
log(tr("Executing analysis..."));
|
|
|
|
for (const CommandDescription &cmd : options.analCmd) {
|
2018-05-27 19:38:19 +00:00
|
|
|
if (isInterrupted()) {
|
|
|
|
return;
|
|
|
|
}
|
2019-08-03 21:58:41 +00:00
|
|
|
log(cmd.description);
|
2020-03-20 18:11:30 +00:00
|
|
|
// use cmd instead of cmdRaw because commands can be unexpected
|
2019-08-03 21:58:41 +00:00
|
|
|
Core()->cmd(cmd.command);
|
2018-05-27 19:38:19 +00:00
|
|
|
}
|
2018-10-30 07:42:43 +00:00
|
|
|
log(tr("Analysis complete!"));
|
2018-05-27 19:38:19 +00:00
|
|
|
} else {
|
2018-10-30 07:42:43 +00:00
|
|
|
log(tr("Skipping Analysis."));
|
2018-05-27 19:38:19 +00:00
|
|
|
}
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|