diff options
| author | Rusty Wagner <rusty@vector35.com> | 2019-08-03 22:40:47 -0400 |
|---|---|---|
| committer | Rusty Wagner <rusty@vector35.com> | 2019-12-19 17:20:53 -0500 |
| commit | c69b76dd1a7e1985f58f71c07dfc8b7b0657f57a (patch) | |
| tree | 25bbbdc261c3b550dd65d66580b016dfb03dade7 | |
| parent | 741fb0538e0ac6ab14928f78697196803dbd2ed5 (diff) | |
Add data flow query options
| -rw-r--r-- | binaryninjaapi.h | 51 | ||||
| -rw-r--r-- | binaryninjacore.h | 37 | ||||
| -rw-r--r-- | lowlevelil.cpp | 80 | ||||
| -rw-r--r-- | mediumlevelil.cpp | 92 | ||||
| -rw-r--r-- | python/lowlevelil.py | 73 | ||||
| -rw-r--r-- | python/mediumlevelil.py | 85 |
6 files changed, 323 insertions, 95 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h index b4b9a602..ec512972 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -3625,21 +3625,29 @@ __attribute__ ((format (printf, 1, 2))) RegisterValue GetExprValue(size_t expr); RegisterValue GetExprValue(const LowLevelILInstruction& expr); - PossibleValueSet GetPossibleExprValues(size_t expr); - PossibleValueSet GetPossibleExprValues(const LowLevelILInstruction& expr); + PossibleValueSet GetPossibleExprValues(size_t expr, + const std::set<BNDataFlowQueryOption>& options = std::set<BNDataFlowQueryOption>()); + PossibleValueSet GetPossibleExprValues(const LowLevelILInstruction& expr, + const std::set<BNDataFlowQueryOption>& options = std::set<BNDataFlowQueryOption>()); RegisterValue GetRegisterValueAtInstruction(uint32_t reg, size_t instr); RegisterValue GetRegisterValueAfterInstruction(uint32_t reg, size_t instr); - PossibleValueSet GetPossibleRegisterValuesAtInstruction(uint32_t reg, size_t instr); - PossibleValueSet GetPossibleRegisterValuesAfterInstruction(uint32_t reg, size_t instr); + PossibleValueSet GetPossibleRegisterValuesAtInstruction(uint32_t reg, size_t instr, + const std::set<BNDataFlowQueryOption>& options = std::set<BNDataFlowQueryOption>()); + PossibleValueSet GetPossibleRegisterValuesAfterInstruction(uint32_t reg, size_t instr, + const std::set<BNDataFlowQueryOption>& options = std::set<BNDataFlowQueryOption>()); RegisterValue GetFlagValueAtInstruction(uint32_t flag, size_t instr); RegisterValue GetFlagValueAfterInstruction(uint32_t flag, size_t instr); - PossibleValueSet GetPossibleFlagValuesAtInstruction(uint32_t flag, size_t instr); - PossibleValueSet GetPossibleFlagValuesAfterInstruction(uint32_t flag, size_t instr); + PossibleValueSet GetPossibleFlagValuesAtInstruction(uint32_t flag, size_t instr, + const std::set<BNDataFlowQueryOption>& options = std::set<BNDataFlowQueryOption>()); + PossibleValueSet GetPossibleFlagValuesAfterInstruction(uint32_t flag, size_t instr, + const std::set<BNDataFlowQueryOption>& options = std::set<BNDataFlowQueryOption>()); RegisterValue GetStackContentsAtInstruction(int32_t offset, size_t len, size_t instr); RegisterValue GetStackContentsAfterInstruction(int32_t offset, size_t len, size_t instr); - PossibleValueSet GetPossibleStackContentsAtInstruction(int32_t offset, size_t len, size_t instr); - PossibleValueSet GetPossibleStackContentsAfterInstruction(int32_t offset, size_t len, size_t instr); + PossibleValueSet GetPossibleStackContentsAtInstruction(int32_t offset, size_t len, size_t instr, + const std::set<BNDataFlowQueryOption>& options = std::set<BNDataFlowQueryOption>()); + PossibleValueSet GetPossibleStackContentsAfterInstruction(int32_t offset, size_t len, size_t instr, + const std::set<BNDataFlowQueryOption>& options = std::set<BNDataFlowQueryOption>()); Ref<MediumLevelILFunction> GetMediumLevelIL() const; Ref<MediumLevelILFunction> GetMappedMediumLevelIL() const; @@ -3951,9 +3959,12 @@ __attribute__ ((format (printf, 1, 2))) RegisterValue GetSSAVarValue(const SSAVariable& var); RegisterValue GetExprValue(size_t expr); RegisterValue GetExprValue(const MediumLevelILInstruction& expr); - PossibleValueSet GetPossibleSSAVarValues(const SSAVariable& var, size_t instr); - PossibleValueSet GetPossibleExprValues(size_t expr); - PossibleValueSet GetPossibleExprValues(const MediumLevelILInstruction& expr); + PossibleValueSet GetPossibleSSAVarValues(const SSAVariable& var, size_t instr, + const std::set<BNDataFlowQueryOption>& options = std::set<BNDataFlowQueryOption>()); + PossibleValueSet GetPossibleExprValues(size_t expr, + const std::set<BNDataFlowQueryOption>& options = std::set<BNDataFlowQueryOption>()); + PossibleValueSet GetPossibleExprValues(const MediumLevelILInstruction& expr, + const std::set<BNDataFlowQueryOption>& options = std::set<BNDataFlowQueryOption>()); size_t GetSSAVarVersionAtInstruction(const Variable& var, size_t instr) const; size_t GetSSAMemoryVersionAtInstruction(size_t instr) const; @@ -3963,16 +3974,22 @@ __attribute__ ((format (printf, 1, 2))) RegisterValue GetRegisterValueAtInstruction(uint32_t reg, size_t instr); RegisterValue GetRegisterValueAfterInstruction(uint32_t reg, size_t instr); - PossibleValueSet GetPossibleRegisterValuesAtInstruction(uint32_t reg, size_t instr); - PossibleValueSet GetPossibleRegisterValuesAfterInstruction(uint32_t reg, size_t instr); + PossibleValueSet GetPossibleRegisterValuesAtInstruction(uint32_t reg, size_t instr, + const std::set<BNDataFlowQueryOption>& options = std::set<BNDataFlowQueryOption>()); + PossibleValueSet GetPossibleRegisterValuesAfterInstruction(uint32_t reg, size_t instr, + const std::set<BNDataFlowQueryOption>& options = std::set<BNDataFlowQueryOption>()); RegisterValue GetFlagValueAtInstruction(uint32_t flag, size_t instr); RegisterValue GetFlagValueAfterInstruction(uint32_t flag, size_t instr); - PossibleValueSet GetPossibleFlagValuesAtInstruction(uint32_t flag, size_t instr); - PossibleValueSet GetPossibleFlagValuesAfterInstruction(uint32_t flag, size_t instr); + PossibleValueSet GetPossibleFlagValuesAtInstruction(uint32_t flag, size_t instr, + const std::set<BNDataFlowQueryOption>& options = std::set<BNDataFlowQueryOption>()); + PossibleValueSet GetPossibleFlagValuesAfterInstruction(uint32_t flag, size_t instr, + const std::set<BNDataFlowQueryOption>& options = std::set<BNDataFlowQueryOption>()); RegisterValue GetStackContentsAtInstruction(int32_t offset, size_t len, size_t instr); RegisterValue GetStackContentsAfterInstruction(int32_t offset, size_t len, size_t instr); - PossibleValueSet GetPossibleStackContentsAtInstruction(int32_t offset, size_t len, size_t instr); - PossibleValueSet GetPossibleStackContentsAfterInstruction(int32_t offset, size_t len, size_t instr); + PossibleValueSet GetPossibleStackContentsAtInstruction(int32_t offset, size_t len, size_t instr, + const std::set<BNDataFlowQueryOption>& options = std::set<BNDataFlowQueryOption>()); + PossibleValueSet GetPossibleStackContentsAfterInstruction(int32_t offset, size_t len, size_t instr, + const std::set<BNDataFlowQueryOption>& options = std::set<BNDataFlowQueryOption>()); BNILBranchDependence GetBranchDependenceAtInstruction(size_t curInstr, size_t branchInstr) const; std::unordered_map<size_t, BNILBranchDependence> GetAllBranchDependenceAtInstruction(size_t instr) const; diff --git a/binaryninjacore.h b/binaryninjacore.h index 2988637f..0e5a420b 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -785,6 +785,11 @@ extern "C" NotInSetOfValues }; + enum BNDataFlowQueryOption + { + FromAddressesInLookupTableQueryOption // Use addresses instead of index in the from list within LookupTableValue results + }; + enum BNPluginOrigin { OfficialPluginOrigin, @@ -3275,32 +3280,33 @@ __attribute__ ((format (printf, 1, 2))) uint32_t flag, size_t version); BINARYNINJACOREAPI BNRegisterValue BNGetLowLevelILExprValue(BNLowLevelILFunction* func, size_t expr); - BINARYNINJACOREAPI BNPossibleValueSet BNGetLowLevelILPossibleExprValues(BNLowLevelILFunction* func, size_t expr); + BINARYNINJACOREAPI BNPossibleValueSet BNGetLowLevelILPossibleExprValues(BNLowLevelILFunction* func, size_t expr, + BNDataFlowQueryOption* options, size_t optionCount); BINARYNINJACOREAPI BNRegisterValue BNGetLowLevelILRegisterValueAtInstruction(BNLowLevelILFunction* func, uint32_t reg, size_t instr); BINARYNINJACOREAPI BNRegisterValue BNGetLowLevelILRegisterValueAfterInstruction(BNLowLevelILFunction* func, uint32_t reg, size_t instr); BINARYNINJACOREAPI BNPossibleValueSet BNGetLowLevelILPossibleRegisterValuesAtInstruction(BNLowLevelILFunction* func, - uint32_t reg, size_t instr); + uint32_t reg, size_t instr, BNDataFlowQueryOption* options, size_t optionCount); BINARYNINJACOREAPI BNPossibleValueSet BNGetLowLevelILPossibleRegisterValuesAfterInstruction(BNLowLevelILFunction* func, - uint32_t reg, size_t instr); + uint32_t reg, size_t instr, BNDataFlowQueryOption* options, size_t optionCount); BINARYNINJACOREAPI BNRegisterValue BNGetLowLevelILFlagValueAtInstruction(BNLowLevelILFunction* func, uint32_t flag, size_t instr); BINARYNINJACOREAPI BNRegisterValue BNGetLowLevelILFlagValueAfterInstruction(BNLowLevelILFunction* func, uint32_t flag, size_t instr); BINARYNINJACOREAPI BNPossibleValueSet BNGetLowLevelILPossibleFlagValuesAtInstruction(BNLowLevelILFunction* func, - uint32_t flag, size_t instr); + uint32_t flag, size_t instr, BNDataFlowQueryOption* options, size_t optionCount); BINARYNINJACOREAPI BNPossibleValueSet BNGetLowLevelILPossibleFlagValuesAfterInstruction(BNLowLevelILFunction* func, - uint32_t flag, size_t instr); + uint32_t flag, size_t instr, BNDataFlowQueryOption* options, size_t optionCount); BINARYNINJACOREAPI BNRegisterValue BNGetLowLevelILStackContentsAtInstruction(BNLowLevelILFunction* func, int64_t offset, size_t len, size_t instr); BINARYNINJACOREAPI BNRegisterValue BNGetLowLevelILStackContentsAfterInstruction(BNLowLevelILFunction* func, int64_t offset, size_t len, size_t instr); BINARYNINJACOREAPI BNPossibleValueSet BNGetLowLevelILPossibleStackContentsAtInstruction(BNLowLevelILFunction* func, - int64_t offset, size_t len, size_t instr); + int64_t offset, size_t len, size_t instr, BNDataFlowQueryOption* options, size_t optionCount); BINARYNINJACOREAPI BNPossibleValueSet BNGetLowLevelILPossibleStackContentsAfterInstruction(BNLowLevelILFunction* func, - int64_t offset, size_t len, size_t instr); + int64_t offset, size_t len, size_t instr, BNDataFlowQueryOption* options, size_t optionCount); BINARYNINJACOREAPI BNMediumLevelILFunction* BNGetMediumLevelILForLowLevelIL(BNLowLevelILFunction* func); BINARYNINJACOREAPI BNMediumLevelILFunction* BNGetMappedMediumLevelIL(BNLowLevelILFunction* func); @@ -3399,8 +3405,9 @@ __attribute__ ((format (printf, 1, 2))) const BNVariable* var, size_t version); BINARYNINJACOREAPI BNRegisterValue BNGetMediumLevelILExprValue(BNMediumLevelILFunction* func, size_t expr); BINARYNINJACOREAPI BNPossibleValueSet BNGetMediumLevelILPossibleSSAVarValues(BNMediumLevelILFunction* func, - const BNVariable* var, size_t version, size_t instr); - BINARYNINJACOREAPI BNPossibleValueSet BNGetMediumLevelILPossibleExprValues(BNMediumLevelILFunction* func, size_t expr); + const BNVariable* var, size_t version, size_t instr, BNDataFlowQueryOption* options, size_t optionCount); + BINARYNINJACOREAPI BNPossibleValueSet BNGetMediumLevelILPossibleExprValues(BNMediumLevelILFunction* func, size_t expr, + BNDataFlowQueryOption* options, size_t optionCount); BINARYNINJACOREAPI size_t BNGetMediumLevelILSSAVarVersionAtILInstruction(BNMediumLevelILFunction* func, const BNVariable* var, size_t instr); @@ -3418,25 +3425,25 @@ __attribute__ ((format (printf, 1, 2))) BINARYNINJACOREAPI BNRegisterValue BNGetMediumLevelILRegisterValueAfterInstruction(BNMediumLevelILFunction* func, uint32_t reg, size_t instr); BINARYNINJACOREAPI BNPossibleValueSet BNGetMediumLevelILPossibleRegisterValuesAtInstruction(BNMediumLevelILFunction* func, - uint32_t reg, size_t instr); + uint32_t reg, size_t instr, BNDataFlowQueryOption* options, size_t optionCount); BINARYNINJACOREAPI BNPossibleValueSet BNGetMediumLevelILPossibleRegisterValuesAfterInstruction(BNMediumLevelILFunction* func, - uint32_t reg, size_t instr); + uint32_t reg, size_t instr, BNDataFlowQueryOption* options, size_t optionCount); BINARYNINJACOREAPI BNRegisterValue BNGetMediumLevelILFlagValueAtInstruction(BNMediumLevelILFunction* func, uint32_t flag, size_t instr); BINARYNINJACOREAPI BNRegisterValue BNGetMediumLevelILFlagValueAfterInstruction(BNMediumLevelILFunction* func, uint32_t flag, size_t instr); BINARYNINJACOREAPI BNPossibleValueSet BNGetMediumLevelILPossibleFlagValuesAtInstruction(BNMediumLevelILFunction* func, - uint32_t flag, size_t instr); + uint32_t flag, size_t instr, BNDataFlowQueryOption* options, size_t optionCount); BINARYNINJACOREAPI BNPossibleValueSet BNGetMediumLevelILPossibleFlagValuesAfterInstruction(BNMediumLevelILFunction* func, - uint32_t flag, size_t instr); + uint32_t flag, size_t instr, BNDataFlowQueryOption* options, size_t optionCount); BINARYNINJACOREAPI BNRegisterValue BNGetMediumLevelILStackContentsAtInstruction(BNMediumLevelILFunction* func, int64_t offset, size_t len, size_t instr); BINARYNINJACOREAPI BNRegisterValue BNGetMediumLevelILStackContentsAfterInstruction(BNMediumLevelILFunction* func, int64_t offset, size_t len, size_t instr); BINARYNINJACOREAPI BNPossibleValueSet BNGetMediumLevelILPossibleStackContentsAtInstruction(BNMediumLevelILFunction* func, - int64_t offset, size_t len, size_t instr); + int64_t offset, size_t len, size_t instr, BNDataFlowQueryOption* options, size_t optionCount); BINARYNINJACOREAPI BNPossibleValueSet BNGetMediumLevelILPossibleStackContentsAfterInstruction(BNMediumLevelILFunction* func, - int64_t offset, size_t len, size_t instr); + int64_t offset, size_t len, size_t instr, BNDataFlowQueryOption* options, size_t optionCount); BINARYNINJACOREAPI BNILBranchDependence BNGetMediumLevelILBranchDependence(BNMediumLevelILFunction* func, size_t curInstr, size_t branchInstr); diff --git a/lowlevelil.cpp b/lowlevelil.cpp index afaacf08..0ea395f8 100644 --- a/lowlevelil.cpp +++ b/lowlevelil.cpp @@ -623,16 +623,22 @@ RegisterValue LowLevelILFunction::GetExprValue(const LowLevelILInstruction& expr } -PossibleValueSet LowLevelILFunction::GetPossibleExprValues(size_t expr) +PossibleValueSet LowLevelILFunction::GetPossibleExprValues(size_t expr, const set<BNDataFlowQueryOption>& options) { - BNPossibleValueSet value = BNGetLowLevelILPossibleExprValues(m_object, expr); + BNDataFlowQueryOption* optionArray = new BNDataFlowQueryOption[options.size()]; + size_t idx = 0; + for (auto i : options) + optionArray[idx++] = i; + BNPossibleValueSet value = BNGetLowLevelILPossibleExprValues(m_object, expr, optionArray, options.size()); + delete[] optionArray; return PossibleValueSet::FromAPIObject(value); } -PossibleValueSet LowLevelILFunction::GetPossibleExprValues(const LowLevelILInstruction& expr) +PossibleValueSet LowLevelILFunction::GetPossibleExprValues(const LowLevelILInstruction& expr, + const set<BNDataFlowQueryOption>& options) { - return GetPossibleExprValues(expr.exprIndex); + return GetPossibleExprValues(expr.exprIndex, options); } @@ -650,16 +656,30 @@ RegisterValue LowLevelILFunction::GetRegisterValueAfterInstruction(uint32_t reg, } -PossibleValueSet LowLevelILFunction::GetPossibleRegisterValuesAtInstruction(uint32_t reg, size_t instr) +PossibleValueSet LowLevelILFunction::GetPossibleRegisterValuesAtInstruction(uint32_t reg, size_t instr, + const set<BNDataFlowQueryOption>& options) { - BNPossibleValueSet value = BNGetLowLevelILPossibleRegisterValuesAtInstruction(m_object, reg, instr); + BNDataFlowQueryOption* optionArray = new BNDataFlowQueryOption[options.size()]; + size_t idx = 0; + for (auto i : options) + optionArray[idx++] = i; + BNPossibleValueSet value = BNGetLowLevelILPossibleRegisterValuesAtInstruction(m_object, reg, instr, + optionArray, options.size()); + delete[] optionArray; return PossibleValueSet::FromAPIObject(value); } -PossibleValueSet LowLevelILFunction::GetPossibleRegisterValuesAfterInstruction(uint32_t reg, size_t instr) +PossibleValueSet LowLevelILFunction::GetPossibleRegisterValuesAfterInstruction(uint32_t reg, size_t instr, + const set<BNDataFlowQueryOption>& options) { - BNPossibleValueSet value = BNGetLowLevelILPossibleRegisterValuesAfterInstruction(m_object, reg, instr); + BNDataFlowQueryOption* optionArray = new BNDataFlowQueryOption[options.size()]; + size_t idx = 0; + for (auto i : options) + optionArray[idx++] = i; + BNPossibleValueSet value = BNGetLowLevelILPossibleRegisterValuesAfterInstruction(m_object, reg, instr, + optionArray, options.size()); + delete[] optionArray; return PossibleValueSet::FromAPIObject(value); } @@ -678,16 +698,30 @@ RegisterValue LowLevelILFunction::GetFlagValueAfterInstruction(uint32_t flag, si } -PossibleValueSet LowLevelILFunction::GetPossibleFlagValuesAtInstruction(uint32_t flag, size_t instr) +PossibleValueSet LowLevelILFunction::GetPossibleFlagValuesAtInstruction(uint32_t flag, size_t instr, + const set<BNDataFlowQueryOption>& options) { - BNPossibleValueSet value = BNGetLowLevelILPossibleFlagValuesAtInstruction(m_object, flag, instr); + BNDataFlowQueryOption* optionArray = new BNDataFlowQueryOption[options.size()]; + size_t idx = 0; + for (auto i : options) + optionArray[idx++] = i; + BNPossibleValueSet value = BNGetLowLevelILPossibleFlagValuesAtInstruction(m_object, flag, instr, + optionArray, options.size()); + delete[] optionArray; return PossibleValueSet::FromAPIObject(value); } -PossibleValueSet LowLevelILFunction::GetPossibleFlagValuesAfterInstruction(uint32_t flag, size_t instr) +PossibleValueSet LowLevelILFunction::GetPossibleFlagValuesAfterInstruction(uint32_t flag, size_t instr, + const set<BNDataFlowQueryOption>& options) { - BNPossibleValueSet value = BNGetLowLevelILPossibleFlagValuesAfterInstruction(m_object, flag, instr); + BNDataFlowQueryOption* optionArray = new BNDataFlowQueryOption[options.size()]; + size_t idx = 0; + for (auto i : options) + optionArray[idx++] = i; + BNPossibleValueSet value = BNGetLowLevelILPossibleFlagValuesAfterInstruction(m_object, flag, instr, + optionArray, options.size()); + delete[] optionArray; return PossibleValueSet::FromAPIObject(value); } @@ -706,16 +740,30 @@ RegisterValue LowLevelILFunction::GetStackContentsAfterInstruction(int32_t offse } -PossibleValueSet LowLevelILFunction::GetPossibleStackContentsAtInstruction(int32_t offset, size_t len, size_t instr) +PossibleValueSet LowLevelILFunction::GetPossibleStackContentsAtInstruction(int32_t offset, size_t len, size_t instr, + const set<BNDataFlowQueryOption>& options) { - BNPossibleValueSet value = BNGetLowLevelILPossibleStackContentsAtInstruction(m_object, offset, len, instr); + BNDataFlowQueryOption* optionArray = new BNDataFlowQueryOption[options.size()]; + size_t idx = 0; + for (auto i : options) + optionArray[idx++] = i; + BNPossibleValueSet value = BNGetLowLevelILPossibleStackContentsAtInstruction(m_object, offset, len, instr, + optionArray, options.size()); + delete[] optionArray; return PossibleValueSet::FromAPIObject(value); } -PossibleValueSet LowLevelILFunction::GetPossibleStackContentsAfterInstruction(int32_t offset, size_t len, size_t instr) +PossibleValueSet LowLevelILFunction::GetPossibleStackContentsAfterInstruction(int32_t offset, size_t len, size_t instr, + const set<BNDataFlowQueryOption>& options) { - BNPossibleValueSet value = BNGetLowLevelILPossibleStackContentsAfterInstruction(m_object, offset, len, instr); + BNDataFlowQueryOption* optionArray = new BNDataFlowQueryOption[options.size()]; + size_t idx = 0; + for (auto i : options) + optionArray[idx++] = i; + BNPossibleValueSet value = BNGetLowLevelILPossibleStackContentsAfterInstruction(m_object, offset, len, instr, + optionArray, options.size()); + delete[] optionArray; return PossibleValueSet::FromAPIObject(value); } diff --git a/mediumlevelil.cpp b/mediumlevelil.cpp index 6ce556f4..ce37f7e0 100644 --- a/mediumlevelil.cpp +++ b/mediumlevelil.cpp @@ -544,23 +544,37 @@ RegisterValue MediumLevelILFunction::GetExprValue(const MediumLevelILInstruction } -PossibleValueSet MediumLevelILFunction::GetPossibleSSAVarValues(const SSAVariable& var, size_t instr) +PossibleValueSet MediumLevelILFunction::GetPossibleSSAVarValues(const SSAVariable& var, size_t instr, + const set<BNDataFlowQueryOption>& options) { - BNPossibleValueSet value = BNGetMediumLevelILPossibleSSAVarValues(m_object, &var.var, var.version, instr); + BNDataFlowQueryOption* optionArray = new BNDataFlowQueryOption[options.size()]; + size_t idx = 0; + for (auto i : options) + optionArray[idx++] = i; + BNPossibleValueSet value = BNGetMediumLevelILPossibleSSAVarValues(m_object, &var.var, var.version, instr, + optionArray, options.size()); + delete[] optionArray; return PossibleValueSet::FromAPIObject(value); } -PossibleValueSet MediumLevelILFunction::GetPossibleExprValues(size_t expr) +PossibleValueSet MediumLevelILFunction::GetPossibleExprValues(size_t expr, + const set<BNDataFlowQueryOption>& options) { - BNPossibleValueSet value = BNGetMediumLevelILPossibleExprValues(m_object, expr); + BNDataFlowQueryOption* optionArray = new BNDataFlowQueryOption[options.size()]; + size_t idx = 0; + for (auto i : options) + optionArray[idx++] = i; + BNPossibleValueSet value = BNGetMediumLevelILPossibleExprValues(m_object, expr, optionArray, options.size()); + delete[] optionArray; return PossibleValueSet::FromAPIObject(value); } -PossibleValueSet MediumLevelILFunction::GetPossibleExprValues(const MediumLevelILInstruction& expr) +PossibleValueSet MediumLevelILFunction::GetPossibleExprValues(const MediumLevelILInstruction& expr, + const set<BNDataFlowQueryOption>& options) { - return GetPossibleExprValues(expr.exprIndex); + return GetPossibleExprValues(expr.exprIndex, options); } @@ -608,16 +622,30 @@ RegisterValue MediumLevelILFunction::GetRegisterValueAfterInstruction(uint32_t r } -PossibleValueSet MediumLevelILFunction::GetPossibleRegisterValuesAtInstruction(uint32_t reg, size_t instr) +PossibleValueSet MediumLevelILFunction::GetPossibleRegisterValuesAtInstruction(uint32_t reg, size_t instr, + const set<BNDataFlowQueryOption>& options) { - BNPossibleValueSet value = BNGetMediumLevelILPossibleRegisterValuesAtInstruction(m_object, reg, instr); + BNDataFlowQueryOption* optionArray = new BNDataFlowQueryOption[options.size()]; + size_t idx = 0; + for (auto i : options) + optionArray[idx++] = i; + BNPossibleValueSet value = BNGetMediumLevelILPossibleRegisterValuesAtInstruction(m_object, reg, instr, + optionArray, options.size()); + delete[] optionArray; return PossibleValueSet::FromAPIObject(value); } -PossibleValueSet MediumLevelILFunction::GetPossibleRegisterValuesAfterInstruction(uint32_t reg, size_t instr) +PossibleValueSet MediumLevelILFunction::GetPossibleRegisterValuesAfterInstruction(uint32_t reg, size_t instr, + const set<BNDataFlowQueryOption>& options) { - BNPossibleValueSet value = BNGetMediumLevelILPossibleRegisterValuesAfterInstruction(m_object, reg, instr); + BNDataFlowQueryOption* optionArray = new BNDataFlowQueryOption[options.size()]; + size_t idx = 0; + for (auto i : options) + optionArray[idx++] = i; + BNPossibleValueSet value = BNGetMediumLevelILPossibleRegisterValuesAfterInstruction(m_object, reg, instr, + optionArray, options.size()); + delete[] optionArray; return PossibleValueSet::FromAPIObject(value); } @@ -636,16 +664,30 @@ RegisterValue MediumLevelILFunction::GetFlagValueAfterInstruction(uint32_t flag, } -PossibleValueSet MediumLevelILFunction::GetPossibleFlagValuesAtInstruction(uint32_t flag, size_t instr) +PossibleValueSet MediumLevelILFunction::GetPossibleFlagValuesAtInstruction(uint32_t flag, size_t instr, + const set<BNDataFlowQueryOption>& options) { - BNPossibleValueSet value = BNGetMediumLevelILPossibleFlagValuesAtInstruction(m_object, flag, instr); + BNDataFlowQueryOption* optionArray = new BNDataFlowQueryOption[options.size()]; + size_t idx = 0; + for (auto i : options) + optionArray[idx++] = i; + BNPossibleValueSet value = BNGetMediumLevelILPossibleFlagValuesAtInstruction(m_object, flag, instr, + optionArray, options.size()); + delete[] optionArray; return PossibleValueSet::FromAPIObject(value); } -PossibleValueSet MediumLevelILFunction::GetPossibleFlagValuesAfterInstruction(uint32_t flag, size_t instr) +PossibleValueSet MediumLevelILFunction::GetPossibleFlagValuesAfterInstruction(uint32_t flag, size_t instr, + const set<BNDataFlowQueryOption>& options) { - BNPossibleValueSet value = BNGetMediumLevelILPossibleFlagValuesAfterInstruction(m_object, flag, instr); + BNDataFlowQueryOption* optionArray = new BNDataFlowQueryOption[options.size()]; + size_t idx = 0; + for (auto i : options) + optionArray[idx++] = i; + BNPossibleValueSet value = BNGetMediumLevelILPossibleFlagValuesAfterInstruction(m_object, flag, instr, + optionArray, options.size()); + delete[] optionArray; return PossibleValueSet::FromAPIObject(value); } @@ -664,16 +706,30 @@ RegisterValue MediumLevelILFunction::GetStackContentsAfterInstruction(int32_t of } -PossibleValueSet MediumLevelILFunction::GetPossibleStackContentsAtInstruction(int32_t offset, size_t len, size_t instr) +PossibleValueSet MediumLevelILFunction::GetPossibleStackContentsAtInstruction(int32_t offset, size_t len, size_t instr, + const set<BNDataFlowQueryOption>& options) { - BNPossibleValueSet value = BNGetMediumLevelILPossibleStackContentsAtInstruction(m_object, offset, len, instr); + BNDataFlowQueryOption* optionArray = new BNDataFlowQueryOption[options.size()]; + size_t idx = 0; + for (auto i : options) + optionArray[idx++] = i; + BNPossibleValueSet value = BNGetMediumLevelILPossibleStackContentsAtInstruction(m_object, offset, len, instr, + optionArray, options.size()); + delete[] optionArray; return PossibleValueSet::FromAPIObject(value); } -PossibleValueSet MediumLevelILFunction::GetPossibleStackContentsAfterInstruction(int32_t offset, size_t len, size_t instr) +PossibleValueSet MediumLevelILFunction::GetPossibleStackContentsAfterInstruction(int32_t offset, size_t len, size_t instr, + const set<BNDataFlowQueryOption>& options) { - BNPossibleValueSet value = BNGetMediumLevelILPossibleStackContentsAfterInstruction(m_object, offset, len, instr); + BNDataFlowQueryOption* optionArray = new BNDataFlowQueryOption[options.size()]; + size_t idx = 0; + for (auto i : options) + optionArray[idx++] = i; + BNPossibleValueSet value = BNGetMediumLevelILPossibleStackContentsAfterInstruction(m_object, offset, len, instr, + optionArray, options.size()); + delete[] optionArray; return PossibleValueSet::FromAPIObject(value); } diff --git a/python/lowlevelil.py b/python/lowlevelil.py index 5f71b80c..da5d5bb5 100644 --- a/python/lowlevelil.py +++ b/python/lowlevelil.py @@ -909,7 +909,7 @@ class LowLevelILInstruction(object): @property def possible_values(self): """Possible values of expression using path-sensitive static data flow analysis (read-only)""" - value = core.BNGetLowLevelILPossibleExprValues(self._function.handle, self.expr_index) + value = core.BNGetLowLevelILPossibleExprValues(self._function.handle, self.expr_index, None, 0) result = binaryninja.function.PossibleValueSet(self._function.arch, value) core.BNFreePossibleValueSet(value) return result @@ -937,6 +937,17 @@ class LowLevelILInstruction(object): result.append(LowLevelILOperationAndSize(self._operation, self._size)) return result + def get_possible_values(self, options = []): + option_array = (ctypes.c_int * len(options))() + idx = 0 + for option in options: + option_array[idx] = option + idx += 1 + value = core.BNGetLowLevelILPossibleExprValues(self._function.handle, self.expr_index, option_array, len(options)) + result = binaryninja.function.PossibleValueSet(self._function.arch, value) + core.BNFreePossibleValueSet(value) + return result + def get_reg_value(self, reg): reg = self._function.arch.get_reg_index(reg) value = core.BNGetLowLevelILRegisterValueAtInstruction(self._function.handle, reg, self._instr_index) @@ -949,16 +960,28 @@ class LowLevelILInstruction(object): result = binaryninja.function.RegisterValue(self._function.arch, value) return result - def get_possible_reg_values(self, reg): + def get_possible_reg_values(self, reg, options = []): reg = self._function.arch.get_reg_index(reg) - value = core.BNGetLowLevelILPossibleRegisterValuesAtInstruction(self._function.handle, reg, self._instr_index) + option_array = (ctypes.c_int * len(options))() + idx = 0 + for option in options: + option_array[idx] = option + idx += 1 + value = core.BNGetLowLevelILPossibleRegisterValuesAtInstruction(self._function.handle, reg, self._instr_index, + option_array, len(options)) result = binaryninja.function.PossibleValueSet(self._function.arch, value) core.BNFreePossibleValueSet(value) return result - def get_possible_reg_values_after(self, reg): + def get_possible_reg_values_after(self, reg, options = []): reg = self._function.arch.get_reg_index(reg) - value = core.BNGetLowLevelILPossibleRegisterValuesAfterInstruction(self._function.handle, reg, self._instr_index) + option_array = (ctypes.c_int * len(options))() + idx = 0 + for option in options: + option_array[idx] = option + idx += 1 + value = core.BNGetLowLevelILPossibleRegisterValuesAfterInstruction(self._function.handle, reg, self._instr_index, + option_array, len(options)) result = binaryninja.function.PossibleValueSet(self._function.arch, value) core.BNFreePossibleValueSet(value) return result @@ -975,16 +998,28 @@ class LowLevelILInstruction(object): result = binaryninja.function.RegisterValue(self._function.arch, value) return result - def get_possible_flag_values(self, flag): + def get_possible_flag_values(self, flag, options = []): flag = self._function.arch.get_flag_index(flag) - value = core.BNGetLowLevelILPossibleFlagValuesAtInstruction(self._function.handle, flag, self._instr_index) + option_array = (ctypes.c_int * len(options))() + idx = 0 + for option in options: + option_array[idx] = option + idx += 1 + value = core.BNGetLowLevelILPossibleFlagValuesAtInstruction(self._function.handle, flag, self._instr_index, + option_array, len(options)) result = binaryninja.function.PossibleValueSet(self._function.arch, value) core.BNFreePossibleValueSet(value) return result - def get_possible_flag_values_after(self, flag): + def get_possible_flag_values_after(self, flag, options = []): flag = self._function.arch.get_flag_index(flag) - value = core.BNGetLowLevelILPossibleFlagValuesAfterInstruction(self._function.handle, flag, self._instr_index) + option_array = (ctypes.c_int * len(options))() + idx = 0 + for option in options: + option_array[idx] = option + idx += 1 + value = core.BNGetLowLevelILPossibleFlagValuesAfterInstruction(self._function.handle, flag, self._instr_index, + option_array, len(options)) result = binaryninja.function.PossibleValueSet(self._function.arch, value) core.BNFreePossibleValueSet(value) return result @@ -999,14 +1034,26 @@ class LowLevelILInstruction(object): result = binaryninja.function.RegisterValue(self._function.arch, value) return result - def get_possible_stack_contents(self, offset, size): - value = core.BNGetLowLevelILPossibleStackContentsAtInstruction(self._function.handle, offset, size, self._instr_index) + def get_possible_stack_contents(self, offset, size, options = []): + option_array = (ctypes.c_int * len(options))() + idx = 0 + for option in options: + option_array[idx] = option + idx += 1 + value = core.BNGetLowLevelILPossibleStackContentsAtInstruction(self._function.handle, offset, size, self._instr_index, + option_array, len(options)) result = binaryninja.function.PossibleValueSet(self._function.arch, value) core.BNFreePossibleValueSet(value) return result - def get_possible_stack_contents_after(self, offset, size): - value = core.BNGetLowLevelILPossibleStackContentsAfterInstruction(self._function.handle, offset, size, self._instr_index) + def get_possible_stack_contents_after(self, offset, size, options = []): + option_array = (ctypes.c_int * len(options))() + idx = 0 + for option in options: + option_array[idx] = option + idx += 1 + value = core.BNGetLowLevelILPossibleStackContentsAfterInstruction(self._function.handle, offset, size, self._instr_index, + option_array, len(options)) result = binaryninja.function.PossibleValueSet(self._function.arch, value) core.BNFreePossibleValueSet(value) return result diff --git a/python/mediumlevelil.py b/python/mediumlevelil.py index 24b87ac7..812914cb 100644 --- a/python/mediumlevelil.py +++ b/python/mediumlevelil.py @@ -24,7 +24,7 @@ import struct # Binary Ninja components import binaryninja from binaryninja import _binaryninjacore as core -from binaryninja.enums import MediumLevelILOperation, InstructionTextTokenType, ILBranchDependence +from binaryninja.enums import MediumLevelILOperation, InstructionTextTokenType, ILBranchDependence, DataFlowQueryOption from binaryninja import basicblock #required for MediumLevelILBasicBlock argument from binaryninja import function from binaryninja import types @@ -434,7 +434,7 @@ class MediumLevelILInstruction(object): @property def possible_values(self): """Possible values of expression using path-sensitive static data flow analysis (read-only)""" - value = core.BNGetMediumLevelILPossibleExprValues(self._function.handle, self._expr_index) + value = core.BNGetMediumLevelILPossibleExprValues(self._function.handle, self._expr_index, None, 0) result = function.PossibleValueSet(self._function.arch, value) core.BNFreePossibleValueSet(value) return result @@ -555,12 +555,29 @@ class MediumLevelILInstruction(object): return types.Type(result.type, platform = platform, confidence = result.confidence) return None - def get_ssa_var_possible_values(self, ssa_var): + def get_possible_values(self, options = []): + option_array = (ctypes.c_int * len(options))() + idx = 0 + for option in options: + option_array[idx] = option + idx += 1 + value = core.BNGetMediumLevelILPossibleExprValues(self._function.handle, self._expr_index, option_array, len(options)) + result = function.PossibleValueSet(self._function.arch, value) + core.BNFreePossibleValueSet(value) + return result + + def get_ssa_var_possible_values(self, ssa_var, options = []): var_data = core.BNVariable() var_data.type = ssa_var.var.source_type var_data.index = ssa_var.var.index var_data.storage = ssa_var.var.storage - value = core.BNGetMediumLevelILPossibleSSAVarValues(self._function.handle, var_data, ssa_var.version, self._instr_index) + option_array = (ctypes.c_int * len(options))() + idx = 0 + for option in options: + option_array[idx] = option + idx += 1 + value = core.BNGetMediumLevelILPossibleSSAVarValues(self._function.handle, var_data, ssa_var.version, + self._instr_index, option_array, len(options)) result = function.PossibleValueSet(self._function.arch, value) core.BNFreePossibleValueSet(value) return result @@ -598,16 +615,28 @@ class MediumLevelILInstruction(object): result = function.RegisterValue(self._function.arch, value) return result - def get_possible_reg_values(self, reg): + def get_possible_reg_values(self, reg, options = []): reg = self._function.arch.get_reg_index(reg) - value = core.BNGetMediumLevelILPossibleRegisterValuesAtInstruction(self._function.handle, reg, self._instr_index) + option_array = (ctypes.c_int * len(options))() + idx = 0 + for option in options: + option_array[idx] = option + idx += 1 + value = core.BNGetMediumLevelILPossibleRegisterValuesAtInstruction(self._function.handle, reg, self._instr_index, + option_array, len(options)) result = function.PossibleValueSet(self._function.arch, value) core.BNFreePossibleValueSet(value) return result - def get_possible_reg_values_after(self, reg): + def get_possible_reg_values_after(self, reg, options = []): reg = self._function.arch.get_reg_index(reg) - value = core.BNGetMediumLevelILPossibleRegisterValuesAfterInstruction(self._function.handle, reg, self._instr_index) + option_array = (ctypes.c_int * len(options))() + idx = 0 + for option in options: + option_array[idx] = option + idx += 1 + value = core.BNGetMediumLevelILPossibleRegisterValuesAfterInstruction(self._function.handle, reg, self._instr_index, + option_array, len(options)) result = function.PossibleValueSet(self._function.arch, value) core.BNFreePossibleValueSet(value) return result @@ -624,16 +653,28 @@ class MediumLevelILInstruction(object): result = function.RegisterValue(self._function.arch, value) return result - def get_possible_flag_values(self, flag): + def get_possible_flag_values(self, flag, options = []): flag = self._function.arch.get_flag_index(flag) - value = core.BNGetMediumLevelILPossibleFlagValuesAtInstruction(self._function.handle, flag, self._instr_index) + option_array = (ctypes.c_int * len(options))() + idx = 0 + for option in options: + option_array[idx] = option + idx += 1 + value = core.BNGetMediumLevelILPossibleFlagValuesAtInstruction(self._function.handle, flag, self._instr_index, + option_array, len(options)) result = function.PossibleValueSet(self._function.arch, value) core.BNFreePossibleValueSet(value) return result - def get_possible_flag_values_after(self, flag): + def get_possible_flag_values_after(self, flag, options = []): flag = self._function.arch.get_flag_index(flag) - value = core.BNGetMediumLevelILPossibleFlagValuesAfterInstruction(self._function.handle, flag, self._instr_index) + option_array = (ctypes.c_int * len(options))() + idx = 0 + for option in options: + option_array[idx] = option + idx += 1 + value = core.BNGetMediumLevelILPossibleFlagValuesAfterInstruction(self._function.handle, flag, self._instr_index, + option_array, len(options)) result = function.PossibleValueSet(self._function.arch, value) core.BNFreePossibleValueSet(value) return result @@ -648,14 +689,26 @@ class MediumLevelILInstruction(object): result = function.RegisterValue(self._function.arch, value) return result - def get_possible_stack_contents(self, offset, size): - value = core.BNGetMediumLevelILPossibleStackContentsAtInstruction(self._function.handle, offset, size, self._instr_index) + def get_possible_stack_contents(self, offset, size, options = []): + option_array = (ctypes.c_int * len(options))() + idx = 0 + for option in options: + option_array[idx] = option + idx += 1 + value = core.BNGetMediumLevelILPossibleStackContentsAtInstruction(self._function.handle, offset, size, self._instr_index, + option_array, len(options)) result = function.PossibleValueSet(self._function.arch, value) core.BNFreePossibleValueSet(value) return result - def get_possible_stack_contents_after(self, offset, size): - value = core.BNGetMediumLevelILPossibleStackContentsAfterInstruction(self._function.handle, offset, size, self._instr_index) + def get_possible_stack_contents_after(self, offset, size, options = []): + option_array = (ctypes.c_int * len(options))() + idx = 0 + for option in options: + option_array[idx] = option + idx += 1 + value = core.BNGetMediumLevelILPossibleStackContentsAfterInstruction(self._function.handle, offset, size, self._instr_index, + option_array, len(options)) result = function.PossibleValueSet(self._function.arch, value) core.BNFreePossibleValueSet(value) return result |
