From bcdc0d9b89605936a1cb6cf3ffaaece60d3c5777 Mon Sep 17 00:00:00 2001 From: Ryan Snyder Date: Fri, 24 Jan 2025 17:57:26 -0500 Subject: uidf refactor --- ui/util.h | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) (limited to 'ui/util.h') diff --git a/ui/util.h b/ui/util.h index 6e81a479..a7681d2f 100644 --- a/ui/util.h +++ b/ui/util.h @@ -3,6 +3,9 @@ #include "uitypes.h" #include "viewframe.h" #include "qfileaccessor.h" +#include "lowlevelilinstruction.h" +#include "mediumlevelilinstruction.h" +#include "highlevelilinstruction.h" #include #include @@ -24,6 +27,79 @@ std::string BINARYNINJAUIAPI getStringForInstructionDataflowDetails(BinaryViewRe std::optional BINARYNINJAUIAPI getPossibleValueSetForToken(View* view, BinaryViewRef data, ArchitectureRef arch, FunctionRef func, HighlightTokenState token, size_t instrIdx); +std::optional BINARYNINJAUIAPI getPossibleValueSetForILToken(View* view, HighlightTokenState token); +std::optional BINARYNINJAUIAPI getAddressOfILTokenExpr(View* view, HighlightTokenState token); + +template +std::optional visitILInstructionForToken(View* view, HighlightTokenState token, + const std::function(BinaryNinja::LowLevelILInstruction&)>& llil, + const std::function(BinaryNinja::MediumLevelILInstruction&)>& mlil, + const std::function(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); -- cgit v1.3.1