From 3096d249988b4103800acb3cbe08512028cb105b Mon Sep 17 00:00:00 2001 From: Paul I Date: Tue, 27 Nov 2018 01:34:34 +0300 Subject: [PATCH] [WIP] Some cleanup (#958) * Some cleanup * Some more * Some more * Some more --- src/AnalTask.cpp | 2 +- src/Cutter.cpp | 232 ++++++++++-------- src/Cutter.h | 55 +++-- src/CutterApplication.cpp | 2 +- src/common/ColorSchemeFileSaver.cpp | 12 +- src/common/Configuration.cpp | 4 +- src/common/JsonTreeItem.cpp | 4 +- src/common/TempConfig.cpp | 4 +- src/dialogs/InitialOptionsDialog.cpp | 4 +- src/dialogs/NewFileDialog.cpp | 2 +- src/dialogs/R2PluginsDialog.cpp | 8 +- src/dialogs/SetFunctionVarTypes.cpp | 15 +- .../preferences/AppearanceOptionsWidget.cpp | 6 +- src/dialogs/preferences/AsmOptionsWidget.cpp | 4 +- .../preferences/DebugOptionsWidget.cpp | 2 +- .../preferences/GraphOptionsWidget.cpp | 4 +- src/widgets/BacktraceWidget.cpp | 4 +- src/widgets/BreakpointWidget.cpp | 4 +- src/widgets/ColorSchemePrefWidget.h | 9 +- src/widgets/CommentsWidget.cpp | 2 +- src/widgets/Dashboard.cpp | 2 +- src/widgets/DisassemblerGraphView.cpp | 14 +- src/widgets/DisassemblerGraphView.h | 4 +- src/widgets/DisassemblyWidget.cpp | 2 +- src/widgets/EntrypointWidget.cpp | 2 +- src/widgets/FlagsWidget.cpp | 4 +- src/widgets/FunctionsWidget.cpp | 2 +- src/widgets/SdbDock.cpp | 4 +- src/widgets/SidebarWidget.cpp | 6 +- src/widgets/StackWidget.cpp | 2 +- src/widgets/StringsWidget.cpp | 2 +- src/widgets/VisualNavbar.cpp | 8 +- src/widgets/ZignaturesWidget.cpp | 2 +- 33 files changed, 235 insertions(+), 198 deletions(-) diff --git a/src/AnalTask.cpp b/src/AnalTask.cpp index c52c58b5..b4223182 100644 --- a/src/AnalTask.cpp +++ b/src/AnalTask.cpp @@ -99,7 +99,7 @@ void AnalTask::runTask() if (!options.analCmd.empty()) { log(tr("Analyzing...")); - for (QString cmd : options.analCmd) { + for (const QString &cmd : options.analCmd) { if (isInterrupted()) { return; } diff --git a/src/Cutter.cpp b/src/Cutter.cpp index 2d41903c..0ea9967d 100644 --- a/src/Cutter.cpp +++ b/src/Cutter.cpp @@ -13,7 +13,7 @@ Q_GLOBAL_STATIC(ccClass, uniqueInstance) -#define R_JSON_KEY(name) static const QLatin1String name = QLatin1Literal(#name) +#define R_JSON_KEY(name) static const QString name = QStringLiteral(#name) namespace RJsonKey { R_JSON_KEY(addr); @@ -50,6 +50,7 @@ namespace RJsonKey { R_JSON_KEY(hw); R_JSON_KEY(in_functions); R_JSON_KEY(index); + R_JSON_KEY(jump); R_JSON_KEY(laddr); R_JSON_KEY(lang); R_JSON_KEY(len); @@ -228,7 +229,7 @@ CutterCore::~CutterCore() QString CutterCore::sanitizeStringForCommand(QString s) { static const QRegExp regexp(";|@"); - return s.replace(regexp, "_"); + return s.replace(regexp, QStringLiteral("_")); } /** @@ -237,14 +238,13 @@ QString CutterCore::sanitizeStringForCommand(QString s) * Note that if you want to seek to an address, you should use CutterCore::seek * @return command output */ -QString CutterCore::cmd(const QString &str) +QString CutterCore::cmd(const char *str) { CORE_LOCK(); RVA offset = core_->offset; - QByteArray cmd = str.toUtf8(); r_core_task_sync_begin(core_); - char *res = r_core_cmd_str(this->core_, cmd.constData()); + char *res = r_core_cmd_str(this->core_, str); r_core_task_sync_end(core_); QString o = QString(res ? res : ""); r_mem_free(res); @@ -257,17 +257,16 @@ QString CutterCore::cmd(const QString &str) QString CutterCore::cmdRaw(const QString &str) { QString cmdStr = str; - cmdStr.replace('\"', "\\\""); - return cmd("\"" + cmdStr + "\""); + cmdStr.replace('\"', QStringLiteral("\\\"")); + return cmd(cmdStr.prepend('\"').append('\"')); } -QJsonDocument CutterCore::cmdj(const QString &str) +QJsonDocument CutterCore::cmdj(const char *str) { CORE_LOCK(); - QByteArray cmd = str.toUtf8(); r_core_task_sync_begin(core_); - char *res = r_core_cmd_str(this->core_, cmd.constData()); + char *res = r_core_cmd_str(this->core_, str); r_core_task_sync_end(core_); QJsonDocument doc = parseJson(res, str); r_mem_free(res); @@ -291,25 +290,25 @@ QJsonDocument CutterCore::cmdjTask(const QString &str) return parseJson(task.getResultRaw(), str); } -QJsonDocument CutterCore::parseJson(const char *res, const QString &cmd) +QJsonDocument CutterCore::parseJson(const char *res, const char *cmd) { - QString resString = QString(res); + QByteArray json(res); - if (resString.isEmpty()) { + if (json.isEmpty()) { return QJsonDocument(); } QJsonParseError jsonError; - QJsonDocument doc = res ? QJsonDocument::fromJson(resString.toUtf8(), &jsonError) : QJsonDocument(); + QJsonDocument doc = QJsonDocument::fromJson(json, &jsonError); if (jsonError.error != QJsonParseError::NoError) { - if (!cmd.isNull()) { - eprintf("Failed to parse JSON for command \"%s\": %s\n", cmd.toLocal8Bit().constData(), + if (cmd) { + eprintf("Failed to parse JSON for command \"%s\": %s\n", cmd, jsonError.errorString().toLocal8Bit().constData()); } else { eprintf("Failed to parse JSON: %s\n", jsonError.errorString().toLocal8Bit().constData()); } - eprintf("%s\n", resString.toLocal8Bit().constData()); + eprintf("%s\n", json.constData()); } return doc; @@ -617,35 +616,34 @@ ut64 CutterCore::math(const QString &expr) return r_num_math(this->core_ ? this->core_->num : NULL, expr.toUtf8().constData()); } -void CutterCore::setConfig(const QString &k, const QString &v) +void CutterCore::setConfig(const char *k, const QString &v) { CORE_LOCK(); - r_config_set(core_->config, k.toUtf8().constData(), v.toUtf8().constData()); + r_config_set(core_->config, k, v.toUtf8().constData()); } -void CutterCore::setConfig(const QString &k, int v) +void CutterCore::setConfig(const char *k, int v) { CORE_LOCK(); - r_config_set_i(core_->config, k.toUtf8().constData(), static_cast(v)); + r_config_set_i(core_->config, k, static_cast(v)); } -void CutterCore::setConfig(const QString &k, bool v) +void CutterCore::setConfig(const char *k, bool v) { CORE_LOCK(); - r_config_set_i(core_->config, k.toUtf8().constData(), v ? 1 : 0); + r_config_set_i(core_->config, k, v ? 1 : 0); } -int CutterCore::getConfigi(const QString &k) +int CutterCore::getConfigi(const char *k) { CORE_LOCK(); - QByteArray key = k.toUtf8(); - return static_cast(r_config_get_i(core_->config, key.constData())); + return static_cast(r_config_get_i(core_->config, k)); } -bool CutterCore::getConfigb(const QString &k) +bool CutterCore::getConfigb(const char *k) { CORE_LOCK(); - return r_config_get_i(core_->config, k.toUtf8().constData()) != 0; + return r_config_get_i(core_->config, k) != 0; } void CutterCore::triggerRefreshAll() @@ -675,14 +673,13 @@ void CutterCore::message(const QString &msg, bool debug) emit newMessage(msg); } -QString CutterCore::getConfig(const QString &k) +QString CutterCore::getConfig(const char *k) { CORE_LOCK(); - QByteArray key = k.toUtf8(); - return QString(r_config_get(core_->config, key.constData())); + return QString(r_config_get(core_->config, k)); } -void CutterCore::setConfig(const QString &k, const QVariant &v) +void CutterCore::setConfig(const char *k, const QVariant &v) { switch (v.type()) { case QVariant::Type::Bool: @@ -762,17 +759,18 @@ QString CutterCore::cmdFunctionAt(RVA addr) return cmdFunctionAt(QString::number(addr)); } -void CutterCore::cmdEsil(QString command) +void CutterCore::cmdEsil(const char *command) { QString res = cmd(command); - if (res.contains("[ESIL] Stopped execution in an invalid instruction")) { + if (res.contains(QStringLiteral("[ESIL] Stopped execution in an invalid instruction"))) { msgBox.showMessage("Stopped when attempted to run an invalid instruction. You can disable this in Preferences"); } } QString CutterCore::createFunctionAt(RVA addr, QString name) { - name.remove(QRegExp("[^a-zA-Z0-9_]")); + static const QRegExp regExp("[^a-zA-Z0-9_]"); + name.remove(regExp); QString command = "af " + name + " " + RAddressString(addr); QString ret = cmd(command); emit functionsChanged(); @@ -788,7 +786,7 @@ RVA CutterCore::getOffsetJump(RVA addr) { bool ok; RVA value = cmdj("aoj @" + QString::number( - addr)).array().first().toObject().value("jump").toVariant().toULongLong(&ok); + addr)).array().first().toObject().value(RJsonKey::jump).toVariant().toULongLong(&ok); if (!ok) { return RVA_INVALID; @@ -804,7 +802,7 @@ QString CutterCore::getDecompiledCodePDC(RVA addr) bool CutterCore::getR2DecAvailable() { - return cmd("e cmd.pdc=?").split('\n').contains("r2dec"); + return cmd("e cmd.pdc=?").split('\n').contains(QStringLiteral("r2dec")); } QString CutterCore::getDecompiledCodeR2Dec(RVA addr) @@ -843,7 +841,7 @@ QList CutterCore::getRegisterRefs() QList ret; QJsonArray registerRefArray = cmdj("drrj").array(); - for (QJsonValue value : registerRefArray) { + for (const QJsonValue &value : registerRefArray) { QJsonObject regRefObject = value.toObject(); RegisterRefDescription regRef; @@ -862,12 +860,15 @@ QJsonObject CutterCore::getRegisterJson() { QJsonArray registerRefArray = cmdj("drrj").array(); QJsonObject registerJson; - for (QJsonValue value : registerRefArray) { + + for (const QJsonValue &value : registerRefArray) { QJsonObject regRefObject = value.toObject(); QJsonObject registers; + registers.insert(RJsonKey::value, regRefObject[RJsonKey::value]); registers.insert(RJsonKey::ref, regRefObject[RJsonKey::ref]); + registerJson.insert(regRefObject[RJsonKey::reg].toString(), registers); } return registerJson; @@ -1067,9 +1068,11 @@ QStringList CutterCore::getDebugPlugins() QStringList plugins; QJsonArray pluginArray = cmdj("dLj").array(); - for (QJsonValue value : pluginArray) { + for (const QJsonValue &value : pluginArray) { QJsonObject pluginObject = value.toObject(); + QString plugin = pluginObject[RJsonKey::name].toString(); + plugins << plugin; } return plugins; @@ -1131,13 +1134,13 @@ QList CutterCore::getBreakpoints() QList ret; QJsonArray breakpointArray = cmdj("dbj").array(); - for (QJsonValue value : breakpointArray) { + for (const QJsonValue &value : breakpointArray) { QJsonObject bpObject = value.toObject(); BreakpointDescription bp; bp.addr = bpObject[RJsonKey::addr].toVariant().toULongLong(); - bp.size = bpObject[RJsonKey::size].toVariant().toInt(); + bp.size = bpObject[RJsonKey::size].toInt(); bp.permission = bpObject[RJsonKey::prot].toString(); bp.hw = bpObject[RJsonKey::hw].toBool(); bp.trace = bpObject[RJsonKey::trace].toBool(); @@ -1152,17 +1155,15 @@ QList CutterCore::getBreakpoints() QList CutterCore::getBreakpointsAddresses() { - QList bps = getBreakpoints(); - BreakpointDescription bp; QList bpAddresses; - foreach (bp, bps) { + for (const BreakpointDescription &bp : getBreakpoints()) { bpAddresses << bp.addr; } return bpAddresses; } -bool CutterCore::isBreakpoint(QList breakpoints, RVA addr) +bool CutterCore::isBreakpoint(const QList &breakpoints, RVA addr) { return breakpoints.contains(addr); } @@ -1175,15 +1176,15 @@ QJsonDocument CutterCore::getBacktrace() QList CutterCore::getAllProcesses() { QList ret; - QJsonArray ProcessArray = cmdj("dplj").array(); + QJsonArray processArray = cmdj("dplj").array(); - for (QJsonValue value : ProcessArray) { + for (const QJsonValue &value : processArray) { QJsonObject procObject = value.toObject(); ProcessDescription proc; - proc.pid = procObject[RJsonKey::pid].toVariant().toInt(); - proc.uid = procObject[RJsonKey::uid].toVariant().toInt(); + proc.pid = procObject[RJsonKey::pid].toInt(); + proc.uid = procObject[RJsonKey::uid].toInt(); proc.status = procObject[RJsonKey::status].toString(); proc.path = procObject[RJsonKey::path].toString(); @@ -1198,7 +1199,7 @@ QList CutterCore::getMemoryMap() QList ret; QJsonArray memoryMapArray = cmdj("dmj").array(); - for (QJsonValue value : memoryMapArray) { + for (const QJsonValue &value : memoryMapArray) { QJsonObject memMapObject = value.toObject(); MemoryMapDescription memMap; @@ -1289,7 +1290,7 @@ QList CutterCore::getSeekHistory() QList ret; QJsonArray jsonArray = cmdj("sj").array(); - for (QJsonValue value : jsonArray) + for (const QJsonValue &value : jsonArray) ret << value.toVariant().toULongLong(); return ret; @@ -1329,7 +1330,7 @@ QStringList CutterCore::getProjectNames() QStringList ret; QJsonArray jsonArray = cmdj("Pj").array(); - for (QJsonValue value : jsonArray) + for (const QJsonValue &value : jsonArray) ret.append(value.toString()); return ret; @@ -1346,13 +1347,16 @@ QList CutterCore::getRBinPluginDescriptions(const QString QJsonArray pluginArray = jsonRoot[key].toArray(); - for (const auto &pluginValue : pluginArray) { + for (const QJsonValue &pluginValue : pluginArray) { QJsonObject pluginObject = pluginValue.toObject(); + RBinPluginDescription desc; + desc.name = pluginObject[RJsonKey::name].toString(); desc.description = pluginObject[RJsonKey::description].toString(); desc.license = pluginObject[RJsonKey::license].toString(); desc.type = key; + ret.append(desc); } } @@ -1365,8 +1369,9 @@ QList CutterCore::getRIOPluginDescriptions() QList ret; QJsonArray plugins = cmdj("oLj").object()["IO_Plugins"].toArray(); - for (QJsonValueRef pluginValue : plugins) { + for (const QJsonValue &pluginValue : plugins) { QJsonObject pluginObject = pluginValue.toObject(); + RIOPluginDescription plugin; plugin.name = pluginObject["Name"].toString(); @@ -1385,8 +1390,9 @@ QList CutterCore::getRCorePluginDescriptions() QList ret; QJsonArray plugins = cmdj("Lsj").array(); - for (QJsonValueRef pluginValue : plugins) { + for (const QJsonValue &pluginValue : plugins) { QJsonObject pluginObject = pluginValue.toObject(); + RCorePluginDescription plugin; plugin.name = pluginObject["Name"].toString(); @@ -1434,7 +1440,7 @@ QList CutterCore::getAllImports() QJsonArray importsArray = cmdj("iij").array(); - for (QJsonValue value : importsArray) { + for (const QJsonValue &value : importsArray) { QJsonObject importObject = value.toObject(); ImportDescription import; @@ -1456,19 +1462,19 @@ QList CutterCore::getAllExports() CORE_LOCK(); QList ret; - QJsonArray importsArray = cmdj("iEj").array(); + QJsonArray exportsArray = cmdj("iEj").array(); - for (QJsonValue value : importsArray) { - QJsonObject importObject = value.toObject(); + for (const QJsonValue &value : exportsArray) { + QJsonObject exportObject = value.toObject(); ExportDescription exp; - exp.vaddr = importObject[RJsonKey::vaddr].toVariant().toULongLong(); - exp.paddr = importObject[RJsonKey::paddr].toVariant().toULongLong(); - exp.size = importObject[RJsonKey::size].toVariant().toULongLong(); - exp.type = importObject[RJsonKey::type].toString(); - exp.name = importObject[RJsonKey::name].toString(); - exp.flag_name = importObject[RJsonKey::flagname].toString(); + exp.vaddr = exportObject[RJsonKey::vaddr].toVariant().toULongLong(); + exp.paddr = exportObject[RJsonKey::paddr].toVariant().toULongLong(); + exp.size = exportObject[RJsonKey::size].toVariant().toULongLong(); + exp.type = exportObject[RJsonKey::type].toString(); + exp.name = exportObject[RJsonKey::name].toString(); + exp.flag_name = exportObject[RJsonKey::flagname].toString(); ret << exp; } @@ -1518,7 +1524,7 @@ QList CutterCore::getAllHeaders() QJsonArray headersArray = cmdj("ihj").array(); - for (QJsonValue value : headersArray) { + for (const QJsonValue &value : headersArray) { QJsonObject headerObject = value.toObject(); HeaderDescription header; @@ -1541,7 +1547,7 @@ QList CutterCore::getAllZignatures() QJsonArray zignaturesArray = cmdj("zj").array(); - for (QJsonValue value : zignaturesArray) { + for (const QJsonValue &value : zignaturesArray) { QJsonObject zignatureObject = value.toObject(); ZignatureDescription zignature; @@ -1549,7 +1555,7 @@ QList CutterCore::getAllZignatures() zignature.name = zignatureObject[RJsonKey::name].toString(); zignature.bytes = zignatureObject[RJsonKey::bytes].toString(); zignature.offset = zignatureObject[RJsonKey::offset].toVariant().toULongLong(); - for (QJsonValue ref : zignatureObject[RJsonKey::refs].toArray()) { + for (const QJsonValue &ref : zignatureObject[RJsonKey::refs].toArray()) { zignature.refs << ref.toString(); } @@ -1571,7 +1577,7 @@ QList CutterCore::getAllComments(const QString &filterType) QList ret; QJsonArray commentsArray = cmdj("CCj").array(); - for (QJsonValue value : commentsArray) { + for (const QJsonValue &value : commentsArray) { QJsonObject commentObject = value.toObject(); QString type = commentObject[RJsonKey::type].toString(); @@ -1624,10 +1630,11 @@ QList CutterCore::parseStringsJson(const QJsonDocument &doc) QList ret; QJsonArray stringsArray = doc.array(); - for (QJsonValue value : stringsArray) { + for (const QJsonValue &value : stringsArray) { QJsonObject stringObject = value.toObject(); StringDescription string; + string.string = QString(QByteArray::fromBase64(stringObject[RJsonKey::string].toVariant().toByteArray())); string.vaddr = stringObject[RJsonKey::vaddr].toVariant().toULongLong(); string.type = stringObject[RJsonKey::type].toString(); @@ -1646,23 +1653,23 @@ QList CutterCore::parseFunctionsJson(const QJsonDocument &d QList ret; QJsonArray jsonArray = doc.array(); - for (QJsonValue value : jsonArray) { + for (const QJsonValue &value : jsonArray) { QJsonObject jsonObject = value.toObject(); FunctionDescription function; - function.offset = (RVA)jsonObject[RJsonKey::offset].toVariant().toULongLong(); - function.size = (RVA)jsonObject[RJsonKey::size].toVariant().toULongLong(); - function.nargs = (RVA)jsonObject[RJsonKey::nargs].toVariant().toULongLong(); - function.nbbs = (RVA)jsonObject[RJsonKey::nbbs].toVariant().toULongLong(); - function.nlocals = (RVA)jsonObject[RJsonKey::nlocals].toVariant().toULongLong(); - function.cc = (RVA)jsonObject[RJsonKey::cc].toVariant().toULongLong(); + function.offset = jsonObject[RJsonKey::offset].toVariant().toULongLong(); + function.size = jsonObject[RJsonKey::size].toVariant().toULongLong(); + function.nargs = jsonObject[RJsonKey::nargs].toVariant().toULongLong(); + function.nbbs = jsonObject[RJsonKey::nbbs].toVariant().toULongLong(); + function.nlocals = jsonObject[RJsonKey::nlocals].toVariant().toULongLong(); + function.cc = jsonObject[RJsonKey::cc].toVariant().toULongLong(); function.calltype = jsonObject[RJsonKey::calltype].toString(); function.name = jsonObject[RJsonKey::name].toString(); - function.edges = (RVA)jsonObject[RJsonKey::edges].toVariant().toULongLong(); - function.cost = (RVA)jsonObject[RJsonKey::cost].toVariant().toULongLong(); - function.calls = (RVA)jsonObject[RJsonKey::outdegree].toVariant().toULongLong(); - function.stackframe = (RVA)jsonObject[RJsonKey::stackframe].toVariant().toULongLong(); + function.edges = jsonObject[RJsonKey::edges].toVariant().toULongLong(); + function.cost = jsonObject[RJsonKey::cost].toVariant().toULongLong(); + function.calls = jsonObject[RJsonKey::outdegree].toVariant().toULongLong(); + function.stackframe = jsonObject[RJsonKey::stackframe].toVariant().toULongLong(); ret << function; } @@ -1676,10 +1683,11 @@ QList CutterCore::getAllFlagspaces() QList ret; QJsonArray flagspacesArray = cmdj("fsj").array(); - for (QJsonValue value : flagspacesArray) { + for (const QJsonValue &value : flagspacesArray) { QJsonObject flagspaceObject = value.toObject(); FlagspaceDescription flagspace; + flagspace.name = flagspaceObject[RJsonKey::name].toString(); ret << flagspace; @@ -1698,10 +1706,11 @@ QList CutterCore::getAllFlags(QString flagspace) cmd("fs *"); QJsonArray flagsArray = cmdj("fj").array(); - for (QJsonValue value : flagsArray) { + for (const QJsonValue &value : flagsArray) { QJsonObject flagObject = value.toObject(); FlagDescription flag; + flag.offset = flagObject[RJsonKey::offset].toVariant().toULongLong(); flag.size = flagObject[RJsonKey::size].toVariant().toULongLong(); flag.name = flagObject[RJsonKey::name].toString(); @@ -1720,7 +1729,7 @@ QList CutterCore::getAllSections() QJsonObject sectionsObj = sectionsDoc.object(); QJsonArray sectionsArray = sectionsObj[RJsonKey::sections].toArray(); - for (QJsonValue value : sectionsArray) { + for (const QJsonValue &value : sectionsArray) { QJsonObject sectionObject = value.toObject(); QString name = sectionObject[RJsonKey::name].toString(); @@ -1747,7 +1756,7 @@ QStringList CutterCore::getSectionList() QStringList ret; QJsonArray sectionsArray = cmdj("iSj").array(); - for (QJsonValue value : sectionsArray) { + for (const QJsonValue &value : sectionsArray) { ret << value.toObject()[RJsonKey::name].toString(); } return ret; @@ -1760,7 +1769,7 @@ QList CutterCore::getAllSegments() QJsonArray segments = cmdj("iSSj").array(); - for (QJsonValue value : segments) { + for (const QJsonValue &value : segments) { QJsonObject segmentObject = value.toObject(); QString name = segmentObject[RJsonKey::name].toString(); @@ -1786,10 +1795,11 @@ QList CutterCore::getAllEntrypoint() QList ret; QJsonArray entrypointsArray = cmdj("iej").array(); - for (QJsonValue value : entrypointsArray) { + for (const QJsonValue &value : entrypointsArray) { QJsonObject entrypointObject = value.toObject(); EntrypointDescription entrypoint; + entrypoint.vaddr = entrypointObject[RJsonKey::vaddr].toVariant().toULongLong(); entrypoint.paddr = entrypointObject[RJsonKey::paddr].toVariant().toULongLong(); entrypoint.baddr = entrypointObject[RJsonKey::baddr].toVariant().toULongLong(); @@ -1808,29 +1818,34 @@ QList CutterCore::getAllClassesFromBin() QList ret; QJsonArray classesArray = cmdj("icj").array(); - for (QJsonValueRef value : classesArray) { + for (const QJsonValue &value : classesArray) { QJsonObject classObject = value.toObject(); ClassDescription cls; + cls.name = classObject[RJsonKey::classname].toString(); cls.addr = classObject[RJsonKey::addr].toVariant().toULongLong(); cls.index = classObject[RJsonKey::index].toVariant().toULongLong(); - for (QJsonValueRef value2 : classObject[RJsonKey::methods].toArray()) { + for (const QJsonValue &value2 : classObject[RJsonKey::methods].toArray()) { QJsonObject methObject = value2.toObject(); ClassMethodDescription meth; + meth.name = methObject[RJsonKey::name].toString(); meth.addr = methObject[RJsonKey::addr].toVariant().toULongLong(); + cls.methods << meth; } - for (QJsonValueRef value2 : classObject[RJsonKey::fields].toArray()) { + for (const QJsonValue &value2 : classObject[RJsonKey::fields].toArray()) { QJsonObject fieldObject = value2.toObject(); ClassFieldDescription field; + field.name = fieldObject[RJsonKey::name].toString(); field.addr = fieldObject[RJsonKey::addr].toVariant().toULongLong(); + cls.fields << field; } @@ -1851,8 +1866,9 @@ QList CutterCore::getAllClassesFromFlags() QMap classesCache; QJsonArray flagsArray = cmdj("fj@F:classes").array(); - for (QJsonValueRef value : flagsArray) { + for (const QJsonValue &value : flagsArray) { QJsonObject flagObject = value.toObject(); + QString flagName = flagObject[RJsonKey::name].toString(); QRegularExpressionMatch match = classFlagRegExp.match(flagName); @@ -1908,10 +1924,11 @@ QList CutterCore::getAllResources() QList ret; QJsonArray resourcesArray = cmdj("iRj").array(); - for (QJsonValueRef value : resourcesArray) { + for (const QJsonValue &value : resourcesArray) { QJsonObject resourceObject = value.toObject(); ResourcesDescription res; + res.name = resourceObject[RJsonKey::name].toInt(); res.vaddr = resourceObject[RJsonKey::vaddr].toVariant().toULongLong(); res.index = resourceObject[RJsonKey::index].toVariant().toULongLong(); @@ -1930,17 +1947,19 @@ QList CutterCore::getAllVTables() QList ret; QJsonArray vTablesArray = cmdj("avj").array(); - for (QJsonValueRef vTableValue : vTablesArray) { + for (const QJsonValue &vTableValue : vTablesArray) { QJsonObject vTableObject = vTableValue.toObject(); VTableDescription res; + res.addr = vTableObject[RJsonKey::offset].toVariant().toULongLong(); QJsonArray methodArray = vTableObject[RJsonKey::methods].toArray(); - for (QJsonValueRef methodValue : methodArray) { + for (const QJsonValue &methodValue : methodArray) { QJsonObject methodObject = methodValue.toObject(); ClassMethodDescription method; + method.addr = methodObject[RJsonKey::offset].toVariant().toULongLong(); method.name = methodObject[RJsonKey::name].toString(); @@ -1959,7 +1978,7 @@ QList CutterCore::getAllTypes() QJsonArray typesArray = cmdj("tj").array(); - for (QJsonValue value : typesArray) { + for (const QJsonValue &value : typesArray) { QJsonObject typeObject = value.toObject(); TypeDescription exp; @@ -1982,11 +2001,13 @@ QList CutterCore::getAllSearch(QString search_for, QString sp QJsonArray searchArray = cmdj(space + QString(" ") + search_for).array(); if (space == "/Rj") { - for (QJsonValue value : searchArray) { + for (const QJsonValue &value : searchArray) { QJsonObject searchObject = value.toObject(); + SearchDescription exp; + exp.code = QString(""); - for (QJsonValue value2 : searchObject[RJsonKey::opcodes].toArray()) { + for (const QJsonValue &value2 : searchObject[RJsonKey::opcodes].toArray()) { QJsonObject gadget = value2.toObject(); exp.code += gadget[RJsonKey::opcode].toString() + "; "; } @@ -1998,8 +2019,9 @@ QList CutterCore::getAllSearch(QString search_for, QString sp ret << exp; } } else { - for (QJsonValue value : searchArray) { + for (const QJsonValue &value : searchArray) { QJsonObject searchObject = value.toObject(); + SearchDescription exp; exp.offset = searchObject[RJsonKey::offset].toVariant().toULongLong(); @@ -2031,7 +2053,9 @@ BlockStatistics CutterCore::getBlockStatistics(unsigned int blocksCount) for (const QJsonValue &value : blocksArray) { QJsonObject blockObj = value.toObject(); + BlockDescription block; + block.addr = blockObj[RJsonKey::offset].toVariant().toULongLong(); block.size = blockObj[RJsonKey::size].toVariant().toULongLong(); block.flags = blockObj[RJsonKey::flags].toInt(0); @@ -2074,10 +2098,11 @@ QList CutterCore::getXRefs(RVA addr, bool to, bool whole_functi xrefsArray = cmdj("axfj@" + QString::number(addr)).array(); } - for (QJsonValue value : xrefsArray) { + for (const QJsonValue &value : xrefsArray) { QJsonObject xrefObject = value.toObject(); XrefDescription xref; + xref.type = xrefObject[RJsonKey::type].toString(); if (!filterType.isNull() && filterType != xref.type) @@ -2151,7 +2176,7 @@ void CutterCore::saveProject(const QString &name) { const QString &rv = cmd("Ps " + name.trimmed()).trimmed(); const bool ok = rv == name.trimmed(); - cmd("Pnj " + notes.toUtf8().toBase64()); + cmd(QString("Pnj ") + notes.toUtf8().toBase64()); emit projectSaved(ok, name); } @@ -2173,10 +2198,11 @@ QList CutterCore::disassembleLines(RVA offset, int lines) offset)).array(); QList r; - for (QJsonValue value : array) { + for (const QJsonValue &value : array) { QJsonObject object = value.toObject(); DisassemblyLine line; + line.offset = object[RJsonKey::offset].toVariant().toULongLong(); line.text = object[RJsonKey::text].toString(); @@ -2245,7 +2271,7 @@ QList CutterCore::getColorThemes() { QList r; QJsonDocument themes = cmdj("ecoj"); - for (auto s : themes.array()) { + for (const QJsonValue &s : themes.array()) { r << s.toString(); } return r; diff --git a/src/Cutter.h b/src/Cutter.h index 0223ffc1..33aeb770 100644 --- a/src/Cutter.h +++ b/src/Cutter.h @@ -18,7 +18,7 @@ #include #define CutterRListForeach(list, it, type, x) \ - if (list) for (it = list->head; it && ((x=(type*)it->data)); it = it->n) + if (list) for (it = list->head; it && ((x=static_cast(it->data))); it = it->n) #define APPNAME "Cutter" @@ -382,21 +382,24 @@ public: /* Core functions (commands) */ static QString sanitizeStringForCommand(QString s); - QString cmd(const QString &str); + QString cmd(const char *str); + QString cmd(const QString &str) { return cmd(str.toUtf8().constData()); } QString cmdRaw(const QString &str); - QJsonDocument cmdj(const QString &str); - QStringList cmdList(const QString &str) - { - auto l = cmd(str).split("\n"); - l.removeAll(""); - return l; - } + QJsonDocument cmdj(const char *str); + QJsonDocument cmdj(const QString &str) { return cmdj(str.toUtf8().constData()); } + QStringList cmdList(const char *str) { return cmd(str).split('\n', QString::SkipEmptyParts); } + QStringList cmdList(const QString &str) { return cmdList(str.toUtf8().constData()); } QString cmdTask(const QString &str); QJsonDocument cmdjTask(const QString &str); - void cmdEsil(QString command); + void cmdEsil(const char *command); + void cmdEsil(const QString &command) { cmdEsil(command.toUtf8().constData()); } QString getVersionInformation(); - QJsonDocument parseJson(const char *res, const QString &cmd = QString()); + QJsonDocument parseJson(const char *res, const char *cmd = nullptr); + QJsonDocument parseJson(const char *res, const QString &cmd = QString()) + { + return parseJson(res, cmd.isNull() ? nullptr : cmd.toLocal8Bit().constData()); + } /* Functions methods */ void renameFunction(const QString &oldName, const QString &newName); @@ -436,7 +439,7 @@ public: /* File related methods */ bool loadFile(QString path, ut64 baddr = 0LL, ut64 mapaddr = 0LL, int perms = R_PERM_R, - int va = 0, bool loadbin = false, const QString &forceBinPlugin = nullptr); + int va = 0, bool loadbin = false, const QString &forceBinPlugin = QString()); bool tryFile(QString path, bool rw); void openFile(QString path, RVA mapaddr); void loadScript(const QString &scriptname); @@ -471,14 +474,20 @@ public: ut64 math(const QString &expr); /* Config functions */ - void setConfig(const QString &k, const QString &v); - void setConfig(const QString &k, int v); - void setConfig(const QString &k, bool v); - void setConfig(const QString &k, const char *v) { setConfig(k, QString(v)); } - void setConfig(const QString &k, const QVariant &v); - int getConfigi(const QString &k); - bool getConfigb(const QString &k); - QString getConfig(const QString &k); + void setConfig(const char *k, const QString &v); + void setConfig(const QString &k, const QString &v) { setConfig(k.toUtf8().constData(), v); } + void setConfig(const char *k, int v); + void setConfig(const QString &k, int v) { setConfig(k.toUtf8().constData(), v); } + void setConfig(const char *k, bool v); + void setConfig(const QString &k, bool v) { setConfig(k.toUtf8().constData(), v); } + void setConfig(const char *k, const QVariant &v); + void setConfig(const QString &k, const QVariant &v) { setConfig(k.toUtf8().constData(), v); } + int getConfigi(const char *k); + int getConfigi(const QString &k) { return getConfigi(k.toUtf8().constData()); } + bool getConfigb(const char *k); + bool getConfigb(const QString &k) { return getConfigb(k.toUtf8().constData()); } + QString getConfig(const char *k); + QString getConfig(const QString &k) { return getConfig(k.toUtf8().constData()); } QList getColorThemes(); /* Assembly related methods */ @@ -521,7 +530,7 @@ public: void delAllBreakpoints(); void enableBreakpoint(RVA addr); void disableBreakpoint(RVA addr); - bool isBreakpoint(QList breakpoints, RVA addr); + bool isBreakpoint(const QList &breakpoints, RVA addr); QList getBreakpointsAddresses(); QString getActiveDebugPlugin(); QStringList getDebugPlugins(); @@ -565,7 +574,7 @@ public: static bool isProjectNameValid(const QString &name); /* Widgets */ - QList getRBinPluginDescriptions(const QString &type = nullptr); + QList getRBinPluginDescriptions(const QString &type = QString()); QList getRIOPluginDescriptions(); QList getRCorePluginDescriptions(); QList getRAsmPluginDescriptions(); @@ -579,7 +588,7 @@ public: QList getAllRelocs(); QList getAllStrings(); QList getAllFlagspaces(); - QList getAllFlags(QString flagspace = NULL); + QList getAllFlags(QString flagspace = QString()); QList getAllSections(); QList getAllSegments(); QList getAllEntrypoint(); diff --git a/src/CutterApplication.cpp b/src/CutterApplication.cpp index 081e604d..dcca08c9 100644 --- a/src/CutterApplication.cpp +++ b/src/CutterApplication.cpp @@ -42,7 +42,7 @@ CutterApplication::CutterApplication(int &argc, char **argv) : QApplication(argc QString langPrefix; if (language != "en") { - for (auto &it : allLocales) { + for (const QLocale &it : allLocales) { langPrefix = it.bcp47Name(); if (langPrefix == language) { const QString &cutterTranslationPath = QCoreApplication::applicationDirPath() + QDir::separator() diff --git a/src/common/ColorSchemeFileSaver.cpp b/src/common/ColorSchemeFileSaver.cpp index 29c82d22..37b78529 100644 --- a/src/common/ColorSchemeFileSaver.cpp +++ b/src/common/ColorSchemeFileSaver.cpp @@ -39,7 +39,7 @@ ColorSchemeFileSaver::ColorSchemeFileSaver(QObject *parent) : QObject (parent) dirs.removeOne(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)); standardR2ThemesLocationPath = ""; - for (auto &it : dirs) { + for (const QString &it : dirs) { currDir = QDir(it).filePath("radare2"); if (currDir.exists()) { break; @@ -90,7 +90,7 @@ QFile::FileError ColorSchemeFileSaver::copy(const QString &srcThemeName, Core()->cmd(QString("eco %1").arg(theme)); QColor back = Config()->getColor(standardBackgroundOptionName); _obj[standardBackgroundOptionName] = QJsonArray({back.red(), back.green(), back.blue()}); - for (auto &it : _obj.keys()) { + for (const QString &it : _obj.keys()) { QJsonArray rgb = _obj[it].toArray(); if (rgb.size() != 3) { continue; @@ -103,7 +103,7 @@ QFile::FileError ColorSchemeFileSaver::copy(const QString &srcThemeName, } QStringList tmp; - for (auto &it : src) { + for (const QString &it : src) { if (it.isEmpty()) { continue; } @@ -117,7 +117,7 @@ QFile::FileError ColorSchemeFileSaver::copy(const QString &srcThemeName, } } - for (auto &it : options) { + for (const QString &it : options) { if (cutterSpecificOptions.contains(it)) { fOut.write("#~"); } else { @@ -146,7 +146,7 @@ QFile::FileError ColorSchemeFileSaver::save(const QString &scheme, const QString bool ColorSchemeFileSaver::isCustomScheme(const QString &schemeName) const { - for (auto &it : QDir(customR2ThemesLocationPath).entryInfoList()) + for (const QFileInfo &it : QDir(customR2ThemesLocationPath).entryInfoList()) if (it.fileName() == schemeName) return true; return false; @@ -166,7 +166,7 @@ QMap ColorSchemeFileSaver::getCutterSpecific() const QMap ret; QStringList data = QString(f.readAll()).split('\n'); - for (auto &it : data) { + for (const QString &it : data) { if (it.length() > 2 && it.left(2) == "#~") { QStringList currLine = it.split(' '); if (currLine.size() > 1) { diff --git a/src/common/Configuration.cpp b/src/common/Configuration.cpp index b2293d42..f972fb5a 100644 --- a/src/common/Configuration.cpp +++ b/src/common/Configuration.cpp @@ -322,14 +322,14 @@ void Configuration::setColorTheme(QString theme) void Configuration::resetToDefaultAsmOptions() { - for (auto it = asmOptions.begin(); it != asmOptions.end(); it++) { + for (auto it = asmOptions.cbegin(); it != asmOptions.cend(); it++) { setConfig(it.key(), it.value()); } } void Configuration::applySavedAsmOptions() { - for (auto it = asmOptions.begin(); it != asmOptions.end(); it++) { + for (auto it = asmOptions.cbegin(); it != asmOptions.cend(); it++) { Core()->setConfig(it.key(), s.value(it.key(), it.value())); } } diff --git a/src/common/JsonTreeItem.cpp b/src/common/JsonTreeItem.cpp index 46735dbb..676fdc17 100644 --- a/src/common/JsonTreeItem.cpp +++ b/src/common/JsonTreeItem.cpp @@ -76,7 +76,7 @@ JsonTreeItem *JsonTreeItem::load(const QJsonValue &value, JsonTreeItem *parent) if ( value.isObject()) { //Get all QJsonValue childs - for (QString key : value.toObject().keys()) { + for (const QString &key : value.toObject().keys()) { QJsonValue v = value.toObject().value(key); JsonTreeItem *child = load(v, rootItem); child->setKey(key); @@ -87,7 +87,7 @@ JsonTreeItem *JsonTreeItem::load(const QJsonValue &value, JsonTreeItem *parent) } else if ( value.isArray()) { //Get all QJsonValue childs int index = 0; - for (QJsonValue v : value.toArray()) { + for (const QJsonValue &v : value.toArray()) { JsonTreeItem *child = load(v, rootItem); child->setKey(QString::number(index)); diff --git a/src/common/TempConfig.cpp b/src/common/TempConfig.cpp index 58acfb36..52ee599e 100644 --- a/src/common/TempConfig.cpp +++ b/src/common/TempConfig.cpp @@ -6,7 +6,7 @@ TempConfig::~TempConfig() { - for (auto i = resetValues.begin(); i != resetValues.end(); i++) { + for (auto i = resetValues.constBegin(); i != resetValues.constEnd(); i++) { switch (i.value().type()) { case QVariant::String: Core()->setConfig(i.key(), i.value().toString()); @@ -52,4 +52,4 @@ TempConfig &TempConfig::set(const QString &key, bool value) Core()->setConfig(key, value); return *this; -} \ No newline at end of file +} diff --git a/src/dialogs/InitialOptionsDialog.cpp b/src/dialogs/InitialOptionsDialog.cpp index 94a8e9ff..b6cc2462 100644 --- a/src/dialogs/InitialOptionsDialog.cpp +++ b/src/dialogs/InitialOptionsDialog.cpp @@ -24,7 +24,7 @@ InitialOptionsDialog::InitialOptionsDialog(MainWindow *main): // Fill the plugins combo asm_plugins = core->getAsmPluginNames(); - for (auto plugin : asm_plugins) + for (const auto &plugin : asm_plugins) ui->archComboBox->addItem(plugin, plugin); ui->archComboBox->setToolTip(core->cmd("e? asm.arch").trimmed()); @@ -42,7 +42,7 @@ InitialOptionsDialog::InitialOptionsDialog(MainWindow *main): ui->entry_analbb->setToolTip(core->cmd("e? anal.bb.maxsize").trimmed()); - for (auto plugin : core->getRBinPluginDescriptions("bin")) + for (const auto &plugin : core->getRBinPluginDescriptions("bin")) ui->formatComboBox->addItem(plugin.name, QVariant::fromValue(plugin)); ui->hideFrame->setVisible(false); diff --git a/src/dialogs/NewFileDialog.cpp b/src/dialogs/NewFileDialog.cpp index fe97f922..20579599 100644 --- a/src/dialogs/NewFileDialog.cpp +++ b/src/dialogs/NewFileDialog.cpp @@ -323,7 +323,7 @@ void NewFileDialog::fillIOPluginsList() int index = 1; QList ioPlugins = Core()->getRIOPluginDescriptions(); - for (RIOPluginDescription plugin : ioPlugins) { + for (const RIOPluginDescription &plugin : ioPlugins) { // Hide debug plugins if (plugin.permissions.contains('d')) { continue; diff --git a/src/dialogs/R2PluginsDialog.cpp b/src/dialogs/R2PluginsDialog.cpp index 1310b65f..0b0f3ead 100644 --- a/src/dialogs/R2PluginsDialog.cpp +++ b/src/dialogs/R2PluginsDialog.cpp @@ -10,7 +10,7 @@ R2PluginsDialog::R2PluginsDialog(QWidget *parent) : { ui->setupUi(this); - for (auto plugin : Core()->getRBinPluginDescriptions()) { + for (const auto &plugin : Core()->getRBinPluginDescriptions()) { QTreeWidgetItem *item = new QTreeWidgetItem(); item->setText(0, plugin.name); item->setText(1, plugin.description); @@ -20,7 +20,7 @@ R2PluginsDialog::R2PluginsDialog(QWidget *parent) : } qhelpers::adjustColumns(ui->RBinTreeWidget, 0); - for (auto plugin : Core()->getRIOPluginDescriptions()) { + for (const auto &plugin : Core()->getRIOPluginDescriptions()) { QTreeWidgetItem *item = new QTreeWidgetItem(); item->setText(0, plugin.name); item->setText(1, plugin.description); @@ -30,7 +30,7 @@ R2PluginsDialog::R2PluginsDialog(QWidget *parent) : } qhelpers::adjustColumns(ui->RIOTreeWidget, 0); - for (auto plugin : Core()->getRCorePluginDescriptions()) { + for (const auto &plugin : Core()->getRCorePluginDescriptions()) { QTreeWidgetItem *item = new QTreeWidgetItem(); item->setText(0, plugin.name); item->setText(1, plugin.description); @@ -38,7 +38,7 @@ R2PluginsDialog::R2PluginsDialog(QWidget *parent) : } qhelpers::adjustColumns(ui->RCoreTreeWidget, 0); - for (auto plugin : Core()->getRAsmPluginDescriptions()) { + for (const auto &plugin : Core()->getRAsmPluginDescriptions()) { QTreeWidgetItem *item = new QTreeWidgetItem(); item->setText(0, plugin.name); item->setText(1, plugin.architecture); diff --git a/src/dialogs/SetFunctionVarTypes.cpp b/src/dialogs/SetFunctionVarTypes.cpp index bf4cd7d0..85f47ff2 100644 --- a/src/dialogs/SetFunctionVarTypes.cpp +++ b/src/dialogs/SetFunctionVarTypes.cpp @@ -75,7 +75,7 @@ void SetFunctionVarTypes::on_OkPressed() .arg(ui->selectedTypeForVar->currentText())); Core()->cmd(QString("afvn %1 %2") - .arg(ui->newVarName->text().replace(" ", "_")) + .arg(ui->newVarName->text().replace(' ', '_')) .arg(ui->dropdownLocalVars->currentText())); } @@ -89,29 +89,24 @@ void SetFunctionVarTypes::populateTypesComboBox() { //gets all loaded types, structures and enums and puts them in a list - QString res; QStringList userStructures; QStringList userEnumerations; QList primitiveTypesTypeList; - res = Core()->cmd(QString("ts")); - userStructures = res.split("\n"); - userStructures.removeAll(QString("")); + userStructures = Core()->cmdList("ts"); ui->selectedTypeForVar->addItems(userStructures); ui->selectedTypeForVar->insertSeparator(ui->selectedTypeForVar->count()); primitiveTypesTypeList = Core()->getAllTypes(); - for (TypeDescription thisType : primitiveTypesTypeList) { + for (const TypeDescription &thisType : primitiveTypesTypeList) { ui->selectedTypeForVar->addItem(thisType.type); } ui->selectedTypeForVar->insertSeparator(ui->selectedTypeForVar->count()); - res = Core()->cmd(QString("te")); - userStructures = res.split("\n"); - userStructures.removeAll(QString("")); - ui->selectedTypeForVar->addItems(userStructures); + userEnumerations = Core()->cmdList("te"); + ui->selectedTypeForVar->addItems(userEnumerations); return; diff --git a/src/dialogs/preferences/AppearanceOptionsWidget.cpp b/src/dialogs/preferences/AppearanceOptionsWidget.cpp index c4922cd3..fa5ce2e3 100644 --- a/src/dialogs/preferences/AppearanceOptionsWidget.cpp +++ b/src/dialogs/preferences/AppearanceOptionsWidget.cpp @@ -23,7 +23,7 @@ static const QHash kRelevantSchemes = { { "onedark", DarkFlag }, { "solarized", DarkFlag }, { "zenburn", DarkFlag }, - { "cutter", LightFlag }, + { "cutter", LightFlag }, { "dark", LightFlag }, { "matrix", LightFlag }, { "tango", LightFlag }, @@ -103,7 +103,7 @@ void AppearanceOptionsWidget::updateThemeFromConfig() for (auto &it : kCutterQtThemesList) { ui->themeComboBox->addItem(it.name); } - uint curQtThemeIndex = Config()->getTheme(); + int curQtThemeIndex = Config()->getTheme(); if (curQtThemeIndex >= kCutterQtThemesList.size()) { curQtThemeIndex = 0; Config()->setTheme(curQtThemeIndex); @@ -161,7 +161,7 @@ void AppearanceOptionsWidget::on_colorComboBox_currentIndexChanged(int index) { QString theme = ui->colorComboBox->itemText(index); - uint curQtThemeIndex = Config()->getTheme(); + int curQtThemeIndex = Config()->getTheme(); if (curQtThemeIndex >= kCutterQtThemesList.size()) { curQtThemeIndex = 0; Config()->setTheme(curQtThemeIndex); diff --git a/src/dialogs/preferences/AsmOptionsWidget.cpp b/src/dialogs/preferences/AsmOptionsWidget.cpp index 76d77299..eb9a0f8e 100644 --- a/src/dialogs/preferences/AsmOptionsWidget.cpp +++ b/src/dialogs/preferences/AsmOptionsWidget.cpp @@ -9,10 +9,12 @@ #include "common/Helpers.h" #include "common/Configuration.h" -AsmOptionsWidget::AsmOptionsWidget(PreferencesDialog */*dialog*/, QWidget *parent) +AsmOptionsWidget::AsmOptionsWidget(PreferencesDialog *dialog, QWidget *parent) : QDialog(parent), ui(new Ui::AsmOptionsWidget) { + Q_UNUSED(dialog) + ui->setupUi(this); ui->syntaxComboBox->blockSignals(true); diff --git a/src/dialogs/preferences/DebugOptionsWidget.cpp b/src/dialogs/preferences/DebugOptionsWidget.cpp index d4b2646e..e8f35dc4 100644 --- a/src/dialogs/preferences/DebugOptionsWidget.cpp +++ b/src/dialogs/preferences/DebugOptionsWidget.cpp @@ -29,7 +29,7 @@ void DebugOptionsWidget::updateDebugPlugin() SLOT(on_pluginComboBox_currentIndexChanged(const QString &))); QStringList plugins = Core()->getDebugPlugins(); - for (QString str : plugins) + for (const QString &str : plugins) ui->pluginComboBox->addItem(str); QString plugin = Core()->getActiveDebugPlugin(); diff --git a/src/dialogs/preferences/GraphOptionsWidget.cpp b/src/dialogs/preferences/GraphOptionsWidget.cpp index edb24fa6..e7540aa8 100644 --- a/src/dialogs/preferences/GraphOptionsWidget.cpp +++ b/src/dialogs/preferences/GraphOptionsWidget.cpp @@ -9,10 +9,12 @@ #include "common/Helpers.h" #include "common/Configuration.h" -GraphOptionsWidget::GraphOptionsWidget(PreferencesDialog */*dialog*/, QWidget *parent) +GraphOptionsWidget::GraphOptionsWidget(PreferencesDialog *dialog, QWidget *parent) : QDialog(parent), ui(new Ui::GraphOptionsWidget) { + Q_UNUSED(dialog) + ui->setupUi(this); updateOptionsFromVars(); diff --git a/src/widgets/BacktraceWidget.cpp b/src/widgets/BacktraceWidget.cpp index 87dc609b..fe6228f4 100644 --- a/src/widgets/BacktraceWidget.cpp +++ b/src/widgets/BacktraceWidget.cpp @@ -39,7 +39,7 @@ void BacktraceWidget::setBacktraceGrid() { QJsonArray backtraceValues = Core()->getBacktrace().array(); int i = 0; - for (QJsonValueRef value : backtraceValues) { + for (const QJsonValue &value : backtraceValues) { QJsonObject backtraceItem = value.toObject(); QString progCounter = RAddressString(backtraceItem["pc"].toVariant().toULongLong()); QString stackPointer = RAddressString(backtraceItem["sp"].toVariant().toULongLong()); @@ -67,4 +67,4 @@ void BacktraceWidget::setBacktraceGrid() void BacktraceWidget::fontsUpdatedSlot() { viewBacktrace->setFont(Config()->getFont()); -} \ No newline at end of file +} diff --git a/src/widgets/BreakpointWidget.cpp b/src/widgets/BreakpointWidget.cpp index 772d447b..803737ba 100644 --- a/src/widgets/BreakpointWidget.cpp +++ b/src/widgets/BreakpointWidget.cpp @@ -183,8 +183,8 @@ void BreakpointWidget::addBreakpointDialog() if (dialog->exec()) { QString bps = dialog->getBreakpoints(); if (!bps.isEmpty()) { - QStringList bpList = bps.split(" ", QString::SkipEmptyParts); - for ( QString bp : bpList) { + QStringList bpList = bps.split(' ', QString::SkipEmptyParts); + for (const QString &bp : bpList) { Core()->toggleBreakpoint(bp); } } diff --git a/src/widgets/ColorSchemePrefWidget.h b/src/widgets/ColorSchemePrefWidget.h index daf81d25..6bc06a76 100644 --- a/src/widgets/ColorSchemePrefWidget.h +++ b/src/widgets/ColorSchemePrefWidget.h @@ -69,14 +69,17 @@ public: QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; - void setColor(const QString &option, - const QColor &color); + void setColor(const QString &option, const QColor &color); QColor getBackroundColor() const; QColor getTextColor() const; - int rowCount(const QModelIndex &parent = QModelIndex()) const override { return m_data.size(); } + int rowCount(const QModelIndex &parent = QModelIndex()) const override + { + Q_UNUSED(parent) + return m_data.size(); + } void updateScheme(); diff --git a/src/widgets/CommentsWidget.cpp b/src/widgets/CommentsWidget.cpp index f22ff9c1..1d2f530a 100644 --- a/src/widgets/CommentsWidget.cpp +++ b/src/widgets/CommentsWidget.cpp @@ -327,7 +327,7 @@ void CommentsWidget::refreshTree() comments = Core()->getAllComments("CCu"); nestedComments.clear(); - for (CommentDescription comment : comments) { + for (const CommentDescription &comment : comments) { QString fcnName = Core()->cmdFunctionAt(comment.offset); nestedComments[fcnName].append(comment); } diff --git a/src/widgets/Dashboard.cpp b/src/widgets/Dashboard.cpp index d013af70..7e7bf9c8 100644 --- a/src/widgets/Dashboard.cpp +++ b/src/widgets/Dashboard.cpp @@ -136,7 +136,7 @@ void Dashboard::updateContents() } } - for (QString lib : lines) { + for (const QString &lib : lines) { QLabel *label = new QLabel(this); label->setText(lib); label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); diff --git a/src/widgets/DisassemblerGraphView.cpp b/src/widgets/DisassemblerGraphView.cpp index 42183d1a..8bb0dafe 100644 --- a/src/widgets/DisassemblerGraphView.cpp +++ b/src/widgets/DisassemblerGraphView.cpp @@ -218,8 +218,8 @@ void DisassemblerGraphView::loadCurrentGraph() RVA entry = func["offset"].toVariant().toULongLong(); setEntry(entry); - for (QJsonValueRef blockRef : func["blocks"].toArray()) { - QJsonObject block = blockRef.toObject(); + for (const QJsonValue &value : func["blocks"].toArray()) { + QJsonObject block = value.toObject(); RVA block_entry = block["offset"].toVariant().toULongLong(); RVA block_size = block["size"].toVariant().toULongLong(); RVA block_fail = block["fail"].toVariant().toULongLong(); @@ -450,7 +450,7 @@ void DisassemblerGraphView::drawBlock(QPainter &p, GraphView::GraphBlock &block) // Draw different background for selected instruction if (selected_instruction != RVA_INVALID) { int y = block.y + (2 * charWidth) + (db.header_text.lines.size() * charHeight); - for (Instr &instr : db.instrs) { + for (const Instr &instr : db.instrs) { if (instr.addr > selected_instruction) { break; } @@ -489,7 +489,7 @@ void DisassemblerGraphView::drawBlock(QPainter &p, GraphView::GraphBlock &block) int y = block.y + (2 * charWidth) + (db.header_text.lines.size() * charHeight); int tokenWidth = mFontMetrics->width(highlight_token->content); - for (Instr &instr : db.instrs) { + for (const Instr &instr : db.instrs) { int pos = -1; while ((pos = instr.plainText.indexOf(highlight_token->content, pos + 1)) != -1) { @@ -521,7 +521,7 @@ void DisassemblerGraphView::drawBlock(QPainter &p, GraphView::GraphBlock &block) // highlight program counter if (PCInBlock) { int y = block.y + (2 * charWidth) + (db.header_text.lines.size() * charHeight); - for (Instr &instr : db.instrs) { + for (const Instr &instr : db.instrs) { if (instr.addr > PCAddr) { break; } @@ -541,7 +541,7 @@ void DisassemblerGraphView::drawBlock(QPainter &p, GraphView::GraphBlock &block) RichTextPainter::paintRichText(&p, x, y, block.width, charHeight, 0, line, mFontMetrics); y += charHeight; } - for (Instr &instr : db.instrs) { + for (const Instr &instr : db.instrs) { if (Core()->isBreakpoint(breakpoints, instr.addr)) { p.fillRect(QRect(block.x + charWidth, y, block.width - (10 + 2 * charWidth), int(instr.text.lines.size()) * charHeight), ConfigColor("gui.breakpoint_background")); @@ -663,7 +663,7 @@ DisassemblerGraphView::DisassemblyBlock *DisassemblerGraphView::blockForAddress( { for (auto &blockIt : disassembly_blocks) { DisassemblyBlock &db = blockIt.second; - for (Instr i : db.instrs) { + for (const Instr &i : db.instrs) { if (i.addr == RVA_INVALID || i.size == RVA_INVALID) { continue; } diff --git a/src/widgets/DisassemblerGraphView.h b/src/widgets/DisassemblerGraphView.h index 0b8c455f..d2bb18d7 100644 --- a/src/widgets/DisassemblerGraphView.h +++ b/src/widgets/DisassemblerGraphView.h @@ -46,8 +46,8 @@ class DisassemblerGraphView : public GraphView QString ToQString() const { QString result; - for (auto &line : lines) { - for (auto &t : line) { + for (const auto &line : lines) { + for (const auto &t : line) { result += t.text; } } diff --git a/src/widgets/DisassemblyWidget.cpp b/src/widgets/DisassemblyWidget.cpp index 3fa089cf..de31aee1 100644 --- a/src/widgets/DisassemblyWidget.cpp +++ b/src/widgets/DisassemblyWidget.cpp @@ -228,7 +228,7 @@ void DisassemblyWidget::refreshDisasm(RVA offset) mDisasTextEdit->document()->clear(); QTextCursor cursor(mDisasTextEdit->document()); QTextBlockFormat regular = cursor.blockFormat(); - for (DisassemblyLine line : disassemblyLines) { + for (const DisassemblyLine &line : disassemblyLines) { if (line.offset < topOffset) { // overflow break; } diff --git a/src/widgets/EntrypointWidget.cpp b/src/widgets/EntrypointWidget.cpp index f8a80c26..1a3764c7 100644 --- a/src/widgets/EntrypointWidget.cpp +++ b/src/widgets/EntrypointWidget.cpp @@ -28,7 +28,7 @@ EntrypointWidget::~EntrypointWidget() {} void EntrypointWidget::fillEntrypoint() { ui->entrypointTreeWidget->clear(); - for (auto i : Core()->getAllEntrypoint()) { + for (const EntrypointDescription &i : Core()->getAllEntrypoint()) { QTreeWidgetItem *item = new QTreeWidgetItem(); item->setText(0, RAddressString(i.vaddr)); item->setText(1, i.type); diff --git a/src/widgets/FlagsWidget.cpp b/src/widgets/FlagsWidget.cpp index b46a8d9e..a561d2be 100644 --- a/src/widgets/FlagsWidget.cpp +++ b/src/widgets/FlagsWidget.cpp @@ -221,7 +221,7 @@ void FlagsWidget::refreshFlagspaces() ui->flagspaceCombo->clear(); ui->flagspaceCombo->addItem(tr("(all)")); - for (auto i : Core()->getAllFlagspaces()) { + for (const FlagspaceDescription &i : Core()->getAllFlagspaces()) { ui->flagspaceCombo->addItem(i.name, QVariant::fromValue(i)); } @@ -250,7 +250,7 @@ void FlagsWidget::refreshFlags() // TODO: this is not a very good place for the following: QStringList flagNames; - for (auto i : flags) + for (const FlagDescription &i : flags) flagNames.append(i.name); main->refreshOmniBar(flagNames); } diff --git a/src/widgets/FunctionsWidget.cpp b/src/widgets/FunctionsWidget.cpp index b48a8545..557457c4 100644 --- a/src/widgets/FunctionsWidget.cpp +++ b/src/widgets/FunctionsWidget.cpp @@ -564,7 +564,7 @@ void FunctionsWidget::refreshTree() this->functions = functions; importAddresses.clear(); - for (ImportDescription import : Core()->getAllImports()) { + for (const ImportDescription &import : Core()->getAllImports()) { importAddresses.insert(import.plt); } diff --git a/src/widgets/SdbDock.cpp b/src/widgets/SdbDock.cpp index 3affa103..a506e856 100644 --- a/src/widgets/SdbDock.cpp +++ b/src/widgets/SdbDock.cpp @@ -33,7 +33,7 @@ void SdbDock::reload(QString _path) QList keys; /* key-values */ keys = Core()->sdbListKeys(path); - for (QString key : keys) { + for (const QString &key : keys) { QTreeWidgetItem *tempItem = new QTreeWidgetItem(); tempItem->setText(0, key); tempItem->setText(1, Core()->sdbGet(path, key)); @@ -45,7 +45,7 @@ void SdbDock::reload(QString _path) /* namespaces */ keys = Core()->sdbList(path); keys.append(".."); - for (QString key : keys) { + for (const QString &key : keys) { QTreeWidgetItem *tempItem = new QTreeWidgetItem(); tempItem->setText(0, key + "/"); tempItem->setText(1, ""); diff --git a/src/widgets/SidebarWidget.cpp b/src/widgets/SidebarWidget.cpp index 6f15bf71..f63163cc 100644 --- a/src/widgets/SidebarWidget.cpp +++ b/src/widgets/SidebarWidget.cpp @@ -184,7 +184,7 @@ void SidebarWidget::fillOffsetInfo(QString off) ui->offsetTreeWidget->clear(); QString raw = Core()->cmd(QString("ao@") + off).trimmed(); QList lines = raw.split("\n", QString::SkipEmptyParts); - for (QString line : lines) { + for (const QString &line : lines) { QList eles = line.split(":", QString::SkipEmptyParts); if (eles.length() < 2) { continue; @@ -225,11 +225,11 @@ void SidebarWidget::fillRegistersInfo() ui->regInfoTreeWidget->clear(); QJsonObject jsonRoot = Core()->getRegistersInfo().object(); - for (QString key : jsonRoot.keys()) { + for (const QString &key : jsonRoot.keys()) { QTreeWidgetItem *tempItem = new QTreeWidgetItem(); QString tempString; tempItem->setText(0, key.toUpper()); - for (QJsonValue value : jsonRoot[key].toArray()) { + for (const QJsonValue &value : jsonRoot[key].toArray()) { tempString.append(value.toString() + " "); } tempItem->setText(1, tempString); diff --git a/src/widgets/StackWidget.cpp b/src/widgets/StackWidget.cpp index a7812fbc..dfc3ff92 100644 --- a/src/widgets/StackWidget.cpp +++ b/src/widgets/StackWidget.cpp @@ -51,7 +51,7 @@ void StackWidget::setStackGrid() { QJsonArray stackValues = Core()->getStack().array(); int i = 0; - for (QJsonValueRef value : stackValues) { + for (const QJsonValue &value : stackValues) { QJsonObject stackItem = value.toObject(); QString addr = RAddressString(stackItem["addr"].toVariant().toULongLong()); QString valueStack = RAddressString(stackItem["value"].toVariant().toULongLong()); diff --git a/src/widgets/StringsWidget.cpp b/src/widgets/StringsWidget.cpp index 1965a916..1f3487fe 100644 --- a/src/widgets/StringsWidget.cpp +++ b/src/widgets/StringsWidget.cpp @@ -223,7 +223,7 @@ void StringsWidget::refreshSectionCombo() combo->clear(); combo->addItem(tr("(all)")); - for (QString §ion : Core()->getSectionList()) { + for (const QString §ion : Core()->getSectionList()) { combo->addItem(section, section); } diff --git a/src/widgets/VisualNavbar.cpp b/src/widgets/VisualNavbar.cpp index d78e2e65..8a806a0e 100644 --- a/src/widgets/VisualNavbar.cpp +++ b/src/widgets/VisualNavbar.cpp @@ -241,7 +241,7 @@ void VisualNavbar::mouseMoveEvent(QMouseEvent *event) RVA VisualNavbar::localXToAddress(double x) { - for (auto x2a : xToAddress) { + for (const XToAddress &x2a : xToAddress) { if ((x2a.x_start <= x) && (x <= x2a.x_end)) { double offset = (x - x2a.x_start) / (x2a.x_end - x2a.x_start); double size = x2a.address_to - x2a.address_from; @@ -253,7 +253,7 @@ RVA VisualNavbar::localXToAddress(double x) double VisualNavbar::addressToLocalX(RVA address) { - for (auto x2a : xToAddress) { + for (const XToAddress &x2a : xToAddress) { if ((x2a.address_from <= address) && (address < x2a.address_to)) { double offset = (double)(address - x2a.address_from) / (double)(x2a.address_to - x2a.address_from); double size = x2a.x_end - x2a.x_start; @@ -267,7 +267,7 @@ QList VisualNavbar::sectionsForAddress(RVA address) { QList ret; QList sections = Core()->getAllSections(); - for (const auto §ion : sections) { + for (const SectionDescription §ion : sections) { if (address >= section.vaddr && address < section.vaddr + section.vsize) { ret << section.name; } @@ -282,7 +282,7 @@ QString VisualNavbar::toolTipForAddress(RVA address) if (sections.count()) { ret += "\nSections: \n"; bool first = true; - for (auto section : sections) { + for (const QString §ion : sections) { if (!first) { ret += "\n"; } else { diff --git a/src/widgets/ZignaturesWidget.cpp b/src/widgets/ZignaturesWidget.cpp index 0d893798..6439c74d 100644 --- a/src/widgets/ZignaturesWidget.cpp +++ b/src/widgets/ZignaturesWidget.cpp @@ -48,7 +48,7 @@ QVariant ZignaturesModel::data(const QModelIndex &index, int role) const "\n Edges: " + RSizeString(zignature.edges) + "\n Ebbs: " + RSizeString(zignature.ebbs) + "\n\nRefs:\n"); - for (QString ref : zignature.refs) { + for (const QString &ref : zignature.refs) { tmp.append("\n " + ref); } return tmp;