summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRusty Wagner <rusty@vector35.com>2017-03-16 03:41:04 -0400
committerRusty Wagner <rusty@vector35.com>2017-03-16 03:41:04 -0400
commitcec08b6240f775a831226d9f36ee7f96b369f285 (patch)
tree2819780c8bac73dbea15a96e313c58936885f70b
parentda77a3011450e694a506c8d16ef084a28bc58214 (diff)
Adding APIs to query register and stack contents from IL
-rw-r--r--binaryninjaapi.h34
-rw-r--r--binaryninjacore.h63
-rw-r--r--function.cpp28
-rw-r--r--lowlevelil.cpp91
-rw-r--r--mediumlevelil.cpp102
-rw-r--r--python/function.py42
-rw-r--r--python/lowlevelil.py98
-rw-r--r--python/mediumlevelil.py149
8 files changed, 503 insertions, 104 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index 3f39c827..131d6a17 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -1894,12 +1894,8 @@ namespace BinaryNinja
std::vector<size_t> GetLowLevelILExitsForInstruction(Architecture* arch, uint64_t addr);
RegisterValue GetRegisterValueAtInstruction(Architecture* arch, uint64_t addr, uint32_t reg);
RegisterValue GetRegisterValueAfterInstruction(Architecture* arch, uint64_t addr, uint32_t reg);
- RegisterValue GetRegisterValueAtLowLevelILInstruction(size_t i, uint32_t reg);
- RegisterValue GetRegisterValueAfterLowLevelILInstruction(size_t i, uint32_t reg);
RegisterValue GetStackContentsAtInstruction(Architecture* arch, uint64_t addr, int64_t offset, size_t size);
RegisterValue GetStackContentsAfterInstruction(Architecture* arch, uint64_t addr, int64_t offset, size_t size);
- RegisterValue GetStackContentsAtLowLevelILInstruction(size_t i, int64_t offset, size_t size);
- RegisterValue GetStackContentsAfterLowLevelILInstruction(size_t i, int64_t offset, size_t size);
RegisterValue GetParameterValueAtInstruction(Architecture* arch, uint64_t addr, Type* functionType, size_t i);
RegisterValue GetParameterValueAtLowLevelILInstruction(size_t instr, Type* functionType, size_t i);
std::vector<uint32_t> GetRegistersReadByInstruction(Architecture* arch, uint64_t addr);
@@ -2183,6 +2179,20 @@ namespace BinaryNinja
RegisterValue GetSSAFlagValue(uint32_t flag, size_t idx);
RegisterValue GetExprValue(size_t expr);
+ RegisterValue GetPossibleExprValues(size_t expr);
+
+ RegisterValue GetRegisterValueAtInstruction(uint32_t reg, size_t instr);
+ RegisterValue GetRegisterValueAfterInstruction(uint32_t reg, size_t instr);
+ RegisterValue GetPossibleRegisterValuesAtInstruction(uint32_t reg, size_t instr);
+ RegisterValue GetPossibleRegisterValuesAfterInstruction(uint32_t reg, size_t instr);
+ RegisterValue GetFlagValueAtInstruction(uint32_t flag, size_t instr);
+ RegisterValue GetFlagValueAfterInstruction(uint32_t flag, size_t instr);
+ RegisterValue GetPossibleFlagValuesAtInstruction(uint32_t flag, size_t instr);
+ RegisterValue GetPossibleFlagValuesAfterInstruction(uint32_t flag, size_t instr);
+ RegisterValue GetStackContentsAtInstruction(int32_t offset, size_t len, size_t instr);
+ RegisterValue GetStackContentsAfterInstruction(int32_t offset, size_t len, size_t instr);
+ RegisterValue GetPossibleStackContentsAtInstruction(int32_t offset, size_t len, size_t instr);
+ RegisterValue GetPossibleStackContentsAfterInstruction(int32_t offset, size_t len, size_t instr);
Ref<MediumLevelILFunction> GetMediumLevelIL() const;
Ref<MediumLevelILFunction> GetMappedMediumLevelIL() const;
@@ -2272,6 +2282,22 @@ namespace BinaryNinja
size_t GetSSAVarIndexAtInstruction(const BNILVariable& var, size_t instr) const;
size_t GetSSAMemoryIndexAtInstruction(size_t instr) const;
+ BNILVariable GetVariableForRegisterAtInstruction(uint32_t reg, size_t instr) const;
+ BNILVariable GetVariableForFlagAtInstruction(uint32_t flag, size_t instr) const;
+ BNILVariable GetVariableForStackLocationAtInstruction(int64_t offset, size_t instr) const;
+
+ RegisterValue GetRegisterValueAtInstruction(uint32_t reg, size_t instr);
+ RegisterValue GetRegisterValueAfterInstruction(uint32_t reg, size_t instr);
+ RegisterValue GetPossibleRegisterValuesAtInstruction(uint32_t reg, size_t instr);
+ RegisterValue GetPossibleRegisterValuesAfterInstruction(uint32_t reg, size_t instr);
+ RegisterValue GetFlagValueAtInstruction(uint32_t flag, size_t instr);
+ RegisterValue GetFlagValueAfterInstruction(uint32_t flag, size_t instr);
+ RegisterValue GetPossibleFlagValuesAtInstruction(uint32_t flag, size_t instr);
+ RegisterValue GetPossibleFlagValuesAfterInstruction(uint32_t flag, size_t instr);
+ RegisterValue GetStackContentsAtInstruction(int32_t offset, size_t len, size_t instr);
+ RegisterValue GetStackContentsAfterInstruction(int32_t offset, size_t len, size_t instr);
+ RegisterValue GetPossibleStackContentsAtInstruction(int32_t offset, size_t len, size_t instr);
+ RegisterValue GetPossibleStackContentsAfterInstruction(int32_t offset, size_t len, size_t instr);
BNILBranchDependence GetBranchDependenceAtInstruction(size_t curInstr, size_t branchInstr) const;
std::map<size_t, BNILBranchDependence> GetAllBranchDependenceAtInstruction(size_t instr) const;
diff --git a/binaryninjacore.h b/binaryninjacore.h
index 4905a73c..eaba1a51 100644
--- a/binaryninjacore.h
+++ b/binaryninjacore.h
@@ -1848,16 +1848,10 @@ extern "C"
uint64_t addr, uint32_t reg);
BINARYNINJACOREAPI BNRegisterValue BNGetRegisterValueAfterInstruction(BNFunction* func, BNArchitecture* arch,
uint64_t addr, uint32_t reg);
- BINARYNINJACOREAPI BNRegisterValue BNGetRegisterValueAtLowLevelILInstruction(BNFunction* func, size_t i, uint32_t reg);
- BINARYNINJACOREAPI BNRegisterValue BNGetRegisterValueAfterLowLevelILInstruction(BNFunction* func, size_t i, uint32_t reg);
BINARYNINJACOREAPI BNRegisterValue BNGetStackContentsAtInstruction(BNFunction* func, BNArchitecture* arch,
uint64_t addr, int64_t offset, size_t size);
BINARYNINJACOREAPI BNRegisterValue BNGetStackContentsAfterInstruction(BNFunction* func, BNArchitecture* arch,
uint64_t addr, int64_t offset, size_t size);
- BINARYNINJACOREAPI BNRegisterValue BNGetStackContentsAtLowLevelILInstruction(BNFunction* func, size_t i,
- int64_t offset, size_t size);
- BINARYNINJACOREAPI BNRegisterValue BNGetStackContentsAfterLowLevelILInstruction(BNFunction* func, size_t i,
- int64_t offset, size_t size);
BINARYNINJACOREAPI BNRegisterValue BNGetParameterValueAtInstruction(BNFunction* func, BNArchitecture* arch,
uint64_t addr, BNType* functionType, size_t i);
BINARYNINJACOREAPI BNRegisterValue BNGetParameterValueAtLowLevelILInstruction(BNFunction* func, size_t instr,
@@ -2186,6 +2180,32 @@ extern "C"
uint32_t flag, size_t idx);
BINARYNINJACOREAPI BNRegisterValue BNGetLowLevelILExprValue(BNLowLevelILFunction* func, size_t expr);
+ BINARYNINJACOREAPI BNRegisterValue BNGetLowLevelILPossibleExprValues(BNLowLevelILFunction* func, size_t expr);
+
+ BINARYNINJACOREAPI BNRegisterValue BNGetLowLevelILRegisterValueAtInstruction(BNLowLevelILFunction* func,
+ uint32_t reg, size_t instr);
+ BINARYNINJACOREAPI BNRegisterValue BNGetLowLevelILRegisterValueAfterInstruction(BNLowLevelILFunction* func,
+ uint32_t reg, size_t instr);
+ BINARYNINJACOREAPI BNRegisterValue BNGetLowLevelILPossibleRegisterValuesAtInstruction(BNLowLevelILFunction* func,
+ uint32_t reg, size_t instr);
+ BINARYNINJACOREAPI BNRegisterValue BNGetLowLevelILPossibleRegisterValuesAfterInstruction(BNLowLevelILFunction* func,
+ uint32_t reg, size_t instr);
+ BINARYNINJACOREAPI BNRegisterValue BNGetLowLevelILFlagValueAtInstruction(BNLowLevelILFunction* func,
+ uint32_t flag, size_t instr);
+ BINARYNINJACOREAPI BNRegisterValue BNGetLowLevelILFlagValueAfterInstruction(BNLowLevelILFunction* func,
+ uint32_t flag, size_t instr);
+ BINARYNINJACOREAPI BNRegisterValue BNGetLowLevelILPossibleFlagValuesAtInstruction(BNLowLevelILFunction* func,
+ uint32_t flag, size_t instr);
+ BINARYNINJACOREAPI BNRegisterValue BNGetLowLevelILPossibleFlagValuesAfterInstruction(BNLowLevelILFunction* func,
+ uint32_t flag, size_t instr);
+ 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 BNRegisterValue BNGetLowLevelILPossibleStackContentsAtInstruction(BNLowLevelILFunction* func,
+ int64_t offset, size_t len, size_t instr);
+ BINARYNINJACOREAPI BNRegisterValue BNGetLowLevelILPossibleStackContentsAfterInstruction(BNLowLevelILFunction* func,
+ int64_t offset, size_t len, size_t instr);
BINARYNINJACOREAPI BNMediumLevelILFunction* BNGetMediumLevelILForLowLevelIL(BNLowLevelILFunction* func);
BINARYNINJACOREAPI BNMediumLevelILFunction* BNGetMappedMediumLevelIL(BNLowLevelILFunction* func);
@@ -2258,6 +2278,37 @@ extern "C"
const BNILVariable* var, size_t instr);
BINARYNINJACOREAPI size_t BNGetMediumLevelILSSAMemoryIndexAtILInstruction(BNMediumLevelILFunction* func,
size_t instr);
+ BINARYNINJACOREAPI BNILVariable BNGetMediumLevelILVariableForRegisterAtInstruction(BNMediumLevelILFunction* func,
+ uint32_t reg, size_t instr);
+ BINARYNINJACOREAPI BNILVariable BNGetMediumLevelILVariableForFlagAtInstruction(BNMediumLevelILFunction* func,
+ uint32_t flag, size_t instr);
+ BINARYNINJACOREAPI BNILVariable BNGetMediumLevelILVariableForStackLocationAtInstruction(BNMediumLevelILFunction* func,
+ int64_t offset, size_t instr);
+
+ BINARYNINJACOREAPI BNRegisterValue BNGetMediumLevelILRegisterValueAtInstruction(BNMediumLevelILFunction* func,
+ uint32_t reg, size_t instr);
+ BINARYNINJACOREAPI BNRegisterValue BNGetMediumLevelILRegisterValueAfterInstruction(BNMediumLevelILFunction* func,
+ uint32_t reg, size_t instr);
+ BINARYNINJACOREAPI BNRegisterValue BNGetMediumLevelILPossibleRegisterValuesAtInstruction(BNMediumLevelILFunction* func,
+ uint32_t reg, size_t instr);
+ BINARYNINJACOREAPI BNRegisterValue BNGetMediumLevelILPossibleRegisterValuesAfterInstruction(BNMediumLevelILFunction* func,
+ uint32_t reg, size_t instr);
+ BINARYNINJACOREAPI BNRegisterValue BNGetMediumLevelILFlagValueAtInstruction(BNMediumLevelILFunction* func,
+ uint32_t flag, size_t instr);
+ BINARYNINJACOREAPI BNRegisterValue BNGetMediumLevelILFlagValueAfterInstruction(BNMediumLevelILFunction* func,
+ uint32_t flag, size_t instr);
+ BINARYNINJACOREAPI BNRegisterValue BNGetMediumLevelILPossibleFlagValuesAtInstruction(BNMediumLevelILFunction* func,
+ uint32_t flag, size_t instr);
+ BINARYNINJACOREAPI BNRegisterValue BNGetMediumLevelILPossibleFlagValuesAfterInstruction(BNMediumLevelILFunction* func,
+ uint32_t flag, size_t instr);
+ 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 BNRegisterValue BNGetMediumLevelILPossibleStackContentsAtInstruction(BNMediumLevelILFunction* func,
+ int64_t offset, size_t len, size_t instr);
+ BINARYNINJACOREAPI BNRegisterValue BNGetMediumLevelILPossibleStackContentsAfterInstruction(BNMediumLevelILFunction* func,
+ int64_t offset, size_t len, size_t instr);
BINARYNINJACOREAPI BNILBranchDependence BNGetMediumLevelILBranchDependence(BNMediumLevelILFunction* func,
size_t curInstr, size_t branchInstr);
diff --git a/function.cpp b/function.cpp
index 9faf68fa..aa56f7af 100644
--- a/function.cpp
+++ b/function.cpp
@@ -205,20 +205,6 @@ RegisterValue Function::GetRegisterValueAfterInstruction(Architecture* arch, uin
}
-RegisterValue Function::GetRegisterValueAtLowLevelILInstruction(size_t i, uint32_t reg)
-{
- BNRegisterValue value = BNGetRegisterValueAtLowLevelILInstruction(m_object, i, reg);
- return RegisterValue::FromAPIObject(value);
-}
-
-
-RegisterValue Function::GetRegisterValueAfterLowLevelILInstruction(size_t i, uint32_t reg)
-{
- BNRegisterValue value = BNGetRegisterValueAfterLowLevelILInstruction(m_object, i, reg);
- return RegisterValue::FromAPIObject(value);
-}
-
-
RegisterValue Function::GetStackContentsAtInstruction(Architecture* arch, uint64_t addr, int64_t offset, size_t size)
{
BNRegisterValue value = BNGetStackContentsAtInstruction(m_object, arch->GetObject(), addr, offset, size);
@@ -233,20 +219,6 @@ RegisterValue Function::GetStackContentsAfterInstruction(Architecture* arch, uin
}
-RegisterValue Function::GetStackContentsAtLowLevelILInstruction(size_t i, int64_t offset, size_t size)
-{
- BNRegisterValue value = BNGetStackContentsAtLowLevelILInstruction(m_object, i, offset, size);
- return RegisterValue::FromAPIObject(value);
-}
-
-
-RegisterValue Function::GetStackContentsAfterLowLevelILInstruction(size_t i, int64_t offset, size_t size)
-{
- BNRegisterValue value = BNGetStackContentsAfterLowLevelILInstruction(m_object, i, offset, size);
- return RegisterValue::FromAPIObject(value);
-}
-
-
RegisterValue Function::GetParameterValueAtInstruction(Architecture* arch, uint64_t addr, Type* functionType, size_t i)
{
BNRegisterValue value = BNGetParameterValueAtInstruction(m_object, arch->GetObject(), addr,
diff --git a/lowlevelil.cpp b/lowlevelil.cpp
index bd038b6e..54e26498 100644
--- a/lowlevelil.cpp
+++ b/lowlevelil.cpp
@@ -780,6 +780,97 @@ RegisterValue LowLevelILFunction::GetExprValue(size_t expr)
}
+RegisterValue LowLevelILFunction::GetPossibleExprValues(size_t expr)
+{
+ BNRegisterValue value = BNGetLowLevelILPossibleExprValues(m_object, expr);
+ return RegisterValue::FromAPIObject(value);
+}
+
+
+RegisterValue LowLevelILFunction::GetRegisterValueAtInstruction(uint32_t reg, size_t instr)
+{
+ BNRegisterValue value = BNGetLowLevelILRegisterValueAtInstruction(m_object, reg, instr);
+ return RegisterValue::FromAPIObject(value);
+}
+
+
+RegisterValue LowLevelILFunction::GetRegisterValueAfterInstruction(uint32_t reg, size_t instr)
+{
+ BNRegisterValue value = BNGetLowLevelILRegisterValueAfterInstruction(m_object, reg, instr);
+ return RegisterValue::FromAPIObject(value);
+}
+
+
+RegisterValue LowLevelILFunction::GetPossibleRegisterValuesAtInstruction(uint32_t reg, size_t instr)
+{
+ BNRegisterValue value = BNGetLowLevelILPossibleRegisterValuesAtInstruction(m_object, reg, instr);
+ return RegisterValue::FromAPIObject(value);
+}
+
+
+RegisterValue LowLevelILFunction::GetPossibleRegisterValuesAfterInstruction(uint32_t reg, size_t instr)
+{
+ BNRegisterValue value = BNGetLowLevelILPossibleRegisterValuesAfterInstruction(m_object, reg, instr);
+ return RegisterValue::FromAPIObject(value);
+}
+
+
+RegisterValue LowLevelILFunction::GetFlagValueAtInstruction(uint32_t flag, size_t instr)
+{
+ BNRegisterValue value = BNGetLowLevelILFlagValueAtInstruction(m_object, flag, instr);
+ return RegisterValue::FromAPIObject(value);
+}
+
+
+RegisterValue LowLevelILFunction::GetFlagValueAfterInstruction(uint32_t flag, size_t instr)
+{
+ BNRegisterValue value = BNGetLowLevelILFlagValueAfterInstruction(m_object, flag, instr);
+ return RegisterValue::FromAPIObject(value);
+}
+
+
+RegisterValue LowLevelILFunction::GetPossibleFlagValuesAtInstruction(uint32_t flag, size_t instr)
+{
+ BNRegisterValue value = BNGetLowLevelILPossibleFlagValuesAtInstruction(m_object, flag, instr);
+ return RegisterValue::FromAPIObject(value);
+}
+
+
+RegisterValue LowLevelILFunction::GetPossibleFlagValuesAfterInstruction(uint32_t flag, size_t instr)
+{
+ BNRegisterValue value = BNGetLowLevelILPossibleFlagValuesAfterInstruction(m_object, flag, instr);
+ return RegisterValue::FromAPIObject(value);
+}
+
+
+RegisterValue LowLevelILFunction::GetStackContentsAtInstruction(int32_t offset, size_t len, size_t instr)
+{
+ BNRegisterValue value = BNGetLowLevelILStackContentsAtInstruction(m_object, offset, len, instr);
+ return RegisterValue::FromAPIObject(value);
+}
+
+
+RegisterValue LowLevelILFunction::GetStackContentsAfterInstruction(int32_t offset, size_t len, size_t instr)
+{
+ BNRegisterValue value = BNGetLowLevelILStackContentsAfterInstruction(m_object, offset, len, instr);
+ return RegisterValue::FromAPIObject(value);
+}
+
+
+RegisterValue LowLevelILFunction::GetPossibleStackContentsAtInstruction(int32_t offset, size_t len, size_t instr)
+{
+ BNRegisterValue value = BNGetLowLevelILPossibleStackContentsAtInstruction(m_object, offset, len, instr);
+ return RegisterValue::FromAPIObject(value);
+}
+
+
+RegisterValue LowLevelILFunction::GetPossibleStackContentsAfterInstruction(int32_t offset, size_t len, size_t instr)
+{
+ BNRegisterValue value = BNGetLowLevelILPossibleStackContentsAfterInstruction(m_object, offset, len, instr);
+ return RegisterValue::FromAPIObject(value);
+}
+
+
Ref<MediumLevelILFunction> LowLevelILFunction::GetMediumLevelIL() const
{
BNMediumLevelILFunction* func = BNGetMediumLevelILForLowLevelIL(m_object);
diff --git a/mediumlevelil.cpp b/mediumlevelil.cpp
index 51dd067d..bb629e64 100644
--- a/mediumlevelil.cpp
+++ b/mediumlevelil.cpp
@@ -476,6 +476,108 @@ size_t MediumLevelILFunction::GetSSAMemoryIndexAtInstruction(size_t instr) const
}
+BNILVariable MediumLevelILFunction::GetVariableForRegisterAtInstruction(uint32_t reg, size_t instr) const
+{
+ return BNGetMediumLevelILVariableForRegisterAtInstruction(m_object, reg, instr);
+}
+
+
+BNILVariable MediumLevelILFunction::GetVariableForFlagAtInstruction(uint32_t flag, size_t instr) const
+{
+ return BNGetMediumLevelILVariableForFlagAtInstruction(m_object, flag, instr);
+}
+
+
+BNILVariable MediumLevelILFunction::GetVariableForStackLocationAtInstruction(int64_t offset, size_t instr) const
+{
+ return BNGetMediumLevelILVariableForStackLocationAtInstruction(m_object, offset, instr);
+}
+
+
+RegisterValue MediumLevelILFunction::GetRegisterValueAtInstruction(uint32_t reg, size_t instr)
+{
+ BNRegisterValue value = BNGetMediumLevelILRegisterValueAtInstruction(m_object, reg, instr);
+ return RegisterValue::FromAPIObject(value);
+}
+
+
+RegisterValue MediumLevelILFunction::GetRegisterValueAfterInstruction(uint32_t reg, size_t instr)
+{
+ BNRegisterValue value = BNGetMediumLevelILRegisterValueAfterInstruction(m_object, reg, instr);
+ return RegisterValue::FromAPIObject(value);
+}
+
+
+RegisterValue MediumLevelILFunction::GetPossibleRegisterValuesAtInstruction(uint32_t reg, size_t instr)
+{
+ BNRegisterValue value = BNGetMediumLevelILPossibleRegisterValuesAtInstruction(m_object, reg, instr);
+ return RegisterValue::FromAPIObject(value);
+}
+
+
+RegisterValue MediumLevelILFunction::GetPossibleRegisterValuesAfterInstruction(uint32_t reg, size_t instr)
+{
+ BNRegisterValue value = BNGetMediumLevelILPossibleRegisterValuesAfterInstruction(m_object, reg, instr);
+ return RegisterValue::FromAPIObject(value);
+}
+
+
+RegisterValue MediumLevelILFunction::GetFlagValueAtInstruction(uint32_t flag, size_t instr)
+{
+ BNRegisterValue value = BNGetMediumLevelILFlagValueAtInstruction(m_object, flag, instr);
+ return RegisterValue::FromAPIObject(value);
+}
+
+
+RegisterValue MediumLevelILFunction::GetFlagValueAfterInstruction(uint32_t flag, size_t instr)
+{
+ BNRegisterValue value = BNGetMediumLevelILFlagValueAfterInstruction(m_object, flag, instr);
+ return RegisterValue::FromAPIObject(value);
+}
+
+
+RegisterValue MediumLevelILFunction::GetPossibleFlagValuesAtInstruction(uint32_t flag, size_t instr)
+{
+ BNRegisterValue value = BNGetMediumLevelILPossibleFlagValuesAtInstruction(m_object, flag, instr);
+ return RegisterValue::FromAPIObject(value);
+}
+
+
+RegisterValue MediumLevelILFunction::GetPossibleFlagValuesAfterInstruction(uint32_t flag, size_t instr)
+{
+ BNRegisterValue value = BNGetMediumLevelILPossibleFlagValuesAfterInstruction(m_object, flag, instr);
+ return RegisterValue::FromAPIObject(value);
+}
+
+
+RegisterValue MediumLevelILFunction::GetStackContentsAtInstruction(int32_t offset, size_t len, size_t instr)
+{
+ BNRegisterValue value = BNGetMediumLevelILStackContentsAtInstruction(m_object, offset, len, instr);
+ return RegisterValue::FromAPIObject(value);
+}
+
+
+RegisterValue MediumLevelILFunction::GetStackContentsAfterInstruction(int32_t offset, size_t len, size_t instr)
+{
+ BNRegisterValue value = BNGetMediumLevelILStackContentsAfterInstruction(m_object, offset, len, instr);
+ return RegisterValue::FromAPIObject(value);
+}
+
+
+RegisterValue MediumLevelILFunction::GetPossibleStackContentsAtInstruction(int32_t offset, size_t len, size_t instr)
+{
+ BNRegisterValue value = BNGetMediumLevelILPossibleStackContentsAtInstruction(m_object, offset, len, instr);
+ return RegisterValue::FromAPIObject(value);
+}
+
+
+RegisterValue MediumLevelILFunction::GetPossibleStackContentsAfterInstruction(int32_t offset, size_t len, size_t instr)
+{
+ BNRegisterValue value = BNGetMediumLevelILPossibleStackContentsAfterInstruction(m_object, offset, len, instr);
+ return RegisterValue::FromAPIObject(value);
+}
+
+
BNILBranchDependence MediumLevelILFunction::GetBranchDependenceAtInstruction(size_t curInstr, size_t branchInstr) const
{
return BNGetMediumLevelILBranchDependence(m_object, curInstr, branchInstr);
diff --git a/python/function.py b/python/function.py
index ed2a537c..928597a7 100644
--- a/python/function.py
+++ b/python/function.py
@@ -459,36 +459,6 @@ class Function(object):
core.BNFreeRegisterValue(value)
return result
- def get_reg_value_at_low_level_il_instruction(self, i, reg, arch=None):
- """
- ``get_reg_value_at_low_level_il_instruction`` returns the value of the specified register ``reg`` at the il address
- i
-
- :param int i: il address of instruction to query
- :param Architecture arch: (optional) Architecture for the given function
- :rtype: function.RegisterValue
- :Example:
-
- >>> func.get_reg_value_at_low_level_il_instruction(15, 'rdi')
- <const 0x2>
- """
- if arch is None:
- arch = self.arch
- if isinstance(reg, str):
- reg = self.arch.regs[reg].index
- value = core.BNGetRegisterValueAtLowLevelILInstruction(self.handle, i, reg)
- result = RegisterValue(arch, value)
- core.BNFreeRegisterValue(value)
- return result
-
- def get_reg_value_after_low_level_il_instruction(self, i, reg):
- if isinstance(reg, str):
- reg = self.arch.regs[reg].index
- value = core.BNGetRegisterValueAfterLowLevelILInstruction(self.handle, i, reg)
- result = RegisterValue(self.arch, value)
- core.BNFreeRegisterValue(value)
- return result
-
def get_stack_contents_at(self, addr, offset, size, arch=None):
"""
``get_stack_contents_at`` returns the RegisterValue for the item on the stack in the current function at the
@@ -523,18 +493,6 @@ class Function(object):
core.BNFreeRegisterValue(value)
return result
- def get_stack_contents_at_low_level_il_instruction(self, i, offset, size):
- value = core.BNGetStackContentsAtLowLevelILInstruction(self.handle, i, offset, size)
- result = RegisterValue(self.arch, value)
- core.BNFreeRegisterValue(value)
- return result
-
- def get_stack_contents_after_low_level_il_instruction(self, i, offset, size):
- value = core.BNGetStackContentsAfterInstruction(self.handle, i, offset, size)
- result = RegisterValue(self.arch, value)
- core.BNFreeRegisterValue(value)
- return result
-
def get_parameter_at(self, addr, func_type, i, arch=None):
if arch is None:
arch = self.arch
diff --git a/python/lowlevelil.py b/python/lowlevelil.py
index 462d4ade..74b030d7 100644
--- a/python/lowlevelil.py
+++ b/python/lowlevelil.py
@@ -260,12 +260,108 @@ class LowLevelILInstruction(object):
@property
def value(self):
- """Value of expression using static data flow analysis (read-only)"""
+ """Value of expression if constant or a known value (read-only)"""
value = core.BNGetLowLevelILExprValue(self.function.handle, self.expr_index)
result = function.RegisterValue(self.function.arch, value)
core.BNFreeRegisterValue(value)
return result
+ @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)
+ result = function.RegisterValue(self.function.arch, value)
+ core.BNFreeRegisterValue(value)
+ return result
+
+ def get_reg_value(self, reg):
+ if isinstance(reg, str):
+ reg = self.function.arch.regs[reg].index
+ value = core.BNGetLowLevelILRegisterValueAtInstruction(self.function.handle, reg, self.instr_index)
+ result = function.RegisterValue(self.function.arch, value)
+ core.BNFreeRegisterValue(value)
+ return result
+
+ def get_reg_value_after(self, reg):
+ if isinstance(reg, str):
+ reg = self.function.arch.regs[reg].index
+ value = core.BNGetLowLevelILRegisterValueAfterInstruction(self.function.handle, reg, self.instr_index)
+ result = function.RegisterValue(self.function.arch, value)
+ core.BNFreeRegisterValue(value)
+ return result
+
+ def get_possible_reg_values(self, reg):
+ if isinstance(reg, str):
+ reg = self.function.arch.regs[reg].index
+ value = core.BNGetLowLevelILPossibleRegisterValuesAtInstruction(self.function.handle, reg, self.instr_index)
+ result = function.RegisterValue(self.function.arch, value)
+ core.BNFreeRegisterValue(value)
+ return result
+
+ def get_possible_reg_values_after(self, reg):
+ if isinstance(reg, str):
+ reg = self.function.arch.regs[reg].index
+ value = core.BNGetLowLevelILPossibleRegisterValuesAfterInstruction(self.function.handle, reg, self.instr_index)
+ result = function.RegisterValue(self.function.arch, value)
+ core.BNFreeRegisterValue(value)
+ return result
+
+ def get_flag_value(self, flag):
+ if isinstance(flag, str):
+ flag = self.function.arch.flags[flag].index
+ value = core.BNGetLowLevelILFlagValueAtInstruction(self.function.handle, flag, self.instr_index)
+ result = function.RegisterValue(self.function.arch, value)
+ core.BNFreeRegisterValue(value)
+ return result
+
+ def get_flag_value_after(self, flag):
+ if isinstance(flag, str):
+ flag = self.function.arch.flags[flag].index
+ value = core.BNGetLowLevelILFlagValueAfterInstruction(self.function.handle, flag, self.instr_index)
+ result = function.RegisterValue(self.function.arch, value)
+ core.BNFreeRegisterValue(value)
+ return result
+
+ def get_possible_flag_values(self, flag):
+ if isinstance(flag, str):
+ flag = self.function.arch.flags[flag].index
+ value = core.BNGetLowLevelILPossibleFlagValuesAtInstruction(self.function.handle, flag, self.instr_index)
+ result = function.RegisterValue(self.function.arch, value)
+ core.BNFreeRegisterValue(value)
+ return result
+
+ def get_possible_flag_values_after(self, flag):
+ if isinstance(flag, str):
+ flag = self.function.arch.flags[flag].index
+ value = core.BNGetLowLevelILPossibleFlagValuesAfterInstruction(self.function.handle, flag, self.instr_index)
+ result = function.RegisterValue(self.function.arch, value)
+ core.BNFreeRegisterValue(value)
+ return result
+
+ def get_stack_contents(self, offset, size):
+ value = core.BNGetLowLevelILStackContentsAtInstruction(self.function.handle, offset, size, self.instr_index)
+ result = function.RegisterValue(self.function.arch, value)
+ core.BNFreeRegisterValue(value)
+ return result
+
+ def get_stack_contents_after(self, offset, size):
+ value = core.BNGetLowLevelILStackContentsAfterInstruction(self.function.handle, offset, size, self.instr_index)
+ result = function.RegisterValue(self.function.arch, value)
+ core.BNFreeRegisterValue(value)
+ return result
+
+ def get_possible_stack_contents(self, offset, size):
+ value = core.BNGetLowLevelILPossibleStackContentsAtInstruction(self.function.handle, offset, size, self.instr_index)
+ result = function.RegisterValue(self.function.arch, value)
+ core.BNFreeRegisterValue(value)
+ return result
+
+ def get_possible_stack_contents_after(self, offset, size):
+ value = core.BNGetLowLevelILPossibleStackContentsAfterInstruction(self.function.handle, offset, size, self.instr_index)
+ result = function.RegisterValue(self.function.arch, value)
+ core.BNFreeRegisterValue(value)
+ return result
+
def __setattr__(self, name, value):
try:
object.__setattr__(self, name, value)
diff --git a/python/mediumlevelil.py b/python/mediumlevelil.py
index a63e1b31..6f482221 100644
--- a/python/mediumlevelil.py
+++ b/python/mediumlevelil.py
@@ -274,7 +274,13 @@ class MediumLevelILInstruction(object):
@property
def branch_dependence(self):
"""Set of branching instructions that must take the true or false path to reach this instruction"""
- return self.function.get_all_branch_dependence_at_instruction(self.instr_index)
+ count = ctypes.c_ulonglong()
+ deps = core.BNGetAllMediumLevelILBranchDependence(self.function.handle, self.instr_index, count)
+ result = {}
+ for i in xrange(0, count.value):
+ result[deps[i].branch] = ILBranchDependence(deps[i].dependence)
+ core.BNFreeILBranchDependenceList(deps)
+ return result
@property
def low_level_il(self):
@@ -284,6 +290,11 @@ class MediumLevelILInstruction(object):
return None
return lowlevelil.LowLevelILInstruction(self.function.low_level_il.ssa_form, expr)
+ @property
+ def ssa_memory_index(self):
+ """Index of active memory contents in SSA form for this instruction"""
+ return core.BNGetMediumLevelILSSAMemoryIndexAtILInstruction(self.function.handle, self.instr_index)
+
def get_ssa_var_possible_values(self, var, index):
var_data = core.BNILVariable()
var_data.type = var.type
@@ -294,6 +305,120 @@ class MediumLevelILInstruction(object):
core.BNFreeRegisterValue(value)
return result
+ def get_ssa_var_index(self, var):
+ var_data = core.BNILVariable()
+ var_data.type = var.type
+ var_data.index = var.index
+ var_data.identifier = var.identifier
+ return core.BNGetMediumLevelILSSAVarIndexAtILInstruction(self.function.handle, var_data, self.instr_index)
+
+ def get_var_for_reg(self, reg):
+ if isinstance(reg, str):
+ reg = self.function.arch.regs[reg].index
+ result = core.BNGetMediumLevelILVariableForRegisterAtInstruction(self.function.handle, reg, self.instr_index)
+ return function.ILVariable(self.function.source_function, result.type, result.index, result.identifier)
+
+ def get_var_for_flag(self, flag):
+ if isinstance(flag, str):
+ flag = self.function.arch.regs[flag].index
+ result = core.BNGetMediumLevelILVariableForFlagAtInstruction(self.function.handle, flag, self.instr_index)
+ return function.ILVariable(self.function.source_function, result.type, result.index, result.identifier)
+
+ def get_var_for_stack_location(self, offset):
+ result = core.BNGetMediumLevelILVariableForStackLocationAtInstruction(self.function.handle, offset, self.instr_index)
+ return function.ILVariable(self.function.source_function, result.type, result.index, result.identifier)
+
+ def get_reg_value(self, reg):
+ if isinstance(reg, str):
+ reg = self.function.arch.regs[reg].index
+ value = core.BNGetMediumLevelILRegisterValueAtInstruction(self.function.handle, reg, self.instr_index)
+ result = function.RegisterValue(self.function.arch, value)
+ core.BNFreeRegisterValue(value)
+ return result
+
+ def get_reg_value_after(self, reg):
+ if isinstance(reg, str):
+ reg = self.function.arch.regs[reg].index
+ value = core.BNGetMediumLevelILRegisterValueAfterInstruction(self.function.handle, reg, self.instr_index)
+ result = function.RegisterValue(self.function.arch, value)
+ core.BNFreeRegisterValue(value)
+ return result
+
+ def get_possible_reg_values(self, reg):
+ if isinstance(reg, str):
+ reg = self.function.arch.regs[reg].index
+ value = core.BNGetMediumLevelILPossibleRegisterValuesAtInstruction(self.function.handle, reg, self.instr_index)
+ result = function.RegisterValue(self.function.arch, value)
+ core.BNFreeRegisterValue(value)
+ return result
+
+ def get_possible_reg_values_after(self, reg):
+ if isinstance(reg, str):
+ reg = self.function.arch.regs[reg].index
+ value = core.BNGetMediumLevelILPossibleRegisterValuesAfterInstruction(self.function.handle, reg, self.instr_index)
+ result = function.RegisterValue(self.function.arch, value)
+ core.BNFreeRegisterValue(value)
+ return result
+
+ def get_flag_value(self, flag):
+ if isinstance(flag, str):
+ flag = self.function.arch.flags[flag].index
+ value = core.BNGetMediumLevelILFlagValueAtInstruction(self.function.handle, flag, self.instr_index)
+ result = function.RegisterValue(self.function.arch, value)
+ core.BNFreeRegisterValue(value)
+ return result
+
+ def get_flag_value_after(self, flag):
+ if isinstance(flag, str):
+ flag = self.function.arch.flags[flag].index
+ value = core.BNGetMediumLevelILFlagValueAfterInstruction(self.function.handle, flag, self.instr_index)
+ result = function.RegisterValue(self.function.arch, value)
+ core.BNFreeRegisterValue(value)
+ return result
+
+ def get_possible_flag_values(self, flag):
+ if isinstance(flag, str):
+ flag = self.function.arch.flags[flag].index
+ value = core.BNGetMediumLevelILPossibleFlagValuesAtInstruction(self.function.handle, flag, self.instr_index)
+ result = function.RegisterValue(self.function.arch, value)
+ core.BNFreeRegisterValue(value)
+ return result
+
+ def get_possible_flag_values_after(self, flag):
+ if isinstance(flag, str):
+ flag = self.function.arch.flags[flag].index
+ value = core.BNGetMediumLevelILPossibleFlagValuesAfterInstruction(self.function.handle, flag, self.instr_index)
+ result = function.RegisterValue(self.function.arch, value)
+ core.BNFreeRegisterValue(value)
+ return result
+
+ def get_stack_contents(self, offset, size):
+ value = core.BNGetMediumLevelILStackContentsAtInstruction(self.function.handle, offset, size, self.instr_index)
+ result = function.RegisterValue(self.function.arch, value)
+ core.BNFreeRegisterValue(value)
+ return result
+
+ def get_stack_contents_after(self, offset, size):
+ value = core.BNGetMediumLevelILStackContentsAfterInstruction(self.function.handle, offset, size, self.instr_index)
+ result = function.RegisterValue(self.function.arch, value)
+ core.BNFreeRegisterValue(value)
+ return result
+
+ def get_possible_stack_contents(self, offset, size):
+ value = core.BNGetMediumLevelILPossibleStackContentsAtInstruction(self.function.handle, offset, size, self.instr_index)
+ result = function.RegisterValue(self.function.arch, value)
+ core.BNFreeRegisterValue(value)
+ return result
+
+ def get_possible_stack_contents_after(self, offset, size):
+ value = core.BNGetMediumLevelILPossibleStackContentsAfterInstruction(self.function.handle, offset, size, self.instr_index)
+ result = function.RegisterValue(self.function.arch, value)
+ core.BNFreeRegisterValue(value)
+ return result
+
+ def get_branch_dependence(self, branch_instr):
+ return ILBranchDependence(core.BNGetMediumLevelILBranchDependence(self.function.handle, self.instr_index, branch_instr))
+
def __setattr__(self, name, value):
try:
object.__setattr__(self, name, value)
@@ -584,28 +709,6 @@ class MediumLevelILFunction(object):
core.BNFreeRegisterValue(value)
return result
- def get_ssa_var_index_at_instruction(self, var, instr):
- var_data = core.BNILVariable()
- var_data.type = var.type
- var_data.index = var.index
- var_data.identifier = var.identifier
- return core.BNGetMediumLevelILSSAVarIndexAtILInstruction(self.handle, var_data, instr)
-
- def get_ssa_memory_index_at_instruction(self, instr):
- return core.BNGetMediumLevelILSSAMemoryIndexAtILInstruction(self.handle, instr)
-
- def get_branch_dependence_at_instruction(self, cur_instr, branch_instr):
- return ILBranchDependence(core.BNGetMediumLevelILBranchDependence(self.handle, cur_instr, branch_instr))
-
- def get_all_branch_dependence_at_instruction(self, instr):
- count = ctypes.c_ulonglong()
- deps = core.BNGetAllMediumLevelILBranchDependence(self.handle, instr, count)
- result = {}
- for i in xrange(0, count.value):
- result[deps[i].branch] = ILBranchDependence(deps[i].dependence)
- core.BNFreeILBranchDependenceList(deps)
- return result
-
def get_low_level_il_instruction_index(self, instr):
low_il = self.low_level_il
if low_il is None: