Various code cleaning (#907)

This commit is contained in:
xarkes 2018-11-05 22:51:27 +01:00 committed by GitHub
parent 71765a5d19
commit b1e9db15fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 35 additions and 42 deletions

View File

@ -1967,10 +1967,11 @@ QList<XrefDescription> CutterCore::getXRefs(RVA addr, bool to, bool whole_functi
QJsonArray xrefsArray; QJsonArray xrefsArray;
if (to) if (to) {
xrefsArray = cmdj("axtj@" + QString::number(addr)).array(); xrefsArray = cmdj("axtj@" + QString::number(addr)).array();
else } else {
xrefsArray = cmdj("axfj@" + QString::number(addr)).array(); xrefsArray = cmdj("axfj@" + QString::number(addr)).array();
}
for (QJsonValue value : xrefsArray) { for (QJsonValue value : xrefsArray) {
QJsonObject xrefObject = value.toObject(); QJsonObject xrefObject = value.toObject();
@ -1994,13 +1995,15 @@ QList<XrefDescription> CutterCore::getXRefs(RVA addr, bool to, bool whole_functi
} }
} }
if (!whole_function && !to && xref.from != addr) if (!whole_function && !to && xref.from != addr) {
continue; continue;
}
if (to && !xrefObject.contains("to")) if (to && !xrefObject.contains("to")) {
xref.to = addr; xref.to = addr;
else } else {
xref.to = xrefObject["to"].toVariant().toULongLong(); xref.to = xrefObject["to"].toVariant().toULongLong();
}
xref.to_str = Core()->cmd("fd " + QString::number(xref.to)).trimmed(); xref.to_str = Core()->cmd("fd " + QString::number(xref.to)).trimmed();
ret << xref; ret << xref;
@ -2141,8 +2144,9 @@ QList<QString> CutterCore::getColorThemes()
{ {
QList<QString> r; QList<QString> r;
QJsonDocument themes = cmdj("ecoj"); QJsonDocument themes = cmdj("ecoj");
for (auto s : themes.array()) for (auto s : themes.array()) {
r << s.toString(); r << s.toString();
}
return r; return r;
} }

View File

@ -236,8 +236,9 @@ void CutterApplication::loadPlugins()
pluginsDir.cdUp(); pluginsDir.cdUp();
} }
#endif #endif
if (!pluginsDir.cd("plugins")) if (!pluginsDir.cd("plugins")) {
return; return;
}
foreach (QString fileName, pluginsDir.entryList(QDir::Files)) { foreach (QString fileName, pluginsDir.entryList(QDir::Files)) {
QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName)); QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName));

View File

