From aa8ecee8e2451a2b3fb4e765808898c93d8e9ae3 Mon Sep 17 00:00:00 2001 From: karliss Date: Fri, 17 Apr 2020 16:01:05 +0300 Subject: [PATCH] Use drrj to read values for RegistersWidget. (#2141) * Avoids problem with 64bit value as number in json * Keeps registers in the order reported by r2 --- src/core/Cutter.cpp | 18 +++++++++--------- src/core/Cutter.h | 2 +- src/core/CutterDescriptions.h | 6 ++++++ src/widgets/RegistersWidget.cpp | 28 +++++++++------------------- 4 files changed, 25 insertions(+), 29 deletions(-) diff --git a/src/core/Cutter.cpp b/src/core/Cutter.cpp index 1d00ef45..059ee151 100644 --- a/src/core/Cutter.cpp +++ b/src/core/Cutter.cpp @@ -1494,22 +1494,22 @@ QList CutterCore::getVariables(RVA at) return ret; } -QJsonObject CutterCore::getRegisterJson() +QVector CutterCore::getRegisterRefValues() { QJsonArray registerRefArray = cmdj("drrj").array(); - QJsonObject registerJson; + QVector result; - for (const QJsonValue &value : registerRefArray) { + for (const QJsonValue value : registerRefArray) { QJsonObject regRefObject = value.toObject(); - QJsonObject registers; + RegisterRefValueDescription desc; + desc.name = regRefObject[RJsonKey::reg].toString(); + desc.value = regRefObject[RJsonKey::value].toString(); + desc.ref = regRefObject[RJsonKey::ref].toString(); - registers.insert(RJsonKey::value, regRefObject[RJsonKey::value]); - registers.insert(RJsonKey::ref, regRefObject[RJsonKey::ref]); - - registerJson.insert(regRefObject[RJsonKey::reg].toString(), registers); + result.push_back(desc); } - return registerJson; + return result; } QString CutterCore::getRegisterName(QString registerRole) diff --git a/src/core/Cutter.h b/src/core/Cutter.h index 215c7a60..836cdf1d 100644 --- a/src/core/Cutter.h +++ b/src/core/Cutter.h @@ -560,7 +560,7 @@ public: * @param depth telescoping depth */ QList getRegisterRefs(int depth = 6); - QJsonObject getRegisterJson(); + QVector getRegisterRefValues(); QList getVariables(RVA at); QList getXRefs(RVA addr, bool to, bool whole_function, diff --git a/src/core/CutterDescriptions.h b/src/core/CutterDescriptions.h index 5f748ebb..91a8587c 100644 --- a/src/core/CutterDescriptions.h +++ b/src/core/CutterDescriptions.h @@ -321,6 +321,12 @@ struct VariableDescription { QString type; }; +struct RegisterRefValueDescription { + QString name; + QString value; + QString ref; +}; + Q_DECLARE_METATYPE(FunctionDescription) Q_DECLARE_METATYPE(ImportDescription) Q_DECLARE_METATYPE(ExportDescription) diff --git a/src/widgets/RegistersWidget.cpp b/src/widgets/RegistersWidget.cpp index 394bdcc3..cc62998a 100644 --- a/src/widgets/RegistersWidget.cpp +++ b/src/widgets/RegistersWidget.cpp @@ -51,17 +51,11 @@ void RegistersWidget::setRegisterGrid() QString regValue; QLabel *registerLabel; QLineEdit *registerEditValue; - QJsonObject registerValues = Core()->getRegisterValues().object(); - QJsonObject registerRefs = Core()->getRegisterJson(); - QStringList registerNames = registerValues.keys(); + const auto registerRefs = Core()->getRegisterRefValues(); - QCollator collator; - collator.setNumericMode(true); - std::sort(registerNames.begin(), registerNames.end(), collator); - - registerLen = registerValues.size(); - for (const QString &key : registerNames) { - regValue = RAddressString(registerValues[key].toVariant().toULongLong()); + registerLen = registerRefs.size(); + for (auto ® : registerRefs) { + regValue = "0x" + reg.value; // check if we already filled this grid space with label/value if (!registerLayout->itemAtPosition(i, col)) { registerLabel = new QLabel; @@ -87,8 +81,6 @@ void RegistersWidget::setRegisterGrid() QString regNameString = registerLabel->text(); QString regValueString = registerEditValue->text(); Core()->setRegister(regNameString, regValueString); - printf("dr %s %s\n", regNameString.toLocal8Bit().constData(), - regValueString.toLocal8Bit().constData()); }); } else { QWidget *regNameWidget = registerLayout->itemAtPosition(i, col)->widget(); @@ -104,13 +96,11 @@ void RegistersWidget::setRegisterGrid() registerEditValue->setStyleSheet(""); } // define register label and value - registerLabel->setText(key); - if (registerRefs.contains(key)) { - // add register references to tooltips - QString reference = registerRefs[key].toObject()["ref"].toString(); - registerLabel->setToolTip(reference); - registerEditValue->setToolTip(reference); - } + registerLabel->setText(reg.name); + + registerLabel->setToolTip(reg.ref); + registerEditValue->setToolTip(reg.ref); + registerEditValue->setPlaceholderText(regValue); registerEditValue->setText(regValue); i++;