diff options
| author | Rusty Wagner <rusty@vector35.com> | 2020-01-03 21:51:50 -0500 |
|---|---|---|
| committer | Rusty Wagner <rusty@vector35.com> | 2020-04-17 14:20:38 -0400 |
| commit | 0e8987bb46b8aa33c5898d5effed25f1124e03dd (patch) | |
| tree | 87943b69c39f4377eedf07c2fa9b9ec1ab018f9d | |
| parent | 620dd96217a49803fe04c6bc286291ddd857dcba (diff) | |
Add types to HLIL expressions
| -rw-r--r-- | binaryninjaapi.h | 3 | ||||
| -rw-r--r-- | binaryninjacore.h | 2 | ||||
| -rw-r--r-- | highlevelil.cpp | 15 | ||||
| -rw-r--r-- | highlevelilinstruction.cpp | 4 | ||||
| -rw-r--r-- | python/highlevelil.py | 12 |
5 files changed, 29 insertions, 7 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 323431c9..19143c13 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -4244,6 +4244,9 @@ __attribute__ ((format (printf, 1, 2))) std::vector<DisassemblyTextLine> GetExprText(ExprId expr, bool asFullAst = true); std::vector<DisassemblyTextLine> GetExprText(const HighLevelILInstruction& instr, bool asFullAst = true); + Confidence<Ref<Type>> GetExprType(size_t expr); + Confidence<Ref<Type>> GetExprType(const HighLevelILInstruction& expr); + void VisitAllExprs(const std::function<bool(const HighLevelILInstruction& expr)>& func); Ref<FlowGraph> CreateFunctionGraph(DisassemblySettings* settings = nullptr); diff --git a/binaryninjacore.h b/binaryninjacore.h index 077f743b..4e0fde4e 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -3760,6 +3760,8 @@ __attribute__ ((format (printf, 1, 2))) BINARYNINJACOREAPI BNDisassemblyTextLine* BNGetHighLevelILExprText(BNHighLevelILFunction* func, size_t expr, bool asFullAst, size_t* count); + BINARYNINJACOREAPI BNTypeWithConfidence BNGetHighLevelILExprType(BNHighLevelILFunction* func, size_t expr); + // Type Libraries BINARYNINJACOREAPI BNTypeLibrary* BNNewTypeLibrary(BNArchitecture* arch, const char* name); BINARYNINJACOREAPI BNTypeLibrary* BNNewTypeLibraryReference(BNTypeLibrary* lib); diff --git a/highlevelil.cpp b/highlevelil.cpp index 679344ce..a3c9e5b2 100644 --- a/highlevelil.cpp +++ b/highlevelil.cpp @@ -295,6 +295,21 @@ vector<DisassemblyTextLine> HighLevelILFunction::GetExprText(const HighLevelILIn } +Confidence<Ref<Type>> HighLevelILFunction::GetExprType(size_t expr) +{ + BNTypeWithConfidence result = BNGetHighLevelILExprType(m_object, expr); + if (!result.type) + return nullptr; + return Confidence<Ref<Type>>(new Type(result.type), result.confidence); +} + + +Confidence<Ref<Type>> HighLevelILFunction::GetExprType(const HighLevelILInstruction& expr) +{ + return GetExprType(expr.exprIndex); +} + + void HighLevelILFunction::VisitAllExprs( const function<bool(const HighLevelILInstruction& expr)>& func) { diff --git a/highlevelilinstruction.cpp b/highlevelilinstruction.cpp index 1468fa78..80d30a92 100644 --- a/highlevelilinstruction.cpp +++ b/highlevelilinstruction.cpp @@ -797,9 +797,7 @@ PossibleValueSet HighLevelILInstructionBase::GetPossibleValues(const set<BNDataF Confidence<Ref<Type>> HighLevelILInstructionBase::GetType() const { - if (!HasMediumLevelIL()) - return nullptr; - return GetMediumLevelILSSAForm().GetType(); + return function->GetExprType(exprIndex); } diff --git a/python/highlevelil.py b/python/highlevelil.py index feac146b..a4140f85 100644 --- a/python/highlevelil.py +++ b/python/highlevelil.py @@ -29,6 +29,7 @@ from binaryninja import function from binaryninja import lowlevelil from binaryninja import mediumlevelil from binaryninja import basicblock +from binaryninja import types # 2-3 compatibility from binaryninja import range @@ -467,10 +468,13 @@ class HighLevelILInstruction(object): @property def expr_type(self): """Type of expression""" - mlil = self.mlil - if mlil is None: - return None - return mlil.expr_type + result = core.BNGetHighLevelILExprType(self._function.handle, self._expr_index) + if result.type: + platform = None + if self._function.source_function: + platform = self._function.source_function.platform + return types.Type(result.type, platform = platform, confidence = result.confidence) + return None def get_possible_values(self, options = []): mlil = self.mlil |
