mirror of
https://github.com/rizinorg/cutter.git
synced 2025-02-18 12:39:46 +00:00
Add TempConfig, Fix some issues with scr.color
This commit is contained in:
parent
03ef0be73d
commit
f7958a802f
@ -849,7 +849,7 @@ void CutterCore::setSettings()
|
||||
//setConfig("bin.rawstr", "true");
|
||||
|
||||
// Colors
|
||||
setConfig("scr.color", true);
|
||||
setConfig("scr.color", false);
|
||||
setConfig("scr.truecolor", false);
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,8 @@ SOURCES += \
|
||||
widgets/HexdumpWidget.cpp \
|
||||
utils/Configuration.cpp \
|
||||
utils/Colors.cpp \
|
||||
dialogs/SaveProjectDialog.cpp
|
||||
dialogs/SaveProjectDialog.cpp \
|
||||
utils/TempConfig.cpp
|
||||
|
||||
HEADERS += \
|
||||
cutter.h \
|
||||
@ -127,7 +128,8 @@ HEADERS += \
|
||||
widgets/HexdumpWidget.h \
|
||||
utils/Configuration.h \
|
||||
utils/Colors.h \
|
||||
dialogs/SaveProjectDialog.h
|
||||
dialogs/SaveProjectDialog.h \
|
||||
utils/TempConfig.h
|
||||
|
||||
FORMS += \
|
||||
widgets/PreviewWidget.ui \
|
||||
|
@ -1,6 +1,8 @@
|
||||
#include "XrefsDialog.h"
|
||||
#include "ui_XrefsDialog.h"
|
||||
|
||||
#include "utils/TempConfig.h"
|
||||
|
||||
#include "MainWindow.h"
|
||||
|
||||
#include <QJsonArray>
|
||||
@ -19,11 +21,14 @@ XrefsDialog::XrefsDialog(QWidget *parent) :
|
||||
QTextDocument *asm_docu = ui->previewTextEdit->document();
|
||||
asm_docu->setDocumentMargin(10);
|
||||
|
||||
// Syntax highlight
|
||||
highlighter = new Highlighter(ui->previewTextEdit->document());
|
||||
setupPreviewFont();
|
||||
setupPreviewColors();
|
||||
|
||||
// Highlight current line
|
||||
connect(ui->previewTextEdit, SIGNAL(cursorPositionChanged()), this, SLOT(highlightCurrentLine()));
|
||||
|
||||
connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(setupPreviewFont()));
|
||||
connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(setupPreviewColors()));
|
||||
}
|
||||
|
||||
XrefsDialog::~XrefsDialog() {}
|
||||
@ -110,6 +115,18 @@ QString XrefsDialog::normalizeAddr(const QString& addr) const
|
||||
}
|
||||
}
|
||||
|
||||
void XrefsDialog::setupPreviewFont()
|
||||
{
|
||||
ui->previewTextEdit->setFont(Config()->getFont());
|
||||
}
|
||||
|
||||
void XrefsDialog::setupPreviewColors()
|
||||
{
|
||||
ui->previewTextEdit->setStyleSheet(QString("QPlainTextEdit { background-color: %1; color: %2; }")
|
||||
.arg(ConfigColor("gui.background").name())
|
||||
.arg(ConfigColor("btext").name()));
|
||||
}
|
||||
|
||||
void XrefsDialog::highlightCurrentLine()
|
||||
{
|
||||
QList<QTextEdit::ExtraSelection> extraSelections;
|
||||
@ -152,20 +169,26 @@ void XrefsDialog::on_toTreeWidget_itemSelectionChanged()
|
||||
|
||||
void XrefsDialog::updatePreview(RVA addr)
|
||||
{
|
||||
// is the address part of a function, so we can use pdf?
|
||||
bool isFunction = !core->cmdj("afij@" + QString::number(addr)).array().isEmpty();
|
||||
|
||||
TempConfig tempConfig;
|
||||
tempConfig.set("scr.html", true);
|
||||
tempConfig.set("scr.color", true);
|
||||
|
||||
QString disass;
|
||||
|
||||
// is the address part of a function, so we can use pdf?
|
||||
if (!core->cmdj("afij@" + QString::number(addr)).array().isEmpty())
|
||||
if (isFunction)
|
||||
disass = core->cmd("pdf @ " + QString::number(addr));
|
||||
else
|
||||
disass = core->cmd("pd 10 @ " + QString::number(addr));
|
||||
|
||||
ui->previewTextEdit->setPlainText(disass.trimmed());
|
||||
ui->previewTextEdit->document()->setHtml(disass);
|
||||
|
||||
// Does it make any sense?
|
||||
ui->previewTextEdit->moveCursor(QTextCursor::End);
|
||||
ui->previewTextEdit->find(this->normalizeAddr(RAddressString(addr)), QTextDocument::FindBackward);
|
||||
ui->previewTextEdit->moveCursor(QTextCursor::StartOfWord, QTextCursor::MoveAnchor);
|
||||
ui->previewTextEdit->moveCursor(QTextCursor::StartOfLine, QTextCursor::MoveAnchor);
|
||||
}
|
||||
|
||||
void XrefsDialog::updateLabels(QString name)
|
||||
@ -176,6 +199,10 @@ void XrefsDialog::updateLabels(QString name)
|
||||
|
||||
void XrefsDialog::fillRefsForAddress(RVA addr, QString name, bool whole_function)
|
||||
{
|
||||
TempConfig tempConfig;
|
||||
tempConfig.set("scr.html", false);
|
||||
tempConfig.set("scr.color", false);
|
||||
|
||||
this->addr = addr;
|
||||
this->func_name = func_name;
|
||||
|
||||
|
@ -25,13 +25,14 @@ public:
|
||||
void fillRefsForAddress(RVA addr, QString name, bool whole_function);
|
||||
|
||||
private slots:
|
||||
|
||||
void on_fromTreeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column);
|
||||
|
||||
void on_toTreeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column);
|
||||
|
||||
QString normalizeAddr(const QString& addr) const;
|
||||
|
||||
void setupPreviewFont();
|
||||
void setupPreviewColors();
|
||||
|
||||
void highlightCurrentLine();
|
||||
void on_fromTreeWidget_itemSelectionChanged();
|
||||
|
||||
@ -44,8 +45,6 @@ private:
|
||||
std::unique_ptr<Ui::XrefsDialog> ui;
|
||||
CutterCore *core;
|
||||
|
||||
Highlighter *highlighter;
|
||||
|
||||
void fillRefs(QList<XrefDescription> refs, QList<XrefDescription> xrefs);
|
||||
void updateLabels(QString name);
|
||||
void updatePreview(RVA addr);
|
||||
|
60
src/utils/TempConfig.cpp
Normal file
60
src/utils/TempConfig.cpp
Normal file
@ -0,0 +1,60 @@
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include "cutter.h"
|
||||
#include "TempConfig.h"
|
||||
|
||||
TempConfig::~TempConfig()
|
||||
{
|
||||
for (auto i = resetValues.begin(); i != resetValues.end(); i++)
|
||||
{
|
||||
switch(i.value().type())
|
||||
{
|
||||
case QVariant::String:
|
||||
Core()->setConfig(i.key(), i.value().toString());
|
||||
break;
|
||||
case QVariant::Int:
|
||||
Core()->setConfig(i.key(), i.value().toInt());
|
||||
break;
|
||||
case QVariant::Bool:
|
||||
Core()->setConfig(i.key(), i.value().toBool());
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TempConfig &TempConfig::set(const QString &key, const QString &value)
|
||||
{
|
||||
if (!resetValues.contains(key))
|
||||
{
|
||||
resetValues[key] = Core()->getConfig(key);
|
||||
}
|
||||
|
||||
Core()->setConfig(key, value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
TempConfig &TempConfig::set(const QString &key, int value)
|
||||
{
|
||||
if (!resetValues.contains(key))
|
||||
{
|
||||
resetValues[key] = Core()->getConfigi(key);
|
||||
}
|
||||
|
||||
Core()->setConfig(key, value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
TempConfig &TempConfig::set(const QString &key, bool value)
|
||||
{
|
||||
if (!resetValues.contains(key))
|
||||
{
|
||||
resetValues[key] = Core()->getConfigb(key);
|
||||
}
|
||||
|
||||
Core()->setConfig(key, value);
|
||||
return *this;
|
||||
}
|
22
src/utils/TempConfig.h
Normal file
22
src/utils/TempConfig.h
Normal file
@ -0,0 +1,22 @@
|
||||
|
||||
#ifndef TEMPCONFIG_H
|
||||
#define TEMPCONFIG_H
|
||||
|
||||
#include <QString>
|
||||
#include <QVariant>
|
||||
|
||||
class TempConfig
|
||||
{
|
||||
public:
|
||||
TempConfig() = default;
|
||||
~TempConfig();
|
||||
|
||||
TempConfig &set(const QString &key, const QString &value);
|
||||
TempConfig &set(const QString &key, int value);
|
||||
TempConfig &set(const QString &key, bool value);
|
||||
|
||||
private:
|
||||
QMap<QString, QVariant> resetValues;
|
||||
};
|
||||
|
||||
#endif //TEMPCONFIG_H
|
@ -4,6 +4,7 @@
|
||||
#include "utils/HexHighlighter.h"
|
||||
#include "utils/Configuration.h"
|
||||
#include "utils/Helpers.h"
|
||||
#include "utils/TempConfig.h"
|
||||
|
||||
#include <QScrollBar>
|
||||
#include <QJsonArray>
|
||||
@ -108,11 +109,11 @@ QWidget* DisassemblyWidget::getTextWidget()
|
||||
|
||||
QString DisassemblyWidget::readDisasm(const QString &cmd, bool stripLastNewline)
|
||||
{
|
||||
Core()->setConfig("scr.html", true);
|
||||
Core()->setConfig("scr.color", true);
|
||||
TempConfig tempConfig;
|
||||
tempConfig.set("scr.html", true)
|
||||
.set("scr.color", true);
|
||||
|
||||
QString disas = Core()->cmd(cmd);
|
||||
Core()->setConfig("scr.html", false);
|
||||
Core()->setConfig("scr.color", false);
|
||||
|
||||
if (stripLastNewline)
|
||||
{
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include "MainWindow.h"
|
||||
#include "utils/Helpers.h"
|
||||
#include "utils/TempConfig.h"
|
||||
|
||||
#include <QTemporaryFile>
|
||||
#include <QFontDialog>
|
||||
@ -482,6 +483,9 @@ void HexdumpWidget::fillPlugins()
|
||||
|
||||
std::array<QString, 3> HexdumpWidget::fetchHexdump(RVA offset, RVA bytes)
|
||||
{
|
||||
TempConfig tempConfig;
|
||||
tempConfig.set("scr.color", false);
|
||||
|
||||
QString hexdump = Core()->cmd(QString("px %1 @ %2").arg(QString::number(bytes), QString::number(offset)));
|
||||
|
||||
QString offsets;
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "DisassemblerGraphView.h"
|
||||
|
||||
#include "utils/Helpers.h"
|
||||
#include "utils/TempConfig.h"
|
||||
|
||||
#include <QTemporaryFile>
|
||||
#include <QFontDialog>
|
||||
@ -149,6 +150,11 @@ void SidebarWidget::get_refs_data(RVA addr)
|
||||
void SidebarWidget::fill_refs(QList<XrefDescription> refs, QList<XrefDescription> xrefs, QList<int> graph_data)
|
||||
{
|
||||
Q_UNUSED(graph_data);
|
||||
|
||||
TempConfig tempConfig;
|
||||
tempConfig.set("scr.html", false)
|
||||
.set("scr.color", false);
|
||||
|
||||
this->xreFromTreeWidget_2->clear();
|
||||
for (int i = 0; i < refs.size(); ++i)
|
||||
{
|
||||
@ -196,6 +202,10 @@ void SidebarWidget::fill_refs(QList<XrefDescription> refs, QList<XrefDescription
|
||||
|
||||
void SidebarWidget::fillOffsetInfo(QString off)
|
||||
{
|
||||
TempConfig tempConfig;
|
||||
tempConfig.set("scr.html", false)
|
||||
.set("scr.color", false);
|
||||
|
||||
ui->offsetTreeWidget->clear();
|
||||
QString raw = Core()->getOffsetInfo(off);
|
||||
QList<QString> lines = raw.split("\n", QString::SkipEmptyParts);
|
||||
|
Loading…
x
Reference in New Issue
Block a user