summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--binaryninjaapi.h3
-rw-r--r--binaryninjacore.h4
-rw-r--r--mediumlevelil.cpp21
-rw-r--r--mediumlevelilinstruction.cpp12
-rw-r--r--mediumlevelilinstruction.h2
-rw-r--r--python/highlevelil.py10
-rw-r--r--python/lowlevelil.py27
-rw-r--r--python/mediumlevelil.py43
8 files changed, 122 insertions, 0 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index ddfa6340..0e281baa 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -4074,6 +4074,9 @@ __attribute__ ((format (printf, 1, 2)))
Ref<LowLevelILFunction> GetLowLevelIL() const;
size_t GetLowLevelILInstructionIndex(size_t instr) const;
size_t GetLowLevelILExprIndex(size_t expr) const;
+ Ref<HighLevelILFunction> GetHighLevelIL() const;
+ size_t GetHighLevelILInstructionIndex(size_t instr) const;
+ size_t GetHighLevelILExprIndex(size_t expr) const;
Confidence<Ref<Type>> GetExprType(size_t expr);
Confidence<Ref<Type>> GetExprType(const MediumLevelILInstruction& expr);
diff --git a/binaryninjacore.h b/binaryninjacore.h
index c71d67fa..2dfea2c8 100644
--- a/binaryninjacore.h
+++ b/binaryninjacore.h
@@ -3933,6 +3933,10 @@ __attribute__ ((format (printf, 1, 2)))
BINARYNINJACOREAPI size_t BNGetLowLevelILInstructionIndex(BNMediumLevelILFunction* func, size_t instr);
BINARYNINJACOREAPI size_t BNGetLowLevelILExprIndex(BNMediumLevelILFunction* func, size_t expr);
+ BINARYNINJACOREAPI BNHighLevelILFunction* BNGetHighLevelILForMediumLevelIL(BNMediumLevelILFunction* func);
+ BINARYNINJACOREAPI size_t BNGetHighLevelILInstructionIndex(BNMediumLevelILFunction* func, size_t instr);
+ BINARYNINJACOREAPI size_t BNGetHighLevelILExprIndex(BNMediumLevelILFunction* func, size_t expr);
+
BINARYNINJACOREAPI BNTypeWithConfidence BNGetMediumLevelILExprType(BNMediumLevelILFunction* func, size_t expr);
// High-level IL
diff --git a/mediumlevelil.cpp b/mediumlevelil.cpp
index 2bbaa90e..6fb43d22 100644
--- a/mediumlevelil.cpp
+++ b/mediumlevelil.cpp
@@ -776,6 +776,27 @@ size_t MediumLevelILFunction::GetLowLevelILExprIndex(size_t expr) const
}
+Ref<HighLevelILFunction> MediumLevelILFunction::GetHighLevelIL() const
+{
+ BNHighLevelILFunction* func = BNGetHighLevelILForMediumLevelIL(m_object);
+ if (!func)
+ return nullptr;
+ return new HighLevelILFunction(func);
+}
+
+
+size_t MediumLevelILFunction::GetHighLevelILInstructionIndex(size_t instr) const
+{
+ return BNGetHighLevelILInstructionIndex(m_object, instr);
+}
+
+
+size_t MediumLevelILFunction::GetHighLevelILExprIndex(size_t expr) const
+{
+ return BNGetHighLevelILExprIndex(m_object, expr);
+}
+
+
Confidence<Ref<Type>> MediumLevelILFunction::GetExprType(size_t expr)
{
BNTypeWithConfidence result = BNGetMediumLevelILExprType(m_object, expr);
diff --git a/mediumlevelilinstruction.cpp b/mediumlevelilinstruction.cpp
index 3779eb90..3d90d7d2 100644
--- a/mediumlevelilinstruction.cpp
+++ b/mediumlevelilinstruction.cpp
@@ -1268,6 +1268,18 @@ size_t MediumLevelILInstructionBase::GetLowLevelILExprIndex() const
}
+size_t MediumLevelILInstructionBase::GetHighLevelILInstructionIndex() const
+{
+ return function->GetHighLevelILInstructionIndex(instructionIndex);
+}
+
+
+size_t MediumLevelILInstructionBase::GetHighLevelILExprIndex() const
+{
+ return function->GetHighLevelILExprIndex(exprIndex);
+}
+
+
bool MediumLevelILInstructionBase::HasLowLevelIL() const
{
Ref<LowLevelILFunction> func = function->GetLowLevelIL();
diff --git a/mediumlevelilinstruction.h b/mediumlevelilinstruction.h
index a8c9b8ec..42567834 100644
--- a/mediumlevelilinstruction.h
+++ b/mediumlevelilinstruction.h
@@ -444,6 +444,8 @@ namespace BinaryNinja
size_t GetLowLevelILInstructionIndex() const;
size_t GetLowLevelILExprIndex() const;
+ size_t GetHighLevelILInstructionIndex() const;
+ size_t GetHighLevelILExprIndex() const;
bool HasLowLevelIL() const;
LowLevelILInstruction GetLowLevelIL() const;
diff --git a/python/highlevelil.py b/python/highlevelil.py
index 589d6505..56619f05 100644
--- a/python/highlevelil.py
+++ b/python/highlevelil.py
@@ -530,6 +530,16 @@ class HighLevelILInstruction(object):
return self.medium_level_il
@property
+ def low_level_il(self):
+ """Low level IL form of this expression"""
+ return self.mlil.llil
+
+ @property
+ def llil(self):
+ """Alias for low_level_il"""
+ return self.low_level_il
+
+ @property
def il_basic_block(self):
"""IL basic block object containing this expression (read-only) (only available on finalized functions)"""
return HighLevelILBasicBlock(self._function.source_function.view, core.BNGetHighLevelILBasicBlockForInstruction(self._function.handle, self._instr_index), self._function)
diff --git a/python/lowlevelil.py b/python/lowlevelil.py
index 9435f07b..64a862d6 100644
--- a/python/lowlevelil.py
+++ b/python/lowlevelil.py
@@ -1026,6 +1026,15 @@ class LowLevelILInstruction(object):
return self.mapped_medium_level_il
@property
+ def high_level_il(self):
+ """Gets the high level IL expression corresponding to this expression (may be None for eliminated instructions)"""
+ return self.mlil.hlil
+
+ @property
+ def hlil(self):
+ return self.high_level_il
+
+ @property
def value(self):
"""Value of expression if constant or a known value (read-only)"""
value = core.BNGetLowLevelILExprValue(self._function.handle, self.expr_index)
@@ -2999,6 +3008,24 @@ class LowLevelILFunction(object):
return None
return result
+ def get_high_level_il_instruction_index(self, instr):
+ med_il = self.medium_level_il
+ if med_il is None:
+ return None
+ mlil_instr = self.get_medium_level_il_instruction_index(instr)
+ if mlil_instr is None:
+ return None
+ return med_il.get_high_level_il_instruction_index(mlil_instr)
+
+ def get_high_level_il_expr_index(self, expr):
+ med_il = self.medium_level_il
+ if med_il is None:
+ return None
+ mlil_expr = self.get_medium_level_il_expr_index(expr)
+ if mlil_expr is None:
+ return None
+ return med_il.get_high_level_il_expr_index(mlil_expr)
+
def create_graph(self, settings = None):
if settings is not None:
settings_obj = settings.handle
diff --git a/python/mediumlevelil.py b/python/mediumlevelil.py
index 857d8cff..68da31f3 100644
--- a/python/mediumlevelil.py
+++ b/python/mediumlevelil.py
@@ -470,6 +470,19 @@ class MediumLevelILInstruction(object):
return self.low_level_il
@property
+ def high_level_il(self):
+ """High level IL form of this expression"""
+ expr = self._function.get_high_level_il_expr_index(self._expr_index)
+ if expr is None:
+ return None
+ return binaryninja.highlevelil.HighLevelILInstruction(self._function.high_level_il, expr)
+
+ @property
+ def hlil(self):
+ """Alias for high_level_il"""
+ return self.high_level_il
+
+ @property
def ssa_memory_version(self):
"""Version of active memory contents in SSA form for this instruction"""
return core.BNGetMediumLevelILSSAMemoryVersionAtILInstruction(self._function.handle, self._instr_index)
@@ -927,6 +940,18 @@ class MediumLevelILFunction(object):
"""Alias for low_level_il"""
return self.low_level_il
+ @property
+ def high_level_il(self):
+ """High level IL for this medium level IL."""
+ result = core.BNGetHighLevelILForMediumLevelIL(self.handle)
+ if not result:
+ return None
+ return binaryninja.highlevelil.HighLevelILFunction(self._arch, result, self._source_function)
+
+ @property
+ def hlil(self):
+ return self.high_level_il
+
def get_instruction_start(self, addr, arch = None):
if arch is None:
arch = self._arch
@@ -1137,6 +1162,24 @@ class MediumLevelILFunction(object):
return None
return result
+ def get_high_level_il_instruction_index(self, instr):
+ high_il = self.high_level_il
+ if high_il is None:
+ return None
+ result = core.BNGetHighLevelILInstructionIndex(self.handle, instr)
+ if result >= core.BNGetHighLevelILInstructionCount(high_il.handle):
+ return None
+ return result
+
+ def get_high_level_il_expr_index(self, expr):
+ high_il = self.high_level_il
+ if high_il is None:
+ return None
+ result = core.BNGetHighLevelILExprIndex(self.handle, expr)
+ if result >= core.BNGetHighLevelILExprCount(high_il.handle):
+ return None
+ return result
+
def create_graph(self, settings = None):
if settings is not None:
settings_obj = settings.handle