From cf762601b42ae4365d271c3825d59720718047a2 Mon Sep 17 00:00:00 2001 From: KyleMiles Date: Mon, 1 Nov 2021 23:32:36 -0400 Subject: Add Function::GetMediumLevelILSSAVariables and Function::GetHighLevelILSSAVariables to the C++ API --- function.cpp | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 3 deletions(-) (limited to 'function.cpp') diff --git a/function.cpp b/function.cpp index 20c978ac..1f649191 100644 --- a/function.cpp +++ b/function.cpp @@ -1098,7 +1098,7 @@ map Function::GetVariables() BNVariableNameAndType* vars = BNGetFunctionVariables(m_object, &count); map result; - for (size_t i = 0; i < count; i++) + for (size_t i = 0; i < count; ++i) { VariableNameAndType var; var.name = vars[i].name; @@ -1115,7 +1115,7 @@ map Function::GetVariables() set Function::GetMediumLevelILVariables() { - auto mlil = this->GetMediumLevelIL(); + Ref mlil = this->GetMediumLevelIL(); if (!mlil) return {}; @@ -1149,9 +1149,33 @@ set Function::GetMediumLevelILAliasedVariables() } +set Function::GetMediumLevelILSSAVariables() +{ + Ref mlil = this->GetMediumLevelIL(); + if (!mlil) + return {}; + + size_t count; + BNVariable* vars = BNGetMediumLevelILVariables(mlil->GetObject(), &count); + + set result; + for (size_t i = 0; i < count; ++i) + { + size_t versionCount; + size_t* versions = BNGetMediumLevelILVariableSSAVersions(mlil->GetObject(), &vars[i], &versionCount); + for (size_t j = 0; j < versionCount; ++j) + result.emplace(vars[i], versions[j]); + BNFreeILInstructionList(versions); + } + + BNFreeVariableList(vars); + return result; +} + + set Function::GetHighLevelILVariables() { - auto hlil = this->GetHighLevelIL(); + Ref hlil = this->GetHighLevelIL(); if (!hlil) return {}; @@ -1185,6 +1209,30 @@ set Function::GetHighLevelILAliasedVariables() } +set Function::GetHighLevelILSSAVariables() +{ + Ref hlil = this->GetHighLevelIL(); + if (!hlil) + return {}; + + size_t count; + BNVariable* vars = BNGetHighLevelILVariables(hlil->GetObject(), &count); + + set result; + for (size_t i = 0; i < count; ++i) + { + size_t versionCount; + size_t* versions = BNGetHighLevelILVariableSSAVersions(hlil->GetObject(), &vars[i], &versionCount); + for (size_t j = 0; j < versionCount; ++j) + result.emplace(vars[i], versions[j]); + BNFreeILInstructionList(versions); + } + + BNFreeVariableList(vars); + return result; +} + + void Function::CreateAutoVariable(const Variable& var, const Confidence>& type, const string& name, bool ignoreDisjointUses) { -- cgit v1.3.1