summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--binaryninjaapi.h8
-rw-r--r--binaryninjacore.h8
-rw-r--r--function.cpp28
-rw-r--r--lowlevelil.cpp22
-rw-r--r--python/__init__.py42
5 files changed, 43 insertions, 65 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index 6d0a8535..054e11f3 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -1335,7 +1335,6 @@ namespace BinaryNinja
void SetCommentForAddress(uint64_t addr, const std::string& comment);
Ref<LowLevelILFunction> GetLowLevelIL() const;
- std::vector<Ref<BasicBlock>> GetLowLevelILBasicBlocks() const;
size_t GetLowLevelILForInstruction(Architecture* arch, uint64_t addr);
std::vector<size_t> GetLowLevelILExitsForInstruction(Architecture* arch, uint64_t addr);
BNRegisterValue GetRegisterValueAtInstruction(Architecture* arch, uint64_t addr, uint32_t reg);
@@ -1347,7 +1346,6 @@ namespace BinaryNinja
std::vector<StackVariableReference> GetStackVariablesReferencedByInstruction(Architecture* arch, uint64_t addr);
Ref<LowLevelILFunction> GetLiftedIL() const;
- std::vector<Ref<BasicBlock>> GetLiftedILBasicBlocks() const;
size_t GetLiftedILForInstruction(Architecture* arch, uint64_t addr);
std::set<size_t> GetLiftedILFlagUsesForDefinition(size_t i, uint32_t flag);
std::set<size_t> GetLiftedILFlagDefinitionsForUse(size_t i, uint32_t flag);
@@ -1452,7 +1450,7 @@ namespace BinaryNinja
BNNewLowLevelILFunctionReference, BNFreeLowLevelILFunction>
{
public:
- LowLevelILFunction();
+ LowLevelILFunction(Architecture* arch);
LowLevelILFunction(BNLowLevelILFunction* func);
uint64_t GetCurrentAddress() const;
@@ -1546,7 +1544,7 @@ namespace BinaryNinja
void AddLabelForAddress(Architecture* arch, ExprId addr);
BNLowLevelILLabel* GetLabelForAddress(Architecture* arch, ExprId addr);
- void Finalize();
+ void Finalize(Function* func = nullptr);
bool GetExprText(Architecture* arch, ExprId expr, std::vector<InstructionTextToken>& tokens);
bool GetInstructionText(Function* func, Architecture* arch, size_t i,
@@ -1554,6 +1552,8 @@ namespace BinaryNinja
uint32_t GetTemporaryRegisterCount();
uint32_t GetTemporaryFlagCount();
+
+ std::vector<Ref<BasicBlock>> GetBasicBlocks() const;
};
class FunctionRecognizer
diff --git a/binaryninjacore.h b/binaryninjacore.h
index aaade7ef..51a3afdf 100644
--- a/binaryninjacore.h
+++ b/binaryninjacore.h
@@ -1092,7 +1092,6 @@ extern "C"
BINARYNINJACOREAPI BNBasicBlock** BNGetBasicBlocksForAddress(BNBinaryView* view, uint64_t addr, size_t* count);
BINARYNINJACOREAPI BNLowLevelILFunction* BNGetFunctionLowLevelIL(BNFunction* func);
- BINARYNINJACOREAPI BNBasicBlock** BNGetFunctionLowLevelILBasicBlockList(BNFunction* func, size_t* count);
BINARYNINJACOREAPI size_t BNGetLowLevelILForInstruction(BNFunction* func, BNArchitecture* arch, uint64_t addr);
BINARYNINJACOREAPI size_t* BNGetLowLevelILExitsForInstruction(BNFunction* func, BNArchitecture* arch, uint64_t addr,
size_t* count);
@@ -1112,7 +1111,6 @@ extern "C"
BINARYNINJACOREAPI void BNFreeStackVariableReferenceList(BNStackVariableReference* refs, size_t count);
BINARYNINJACOREAPI BNLowLevelILFunction* BNGetFunctionLiftedIL(BNFunction* func);
- BINARYNINJACOREAPI BNBasicBlock** BNGetFunctionLiftedILBasicBlockList(BNFunction* func, size_t* count);
BINARYNINJACOREAPI size_t BNGetLiftedILForInstruction(BNFunction* func, BNArchitecture* arch, uint64_t addr);
BINARYNINJACOREAPI size_t* BNGetLiftedILFlagUsesForDefinition(BNFunction* func, size_t i, uint32_t flag, size_t* count);
BINARYNINJACOREAPI size_t* BNGetLiftedILFlagDefinitionsForUse(BNFunction* func, size_t i, uint32_t flag, size_t* count);
@@ -1245,7 +1243,7 @@ extern "C"
BINARYNINJACOREAPI BNSymbol* BNImportedFunctionFromImportAddressSymbol(BNSymbol* sym, uint64_t addr);
// Low-level IL
- BINARYNINJACOREAPI BNLowLevelILFunction* BNCreateLowLevelILFunction(void);
+ BINARYNINJACOREAPI BNLowLevelILFunction* BNCreateLowLevelILFunction(BNArchitecture* arch);
BINARYNINJACOREAPI BNLowLevelILFunction* BNNewLowLevelILFunctionReference(BNLowLevelILFunction* func);
BINARYNINJACOREAPI void BNFreeLowLevelILFunction(BNLowLevelILFunction* func);
BINARYNINJACOREAPI uint64_t BNLowLevelILGetCurrentAddress(BNLowLevelILFunction* func);
@@ -1261,7 +1259,7 @@ extern "C"
BINARYNINJACOREAPI size_t BNLowLevelILIf(BNLowLevelILFunction* func, uint64_t op, BNLowLevelILLabel* t, BNLowLevelILLabel* f);
BINARYNINJACOREAPI void BNLowLevelILInitLabel(BNLowLevelILLabel* label);
BINARYNINJACOREAPI void BNLowLevelILMarkLabel(BNLowLevelILFunction* func, BNLowLevelILLabel* label);
- BINARYNINJACOREAPI void BNFinalizeLowLevelILFunction(BNLowLevelILFunction* func);
+ BINARYNINJACOREAPI void BNFinalizeLowLevelILFunction(BNLowLevelILFunction* func, BNFunction* sourceFunc);
BINARYNINJACOREAPI size_t BNLowLevelILAddLabelList(BNLowLevelILFunction* func, BNLowLevelILLabel** labels, size_t count);
BINARYNINJACOREAPI size_t BNLowLevelILAddOperandList(BNLowLevelILFunction* func, uint64_t* operands, size_t count);
@@ -1285,6 +1283,8 @@ extern "C"
BINARYNINJACOREAPI uint32_t BNGetLowLevelILTemporaryRegisterCount(BNLowLevelILFunction* func);
BINARYNINJACOREAPI uint32_t BNGetLowLevelILTemporaryFlagCount(BNLowLevelILFunction* func);
+ BINARYNINJACOREAPI BNBasicBlock** BNGetLowLevelILBasicBlockList(BNLowLevelILFunction* func, size_t* count);
+
// Types
BINARYNINJACOREAPI BNType* BNCreateVoidType(void);
BINARYNINJACOREAPI BNType* BNCreateBoolType(void);
diff --git a/function.cpp b/function.cpp
index 209537b7..b8429998 100644
--- a/function.cpp
+++ b/function.cpp
@@ -124,20 +124,6 @@ Ref<LowLevelILFunction> Function::GetLowLevelIL() const
}
-vector<Ref<BasicBlock>> Function::GetLowLevelILBasicBlocks() const
-{
- size_t count;
- BNBasicBlock** blocks = BNGetFunctionLowLevelILBasicBlockList(m_object, &count);
-
- vector<Ref<BasicBlock>> result;
- for (size_t i = 0; i < count; i++)
- result.push_back(new BasicBlock(BNNewBasicBlockReference(blocks[i])));
-
- BNFreeBasicBlockList(blocks, count);
- return result;
-}
-
-
size_t Function::GetLowLevelILForInstruction(Architecture* arch, uint64_t addr)
{
return BNGetLowLevelILForInstruction(m_object, arch->GetObject(), addr);
@@ -235,20 +221,6 @@ Ref<LowLevelILFunction> Function::GetLiftedIL() const
}
-vector<Ref<BasicBlock>> Function::GetLiftedILBasicBlocks() const
-{
- size_t count;
- BNBasicBlock** blocks = BNGetFunctionLiftedILBasicBlockList(m_object, &count);
-
- vector<Ref<BasicBlock>> result;
- for (size_t i = 0; i < count; i++)
- result.push_back(new BasicBlock(BNNewBasicBlockReference(blocks[i])));
-
- BNFreeBasicBlockList(blocks, count);
- return result;
-}
-
-
size_t Function::GetLiftedILForInstruction(Architecture* arch, uint64_t addr)
{
return BNGetLiftedILForInstruction(m_object, arch->GetObject(), addr);
diff --git a/lowlevelil.cpp b/lowlevelil.cpp
index 385c55c5..d86bb523 100644
--- a/lowlevelil.cpp
+++ b/lowlevelil.cpp
@@ -30,9 +30,9 @@ LowLevelILLabel::LowLevelILLabel()
}
-LowLevelILFunction::LowLevelILFunction()
+LowLevelILFunction::LowLevelILFunction(Architecture* arch)
{
- m_object = BNCreateLowLevelILFunction();
+ m_object = BNCreateLowLevelILFunction(arch->GetObject());
}
@@ -553,9 +553,9 @@ BNLowLevelILLabel* LowLevelILFunction::GetLabelForAddress(Architecture* arch, Ex
}
-void LowLevelILFunction::Finalize()
+void LowLevelILFunction::Finalize(Function* func)
{
- BNFinalizeLowLevelILFunction(m_object);
+ BNFinalizeLowLevelILFunction(m_object, func ? func->GetObject() : nullptr);
}
@@ -615,3 +615,17 @@ uint32_t LowLevelILFunction::GetTemporaryFlagCount()
{
return BNGetLowLevelILTemporaryFlagCount(m_object);
}
+
+
+vector<Ref<BasicBlock>> LowLevelILFunction::GetBasicBlocks() const
+{
+ size_t count;
+ BNBasicBlock** blocks = BNGetLowLevelILBasicBlockList(m_object, &count);
+
+ vector<Ref<BasicBlock>> result;
+ for (size_t i = 0; i < count; i++)
+ result.push_back(new BasicBlock(BNNewBasicBlockReference(blocks[i])));
+
+ BNFreeBasicBlockList(blocks, count);
+ return result;
+}
diff --git a/python/__init__.py b/python/__init__.py
index ebaf030e..06cda6e1 100644
--- a/python/__init__.py
+++ b/python/__init__.py
@@ -2157,34 +2157,12 @@ class Function(object):
core.BNGetFunctionLowLevelIL(self.handle)), self)
@property
- def low_level_il_basic_blocks(self):
- """Function low level IL basic blocks (read-only)"""
- count = ctypes.c_ulonglong()
- blocks = core.BNGetFunctionLowLevelILBasicBlockList(self.handle, count)
- result = []
- for i in xrange(0, count.value):
- result.append(BasicBlock(self._view, core.BNNewBasicBlockReference(blocks[i])))
- core.BNFreeBasicBlockList(blocks, count.value)
- return result
-
- @property
def lifted_il(self):
"""Function lifted IL (read-only)"""
return LowLevelILFunction(self.arch, core.BNNewLowLevelILFunctionReference(
core.BNGetFunctionLiftedIL(self.handle)), self)
@property
- def lifted_il_basic_blocks(self):
- """Function lifted IL basic blocks (read-only)"""
- count = ctypes.c_ulonglong()
- blocks = core.BNGetFunctionLiftedILBasicBlockList(self.handle, count)
- result = []
- for i in xrange(0, count.value):
- result.append(BasicBlock(self._view, core.BNNewBasicBlockReference(blocks[i])))
- core.BNFreeBasicBlockList(blocks, count.value)
- return result
-
- @property
def type(self):
"""Function type (read-only)"""
return Type(core.BNGetFunctionType(self.handle))
@@ -3962,7 +3940,7 @@ class LowLevelILFunction(object):
if handle is not None:
self.handle = core.handle_of_type(handle, core.BNLowLevelILFunction)
else:
- self.handle = core.BNCreateLowLevelILFunction()
+ self.handle = core.BNCreateLowLevelILFunction(arch.handle)
def __del__(self):
core.BNFreeLowLevelILFunction(self.handle)
@@ -3985,6 +3963,17 @@ class LowLevelILFunction(object):
"""Number of temporary flags (read-only)"""
return core.BNGetLowLevelILTemporaryFlagCount(self.handle)
+ @property
+ def basic_blocks(self):
+ """Low level IL basic blocks (read-only)"""
+ count = ctypes.c_ulonglong()
+ blocks = core.BNGetLowLevelILBasicBlockList(self.handle, count)
+ result = []
+ for i in xrange(0, count.value):
+ result.append(BasicBlock(self._view, core.BNNewBasicBlockReference(blocks[i])))
+ core.BNFreeBasicBlockList(blocks, count.value)
+ return result
+
def __setattr__(self, name, value):
try:
object.__setattr__(self,name,value)
@@ -4252,8 +4241,11 @@ class LowLevelILFunction(object):
core.BNLowLevelILSetExprSourceOperand(self.handle, expr.index, n)
return expr
- def finalize(self):
- core.BNFinalizeLowLevelILFunction(self.handle)
+ def finalize(self, func = None):
+ if func is None:
+ core.BNFinalizeLowLevelILFunction(self.handle, None)
+ else:
+ core.BNFinalizeLowLevelILFunction(self.handle, func.handle)
def add_label_for_address(self, arch, addr):
if arch is not None: