diff options
| author | Brian Potchik <brian@vector35.com> | 2022-02-07 13:40:03 -0500 |
|---|---|---|
| committer | Brian Potchik <brian@vector35.com> | 2022-02-07 13:40:03 -0500 |
| commit | 8040830ef060f98801b797c58caba2848e36937c (patch) | |
| tree | 275aa0e14e862821051b65d062cfd14a2d9394d4 | |
| parent | a9ecb3d5566f86eb4d690a0672e6d5cdcb6ecbe8 (diff) | |
Expose HLIL GenerateSSAForm via API and add python wrapper.
| -rw-r--r-- | binaryninjaapi.h | 1 | ||||
| -rw-r--r-- | binaryninjacore.h | 3 | ||||
| -rw-r--r-- | highlevelil.cpp | 19 | ||||
| -rw-r--r-- | python/highlevelil.py | 14 |
4 files changed, 36 insertions, 1 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 72c03650..f6a3ab51 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -4987,6 +4987,7 @@ namespace BinaryNinja { void ReplaceExpr(size_t expr, size_t newExpr); void Finalize(); + void GenerateSSAForm(const std::set<Variable>& aliases = std::set<Variable>()); std::vector<DisassemblyTextLine> GetExprText( ExprId expr, bool asFullAst = true, DisassemblySettings* settings = nullptr); diff --git a/binaryninjacore.h b/binaryninjacore.h index 4033a457..1062a244 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -28,7 +28,7 @@ // Current ABI version for linking to the core. This is incremented any time // there are changes to the API that affect linking, including new functions, // new types, or modifications to existing functions or types. -#define BN_CURRENT_CORE_ABI_VERSION 16 +#define BN_CURRENT_CORE_ABI_VERSION 17 // Minimum ABI version that is supported for loading of plugins. Plugins that // are linked to an ABI version less than this will not be able to load and @@ -4758,6 +4758,7 @@ extern "C" BINARYNINJACOREAPI size_t BNGetHighLevelILRootExpr(BNHighLevelILFunction* func); BINARYNINJACOREAPI void BNSetHighLevelILRootExpr(BNHighLevelILFunction* func, size_t expr); BINARYNINJACOREAPI void BNFinalizeHighLevelILFunction(BNHighLevelILFunction* func); + BINARYNINJACOREAPI void BNGenerateHighLevelILSSAForm(BNHighLevelILFunction* func, BNVariable* aliases, size_t aliasCount); BINARYNINJACOREAPI size_t BNHighLevelILAddOperandList( BNHighLevelILFunction* func, uint64_t* operands, size_t count); diff --git a/highlevelil.cpp b/highlevelil.cpp index 5bebcca8..aab49ea0 100644 --- a/highlevelil.cpp +++ b/highlevelil.cpp @@ -428,6 +428,25 @@ void HighLevelILFunction::Finalize() } +void HighLevelILFunction::GenerateSSAForm(const set<Variable>& aliases) +{ + BNVariable* aliasList = new BNVariable[aliases.size()]; + + size_t i = 0; + for (auto& alias : aliases) + { + aliasList[i].type = alias.type; + aliasList[i].index = alias.index; + aliasList[i].storage = alias.storage; + i++; + } + + BNGenerateHighLevelILSSAForm(m_object, aliasList, aliases.size()); + + delete[] aliasList; +} + + vector<DisassemblyTextLine> HighLevelILFunction::GetExprText(ExprId expr, bool asFullAst, DisassemblySettings* settings) { size_t count; diff --git a/python/highlevelil.py b/python/highlevelil.py index 1aafd316..cb0a0980 100644 --- a/python/highlevelil.py +++ b/python/highlevelil.py @@ -2372,6 +2372,20 @@ class HighLevelILFunction: """ core.BNFinalizeHighLevelILFunction(self.handle) + def generate_ssa_form(self, variables: Optional[List["variable.Variable"]] = None) -> None: + """ + ``generate_ssa_form`` generate SSA form given the current HLIL + + :param list(Variable) variables: optional list of aliased variables + :rtype: None + """ + if variables is None: + variables = [] + variable_list = (core.BNVariable * len(variables))() + for i in range(len(variables)): + variable_list[i] = variables[i].to_BNVariable() + core.BNGenerateHighLevelILSSAForm(self.handle, variable_list, len(variable_list)) + def create_graph(self, settings: 'function.DisassemblySettings' = None) -> 'flowgraph.CoreFlowGraph': if settings is not None: settings_obj = settings.handle |
