summaryrefslogtreecommitdiff
path: root/ui/util.h
diff options
context:
space:
mode:
authorRyan Snyder <ryan@vector35.com>2025-01-24 17:57:26 -0500
committerRyan Snyder <ryan@vector35.com>2025-02-14 15:58:56 -0500
commitbcdc0d9b89605936a1cb6cf3ffaaece60d3c5777 (patch)
tree7286bd0963a49d9b90ddccf3a4b70b71c08e6ce5 /ui/util.h
parent071811547bded7cf570125a03bb12d0b7c56a5ac (diff)
uidf refactor
Diffstat (limited to 'ui/util.h')
-rw-r--r--ui/util.h76
1 files changed, 76 insertions, 0 deletions
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 <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);