From b4b9b312e7a3ed1ea05e485d045e5e05405be578 Mon Sep 17 00:00:00 2001 From: GustavoLCR Date: Wed, 24 Feb 2021 05:10:54 -0300 Subject: [PATCH] Offer a default function name in actionAnalyzeFunction input box (#2572) --- .gitignore | 1 + dist/WindowsBundleQt.cmake | 8 ++++++-- src/core/Cutter.cpp | 6 +++--- src/menus/DisassemblyContextMenu.cpp | 15 +++++++++++++-- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 06965556..e2884f4b 100644 --- a/.gitignore +++ b/.gitignore @@ -55,6 +55,7 @@ src/*_automoc.cpp *CMakeCache.txt* *cmake_install.cmake* src/CMakeFiles/* +CMakeSettings.json # Prepare_r2 ninja.exe diff --git a/dist/WindowsBundleQt.cmake b/dist/WindowsBundleQt.cmake index c9140140..4a99d221 100644 --- a/dist/WindowsBundleQt.cmake +++ b/dist/WindowsBundleQt.cmake @@ -1,10 +1,14 @@ message("Running windeployqt") -execute_process(COMMAND windeployqt cutter.exe +find_program(WINDEPLOYQT_EXECUTABLE windeployqt HINTS "${_qt_bin_dir}") +if(NOT WINDEPLOYQT_EXECUTABLE) + message(FATAL_ERROR "Failed to find windeployqt") +endif() +execute_process(COMMAND "${WINDEPLOYQT_EXECUTABLE}" cutter.exe --plugindir "qtplugins" --no-translations # Cutter currently isn't loading Qt translation file WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX} RESULT_VARIABLE SCRIPT_RESULT) if (SCRIPT_RESULT) - message(FATAL_ERROR "Failed to bundle python") + message(FATAL_ERROR "Failed to bundle qt") endif() file(WRITE "${CMAKE_INSTALL_PREFIX}/qt.conf" "[PATHS]\nPlugins = qtplugins") diff --git a/src/core/Cutter.cpp b/src/core/Cutter.cpp index 63e38ec1..1fb03120 100644 --- a/src/core/Cutter.cpp +++ b/src/core/Cutter.cpp @@ -1248,7 +1248,7 @@ QString CutterCore::createFunctionAt(RVA addr) QString CutterCore::createFunctionAt(RVA addr, QString name) { - static const QRegularExpression regExp("[^a-zA-Z0-9_]"); + static const QRegularExpression regExp("[^a-zA-Z0-9_.]"); name.remove(regExp); QString ret = cmdRawAt(QString("af %1").arg(name), addr); emit functionsChanged(); @@ -3742,8 +3742,8 @@ QString CutterCore::nearestFlag(RVA offset, RVA *flagOffsetOut) auto r = cmdj(QString("fdj @") + QString::number(offset)).object(); QString name = r.value("name").toString(); if (flagOffsetOut) { - int queryOffset = r.value("offset").toInt(0); - *flagOffsetOut = offset + static_cast(-queryOffset); + auto offsetValue = r.value("offset"); + *flagOffsetOut = offsetValue.isUndefined() ? offset : offsetValue.toVariant().toULongLong(); } return name; } diff --git a/src/menus/DisassemblyContextMenu.cpp b/src/menus/DisassemblyContextMenu.cpp index e533d521..94d9c8a6 100644 --- a/src/menus/DisassemblyContextMenu.cpp +++ b/src/menus/DisassemblyContextMenu.cpp @@ -811,10 +811,21 @@ void DisassemblyContextMenu::on_actionAddComment_triggered() void DisassemblyContextMenu::on_actionAnalyzeFunction_triggered() { bool ok; + RVA flagOffset; + QString name = Core()->nearestFlag(offset, &flagOffset); + if (name.isEmpty() || flagOffset != offset) { + // Create a default name for the function + QString pfx = Config()->getConfigString("analysis.fcnprefix"); + if (pfx.isEmpty()) { + pfx = QString("fcn"); + } + name = pfx + QString::asprintf(".%llx", offset); + } + // Create dialog QString functionName = - QInputDialog::getText(this, tr("New function %1").arg(RAddressString(offset)), - tr("Function name:"), QLineEdit::Normal, QString(), &ok); + QInputDialog::getText(this, tr("New function at %1").arg(RAddressString(offset)), + tr("Function name:"), QLineEdit::Normal, name, &ok); // If user accepted if (ok && !functionName.isEmpty()) {