summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRusty Wagner <rusty@vector35.com>2018-02-02 18:02:57 -0500
committerRusty Wagner <rusty@vector35.com>2018-02-02 18:02:57 -0500
commit331bfd4e4a648de8aba4fefd8301703a6a3440c9 (patch)
tree6a2287c7d4731c787918e47161eb944fc225051c
parentfd51307c7fa5baff29860b1e3be09aafca13c2f0 (diff)
Add rounding instructions
-rw-r--r--binaryninjaapi.h8
-rw-r--r--binaryninjacore.h8
-rw-r--r--lowlevelilinstruction.cpp36
-rw-r--r--lowlevelilinstruction.h4
-rw-r--r--mediumlevelilinstruction.cpp36
-rw-r--r--mediumlevelilinstruction.h4
-rw-r--r--python/lowlevelil.py52
-rw-r--r--python/mediumlevelil.py4
8 files changed, 152 insertions, 0 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index 3decc4e9..650299ed 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -2702,6 +2702,10 @@ namespace BinaryNinja
ExprId FloatToInt(size_t size, ExprId a, uint32_t flags = 0, const ILSourceLocation& loc = ILSourceLocation());
ExprId IntToFloat(size_t size, ExprId a, uint32_t flags = 0, const ILSourceLocation& loc = ILSourceLocation());
ExprId FloatConvert(size_t size, ExprId a, uint32_t flags = 0, const ILSourceLocation& loc = ILSourceLocation());
+ ExprId RoundToInt(size_t size, ExprId a, uint32_t flags = 0, const ILSourceLocation& loc = ILSourceLocation());
+ ExprId Floor(size_t size, ExprId a, uint32_t flags = 0, const ILSourceLocation& loc = ILSourceLocation());
+ ExprId Ceil(size_t size, ExprId a, uint32_t flags = 0, const ILSourceLocation& loc = ILSourceLocation());
+ ExprId FloatTrunc(size_t size, ExprId a, uint32_t flags = 0, const ILSourceLocation& loc = ILSourceLocation());
ExprId FloatCompareEqual(size_t size, ExprId a, ExprId b, const ILSourceLocation& loc = ILSourceLocation());
ExprId FloatCompareNotEqual(size_t size, ExprId a, ExprId b, const ILSourceLocation& loc = ILSourceLocation());
ExprId FloatCompareLessThan(size_t size, ExprId a, ExprId b, const ILSourceLocation& loc = ILSourceLocation());
@@ -3012,6 +3016,10 @@ namespace BinaryNinja
ExprId FloatToInt(size_t size, ExprId a, const ILSourceLocation& loc = ILSourceLocation());
ExprId IntToFloat(size_t size, ExprId a, const ILSourceLocation& loc = ILSourceLocation());
ExprId FloatConvert(size_t size, ExprId a, const ILSourceLocation& loc = ILSourceLocation());
+ ExprId RoundToInt(size_t size, ExprId a, const ILSourceLocation& loc = ILSourceLocation());
+ ExprId Floor(size_t size, ExprId a, const ILSourceLocation& loc = ILSourceLocation());
+ ExprId Ceil(size_t size, ExprId a, const ILSourceLocation& loc = ILSourceLocation());
+ ExprId FloatTrunc(size_t size, ExprId a, const ILSourceLocation& loc = ILSourceLocation());
ExprId FloatCompareEqual(size_t size, ExprId a, ExprId b, const ILSourceLocation& loc = ILSourceLocation());
ExprId FloatCompareNotEqual(size_t size, ExprId a, ExprId b, const ILSourceLocation& loc = ILSourceLocation());
ExprId FloatCompareLessThan(size_t size, ExprId a, ExprId b, const ILSourceLocation& loc = ILSourceLocation());
diff --git a/binaryninjacore.h b/binaryninjacore.h
index a946df31..945badce 100644
--- a/binaryninjacore.h
+++ b/binaryninjacore.h
@@ -368,6 +368,10 @@ extern "C"
LLIL_FLOAT_TO_INT,
LLIL_INT_TO_FLOAT,
LLIL_FLOAT_CONV,
+ LLIL_ROUND_TO_INT,
+ LLIL_FLOOR,
+ LLIL_CEIL,
+ LLIL_FTRUNC,
LLIL_FCMP_E,
LLIL_FCMP_NE,
LLIL_FCMP_LT,
@@ -878,6 +882,10 @@ extern "C"
MLIL_FLOAT_TO_INT,
MLIL_INT_TO_FLOAT,
MLIL_FLOAT_CONV,
+ MLIL_ROUND_TO_INT,
+ MLIL_FLOOR,
+ MLIL_CEIL,
+ MLIL_FTRUNC,
MLIL_FCMP_E,
MLIL_FCMP_NE,
MLIL_FCMP_LT,
diff --git a/lowlevelilinstruction.cpp b/lowlevelilinstruction.cpp
index 1a834435..c38d742f 100644
--- a/lowlevelilinstruction.cpp
+++ b/lowlevelilinstruction.cpp
@@ -220,6 +220,10 @@ unordered_map<BNLowLevelILOperation, vector<LowLevelILOperandUsage>>
{LLIL_FLOAT_TO_INT, {SourceExprLowLevelOperandUsage}},
{LLIL_INT_TO_FLOAT, {SourceExprLowLevelOperandUsage}},
{LLIL_FLOAT_CONV, {SourceExprLowLevelOperandUsage}},
+ {LLIL_ROUND_TO_INT, {SourceExprLowLevelOperandUsage}},
+ {LLIL_FLOOR, {SourceExprLowLevelOperandUsage}},
+ {LLIL_CEIL, {SourceExprLowLevelOperandUsage}},
+ {LLIL_FTRUNC, {SourceExprLowLevelOperandUsage}},
{LLIL_FCMP_E, {LeftExprLowLevelOperandUsage, RightExprLowLevelOperandUsage}},
{LLIL_FCMP_NE, {LeftExprLowLevelOperandUsage, RightExprLowLevelOperandUsage}},
{LLIL_FCMP_LT, {LeftExprLowLevelOperandUsage, RightExprLowLevelOperandUsage}},
@@ -1816,6 +1820,10 @@ void LowLevelILInstruction::VisitExprs(const std::function<bool(const LowLevelIL
case LLIL_FLOAT_TO_INT:
case LLIL_INT_TO_FLOAT:
case LLIL_FLOAT_CONV:
+ case LLIL_ROUND_TO_INT:
+ case LLIL_FLOOR:
+ case LLIL_CEIL:
+ case LLIL_FTRUNC:
AsOneOperand().GetSourceExpr().VisitExprs(func);
break;
case LLIL_ADD:
@@ -2078,6 +2086,10 @@ ExprId LowLevelILInstruction::CopyTo(LowLevelILFunction* dest,
case LLIL_FLOAT_TO_INT:
case LLIL_INT_TO_FLOAT:
case LLIL_FLOAT_CONV:
+ case LLIL_ROUND_TO_INT:
+ case LLIL_FLOOR:
+ case LLIL_CEIL:
+ case LLIL_FTRUNC:
return dest->AddExprWithLocation(operation, *this, size, flags,
subExprHandler(AsOneOperand().GetSourceExpr()));
case LLIL_ADD:
@@ -3349,6 +3361,30 @@ ExprId LowLevelILFunction::FloatConvert(size_t size, ExprId a, uint32_t flags, c
}
+ExprId LowLevelILFunction::RoundToInt(size_t size, ExprId a, uint32_t flags, const ILSourceLocation& loc)
+{
+ return AddExprWithLocation(LLIL_ROUND_TO_INT, loc, size, flags, a);
+}
+
+
+ExprId LowLevelILFunction::Floor(size_t size, ExprId a, uint32_t flags, const ILSourceLocation& loc)
+{
+ return AddExprWithLocation(LLIL_FLOOR, loc, size, flags, a);
+}
+
+
+ExprId LowLevelILFunction::Ceil(size_t size, ExprId a, uint32_t flags, const ILSourceLocation& loc)
+{
+ return AddExprWithLocation(LLIL_CEIL, loc, size, flags, a);
+}
+
+
+ExprId LowLevelILFunction::FloatTrunc(size_t size, ExprId a, uint32_t flags, const ILSourceLocation& loc)
+{
+ return AddExprWithLocation(LLIL_FTRUNC, loc, size, flags, a);
+}
+
+
ExprId LowLevelILFunction::FloatCompareEqual(size_t size, ExprId a, ExprId b, const ILSourceLocation& loc)
{
return AddExprWithLocation(LLIL_FCMP_E, loc, size, 0, a, b);
diff --git a/lowlevelilinstruction.h b/lowlevelilinstruction.h
index 4679f556..3cd1c8f4 100644
--- a/lowlevelilinstruction.h
+++ b/lowlevelilinstruction.h
@@ -1249,4 +1249,8 @@ namespace BinaryNinja
template <> struct LowLevelILInstructionAccessor<LLIL_FLOAT_TO_INT>: public LowLevelILOneOperandInstruction {};
template <> struct LowLevelILInstructionAccessor<LLIL_INT_TO_FLOAT>: public LowLevelILOneOperandInstruction {};
template <> struct LowLevelILInstructionAccessor<LLIL_FLOAT_CONV>: public LowLevelILOneOperandInstruction {};
+ template <> struct LowLevelILInstructionAccessor<LLIL_ROUND_TO_INT>: public LowLevelILOneOperandInstruction {};
+ template <> struct LowLevelILInstructionAccessor<LLIL_FLOOR>: public LowLevelILOneOperandInstruction {};
+ template <> struct LowLevelILInstructionAccessor<LLIL_CEIL>: public LowLevelILOneOperandInstruction {};
+ template <> struct LowLevelILInstructionAccessor<LLIL_FTRUNC>: public LowLevelILOneOperandInstruction {};
}
diff --git a/mediumlevelilinstruction.cpp b/mediumlevelilinstruction.cpp
index 7e1e663f..c4800837 100644
--- a/mediumlevelilinstruction.cpp
+++ b/mediumlevelilinstruction.cpp
@@ -215,6 +215,10 @@ unordered_map<BNMediumLevelILOperation, vector<MediumLevelILOperandUsage>>
{MLIL_FLOAT_TO_INT, {SourceExprMediumLevelOperandUsage}},
{MLIL_INT_TO_FLOAT, {SourceExprMediumLevelOperandUsage}},
{MLIL_FLOAT_CONV, {SourceExprMediumLevelOperandUsage}},
+ {MLIL_ROUND_TO_INT, {SourceExprMediumLevelOperandUsage}},
+ {MLIL_FLOOR, {SourceExprMediumLevelOperandUsage}},
+ {MLIL_CEIL, {SourceExprMediumLevelOperandUsage}},
+ {MLIL_FTRUNC, {SourceExprMediumLevelOperandUsage}},
{MLIL_FCMP_E, {LeftExprMediumLevelOperandUsage, RightExprMediumLevelOperandUsage}},
{MLIL_FCMP_NE, {LeftExprMediumLevelOperandUsage, RightExprMediumLevelOperandUsage}},
{MLIL_FCMP_LT, {LeftExprMediumLevelOperandUsage, RightExprMediumLevelOperandUsage}},
@@ -1300,6 +1304,10 @@ void MediumLevelILInstruction::VisitExprs(const std::function<bool(const MediumL
case MLIL_FLOAT_TO_INT:
case MLIL_INT_TO_FLOAT:
case MLIL_FLOAT_CONV:
+ case MLIL_ROUND_TO_INT:
+ case MLIL_FLOOR:
+ case MLIL_CEIL:
+ case MLIL_FTRUNC:
AsOneOperand().GetSourceExpr().VisitExprs(func);
break;
case MLIL_ADD:
@@ -1539,6 +1547,10 @@ ExprId MediumLevelILInstruction::CopyTo(MediumLevelILFunction* dest,
case MLIL_FLOAT_TO_INT:
case MLIL_INT_TO_FLOAT:
case MLIL_FLOAT_CONV:
+ case MLIL_ROUND_TO_INT:
+ case MLIL_FLOOR:
+ case MLIL_CEIL:
+ case MLIL_FTRUNC:
return dest->AddExprWithLocation(operation, *this, size,
subExprHandler(AsOneOperand().GetSourceExpr()));
case MLIL_ADD:
@@ -2731,6 +2743,30 @@ ExprId MediumLevelILFunction::FloatConvert(size_t size, ExprId a, const ILSource
}
+ExprId MediumLevelILFunction::RoundToInt(size_t size, ExprId a, const ILSourceLocation& loc)
+{
+ return AddExprWithLocation(MLIL_ROUND_TO_INT, loc, size, a);
+}
+
+
+ExprId MediumLevelILFunction::Floor(size_t size, ExprId a, const ILSourceLocation& loc)
+{
+ return AddExprWithLocation(MLIL_FLOOR, loc, size, a);
+}
+
+
+ExprId MediumLevelILFunction::Ceil(size_t size, ExprId a, const ILSourceLocation& loc)
+{
+ return AddExprWithLocation(MLIL_CEIL, loc, size, a);
+}
+
+
+ExprId MediumLevelILFunction::FloatTrunc(size_t size, ExprId a, const ILSourceLocation& loc)
+{
+ return AddExprWithLocation(MLIL_FTRUNC, loc, size, a);
+}
+
+
ExprId MediumLevelILFunction::FloatCompareEqual(size_t size, ExprId a, ExprId b, const ILSourceLocation& loc)
{
return AddExprWithLocation(MLIL_FCMP_E, loc, size, a, b);
diff --git a/mediumlevelilinstruction.h b/mediumlevelilinstruction.h
index de92764d..cdda87f5 100644
--- a/mediumlevelilinstruction.h
+++ b/mediumlevelilinstruction.h
@@ -1012,4 +1012,8 @@ namespace BinaryNinja
template <> struct MediumLevelILInstructionAccessor<MLIL_FLOAT_TO_INT>: public MediumLevelILOneOperandInstruction {};
template <> struct MediumLevelILInstructionAccessor<MLIL_INT_TO_FLOAT>: public MediumLevelILOneOperandInstruction {};
template <> struct MediumLevelILInstructionAccessor<MLIL_FLOAT_CONV>: public MediumLevelILOneOperandInstruction {};
+ template <> struct MediumLevelILInstructionAccessor<MLIL_ROUND_TO_INT>: public MediumLevelILOneOperandInstruction {};
+ template <> struct MediumLevelILInstructionAccessor<MLIL_FLOOR>: public MediumLevelILOneOperandInstruction {};
+ template <> struct MediumLevelILInstructionAccessor<MLIL_CEIL>: public MediumLevelILOneOperandInstruction {};
+ template <> struct MediumLevelILInstructionAccessor<MLIL_FTRUNC>: public MediumLevelILOneOperandInstruction {};
}
diff --git a/python/lowlevelil.py b/python/lowlevelil.py
index 273d3aeb..8a132478 100644
--- a/python/lowlevelil.py
+++ b/python/lowlevelil.py
@@ -295,6 +295,10 @@ class LowLevelILInstruction(object):
LowLevelILOperation.LLIL_FLOAT_TO_INT: [("src", "expr")],
LowLevelILOperation.LLIL_INT_TO_FLOAT: [("src", "expr")],
LowLevelILOperation.LLIL_FLOAT_CONV: [("src", "expr")],
+ LowLevelILOperation.LLIL_ROUND_TO_INT: [("src", "expr")],
+ LowLevelILOperation.LLIL_FLOOR: [("src", "expr")],
+ LowLevelILOperation.LLIL_CEIL: [("src", "expr")],
+ LowLevelILOperation.LLIL_FTRUNC: [("src", "expr")],
LowLevelILOperation.LLIL_FCMP_E: [("left", "expr"), ("right", "expr")],
LowLevelILOperation.LLIL_FCMP_NE: [("left", "expr"), ("right", "expr")],
LowLevelILOperation.LLIL_FCMP_LT: [("left", "expr"), ("right", "expr")],
@@ -1967,6 +1971,54 @@ class LowLevelILFunction(object):
"""
return self.expr(LowLevelILOperation.LLIL_FLOAT_CONV, value.index, size=size, flags=flags)
+ def round_to_int(self, size, value, flags=None):
+ """
+ ``round_to_int`` rounds a floating point value to the nearest integer
+
+ :param int size: the size of the result in bytes
+ :param LowLevelILExpr value: the expression to negate
+ :param str flags: optional, flags to set
+ :return: The expression ``roundint.<size>{<flags>}(value)``
+ :rtype: LowLevelILExpr
+ """
+ return self.expr(LowLevelILOperation.LLIL_ROUND_TO_INT, value.index, size=size, flags=flags)
+
+ def floor(self, size, value, flags=None):
+ """
+ ``floor`` rounds a floating point value to an integer towards negative infinity
+
+ :param int size: the size of the result in bytes
+ :param LowLevelILExpr value: the expression to negate
+ :param str flags: optional, flags to set
+ :return: The expression ``roundint.<size>{<flags>}(value)``
+ :rtype: LowLevelILExpr
+ """
+ return self.expr(LowLevelILOperation.LLIL_FLOOR, value.index, size=size, flags=flags)
+
+ def ceil(self, size, value, flags=None):
+ """
+ ``ceil`` rounds a floating point value to an integer towards positive infinity
+
+ :param int size: the size of the result in bytes
+ :param LowLevelILExpr value: the expression to negate
+ :param str flags: optional, flags to set
+ :return: The expression ``roundint.<size>{<flags>}(value)``
+ :rtype: LowLevelILExpr
+ """
+ return self.expr(LowLevelILOperation.LLIL_CEIL, value.index, size=size, flags=flags)
+
+ def float_trunc(self, size, value, flags=None):
+ """
+ ``float_trunc`` rounds a floating point value to an integer towards zero
+
+ :param int size: the size of the result in bytes
+ :param LowLevelILExpr value: the expression to negate
+ :param str flags: optional, flags to set
+ :return: The expression ``roundint.<size>{<flags>}(value)``
+ :rtype: LowLevelILExpr
+ """
+ return self.expr(LowLevelILOperation.LLIL_FTRUNC, value.index, size=size, flags=flags)
+
def float_compare_equal(self, size, a, b):
"""
``float_compare_equal`` returns floating point comparison expression of size ``size`` checking if
diff --git a/python/mediumlevelil.py b/python/mediumlevelil.py
index 3c4ba3fd..a842c3c4 100644
--- a/python/mediumlevelil.py
+++ b/python/mediumlevelil.py
@@ -165,6 +165,10 @@ class MediumLevelILInstruction(object):
MediumLevelILOperation.MLIL_FLOAT_TO_INT: [("src", "expr")],
MediumLevelILOperation.MLIL_INT_TO_FLOAT: [("src", "expr")],
MediumLevelILOperation.MLIL_FLOAT_CONV: [("src", "expr")],
+ MediumLevelILOperation.MLIL_ROUND_TO_INT: [("src", "expr")],
+ MediumLevelILOperation.MLIL_FLOOR: [("src", "expr")],
+ MediumLevelILOperation.MLIL_CEIL: [("src", "expr")],
+ MediumLevelILOperation.MLIL_FTRUNC: [("src", "expr")],
MediumLevelILOperation.MLIL_FCMP_E: [("left", "expr"), ("right", "expr")],
MediumLevelILOperation.MLIL_FCMP_NE: [("left", "expr"), ("right", "expr")],
MediumLevelILOperation.MLIL_FCMP_LT: [("left", "expr"), ("right", "expr")],