Remove Type Link features in light of global variables (#2775)

This commit is contained in:
Florian Märkl 2021-09-23 17:57:51 +02:00 committed by GitHub
parent dada19cf1c
commit 3ba7363f99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 0 additions and 373 deletions

View File

@ -103,15 +103,6 @@ Set Structure Offset
**Steps:** -> Structure offset
Link a Type to Address
----------------------------------------
**Description:** You can link type, enum or structure to a specific address. Types, structures and enums can be defined in the Types widget.
**Steps:** Right-click on an instruction and choose ``Link Type to Address``.
**Shortcut:** :kbd:`L`
Show Cross References
----------------------------------------
**Description:** Show X-Refs from and to the specific location. This option will open Cutter's X-Refs dialog in which you will be able to see a list of X-Refs from and to the selected location, in addition to a preview of each cross-reference to quickly inspect the different usages.

View File

@ -62,8 +62,6 @@ Disassembly View Shortcuts
+-------------+----------------------------------+
| Y | Edit/rename local variables |
+-------------+----------------------------------+
| L | Link a type/struct to address |
+-------------+----------------------------------+
| A | Set current address to String |
+-------------+----------------------------------+
| C | Set current address to Code |

View File

@ -109,7 +109,6 @@ set(SOURCES
plugins/PluginManager.cpp
common/BasicBlockHighlighter.cpp
common/BasicInstructionHighlighter.cpp
dialogs/LinkTypeDialog.cpp
widgets/ColorPicker.cpp
common/ColorThemeWorker.cpp
widgets/ColorThemeComboBox.cpp
@ -271,7 +270,6 @@ set(HEADER_FILES
widgets/MemoryDockWidget.h
widgets/ColorThemeListView.h
dialogs/preferences/ColorThemeEditDialog.h
dialogs/LinkTypeDialog.h
common/BugReporting.h
common/HighDpiPixmap.h
widgets/GraphLayout.h
@ -365,7 +363,6 @@ set(UI_FILES
dialogs/EditMethodDialog.ui
dialogs/TypesInteractionDialog.ui
widgets/SdbWidget.ui
dialogs/LinkTypeDialog.ui
widgets/ColorPicker.ui
dialogs/preferences/ColorThemeEditDialog.ui
widgets/ListDockWidget.ui

View File

@ -1,114 +0,0 @@
#include "LinkTypeDialog.h"
#include "ui_LinkTypeDialog.h"
LinkTypeDialog::LinkTypeDialog(QWidget *parent) : QDialog(parent), ui(new Ui::LinkTypeDialog)
{
addrValid = false;
ui->setupUi(this);
setWindowTitle(tr("Link type to address"));
// Populate the structureTypeComboBox
ui->structureTypeComboBox->addItem(tr("(No Type)"));
for (const TypeDescription &thisType : Core()->getAllStructs()) {
ui->structureTypeComboBox->addItem(thisType.type);
}
}
LinkTypeDialog::~LinkTypeDialog()
{
delete ui;
}
void LinkTypeDialog::setDefaultType(const QString &type)
{
int index = ui->structureTypeComboBox->findText(type);
if (index != -1) {
// index is valid so set is as the default
ui->structureTypeComboBox->setCurrentIndex(index);
}
}
bool LinkTypeDialog::setDefaultAddress(const QString &address)
{
// setting the text here will trigger on_exprLineEdit_textChanged, which will update addrValid
ui->exprLineEdit->setText(address);
if (!addrValid) {
return false;
}
// check if the current address is already linked to a type and set it as default
QString type = findLinkedType(Core()->math(ui->addressLineEdit->text()));
if (!type.isEmpty()) {
setDefaultType(type);
}
return true;
}
void LinkTypeDialog::done(int r)
{
if (r == QDialog::Accepted) {
QString address = ui->addressLineEdit->text();
if (Core()->isAddressMapped(Core()->math(address))) {
// Address is valid so link the type to the address
QString type = ui->structureTypeComboBox->currentText();
if (type == tr("(No Type)")) {
// Delete link
RzCoreLocked core(Core());
ut64 addr = rz_num_math(core->num, address.toUtf8().constData());
rz_analysis_type_unlink(core->analysis, addr);
} else {
// Create link
RzCoreLocked core(Core());
ut64 addr = rz_num_math(core->num, address.toUtf8().constData());
rz_core_types_link(core, type.toUtf8().constData(), addr);
}
QDialog::done(r);
// Seek to the specified address
Core()->seekAndShow(address);
// Refresh the views
emit Core()->refreshCodeViews();
return;
}
// Address is invalid so display error message
QMessageBox::warning(this, tr("Error"), tr("The given address is invalid"));
} else {
QDialog::done(r);
}
}
QString LinkTypeDialog::findLinkedType(RVA address)
{
if (address == RVA_INVALID) {
return QString();
}
RzCoreLocked core(Core());
RzType *link = rz_analysis_type_link_at(core->analysis, address);
if (!link) {
return QString();
}
RzBaseType *base = rz_type_get_base_type(core->analysis->typedb, link);
if (!base) {
return QString();
}
return QString(base->name);
}
void LinkTypeDialog::on_exprLineEdit_textChanged(const QString &text)
{
RVA addr = Core()->math(text);
if (Core()->isAddressMapped(addr)) {
ui->addressLineEdit->setText(RzAddressString(addr));
addrValid = true;
} else {
ui->addressLineEdit->setText(tr("Invalid Address"));
addrValid = false;
}
}

View File

@ -1,66 +0,0 @@
#ifndef LINKTYPEDIALOG_H
#define LINKTYPEDIALOG_H
#include "core/Cutter.h"
#include <QDialog>
namespace Ui {
class LinkTypeDialog;
}
class LinkTypeDialog : public QDialog
{
Q_OBJECT
public:
explicit LinkTypeDialog(QWidget *parent = nullptr);
~LinkTypeDialog();
/**
* @brief Sets the default type which will be displayed in the combo box
* @param type Default type to be used as default type
*/
void setDefaultType(const QString &type);
/**
* @brief Sets the value of the default address which will be displayed
* If the given address is linked to a type, then it also sets the default
* type to the currently linked type
* @param address The address to be used as default address
* @return true iff the given address string was valid
*/
bool setDefaultAddress(const QString &address);
private slots:
/**
* @brief Overrides the done() method of QDialog
* On clicking the Ok button, it links a valid address to a type.
* If "(No Type)" is selected as type, it removes the link.
* In case of an invalid address, it displays error message
* @param r The value which will be returned by exec()
*/
void done(int r) override;
/**
* @brief Executed whenever the text inside exprLineEdit changes
* If expression evaluates to valid address, it is displayed in addressLineEdit
* Otherwise "Invalid Address" is shown in addressLineEdit
* @param text The current value of exprLineEdit
*/
void on_exprLineEdit_textChanged(const QString &text);
private:
Ui::LinkTypeDialog *ui;
bool addrValid;
/**
* @brief Used for finding the type which is linked to the given address
* @param address
* @return The type linked to "address" if it exists, or empty string otherwise
*/
QString findLinkedType(RVA address);
};
#endif // LINKTYPEDIALOG_H

View File

@ -1,117 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>LinkTypeDialog</class>
<widget class="QDialog" name="LinkTypeDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>500</width>
<height>105</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>500</width>
<height>0</height>
</size>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="2">
<widget class="QLabel" name="equalSymbolLabel">
<property name="text">
<string>=</string>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QLineEdit" name="addressLineEdit">
<property name="enabled">
<bool>true</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="exprLineEdit">
<property name="placeholderText">
<string>Enter Address</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="structureTypeLabel">
<property name="text">
<string>Structure Type</string>
</property>
<property name="buddy">
<cstring>structureTypeComboBox</cstring>
</property>
</widget>
</item>
<item row="0" column="1" colspan="3">
<widget class="QComboBox" name="structureTypeComboBox"/>
</item>
<item row="2" column="3">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="addressLabel">
<property name="text">
<string>Address/Flag</string>
</property>
<property name="buddy">
<cstring>exprLineEdit</cstring>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>LinkTypeDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>LinkTypeDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -7,7 +7,6 @@
#include "dialogs/EditVariablesDialog.h"
#include "dialogs/SetToDataDialog.h"
#include "dialogs/EditFunctionDialog.h"
#include "dialogs/LinkTypeDialog.h"
#include "dialogs/EditStringDialog.h"
#include "dialogs/BreakpointsDialog.h"
#include "MainWindow.h"
@ -42,7 +41,6 @@ DisassemblyContextMenu::DisassemblyContextMenu(QWidget *parent, MainWindow *main
actionDeleteComment(this),
actionDeleteFlag(this),
actionDeleteFunction(this),
actionLinkType(this),
actionSetBaseBinary(this),
actionSetBaseOctal(this),
actionSetBaseDecimal(this),
@ -122,10 +120,6 @@ DisassemblyContextMenu::DisassemblyContextMenu(QWidget *parent, MainWindow *main
connect(structureOffsetMenu, &QMenu::triggered, this,
&DisassemblyContextMenu::on_actionStructureOffsetMenu_triggered);
initAction(&actionLinkType, tr("Link Type to Address"), SLOT(on_actionLinkType_triggered()),
getLinkTypeSequence());
addAction(&actionLinkType);
addSetAsMenu();
addSeparator();
@ -667,11 +661,6 @@ QKeySequence DisassemblyContextMenu::getDisplayOptionsSequence() const
return {}; // TODO insert correct sequence
}
QKeySequence DisassemblyContextMenu::getLinkTypeSequence() const
{
return { Qt::Key_L };
}
QList<QKeySequence> DisassemblyContextMenu::getAddBPSequence() const
{
return { Qt::Key_F2, Qt::CTRL | Qt::Key_B };
@ -986,15 +975,6 @@ void DisassemblyContextMenu::on_actionStructureOffsetMenu_triggered(QAction *act
Core()->applyStructureOffset(action->data().toString(), offset);
}
void DisassemblyContextMenu::on_actionLinkType_triggered()
{
LinkTypeDialog dialog(mainWindow);
if (!dialog.setDefaultAddress(curHighlightedWord)) {
dialog.setDefaultAddress(RzAddressString(offset));
}
dialog.exec();
}
void DisassemblyContextMenu::on_actionDeleteComment_triggered()
{
Core()->delComment(offset);

View File

@ -74,13 +74,6 @@ private slots:
*/
void on_actionStructureOffsetMenu_triggered(QAction *action);
/**
* @brief Executed on selecting the "Link Type to Address" option
* Opens the LinkTypeDialog box from where the user can link the address
* to a type
*/
void on_actionLinkType_triggered();
private:
QKeySequence getCopySequence() const;
QKeySequence getCommentSequence() const;
@ -99,11 +92,6 @@ private:
QKeySequence getEditFunctionSequence() const;
QList<QKeySequence> getAddBPSequence() const;
/**
* @return the shortcut key for "Link Type to Address" option
*/
QKeySequence getLinkTypeSequence() const;
RVA offset;
bool canCopy;
QString curHighlightedWord; // The current highlighted word
@ -137,8 +125,6 @@ private:
QMenu *structureOffsetMenu;
QAction actionLinkType;
QMenu *setBaseMenu;
QAction actionSetBaseBinary;
QAction actionSetBaseOctal;

View File

@ -3,7 +3,6 @@
#include "core/MainWindow.h"
#include "common/Helpers.h"
#include "dialogs/TypesInteractionDialog.h"
#include "dialogs/LinkTypeDialog.h"
#include <QMenu>
#include <QFileDialog>
@ -242,9 +241,6 @@ void TypesWidget::showTypesContextMenu(const QPoint &pt)
// Add "Link To Address" option
menu.addAction(actionViewType);
menu.addAction(actionEditType);
if (t.category == "Struct") {
menu.addAction(ui->actionLink_Type_To_Address);
}
}
}
@ -338,19 +334,6 @@ void TypesWidget::on_actionDelete_Type_triggered()
}
}
void TypesWidget::on_actionLink_Type_To_Address_triggered()
{
LinkTypeDialog dialog(this);
QModelIndex index = ui->typesTreeView->currentIndex();
if (index.isValid()) {
TypeDescription t = index.data(TypesModel::TypeDescriptionRole).value<TypeDescription>();
dialog.setDefaultType(t.type);
dialog.setDefaultAddress(RzAddressString(Core()->getOffset()));
dialog.exec();
}
}
void TypesWidget::typeItemDoubleClicked(const QModelIndex &index)
{
if (!index.isValid()) {

View File

@ -105,12 +105,6 @@ private slots:
*/
void on_actionDelete_Type_triggered();
/**
* @brief Executed on clicking the Link To Address option in the context menu
* Opens the LinkTypeDialog box from where the user can link a address to a type
*/
void on_actionLink_Type_To_Address_triggered();
/**
* @brief triggers when the user double-clicks an item. This will open
* a dialog that shows the Type's content

View File

@ -95,11 +95,6 @@
<string>Delete Type</string>
</property>
</action>
<action name="actionLink_Type_To_Address">
<property name="text">
<string>Link Type to Address</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>