summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan Wiens <jordan@psifertex.com>2016-05-15 20:21:41 -0400
committerJordan Wiens <jordan@psifertex.com>2016-05-15 20:21:41 -0400
commit675c7e8d0b4e1bc1a488c73729e94bec96373fbc (patch)
treeb2bfb2020c4d345adde4fb64c53d7009247249c8
parentc17b562736dba5a2d042b2c7979f5dc32507388c (diff)
parent72bf56348109d87994928dee244dd97a27480c6d (diff)
Merge branch 'dev' of github.com:Vector35/binaryninja-api into dev
-rw-r--r--binaryninjaapi.h3
-rw-r--r--binaryninjacore.h6
-rw-r--r--lowlevelil.cpp6
-rw-r--r--python/__init__.py29
4 files changed, 27 insertions, 17 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index 97caebb6..6d0a8535 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -1549,7 +1549,8 @@ namespace BinaryNinja
void Finalize();
bool GetExprText(Architecture* arch, ExprId expr, std::vector<InstructionTextToken>& tokens);
- bool GetInstructionText(Architecture* arch, size_t i, std::vector<InstructionTextToken>& tokens);
+ bool GetInstructionText(Function* func, Architecture* arch, size_t i,
+ std::vector<InstructionTextToken>& tokens);
uint32_t GetTemporaryRegisterCount();
uint32_t GetTemporaryFlagCount();
diff --git a/binaryninjacore.h b/binaryninjacore.h
index 2a9eb187..aaade7ef 100644
--- a/binaryninjacore.h
+++ b/binaryninjacore.h
@@ -1278,9 +1278,9 @@ extern "C"
BNArchitecture* arch, uint64_t addr);
BINARYNINJACOREAPI bool BNGetLowLevelILExprText(BNLowLevelILFunction* func, BNArchitecture* arch, size_t i,
- BNInstructionTextToken** tokens, size_t* count);
- BINARYNINJACOREAPI bool BNGetLowLevelILInstructionText(BNLowLevelILFunction* func, BNArchitecture* arch, size_t i,
- BNInstructionTextToken** tokens, size_t* count);
+ BNInstructionTextToken** tokens, size_t* count);
+ BINARYNINJACOREAPI bool BNGetLowLevelILInstructionText(BNLowLevelILFunction* il, BNFunction* func,
+ BNArchitecture* arch, size_t i, BNInstructionTextToken** tokens, size_t* count);
BINARYNINJACOREAPI uint32_t BNGetLowLevelILTemporaryRegisterCount(BNLowLevelILFunction* func);
BINARYNINJACOREAPI uint32_t BNGetLowLevelILTemporaryFlagCount(BNLowLevelILFunction* func);
diff --git a/lowlevelil.cpp b/lowlevelil.cpp
index 81104419..385c55c5 100644
--- a/lowlevelil.cpp
+++ b/lowlevelil.cpp
@@ -581,11 +581,13 @@ bool LowLevelILFunction::GetExprText(Architecture* arch, ExprId expr, vector<Ins
}
-bool LowLevelILFunction::GetInstructionText(Architecture* arch, size_t instr, vector<InstructionTextToken>& tokens)
+bool LowLevelILFunction::GetInstructionText(Function* func, Architecture* arch, size_t instr,
+ vector<InstructionTextToken>& tokens)
{
size_t count;
BNInstructionTextToken* list;
- if (!BNGetLowLevelILInstructionText(m_object, arch->GetObject(), instr, &list, &count))
+ if (!BNGetLowLevelILInstructionText(m_object, func ? func->GetObject() : nullptr, arch->GetObject(),
+ instr, &list, &count))
return false;
tokens.clear();
diff --git a/python/__init__.py b/python/__init__.py
index bf2ebfaa..ebaf030e 100644
--- a/python/__init__.py
+++ b/python/__init__.py
@@ -2154,7 +2154,7 @@ class Function(object):
def low_level_il(self):
"""Function low level IL (read-only)"""
return LowLevelILFunction(self.arch, core.BNNewLowLevelILFunctionReference(
- core.BNGetFunctionLowLevelIL(self.handle)))
+ core.BNGetFunctionLowLevelIL(self.handle)), self)
@property
def low_level_il_basic_blocks(self):
@@ -2171,7 +2171,7 @@ class Function(object):
def lifted_il(self):
"""Function lifted IL (read-only)"""
return LowLevelILFunction(self.arch, core.BNNewLowLevelILFunctionReference(
- core.BNGetFunctionLiftedIL(self.handle)))
+ core.BNGetFunctionLiftedIL(self.handle)), self)
@property
def lifted_il_basic_blocks(self):
@@ -3868,10 +3868,11 @@ class LowLevelILInstruction(object):
core.LLIL_UNIMPL_MEM: [("src", "expr")]
}
- def __init__(self, func, i):
- instr = core.BNGetLowLevelILByIndex(func.handle, i)
+ def __init__(self, func, expr_index, instr_index = None):
+ instr = core.BNGetLowLevelILByIndex(func.handle, expr_index)
self.function = func
- self.index = i
+ self.expr_index = expr_index
+ self.instr_index = instr_index
self.operation = instr.operation
self.operation_name = core.BNLowLevelILOperation_names[instr.operation]
self.size = instr.size
@@ -3902,7 +3903,7 @@ class LowLevelILInstruction(object):
value = core.BNLowLevelILFlagCondition_names[instr.operands[i]]
elif operand_type == "int_list":
count = ctypes.c_ulonglong()
- operands = core.BNLowLevelILGetOperandList(func.handle, self.index, i, count)
+ operands = core.BNLowLevelILGetOperandList(func.handle, self.expr_index, i, count)
value = []
for i in xrange(count.value):
value.append(operands[i])
@@ -3927,9 +3928,14 @@ class LowLevelILInstruction(object):
"""LLIL tokens (read-only)"""
count = ctypes.c_ulonglong()
tokens = ctypes.POINTER(core.BNInstructionTextToken)()
- if not core.BNGetLowLevelILExprText(self.function.handle, self.function.arch.handle,
- self.index, tokens, count):
- return None
+ if (self.instr_index is not None) and (self.function.source_function is not None):
+ if not core.BNGetLowLevelILInstructionText(self.function.handle, self.function.source_function.handle,
+ self.function.arch.handle, self.instr_index, tokens, count):
+ return None
+ else:
+ if not core.BNGetLowLevelILExprText(self.function.handle, self.function.arch.handle,
+ self.expr_index, tokens, count):
+ return None
result = []
for i in xrange(0, count.value):
token_type = core.BNInstructionTextTokenType_names[tokens[i].type]
@@ -3950,8 +3956,9 @@ class LowLevelILExpr:
self.index = index
class LowLevelILFunction(object):
- def __init__(self, arch, handle = None):
+ def __init__(self, arch, handle = None, source_func = None):
self.arch = arch
+ self.source_function = source_func
if handle is not None:
self.handle = core.handle_of_type(handle, core.BNLowLevelILFunction)
else:
@@ -3994,7 +4001,7 @@ class LowLevelILFunction(object):
return LowLevelILInstruction(self, i.index)
if (i < 0) or (i >= len(self)):
raise IndexError, "index out of range"
- return LowLevelILInstruction(self, core.BNGetLowLevelILIndexForInstruction(self.handle, i))
+ return LowLevelILInstruction(self, core.BNGetLowLevelILIndexForInstruction(self.handle, i), i)
def __setitem__(self, i):
raise IndexError, "instruction modification not implemented"