diff options
| author | Ryan Snyder <ryan@vector35.com> | 2025-01-24 17:57:26 -0500 |
|---|---|---|
| committer | Ryan Snyder <ryan@vector35.com> | 2025-02-14 15:58:56 -0500 |
| commit | bcdc0d9b89605936a1cb6cf3ffaaece60d3c5777 (patch) | |
| tree | 7286bd0963a49d9b90ddccf3a4b70b71c08e6ce5 /ui | |
| parent | 071811547bded7cf570125a03bb12d0b7c56a5ac (diff) | |
uidf refactor
Diffstat (limited to 'ui')
| -rw-r--r-- | ui/commands.h | 14 | ||||
| -rw-r--r-- | ui/flowgraphwidget.h | 2 | ||||
| -rw-r--r-- | ui/linearview.h | 2 | ||||
| -rw-r--r-- | ui/util.h | 76 |
4 files changed, 90 insertions, 4 deletions
diff --git a/ui/commands.h b/ui/commands.h index 08691703..662e1d6c 100644 --- a/ui/commands.h +++ b/ui/commands.h @@ -34,6 +34,20 @@ bool BINARYNINJAUIAPI createStructMembers( bool BINARYNINJAUIAPI inputPossibleValueSet(QWidget* parent, BinaryViewRef data, FunctionRef currentFunction, const BinaryNinja::FunctionViewType& funcType, const BinaryNinja::Variable& var, size_t ilInstructionIndex = BN_INVALID_EXPR); + +bool BINARYNINJAUIAPI inputUserVariableValue(View* parent, HighlightTokenState& highlight); +bool BINARYNINJAUIAPI eligibleForUserVariableValue(View* parent, HighlightTokenState& highlight); + +bool BINARYNINJAUIAPI clearUserVariableValue(View* parent, HighlightTokenState& highlight); +bool BINARYNINJAUIAPI eligibleToClearUserVariableValue(View* parent, HighlightTokenState& highlight); + +bool BINARYNINJAUIAPI forceVariableVersion(View* parent, HighlightTokenState& highlight); +bool BINARYNINJAUIAPI eligibleToForceVariableVersion(View* parent, HighlightTokenState& highlight); + +bool BINARYNINJAUIAPI clearVariableVersion(View* parent, HighlightTokenState& highlight); +bool BINARYNINJAUIAPI eligibleToClearVariableVersion(View* parent, HighlightTokenState& highlight); + + bool BINARYNINJAUIAPI getEnumSelection(QWidget* parent, BinaryViewRef data, FunctionRef func, uint64_t constValue, TypeRef& selectedEnum, bool checkValue, bool canTruncate); diff --git a/ui/flowgraphwidget.h b/ui/flowgraphwidget.h index 3ef1b111..3d1434de 100644 --- a/ui/flowgraphwidget.h +++ b/ui/flowgraphwidget.h @@ -347,8 +347,6 @@ class BINARYNINJAUIAPI FlowGraphWidget : void followPointer(); void defineName(); void undefine(); - void setUserVariableValue(); - void clearUserVariableValue(); void defineFuncName(); void editFunctionProperties(); void createFunc(const UIActionContext& context); diff --git a/ui/linearview.h b/ui/linearview.h index d328fd7c..727f8634 100644 --- a/ui/linearview.h +++ b/ui/linearview.h @@ -329,8 +329,6 @@ private Q_SLOTS: void defineNameAtAddr(uint64_t addr); void defineName(); void undefine(); - void setUserVariableValue(); - void clearUserVariableValue(); void createFunc(const UIActionContext& context); void createFuncWithPlatform(PlatformRef platform, bool autoSelect = false); void defineFuncName(); @@ -3,6 +3,9 @@ #include "uitypes.h" #include "viewframe.h" #include "qfileaccessor.h" +#include "lowlevelilinstruction.h" +#include "mediumlevelilinstruction.h" +#include "highlevelilinstruction.h" #include <QtWidgets/QWidget> #include <QtCore/QFileInfo> @@ -24,6 +27,79 @@ std::string BINARYNINJAUIAPI getStringForInstructionDataflowDetails(BinaryViewRe std::optional<BinaryNinja::PossibleValueSet> BINARYNINJAUIAPI getPossibleValueSetForToken(View* view, BinaryViewRef data, ArchitectureRef arch, FunctionRef func, HighlightTokenState token, size_t instrIdx); +std::optional<BinaryNinja::PossibleValueSet> BINARYNINJAUIAPI getPossibleValueSetForILToken(View* view, HighlightTokenState token); +std::optional<uint64_t> BINARYNINJAUIAPI getAddressOfILTokenExpr(View* view, HighlightTokenState token); + +template <typename T> +std::optional<T> visitILInstructionForToken(View* view, HighlightTokenState token, + const std::function<std::optional<T>(BinaryNinja::LowLevelILInstruction&)>& llil, + const std::function<std::optional<T>(BinaryNinja::MediumLevelILInstruction&)>& mlil, + const std::function<std::optional<T>(BinaryNinja::HighLevelILInstruction&)>& hlil) +{ + if (token.token.exprIndex == BN_INVALID_EXPR) + return {}; + + BNFunctionGraphType type = view->getILViewType().type; + switch (type) + { + case InvalidILViewType: + case NormalFunctionGraph: + break; + case LiftedILFunctionGraph: + case MappedMediumLevelILFunctionGraph: + case MappedMediumLevelILSSAFormFunctionGraph: + // omitted because I don't know how to get to _exactly_ the right mapped mlil + // function from the View frame -- if we go through the Function object we may + // not get the same IL function object the token corresponds to due to an update + break; + case LowLevelILFunctionGraph: + case LowLevelILSSAFormFunctionGraph: + { + LowLevelILFunctionRef llilFunc = view->getCurrentLowLevelILFunction(); + if (llilFunc && type == LowLevelILSSAFormFunctionGraph) + llilFunc = llilFunc->GetSSAForm(); + if (llilFunc) + { + BinaryNinja::LowLevelILInstruction instr = llilFunc->GetExpr(token.token.exprIndex); + return llil(instr); + } + + break; + } + case MediumLevelILFunctionGraph: + case MediumLevelILSSAFormFunctionGraph: + { + MediumLevelILFunctionRef mlilFunc = view->getCurrentMediumLevelILFunction(); + if (mlilFunc && type == MediumLevelILSSAFormFunctionGraph) + mlilFunc = mlilFunc->GetSSAForm(); + if (mlilFunc) + { + BinaryNinja::MediumLevelILInstruction instr = mlilFunc->GetExpr(token.token.exprIndex); + return mlil(instr); + } + break; + } + case HighLevelILFunctionGraph: + case HighLevelILSSAFormFunctionGraph: + case HighLevelLanguageRepresentationFunctionGraph: + { + HighLevelILFunctionRef hlilFunc = view->getCurrentHighLevelILFunction(); + if (hlilFunc && type == HighLevelILSSAFormFunctionGraph) + hlilFunc = hlilFunc->GetSSAForm(); + if (hlilFunc) + { + BinaryNinja::HighLevelILInstruction instr = hlilFunc->GetExpr(token.token.exprIndex); + return hlil(instr); + } + break; + } + default: + break; + } + + return {}; +} + void BINARYNINJAUIAPI showHexPreview(QWidget* parent, ViewFrame* frame, const QPoint& previewPos, BinaryViewRef data, uint64_t address); bool BINARYNINJAUIAPI showDisassemblyPreview(QWidget* parent, ViewFrame* frame, const QPoint& previewPos,BinaryViewRef data, FunctionRef func, const ViewLocation& location); |
