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