summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRusty Wagner <rusty@vector35.com>2017-05-03 23:37:30 -0400
committerRusty Wagner <rusty@vector35.com>2017-05-03 23:37:30 -0400
commit26c8f70fd837baec98bcf2aac89ae658c5590013 (patch)
treec7bf02f87133b36c40e756f63bbf570a6bdbd3cc
parent04474d6ae818ddfa9978ffac6f1cdcaae56a87b5 (diff)
Adding IL instruction for truncating result to smaller value
-rw-r--r--binaryninjaapi.h5
-rw-r--r--binaryninjacore.h2
-rw-r--r--lowlevelil.cpp14
-rw-r--r--python/lowlevelil.py16
-rw-r--r--python/mediumlevelil.py1
5 files changed, 30 insertions, 8 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index 41beb852..a179a810 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -2144,8 +2144,9 @@ namespace BinaryNinja
ExprId ModDoublePrecSigned(size_t size, ExprId high, ExprId low, ExprId div, uint32_t flags = 0);
ExprId Neg(size_t size, ExprId a, uint32_t flags = 0);
ExprId Not(size_t size, ExprId a, uint32_t flags = 0);
- ExprId SignExtend(size_t size, ExprId a);
- ExprId ZeroExtend(size_t size, ExprId a);
+ ExprId SignExtend(size_t size, ExprId a, uint32_t flags = 0);
+ ExprId ZeroExtend(size_t size, ExprId a, uint32_t flags = 0);
+ ExprId LowPart(size_t size, ExprId a, uint32_t flags = 0);
ExprId Jump(ExprId dest);
ExprId Call(ExprId dest);
ExprId Return(size_t dest);
diff --git a/binaryninjacore.h b/binaryninjacore.h
index 730cbe8d..abb53a7b 100644
--- a/binaryninjacore.h
+++ b/binaryninjacore.h
@@ -313,6 +313,7 @@ extern "C"
LLIL_NOT,
LLIL_SX,
LLIL_ZX,
+ LLIL_LOW_PART,
LLIL_JUMP,
LLIL_JUMP_TO,
LLIL_CALL,
@@ -751,6 +752,7 @@ extern "C"
MLIL_NOT,
MLIL_SX,
MLIL_ZX,
+ MLIL_LOW_PART,
MLIL_JUMP,
MLIL_JUMP_TO,
MLIL_CALL, // Not valid in SSA form (see MLIL_CALL_SSA)
diff --git a/lowlevelil.cpp b/lowlevelil.cpp
index d266c2c9..0b2837f1 100644
--- a/lowlevelil.cpp
+++ b/lowlevelil.cpp
@@ -326,15 +326,21 @@ ExprId LowLevelILFunction::Not(size_t size, ExprId a, uint32_t flags)
}
-ExprId LowLevelILFunction::SignExtend(size_t size, ExprId a)
+ExprId LowLevelILFunction::SignExtend(size_t size, ExprId a, uint32_t flags)
{
- return AddExpr(LLIL_SX, size, 0, a);
+ return AddExpr(LLIL_SX, size, flags, a);
}
-ExprId LowLevelILFunction::ZeroExtend(size_t size, ExprId a)
+ExprId LowLevelILFunction::ZeroExtend(size_t size, ExprId a, uint32_t flags)
{
- return AddExpr(LLIL_ZX, size, 0, a);
+ return AddExpr(LLIL_ZX, size, flags, a);
+}
+
+
+ExprId LowLevelILFunction::LowPart(size_t size, ExprId a, uint32_t flags)
+{
+ return AddExpr(LLIL_LOW_PART, size, flags, a);
}
diff --git a/python/lowlevelil.py b/python/lowlevelil.py
index 21f43db3..fd713b44 100644
--- a/python/lowlevelil.py
+++ b/python/lowlevelil.py
@@ -153,6 +153,7 @@ class LowLevelILInstruction(object):
LowLevelILOperation.LLIL_NOT: [("src", "expr")],
LowLevelILOperation.LLIL_SX: [("src", "expr")],
LowLevelILOperation.LLIL_ZX: [("src", "expr")],
+ LowLevelILOperation.LLIL_LOW_PART: [("src", "expr")],
LowLevelILOperation.LLIL_JUMP: [("dest", "expr")],
LowLevelILOperation.LLIL_JUMP_TO: [("dest", "expr"), ("targets", "int_list")],
LowLevelILOperation.LLIL_CALL: [("dest", "expr")],
@@ -1188,7 +1189,7 @@ class LowLevelILFunction(object):
"""
return self.expr(LowLevelILOperation.LLIL_SX, value.index, size=size, flags=flags)
- def zero_extend(self, size, value):
+ def zero_extend(self, size, value, flags=None):
"""
``zero_extend`` zero-extends the expression in ``value`` to ``size`` bytes
@@ -1197,7 +1198,18 @@ class LowLevelILFunction(object):
:return: The expression ``sx.<size>(value)``
:rtype: LowLevelILExpr
"""
- return self.expr(LowLevelILOperation.LLIL_ZX, value.index, size=size)
+ return self.expr(LowLevelILOperation.LLIL_ZX, value.index, size=size, flags=flags)
+
+ def low_part(self, size, value, flags=None):
+ """
+ ``low_part`` truncates ``value`` to ``size`` bytes
+
+ :param int size: the size of the result in bytes
+ :param LowLevelILExpr value: the expression to zero extend
+ :return: The expression ``(value).<size>``
+ :rtype: LowLevelILExpr
+ """
+ return self.expr(LowLevelILOperation.LLIL_LOW_PART, value.index, size=size, flags=flags)
def jump(self, dest):
"""
diff --git a/python/mediumlevelil.py b/python/mediumlevelil.py
index e8c5b0f3..cef8d83e 100644
--- a/python/mediumlevelil.py
+++ b/python/mediumlevelil.py
@@ -105,6 +105,7 @@ class MediumLevelILInstruction(object):
MediumLevelILOperation.MLIL_NOT: [("src", "expr")],
MediumLevelILOperation.MLIL_SX: [("src", "expr")],
MediumLevelILOperation.MLIL_ZX: [("src", "expr")],
+ MediumLevelILOperation.MLIL_LOW_PART: [("src", "expr")],
MediumLevelILOperation.MLIL_JUMP: [("dest", "expr")],
MediumLevelILOperation.MLIL_JUMP_TO: [("dest", "expr"), ("targets", "int_list")],
MediumLevelILOperation.MLIL_CALL: [("output", "var_list"), ("dest", "expr"), ("params", "expr_list")],