summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRusty Wagner <rusty@vector35.com>2017-07-14 01:05:18 -0400
committerRusty Wagner <rusty@vector35.com>2017-07-14 01:05:18 -0400
commit35c65d909d1ec36a4a1bad7404c9f986e259f662 (patch)
tree213cc0371f20f8d9189387d28694d04d7153370a
parent3d403cfae9d5a366f112c8a5936a371a01cfd230 (diff)
Adding API to get type of MLIL expression
-rw-r--r--binaryninjaapi.h2
-rw-r--r--binaryninjacore.h2
-rw-r--r--mediumlevelil.cpp9
-rw-r--r--python/callingconvention.py2
-rw-r--r--python/function.py4
-rw-r--r--python/mediumlevelil.py9
-rw-r--r--python/types.py12
7 files changed, 31 insertions, 9 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index 2341e39f..f079e7c0 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -2550,6 +2550,8 @@ namespace BinaryNinja
Ref<LowLevelILFunction> GetLowLevelIL() const;
size_t GetLowLevelILInstructionIndex(size_t instr) const;
size_t GetLowLevelILExprIndex(size_t expr) const;
+
+ Confidence<Ref<Type>> GetExprType(size_t expr);
};
class FunctionRecognizer
diff --git a/binaryninjacore.h b/binaryninjacore.h
index f5b89437..0414b512 100644
--- a/binaryninjacore.h
+++ b/binaryninjacore.h
@@ -2488,6 +2488,8 @@ extern "C"
BINARYNINJACOREAPI size_t BNGetLowLevelILInstructionIndex(BNMediumLevelILFunction* func, size_t instr);
BINARYNINJACOREAPI size_t BNGetLowLevelILExprIndex(BNMediumLevelILFunction* func, size_t expr);
+ BINARYNINJACOREAPI BNTypeWithConfidence BNGetMediumLevelILExprType(BNMediumLevelILFunction* func, size_t expr);
+
// Types
BINARYNINJACOREAPI BNType* BNCreateVoidType(void);
BINARYNINJACOREAPI BNType* BNCreateBoolType(void);
diff --git a/mediumlevelil.cpp b/mediumlevelil.cpp
index 8bbb2746..df78de2d 100644
--- a/mediumlevelil.cpp
+++ b/mediumlevelil.cpp
@@ -494,3 +494,12 @@ size_t MediumLevelILFunction::GetLowLevelILExprIndex(size_t expr) const
{
return BNGetLowLevelILExprIndex(m_object, expr);
}
+
+
+Confidence<Ref<Type>> MediumLevelILFunction::GetExprType(size_t expr)
+{
+ BNTypeWithConfidence result = BNGetMediumLevelILExprType(m_object, expr);
+ if (!result.type)
+ return nullptr;
+ return Confidence<Ref<Type>>(new Type(result.type), result.confidence);
+}
diff --git a/python/callingconvention.py b/python/callingconvention.py
index e6aa323c..db473c53 100644
--- a/python/callingconvention.py
+++ b/python/callingconvention.py
@@ -41,7 +41,7 @@ class CallingConvention(object):
_registered_calling_conventions = []
- def __init__(self, arch, handle = None, confidence = types.Type.max_confidence):
+ def __init__(self, arch, handle = None, confidence = types.max_confidence):
if handle is None:
self.arch = arch
self._pending_reg_lists = {}
diff --git a/python/function.py b/python/function.py
index 3cd5396f..aa0d05eb 100644
--- a/python/function.py
+++ b/python/function.py
@@ -185,7 +185,7 @@ class Variable(object):
if var_type is None:
var_type_conf = core.BNGetVariableType(func.handle, var)
if var_type_conf.type:
- var_type = types.Type(var_type, confidence = var_type_conf.confidence)
+ var_type = types.Type(var_type_conf.type, confidence = var_type_conf.confidence)
else:
var_type = None
@@ -1401,7 +1401,7 @@ class InstructionTextToken(object):
"""
def __init__(self, token_type, text, value = 0, size = 0, operand = 0xffffffff,
- context = InstructionTextTokenContext.NoTokenContext, address = 0, confidence = types.Type.max_confidence):
+ context = InstructionTextTokenContext.NoTokenContext, address = 0, confidence = types.max_confidence):
self.type = InstructionTextTokenType(token_type)
self.text = text
self.value = value
diff --git a/python/mediumlevelil.py b/python/mediumlevelil.py
index 275746cc..76a85a86 100644
--- a/python/mediumlevelil.py
+++ b/python/mediumlevelil.py
@@ -26,6 +26,7 @@ from .enums import MediumLevelILOperation, InstructionTextTokenType, ILBranchDep
import function
import basicblock
import lowlevelil
+import types
class SSAVariable(object):
@@ -397,6 +398,14 @@ class MediumLevelILInstruction(object):
result += operand.vars_read
return result
+ @property
+ def expr_type(self):
+ """Type of expression"""
+ result = core.BNGetMediumLevelILExprType(self.function.handle, self.expr_index)
+ if result.type:
+ return types.Type(result.type, confidence = result.confidence)
+ return None
+
def get_ssa_var_possible_values(self, ssa_var):
var_data = core.BNVariable()
var_data.type = ssa_var.var.source_type
diff --git a/python/types.py b/python/types.py
index c3d7156e..5933661a 100644
--- a/python/types.py
+++ b/python/types.py
@@ -18,6 +18,8 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
+max_confidence = 255
+
import ctypes
# Binary Ninja components
@@ -198,8 +200,6 @@ class Symbol(object):
class Type(object):
- max_confidence = 255
-
def __init__(self, handle, confidence = max_confidence):
self.handle = handle
self.confidence = confidence
@@ -336,8 +336,8 @@ class Type(object):
return core.BNGetTypeString(self.handle)
def __repr__(self):
- if self.confidence < Type.max_confidence:
- return "<type: %s, %d%% confidence>" % (str(self), (self.confidence * 100) / Type.max_confidence)
+ if self.confidence < max_confidence:
+ return "<type: %s, %d%% confidence>" % (str(self), (self.confidence * 100) / max_confidence)
return "<type: %s>" % str(self)
def get_string_before_name(self):
@@ -560,7 +560,7 @@ class Type(object):
class BoolWithConfidence(object):
- def __init__(self, value, confidence = Type.max_confidence):
+ def __init__(self, value, confidence = max_confidence):
self.value = value
self.confidence = confidence
@@ -578,7 +578,7 @@ class BoolWithConfidence(object):
class ReferenceTypeWithConfidence(object):
- def __init__(self, value, confidence = Type.max_confidence):
+ def __init__(self, value, confidence = max_confidence):
self.value = value
self.confidence = confidence