Add a toggle for showing raw strings in Strings Widget (#3617)

This commit is contained in:
Premade 2026-06-19 17:56:16 +05:00 committed by GitHub
parent 12c119fa85
commit dd557df46a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 69 additions and 20 deletions

View file

@ -817,6 +817,16 @@ bool Configuration::getPreviewValue() const
return s.value("asm.preview").toBool();
}
void Configuration::setShowRawStrings(bool enabled)
{
s.setValue("showRawStrings", enabled);
}
bool Configuration::getShowRawStrings() const
{
return s.value("showRawStrings", false).toBool();
}
void Configuration::setShowVarTooltips(bool enabled)
{
s.setValue("showVarTooltips", enabled);

View file

@ -245,6 +245,14 @@ public:
void setPreviewValue(bool checked);
bool getPreviewValue() const;
// Strings
/**
* @brief Set whether to show raw strings in @ref StringsWidget
*/
void setShowRawStrings(bool enabled);
bool getShowRawStrings() const;
// Tooltip
/**

View file

@ -12,6 +12,7 @@ class StringsTask : public AsyncTask
Q_OBJECT
public:
explicit StringsTask(bool raw) : raw(raw) {}
QString getTitle() const override { return tr("Searching for Strings"); }
signals:
@ -20,9 +21,12 @@ signals:
protected:
void runTask() override
{
auto strings = Core()->getAllStrings();
auto strings = Core()->getAllStrings(raw);
emit stringSearchFinished(strings);
}
private:
bool raw;
};
#endif // STRINGSTASK_H

View file

@ -3476,7 +3476,7 @@ QList<RelocDescription> CutterCore::getAllRelocs()
return ret;
}
QList<StringDescription> CutterCore::getAllStrings()
QList<StringDescription> CutterCore::getAllStrings(bool raw)
{
CORE_LOCK();
RzBinFile *bf = rz_bin_cur(core->bin);
@ -3488,7 +3488,13 @@ QList<StringDescription> CutterCore::getAllStrings()
return {};
}
const RzPVector *strings = rz_core_bin_whole_strings(core, bf);
const RzPVector *strings = nullptr;
if (raw) {
strings = rz_core_bin_whole_strings(core, bf);
} else if (auto *bf = rz_bin_cur(core->bin)) {
strings = rz_bin_object_get_strings(bf->o);
}
if (!strings) {
return {};
}

View file

@ -745,7 +745,7 @@ public:
QList<FlirtDescription> getSignaturesDB();
QList<CommentDescription> getAllComments(const QString &filterType);
QList<RelocDescription> getAllRelocs();
QList<StringDescription> getAllStrings();
QList<StringDescription> getAllStrings(bool raw);
QList<FlagspaceDescription> getAllFlagspaces();
QList<FlagDescription> getAllFlags(const QString &flagspace = QString());
QList<SectionDescription> getAllSections();

View file

@ -205,6 +205,7 @@ void XrefsDialog::hideXrefFromSection()
{
ui->labelXFrom->hide();
ui->fromTreeWidget->hide();
ui->fromQuickFilter->hide();
}
void XrefsDialog::fillRefsForAddress(RVA addr, const QString &name, bool whole_function)
@ -375,7 +376,7 @@ bool XrefFilterProxyModel::filterAcceptsRow(int row, const QModelIndex &parent)
{
const QModelIndex index = sourceModel()->index(row, 0, parent);
const auto xref = index.data(XrefModel::flagDescriptionRole).value<XrefDescription>();
return qhelpers::filterStringContains(to ? xref.toStr : xref.fromStr, this);
return qhelpers::filterStringContains(to ? xref.fromStr : xref.toStr, this);
}
bool XrefFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const

View file

@ -187,7 +187,14 @@ StringsWidget::StringsWidget(MainWindow *main)
ui->stringsTreeView->setModel(static_cast<AddressableItemModelI *>(proxyModel));
ui->stringsTreeView->sortByColumn(-1, Qt::AscendingOrder);
//
ui->rawStringsCheckBox->setChecked(Config()->getShowRawStrings());
ui->rawStringsCheckBox->setStyleSheet("QCheckBox {"
" padding-left: 10px;"
" padding-right: 10px;"
" padding-top: 5px;"
" padding-bottom: 0px;"
"}");
auto menu = ui->stringsTreeView->getItemContextMenu();
menu->addAction(ui->actionCopyString);
@ -219,11 +226,15 @@ StringsWidget::StringsWidget(MainWindow *main)
ui->quickFilterView->setItemCount(proxyModel->rowCount());
});
auto header = ui->stringsTreeView->header();
header->setSectionResizeMode(QHeaderView::ResizeMode::ResizeToContents);
header->setSectionResizeMode(StringsModel::StringColumn, QHeaderView::ResizeMode::Stretch);
header->setStretchLastSection(false);
header->setResizeContentsPrecision(256);
auto showRawStringsChecked = [this](bool checked) {
Config()->setShowRawStrings(checked);
refreshStrings();
};
#if QT_VERSION >= QT_VERSION_CHECK(6, 9, 0)
connect(ui->rawStringsCheckBox, &QCheckBox::checkStateChanged, this, showRawStringsChecked);
#else
connect(ui->rawStringsCheckBox, &QCheckBox::stateChanged, this, showRawStringsChecked);
#endif
}
StringsWidget::~StringsWidget() {}
@ -234,7 +245,7 @@ void StringsWidget::refreshStrings()
task->wait();
}
task = std::shared_ptr<StringsTask>(new StringsTask());
task = std::shared_ptr<StringsTask>(new StringsTask(ui->rawStringsCheckBox->isChecked()));
connect(task.get(), &StringsTask::stringSearchFinished, this,
&StringsWidget::stringSearchFinished);
Core()->getAsyncTaskManager()->start(task);
@ -262,6 +273,8 @@ void StringsWidget::stringSearchFinished(const QList<StringDescription> &strings
model->strings = strings;
model->endResetModel();
qhelpers::adjustColumns(ui->stringsTreeView, StringsModel::ColumnCount, 0);
// set the initial item count
ui->quickFilterView->setItemCount(proxyModel->rowCount());

View file

@ -14,7 +14,7 @@
<string>Strings</string>
</property>
<widget class="QWidget" name="dockWidgetContents">
<layout class="QVBoxLayout" name="verticalLayout">
<layout class="QVBoxLayout" name="verticalLayout" stretch="9,0">
<property name="spacing">
<number>0</number>
</property>
@ -60,14 +60,21 @@
</widget>
</item>
<item>
<widget class="ComboQuickFilterView" name="quickFilterView" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,9">
<property name="leftMargin">
<number>0</number>
</property>
</widget>
<item>
<widget class="QCheckBox" name="rawStringsCheckBox">
<property name="text">
<string>Show Raw Strings</string>
</property>
</widget>
</item>
<item>
<widget class="ComboQuickFilterView" name="quickFilterView" native="true"/>
</item>
</layout>
</item>
</layout>
</widget>