summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Snyder <ryan@vector35.com>2018-08-20 18:58:00 -0400
committerRyan Snyder <ryan@vector35.com>2018-08-20 18:59:04 -0400
commitcecb2af5e8ec590500379e4b103531649de4e5a2 (patch)
treec214a9910d3f67d94087ba507951b8dd95d4026d
parent1e6336e12229add2f1716019d1b050c7f989dbaa (diff)
api: add methods to get basic block objects from IL instrs
-rw-r--r--binaryninjaapi.h2
-rw-r--r--binaryninjacore.h2
-rw-r--r--lowlevelil.cpp9
-rw-r--r--mediumlevelil.cpp9
-rw-r--r--python/lowlevelil.py5
-rw-r--r--python/mediumlevelil.py5
6 files changed, 32 insertions, 0 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index 620c0472..b00689e0 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -2937,6 +2937,7 @@ namespace BinaryNinja
uint32_t GetTemporaryFlagCount();
std::vector<Ref<BasicBlock>> GetBasicBlocks() const;
+ Ref<BasicBlock> GetBasicBlockForInstruction(size_t i) const;
Ref<LowLevelILFunction> GetSSAForm() const;
Ref<LowLevelILFunction> GetNonSSAForm() const;
@@ -3256,6 +3257,7 @@ namespace BinaryNinja
void VisitAllExprs(const std::function<bool(BasicBlock* block, const MediumLevelILInstruction& expr)>& func);
std::vector<Ref<BasicBlock>> GetBasicBlocks() const;
+ Ref<BasicBlock> GetBasicBlockForInstruction(size_t i) const;
Ref<MediumLevelILFunction> GetSSAForm() const;
Ref<MediumLevelILFunction> GetNonSSAForm() const;
diff --git a/binaryninjacore.h b/binaryninjacore.h
index e5949066..c2d9f9f7 100644
--- a/binaryninjacore.h
+++ b/binaryninjacore.h
@@ -2768,6 +2768,7 @@ extern "C"
BINARYNINJACOREAPI uint32_t BNGetLowLevelILTemporaryFlagCount(BNLowLevelILFunction* func);
BINARYNINJACOREAPI BNBasicBlock** BNGetLowLevelILBasicBlockList(BNLowLevelILFunction* func, size_t* count);
+ BINARYNINJACOREAPI BNBasicBlock* BNGetLowLevelILBasicBlockForInstruction(BNLowLevelILFunction* func, size_t i);
BINARYNINJACOREAPI BNLowLevelILFunction* BNGetLowLevelILSSAForm(BNLowLevelILFunction* func);
BINARYNINJACOREAPI BNLowLevelILFunction* BNGetLowLevelILNonSSAForm(BNLowLevelILFunction* func);
@@ -2889,6 +2890,7 @@ extern "C"
BNArchitecture* arch, size_t i, BNInstructionTextToken** tokens, size_t* count);
BINARYNINJACOREAPI BNBasicBlock** BNGetMediumLevelILBasicBlockList(BNMediumLevelILFunction* func, size_t* count);
+ BINARYNINJACOREAPI BNBasicBlock* BNGetMediumLevelILBasicBlockForInstruction(BNMediumLevelILFunction* func, size_t i);
BINARYNINJACOREAPI BNMediumLevelILFunction* BNGetMediumLevelILSSAForm(BNMediumLevelILFunction* func);
BINARYNINJACOREAPI BNMediumLevelILFunction* BNGetMediumLevelILNonSSAForm(BNMediumLevelILFunction* func);
diff --git a/lowlevelil.cpp b/lowlevelil.cpp
index 79138159..40748327 100644
--- a/lowlevelil.cpp
+++ b/lowlevelil.cpp
@@ -491,6 +491,15 @@ vector<Ref<BasicBlock>> LowLevelILFunction::GetBasicBlocks() const
}
+Ref<BasicBlock> LowLevelILFunction::GetBasicBlockForInstruction(size_t i) const
+{
+ BNBasicBlock* block = BNGetLowLevelILBasicBlockForInstruction(m_object, i);
+ if (!block)
+ return nullptr;
+ return new BasicBlock(block);
+}
+
+
Ref<LowLevelILFunction> LowLevelILFunction::GetSSAForm() const
{
BNLowLevelILFunction* func = BNGetLowLevelILSSAForm(m_object);
diff --git a/mediumlevelil.cpp b/mediumlevelil.cpp
index 1795a54d..cac45dd6 100644
--- a/mediumlevelil.cpp
+++ b/mediumlevelil.cpp
@@ -404,6 +404,15 @@ vector<Ref<BasicBlock>> MediumLevelILFunction::GetBasicBlocks() const
}
+Ref<BasicBlock> MediumLevelILFunction::GetBasicBlockForInstruction(size_t i) const
+{
+ BNBasicBlock* block = BNGetMediumLevelILBasicBlockForInstruction(m_object, i);
+ if (!block)
+ return nullptr;
+ return new BasicBlock(block);
+}
+
+
Ref<MediumLevelILFunction> MediumLevelILFunction::GetSSAForm() const
{
BNMediumLevelILFunction* func = BNGetMediumLevelILSSAForm(m_object);
diff --git a/python/lowlevelil.py b/python/lowlevelil.py
index e714eb48..41579719 100644
--- a/python/lowlevelil.py
+++ b/python/lowlevelil.py
@@ -537,6 +537,11 @@ class LowLevelILInstruction(object):
return result
@property
+ def il_basic_block(self):
+ """IL basic block object containing this expression (read-only) (only available on finalized functions)"""
+ return LowLevelILBasicBlock(self.function.source_function.view, core.BNGetLowLevelILBasicBlockForInstruction(self.function.handle, self.instr_index), self.function)
+
+ @property
def ssa_form(self):
"""SSA form of expression (read-only)"""
return LowLevelILInstruction(self.function.ssa_form,
diff --git a/python/mediumlevelil.py b/python/mediumlevelil.py
index cfa8f900..c024d287 100644
--- a/python/mediumlevelil.py
+++ b/python/mediumlevelil.py
@@ -334,6 +334,11 @@ class MediumLevelILInstruction(object):
return result
@property
+ def il_basic_block(self):
+ """IL basic block object containing this expression (read-only) (only available on finalized functions)"""
+ return MediumLevelILBasicBlock(self.function.source_function.view, core.BNGetMediumLevelILBasicBlockForInstruction(self.function.handle, self.instr_index), self.function)
+
+ @property
def ssa_form(self):
"""SSA form of expression (read-only)"""
return MediumLevelILInstruction(self.function.ssa_form,