mirror of
https://github.com/rizinorg/cutter.git
synced 2025-02-22 14:43:46 +00:00
A bit of AnalThread cleaning
This commit is contained in:
parent
53a7d5a959
commit
923a7e888c
@ -1,15 +1,15 @@
|
|||||||
#include <QDebug>
|
|
||||||
#include "Cutter.h"
|
#include "Cutter.h"
|
||||||
#include "AnalThread.h"
|
#include "AnalThread.h"
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
#include "dialogs/OptionsDialog.h"
|
#include "dialogs/OptionsDialog.h"
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QCheckBox>
|
||||||
|
|
||||||
AnalThread::AnalThread(OptionsDialog *parent) :
|
AnalThread::AnalThread(OptionsDialog *parent) :
|
||||||
QThread(parent),
|
QThread(parent),
|
||||||
level(2),
|
level(2),
|
||||||
main(nullptr),
|
main(nullptr),
|
||||||
core(Core()),
|
|
||||||
interrupted(false)
|
interrupted(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -46,41 +46,23 @@ void AnalThread::run()
|
|||||||
{
|
{
|
||||||
const auto optionsDialog = dynamic_cast<OptionsDialog *>(parent());
|
const auto optionsDialog = dynamic_cast<OptionsDialog *>(parent());
|
||||||
const auto &ui = optionsDialog->ui;
|
const auto &ui = optionsDialog->ui;
|
||||||
int va = ui->vaCheckBox->isChecked();
|
bool va = ui->vaCheckBox->isChecked();
|
||||||
ut64 loadaddr = 0LL;
|
ut64 binLoadAddr = Core()->math(ui->entry_loadOffset->text()); // Where the bin header is located in the file (-B)
|
||||||
ut64 mapaddr = 0LL;
|
ut64 mapAddr = Core()->math(ui->entry_mapOffset->text()); // Where to map the file once loaded (-m)
|
||||||
|
|
||||||
interrupted = false;
|
interrupted = false;
|
||||||
|
emit updateProgress(tr("Loading binary..."));
|
||||||
|
|
||||||
//
|
// Set the CPU details (handle auto)
|
||||||
// Advanced Options
|
Core()->setCPU(optionsDialog->getSelectedArch(), optionsDialog->getSelectedCPU(),
|
||||||
//
|
|
||||||
|
|
||||||
core->setCPU(optionsDialog->getSelectedArch(), optionsDialog->getSelectedCPU(),
|
|
||||||
optionsDialog->getSelectedBits());
|
optionsDialog->getSelectedBits());
|
||||||
|
|
||||||
|
// Binary opening permissions (read/write/execute)
|
||||||
int perms = R_IO_READ | R_IO_EXEC;
|
int perms = R_IO_READ | R_IO_EXEC;
|
||||||
if (ui->writeCheckBox->isChecked())
|
if (ui->writeCheckBox->isChecked())
|
||||||
perms |= R_IO_WRITE;
|
perms |= R_IO_WRITE;
|
||||||
|
|
||||||
|
// Check if we must load and parse binary header (ELF, PE, ...)
|
||||||
bool loadBinInfo = !ui->binCheckBox->isChecked();
|
bool loadBinInfo = !ui->binCheckBox->isChecked();
|
||||||
|
|
||||||
if (loadBinInfo) {
|
|
||||||
if (!va) {
|
|
||||||
va = 2;
|
|
||||||
loadaddr = UT64_MAX;
|
|
||||||
r_config_set_i(core->core()->config, "bin.laddr", loadaddr);
|
|
||||||
mapaddr = 0;
|
|
||||||
}
|
|
||||||
} 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;
|
QString forceBinPlugin = nullptr;
|
||||||
QVariant forceBinPluginData = ui->formatComboBox->currentData();
|
QVariant forceBinPluginData = ui->formatComboBox->currentData();
|
||||||
if (!forceBinPluginData.isNull()) {
|
if (!forceBinPluginData.isNull()) {
|
||||||
@ -88,36 +70,40 @@ void AnalThread::run()
|
|||||||
forceBinPlugin = pluginDesc.name;
|
forceBinPlugin = pluginDesc.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
core->setConfig("bin.demangle", ui->demangleCheckBox->isChecked());
|
// Demangle (must be before file Core()->loadFile)
|
||||||
|
Core()->setConfig("bin.demangle", ui->demangleCheckBox->isChecked());
|
||||||
|
|
||||||
|
// Do not reload the file if already loaded
|
||||||
QJsonArray openedFiles = Core()->getOpenedFiles();
|
QJsonArray openedFiles = Core()->getOpenedFiles();
|
||||||
if (!openedFiles.size()) {
|
if (!openedFiles.size()) {
|
||||||
core->loadFile(main->getFilename(), loadaddr, mapaddr, perms, va, binidx, loadBinInfo,
|
Core()->loadFile(main->getFilename(), binLoadAddr, mapAddr, perms, va, loadBinInfo,
|
||||||
forceBinPlugin);
|
forceBinPlugin);
|
||||||
}
|
}
|
||||||
emit updateProgress("Analysis in progress.");
|
|
||||||
|
|
||||||
|
// Set asm OS configuration
|
||||||
QString os = optionsDialog->getSelectedOS();
|
QString os = optionsDialog->getSelectedOS();
|
||||||
if (!os.isNull()) {
|
if (!os.isNull()) {
|
||||||
core->cmd("e asm.os=" + os);
|
Core()->cmd("e asm.os=" + os);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load PDB and/or scripts
|
||||||
if (ui->pdbCheckBox->isChecked()) {
|
if (ui->pdbCheckBox->isChecked()) {
|
||||||
core->loadPDB(ui->pdbLineEdit->text());
|
Core()->loadPDB(ui->pdbLineEdit->text());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ui->scriptCheckBox->isChecked()) {
|
if (ui->scriptCheckBox->isChecked()) {
|
||||||
core->loadScript(ui->scriptLineEdit->text());
|
Core()->loadScript(ui->scriptLineEdit->text());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set various options
|
||||||
if (optionsDialog->getSelectedEndianness() != OptionsDialog::Endianness::Auto) {
|
if (optionsDialog->getSelectedEndianness() != OptionsDialog::Endianness::Auto) {
|
||||||
core->setEndianness(optionsDialog->getSelectedEndianness() == OptionsDialog::Endianness::Big);
|
Core()->setEndianness(optionsDialog->getSelectedEndianness() == OptionsDialog::Endianness::Big);
|
||||||
}
|
}
|
||||||
|
Core()->setBBSize(optionsDialog->getSelectedBBSize());
|
||||||
|
// Use prj.simple as default as long as regular projects are broken
|
||||||
|
Core()->setConfig("prj.simple", true);
|
||||||
|
|
||||||
core->setBBSize(optionsDialog->getSelectedBBSize());
|
// Start analysis
|
||||||
|
emit updateProgress(tr("Analysis in progress..."));
|
||||||
// use prj.simple as default as long as regular projects are broken
|
Core()->analyze(this->level, this->advanced);
|
||||||
core->setConfig("prj.simple", true);
|
emit updateProgress(tr("Analysis complete!"));
|
||||||
|
|
||||||
core->analyze(this->level, this->advanced);
|
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,6 @@ private:
|
|||||||
int level;
|
int level;
|
||||||
QList<QString> advanced;
|
QList<QString> advanced;
|
||||||
MainWindow *main;
|
MainWindow *main;
|
||||||
CutterCore *core;
|
|
||||||
|
|
||||||
bool interrupted;
|
bool interrupted;
|
||||||
};
|
};
|
||||||
|
@ -71,9 +71,6 @@ CutterCore::CutterCore(QObject *parent) :
|
|||||||
# endif
|
# endif
|
||||||
setConfig("dir.prefix", prefix.absolutePath());
|
setConfig("dir.prefix", prefix.absolutePath());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
default_bits = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -209,15 +206,11 @@ QJsonDocument CutterCore::cmdj(const QString &str)
|
|||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CutterCore::loadFile(QString path, uint64_t loadaddr, uint64_t mapaddr, int perms, int va,
|
bool CutterCore::loadFile(QString path, ut64 baddr, ut64 mapaddr, int perms, int va,
|
||||||
int idx, bool loadbin, const QString &forceBinPlugin)
|
bool loadbin, const QString &forceBinPlugin)
|
||||||
{
|
{
|
||||||
Q_UNUSED(loadaddr);
|
|
||||||
Q_UNUSED(idx);
|
|
||||||
|
|
||||||
CORE_LOCK();
|
CORE_LOCK();
|
||||||
RCoreFile *f;
|
RCoreFile *f;
|
||||||
if (va == 0 || va == 2)
|
|
||||||
r_config_set_i(core_->config, "io.va", va);
|
r_config_set_i(core_->config, "io.va", va);
|
||||||
|
|
||||||
f = r_core_file_open(core_, path.toUtf8().constData(), perms, mapaddr);
|
f = r_core_file_open(core_, path.toUtf8().constData(), perms, mapaddr);
|
||||||
@ -230,16 +223,10 @@ bool CutterCore::loadFile(QString path, uint64_t loadaddr, uint64_t mapaddr, int
|
|||||||
r_bin_force_plugin(r_core_get_bin(core_), forceBinPlugin.toUtf8().constData());
|
r_bin_force_plugin(r_core_get_bin(core_), forceBinPlugin.toUtf8().constData());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loadbin) {
|
if (loadbin && va) {
|
||||||
if (va == 1) {
|
if (!r_core_bin_load(core_, path.toUtf8().constData(), baddr)) {
|
||||||
if (!r_core_bin_load(core_, path.toUtf8().constData(), UT64_MAX)) {
|
|
||||||
eprintf("CANNOT GET RBIN INFO\n");
|
eprintf("CANNOT GET RBIN INFO\n");
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (!r_core_bin_load(core_, path.toUtf8().constData(), UT64_MAX)) {
|
|
||||||
eprintf("CANNOT GET RBIN INFO\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#if HAVE_MULTIPLE_RBIN_FILES_INSIDE_SELECT_WHICH_ONE
|
#if HAVE_MULTIPLE_RBIN_FILES_INSIDE_SELECT_WHICH_ONE
|
||||||
if (!r_core_file_open(core, path.toUtf8(), R_IO_READ | (rw ? R_IO_WRITE : 0, mapaddr))) {
|
if (!r_core_file_open(core, path.toUtf8(), R_IO_READ | (rw ? R_IO_WRITE : 0, mapaddr))) {
|
||||||
@ -247,7 +234,7 @@ bool CutterCore::loadFile(QString path, uint64_t loadaddr, uint64_t mapaddr, int
|
|||||||
} else {
|
} else {
|
||||||
// load RBin information
|
// load RBin information
|
||||||
// XXX only for sub-bins
|
// XXX only for sub-bins
|
||||||
r_core_bin_load(core, path.toUtf8(), loadaddr);
|
r_core_bin_load(core, path.toUtf8(), baddr);
|
||||||
r_bin_select_idx(core_->bin, NULL, idx);
|
r_bin_select_idx(core_->bin, NULL, idx);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -267,8 +254,6 @@ bool CutterCore::loadFile(QString path, uint64_t loadaddr, uint64_t mapaddr, int
|
|||||||
r_core_cmd0 (core_, "omfg+w");
|
r_core_cmd0 (core_, "omfg+w");
|
||||||
}
|
}
|
||||||
|
|
||||||
setDefaultCPU();
|
|
||||||
|
|
||||||
r_core_hash_load(core_, path.toUtf8().constData());
|
r_core_hash_load(core_, path.toUtf8().constData());
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
return true;
|
return true;
|
||||||
@ -541,16 +526,11 @@ void CutterCore::setConfig(const QString &k, const QVariant &v)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CutterCore::setCPU(QString arch, QString cpu, int bits, bool temporary)
|
void CutterCore::setCPU(QString arch, QString cpu, int bits)
|
||||||
{
|
{
|
||||||
setConfig("asm.arch", arch);
|
setConfig("asm.arch", arch);
|
||||||
setConfig("asm.cpu", cpu);
|
setConfig("asm.cpu", cpu);
|
||||||
setConfig("asm.bits", bits);
|
setConfig("asm.bits", bits);
|
||||||
if (!temporary) {
|
|
||||||
default_arch = arch;
|
|
||||||
default_cpu = cpu;
|
|
||||||
default_bits = bits;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CutterCore::setEndianness(bool big)
|
void CutterCore::setEndianness(bool big)
|
||||||
@ -563,16 +543,6 @@ void CutterCore::setBBSize(int size)
|
|||||||
setConfig("anal.bb.maxsize", size);
|
setConfig("anal.bb.maxsize", size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CutterCore::setDefaultCPU()
|
|
||||||
{
|
|
||||||
if (!default_arch.isEmpty())
|
|
||||||
setConfig("asm.arch", default_arch);
|
|
||||||
if (!default_cpu.isEmpty())
|
|
||||||
setConfig("asm.cpu", default_cpu);
|
|
||||||
if (default_bits)
|
|
||||||
setConfig("asm.bits", QString::number(default_bits));
|
|
||||||
}
|
|
||||||
|
|
||||||
QString CutterCore::assemble(const QString &code)
|
QString CutterCore::assemble(const QString &code)
|
||||||
{
|
{
|
||||||
CORE_LOCK();
|
CORE_LOCK();
|
||||||
|
11
src/Cutter.h
11
src/Cutter.h
@ -325,8 +325,8 @@ public:
|
|||||||
void setImmediateBase(const QString &r2BaseName, RVA offset = RVA_INVALID);
|
void setImmediateBase(const QString &r2BaseName, RVA offset = RVA_INVALID);
|
||||||
void setCurrentBits(int bits, RVA offset = RVA_INVALID);
|
void setCurrentBits(int bits, RVA offset = RVA_INVALID);
|
||||||
|
|
||||||
bool loadFile(QString path, uint64_t loadaddr = 0LL, uint64_t mapaddr = 0LL, int perms = R_IO_READ,
|
bool loadFile(QString path, ut64 baddr = 0LL, ut64 mapaddr = 0LL, int perms = R_IO_READ,
|
||||||
int va = 0, int idx = 0, bool loadbin = false, const QString &forceBinPlugin = nullptr);
|
int va = 0, bool loadbin = false, const QString &forceBinPlugin = nullptr);
|
||||||
bool tryFile(QString path, bool rw);
|
bool tryFile(QString path, bool rw);
|
||||||
void analyze(int level, QList<QString> advanced);
|
void analyze(int level, QList<QString> advanced);
|
||||||
|
|
||||||
@ -371,8 +371,7 @@ public:
|
|||||||
QString assemble(const QString &code);
|
QString assemble(const QString &code);
|
||||||
QString disassemble(const QString &hex);
|
QString disassemble(const QString &hex);
|
||||||
QString disassembleSingleInstruction(RVA addr);
|
QString disassembleSingleInstruction(RVA addr);
|
||||||
void setDefaultCPU();
|
void setCPU(QString arch, QString cpu, int bits);
|
||||||
void setCPU(QString arch, QString cpu, int bits, bool temporary = false);
|
|
||||||
void setEndianness(bool big);
|
void setEndianness(bool big);
|
||||||
void setBBSize(int size);
|
void setBBSize(int size);
|
||||||
|
|
||||||
@ -500,10 +499,6 @@ signals:
|
|||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString default_arch;
|
|
||||||
QString default_cpu;
|
|
||||||
int default_bits;
|
|
||||||
|
|
||||||
MemoryWidgetType memoryWidgetPriority;
|
MemoryWidgetType memoryWidgetPriority;
|
||||||
|
|
||||||
QString notes;
|
QString notes;
|
||||||
|
@ -220,9 +220,9 @@
|
|||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>-636</y>
|
<y>-672</y>
|
||||||
<width>564</width>
|
<width>564</width>
|
||||||
<height>831</height>
|
<height>867</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_5">
|
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||||
@ -791,7 +791,7 @@
|
|||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Load offset:</string>
|
<string>Load bin offset (-B)</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -801,7 +801,7 @@
|
|||||||
<string notr="true"/>
|
<string notr="true"/>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string notr="true">0</string>
|
<string notr="true"/>
|
||||||
</property>
|
</property>
|
||||||
<property name="frame">
|
<property name="frame">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
@ -809,6 +809,9 @@
|
|||||||
<property name="alignment">
|
<property name="alignment">
|
||||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="placeholderText">
|
||||||
|
<string>1024</string>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0">
|
<item row="1" column="0">
|
||||||
@ -826,14 +829,14 @@
|
|||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Map offset:</string>
|
<string>Map offset (-m)</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="1" column="1">
|
||||||
<widget class="QLineEdit" name="entry_mapOffset">
|
<widget class="QLineEdit" name="entry_mapOffset">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>0</string>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
<property name="frame">
|
<property name="frame">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
@ -841,6 +844,9 @@
|
|||||||
<property name="alignment">
|
<property name="alignment">
|
||||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="placeholderText">
|
||||||
|
<string>0x40000</string>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="0">
|
<item row="2" column="0">
|
||||||
@ -871,7 +877,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="pdbLineEdit">
|
<widget class="QLineEdit" name="pdbLineEdit">
|
||||||
<property name="placeholderText">
|
<property name="placeholderText">
|
||||||
<string>pdb file</string>
|
<string>PDB File path</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -885,7 +891,6 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
||||||
<item row="3" column="0">
|
<item row="3" column="0">
|
||||||
<widget class="QCheckBox" name="scriptCheckBox">
|
<widget class="QCheckBox" name="scriptCheckBox">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -928,7 +933,6 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
||||||
<item row="4" column="0">
|
<item row="4" column="0">
|
||||||
<widget class="QLabel" name="analbbLabel">
|
<widget class="QLabel" name="analbbLabel">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
|
@ -19,8 +19,6 @@ HexdumpWidget::HexdumpWidget(MainWindow *main, QAction *action) :
|
|||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
//this->on_actionSettings_menu_1_triggered();
|
|
||||||
|
|
||||||
// Setup hex highlight
|
// Setup hex highlight
|
||||||
//connect(ui->hexHexText, SIGNAL(cursorPositionChanged()), this, SLOT(highlightHexCurrentLine()));
|
//connect(ui->hexHexText, SIGNAL(cursorPositionChanged()), this, SLOT(highlightHexCurrentLine()));
|
||||||
//highlightHexCurrentLine();
|
//highlightHexCurrentLine();
|
||||||
@ -297,8 +295,8 @@ void HexdumpWidget::refresh(RVA addr)
|
|||||||
// TODO: Figure out how to calculate a sane value for this
|
// TODO: Figure out how to calculate a sane value for this
|
||||||
bufferLines = qhelpers::getMaxFullyDisplayedLines(ui->hexHexText);
|
bufferLines = qhelpers::getMaxFullyDisplayedLines(ui->hexHexText);
|
||||||
|
|
||||||
int loadLines = bufferLines * 3; // total lines to load
|
ut64 loadLines = bufferLines * 3; // total lines to load
|
||||||
int curAddrLineOffset = bufferLines; // line number where seek should be
|
ut64 curAddrLineOffset = bufferLines; // line number where seek should be
|
||||||
|
|
||||||
if (addr < curAddrLineOffset * cols) {
|
if (addr < curAddrLineOffset * cols) {
|
||||||
curAddrLineOffset = static_cast<int>(addr / cols);
|
curAddrLineOffset = static_cast<int>(addr / cols);
|
||||||
|
Loading…
Reference in New Issue
Block a user