@ -274,7 +274,7 @@ void DisassemblyContextMenu::aboutToShowSlot()
actionRename.setVisible(false); actionRename.setVisible(false);
} }
//only show retype for local vars if in a function // Only show retype for local vars if in a function
if (in_fcn) { if (in_fcn) {
actionSetFunctionVarTypes.setVisible(true); actionSetFunctionVarTypes.setVisible(true);
actionEditFunction.setVisible(true); actionEditFunction.setVisible(true);
@ -285,7 +285,7 @@ void DisassemblyContextMenu::aboutToShowSlot()
} }
// only show "rename X used here" if there is something to rename // Only show "rename X used here" if there is something to rename
QJsonArray thingUsedHereArray = Core()->cmdj("anj @ " + QString::number(offset)).array(); QJsonArray thingUsedHereArray = Core()->cmdj("anj @ " + QString::number(offset)).array();
if (!thingUsedHereArray.isEmpty()) { if (!thingUsedHereArray.isEmpty()) {
actionRenameUsedHere.setVisible(true); actionRenameUsedHere.setVisible(true);
@ -305,10 +305,10 @@ void DisassemblyContextMenu::aboutToShowSlot()
actionRenameUsedHere.setVisible(false); actionRenameUsedHere.setVisible(false);
} }
// decide to show Reverse jmp option // Decide to show Reverse jmp option
showReverseJmpQuery(); showReverseJmpQuery();
// only show debug options if we are currently debugging // Only show debug options if we are currently debugging
debugMenu->menuAction()->setVisible(Core()->currentlyDebugging); debugMenu->menuAction()->setVisible(Core()->currentlyDebugging);
QString progCounterName = Core()->getRegisterName("PC"); QString progCounterName = Core()->getRegisterName("PC");
actionSetPC.setText("Set " + progCounterName + " here"); actionSetPC.setText("Set " + progCounterName + " here");
@ -390,7 +390,7 @@ void DisassemblyContextMenu::on_actionEditInstruction_triggered()
if (userInstructionOpcode != oldInstructionOpcode) { if (userInstructionOpcode != oldInstructionOpcode) {
Core()->editInstruction(offset, userInstructionOpcode); Core()->editInstruction(offset, userInstructionOpcode);
// check if the write failed // Check if the write failed
auto newInstructionBytes = Core()->getInstructionBytes(offset); auto newInstructionBytes = Core()->getInstructionBytes(offset);
if (newInstructionBytes == oldInstructionBytes) { if (newInstructionBytes == oldInstructionBytes) {
if (!writeFailed()) { if (!writeFailed()) {

View File

@ -9,7 +9,6 @@
SideBar::SideBar(MainWindow *main) : SideBar::SideBar(MainWindow *main) :
QWidget(main), QWidget(main),
ui(new Ui::SideBar), ui(new Ui::SideBar),
// Radare core found in:
main(main) main(main)
{ {
ui->setupUi(this); ui->setupUi(this);

View File

@ -130,10 +130,7 @@ void SidebarWidget::on_regInfoToolButton_clicked()
void SidebarWidget::updateRefs(RVA addr) void SidebarWidget::updateRefs(RVA addr)
{ {
// refs = calls q hace esa funcion
QList<XrefDescription> refs = Core()->getXRefs(addr, false, false); QList<XrefDescription> refs = Core()->getXRefs(addr, false, false);
// xrefs = calls a esa funcion
QList<XrefDescription> xrefs = Core()->getXRefs(addr, true, false); QList<XrefDescription> xrefs = Core()->getXRefs(addr, true, false);
// Update disasm side bar // Update disasm side bar
@ -171,12 +168,9 @@ void SidebarWidget::fillRefs(QList<XrefDescription> refs, QList<XrefDescription>
tempItem->setData(0, Qt::UserRole, QVariant::fromValue(xref)); tempItem->setData(0, Qt::UserRole, QVariant::fromValue(xref));
QString tooltip = Core()->cmd("pdi 10 @ " + QString::number(xref.from)).trimmed(); QString tooltip = Core()->cmd("pdi 10 @ " + QString::number(xref.from)).trimmed();
// TODO wtf is this?
//tempItem->setToolTip(0, this->core->cmd("pdi 10 @ " + tooltip).trimmed());
//tempItem->setToolTip(1, this->core->cmd("pdi 10 @ " + tooltip).trimmed());
ui->xrefToTreeWidget->insertTopLevelItem(0, tempItem); ui->xrefToTreeWidget->insertTopLevelItem(0, tempItem);
} }
// Adjust columns to content // Adjust columns to content
qhelpers::adjustColumns(ui->xrefToTreeWidget, 0); qhelpers::adjustColumns(ui->xrefToTreeWidget, 0);
} }

View File

@ -14,7 +14,7 @@ StackWidget::StackWidget(MainWindow *main, QAction *action) :
{ {
ui->setupUi(this); ui->setupUi(this);
// setup stack model // Setup stack model
modelStack->setHorizontalHeaderItem(0, new QStandardItem(tr("Offset"))); modelStack->setHorizontalHeaderItem(0, new QStandardItem(tr("Offset")));
modelStack->setHorizontalHeaderItem(1, new QStandardItem(tr("Value"))); modelStack->setHorizontalHeaderItem(1, new QStandardItem(tr("Value")));
modelStack->setHorizontalHeaderItem(2, new QStandardItem(tr("Reference"))); modelStack->setHorizontalHeaderItem(2, new QStandardItem(tr("Reference")));
@ -97,7 +97,7 @@ void StackWidget::onDoubleClicked(const QModelIndex &index)
{ {
if (!index.isValid()) if (!index.isValid())
return; return;
// check if we are clicking on the offset or value columns and seek if it is the case // Check if we are clicking on the offset or value columns and seek if it is the case
if (index.column() <= 1) { if (index.column() <= 1) {
QString item = index.data().toString(); QString item = index.data().toString();
Core()->seek(item); Core()->seek(item);
@ -132,7 +132,7 @@ void StackWidget::editStack()
if (e->exec()) { if (e->exec()) {
QString bytes = e->getInstruction(); QString bytes = e->getInstruction();
if (bytes != oldBytes) { if (bytes != oldBytes) {
Core()->editBytesEndian((RVA)offset.toULongLong(&ok, 16), bytes); Core()->editBytesEndian(offset.toULongLong(&ok, 16), bytes);
} }
} }
} }

View File

@ -185,8 +185,9 @@ StringsWidget::~StringsWidget() {}
void StringsWidget::on_stringsTreeView_doubleClicked(const QModelIndex &index) void StringsWidget::on_stringsTreeView_doubleClicked(const QModelIndex &index)
{ {
if (!index.isValid()) if (!index.isValid()) {
return; return;
}
StringDescription str = index.data(StringsModel::StringDescriptionRole).value<StringDescription>(); StringDescription str = index.data(StringsModel::StringDescriptionRole).value<StringDescription>();
Core()->seek(str.vaddr); Core()->seek(str.vaddr);
@ -253,10 +254,11 @@ void StringsWidget::on_actionCopy()
QModelIndex index; QModelIndex index;
if(sender() == ui->actionCopy_String) if (sender() == ui->actionCopy_String) {
index = ui->stringsTreeView->model()->index(row, 1); index = ui->stringsTreeView->model()->index(row, 1);
else if(sender() == ui->actionCopy_Address) } else if (sender() == ui->actionCopy_Address) {
index = ui->stringsTreeView->model()->index(row, 0); index = ui->stringsTreeView->model()->index(row, 0);
}
QClipboard *clipboard = QApplication::clipboard(); QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(index.data().toString()); clipboard->setText(index.data().toString());

View File

@ -22,8 +22,9 @@ int SymbolsModel::columnCount(const QModelIndex &) const
QVariant SymbolsModel::data(const QModelIndex &index, int role) const QVariant SymbolsModel::data(const QModelIndex &index, int role) const
{ {
if (index.row() >= symbols->count()) if (index.row() >= symbols->count()) {
return QVariant(); return QVariant();
}
const SymbolDescription &symbol = symbols->at(index.row()); const SymbolDescription &symbol = symbols->at(index.row());
@ -143,8 +144,9 @@ SymbolsWidget::~SymbolsWidget() {}
void SymbolsWidget::on_symbolsTreeView_doubleClicked(const QModelIndex &index) void SymbolsWidget::on_symbolsTreeView_doubleClicked(const QModelIndex &index)
{ {
if (!index.isValid()) if (!index.isValid()) {
return; return;
}
auto symbol = index.data(SymbolsModel::SymbolDescriptionRole).value<SymbolDescription>(); auto symbol = index.data(SymbolsModel::SymbolDescriptionRole).value<SymbolDescription>();
Core()->seek(symbol.vaddr); Core()->seek(symbol.vaddr);

View File

@ -130,12 +130,3 @@ void TypesWidget::setScrollMode()
{ {
qhelpers::setVerticalScrollMode(ui->typesTreeView); qhelpers::setVerticalScrollMode(ui->typesTreeView);
} }
void TypesWidget::on_typesTreeView_doubleClicked(const QModelIndex &index)
{
if (!index.isValid())
return;
// TypeDescription exp = index.data(TypesModel::TypeDescriptionRole).value<TypeDescription>();
// Core()->seek(exp.vaddr);
}

View File

@ -69,8 +69,6 @@ public:
~TypesWidget(); ~TypesWidget();
private slots: private slots:
void on_typesTreeView_doubleClicked(const QModelIndex &index);
void refreshTypes(); void refreshTypes();
private: private:

View File

@ -182,14 +182,16 @@ void VTablesWidget::refreshVTables()
void VTablesWidget::on_vTableTreeView_doubleClicked(const QModelIndex &index) void VTablesWidget::on_vTableTreeView_doubleClicked(const QModelIndex &index)
{ {
if (!index.isValid()) if (!index.isValid()) {
return; return;
}
QModelIndex parent = index.parent(); QModelIndex parent = index.parent();
if (parent.isValid()) if (parent.isValid()) {
Core()->seek(index.data( Core()->seek(index.data(
VTableModel::VTableDescriptionRole).value<ClassMethodDescription>().addr); VTableModel::VTableDescriptionRole).value<ClassMethodDescription>().addr);
else } else {
Core()->seek(index.data( Core()->seek(index.data(
VTableModel::VTableDescriptionRole).value<VTableDescription>().addr); VTableModel::VTableDescriptionRole).value<VTableDescription>().addr);
}
} }