diff options
| author | Mark Rowe <mark@vector35.com> | 2026-06-07 16:04:21 -0700 |
|---|---|---|
| committer | Mark Rowe <mark@vector35.com> | 2026-06-07 16:12:52 -0700 |
| commit | e1ebfcd751ee5933da99bb21606b779edfe440b2 (patch) | |
| tree | c119d4e2c533321a9107f1be5a55933c9c590dc3 /python | |
| parent | 61b068347672bf2dbea4ee31d7080d32a3b919fe (diff) | |
[Python] Fix copy_expr_to and add builder methods for recently-added instructions
Diffstat (limited to 'python')
| -rw-r--r-- | python/examples/pseudo_python.py | 118 | ||||
| -rw-r--r-- | python/highlevelil.py | 147 | ||||
| -rw-r--r-- | python/lowlevelil.py | 198 | ||||
| -rw-r--r-- | python/mediumlevelil.py | 158 |
4 files changed, 621 insertions, 0 deletions
diff --git a/python/examples/pseudo_python.py b/python/examples/pseudo_python.py index af06b461..21398f38 100644 --- a/python/examples/pseudo_python.py +++ b/python/examples/pseudo_python.py @@ -889,6 +889,124 @@ class PseudoPythonFunction(LanguageRepresentationFunction): tokens.append_close_paren() if parens: tokens.append_close_paren() + elif instr.operation == HighLevelILOperation.HLIL_BSWAP: + parens = precedence > OperatorPrecedence.MemberAndFunctionOperatorPrecedence + if parens: + tokens.append_open_paren() + tokens.append(InstructionTextToken(InstructionTextTokenType.OperationToken, "bswap")) + tokens.append_open_paren() + self.perform_get_expr_text(instr.src, tokens, settings) + tokens.append_close_paren() + if parens: + tokens.append_close_paren() + elif instr.operation == HighLevelILOperation.HLIL_POPCNT: + parens = precedence > OperatorPrecedence.MemberAndFunctionOperatorPrecedence + if parens: + tokens.append_open_paren() + tokens.append(InstructionTextToken(InstructionTextTokenType.OperationToken, "popcnt")) + tokens.append_open_paren() + self.perform_get_expr_text(instr.src, tokens, settings) + tokens.append_close_paren() + if parens: + tokens.append_close_paren() + elif instr.operation == HighLevelILOperation.HLIL_CLZ: + parens = precedence > OperatorPrecedence.MemberAndFunctionOperatorPrecedence + if parens: + tokens.append_open_paren() + tokens.append(InstructionTextToken(InstructionTextTokenType.OperationToken, "clz")) + tokens.append_open_paren() + self.perform_get_expr_text(instr.src, tokens, settings) + tokens.append_close_paren() + if parens: + tokens.append_close_paren() + elif instr.operation == HighLevelILOperation.HLIL_CTZ: + parens = precedence > OperatorPrecedence.MemberAndFunctionOperatorPrecedence + if parens: + tokens.append_open_paren() + tokens.append(InstructionTextToken(InstructionTextTokenType.OperationToken, "ctz")) + tokens.append_open_paren() + self.perform_get_expr_text(instr.src, tokens, settings) + tokens.append_close_paren() + if parens: + tokens.append_close_paren() + elif instr.operation == HighLevelILOperation.HLIL_RBIT: + parens = precedence > OperatorPrecedence.MemberAndFunctionOperatorPrecedence + if parens: + tokens.append_open_paren() + tokens.append(InstructionTextToken(InstructionTextTokenType.OperationToken, "rbit")) + tokens.append_open_paren() + self.perform_get_expr_text(instr.src, tokens, settings) + tokens.append_close_paren() + if parens: + tokens.append_close_paren() + elif instr.operation == HighLevelILOperation.HLIL_CLS: + parens = precedence > OperatorPrecedence.MemberAndFunctionOperatorPrecedence + if parens: + tokens.append_open_paren() + tokens.append(InstructionTextToken(InstructionTextTokenType.OperationToken, "cls")) + tokens.append_open_paren() + self.perform_get_expr_text(instr.src, tokens, settings) + tokens.append_close_paren() + if parens: + tokens.append_close_paren() + elif instr.operation == HighLevelILOperation.HLIL_ABS: + parens = precedence > OperatorPrecedence.MemberAndFunctionOperatorPrecedence + if parens: + tokens.append_open_paren() + tokens.append(InstructionTextToken(InstructionTextTokenType.OperationToken, "abs")) + tokens.append_open_paren() + self.perform_get_expr_text(instr.src, tokens, settings) + tokens.append_close_paren() + if parens: + tokens.append_close_paren() + elif instr.operation == HighLevelILOperation.HLIL_MINS: + parens = precedence > OperatorPrecedence.MemberAndFunctionOperatorPrecedence + if parens: + tokens.append_open_paren() + tokens.append(InstructionTextToken(InstructionTextTokenType.OperationToken, "mins")) + tokens.append_open_paren() + self.perform_get_expr_text(instr.left, tokens, settings) + tokens.append(InstructionTextToken(InstructionTextTokenType.TextToken, ", ")) + self.perform_get_expr_text(instr.right, tokens, settings) + tokens.append_close_paren() + if parens: + tokens.append_close_paren() + elif instr.operation == HighLevelILOperation.HLIL_MAXS: + parens = precedence > OperatorPrecedence.MemberAndFunctionOperatorPrecedence + if parens: + tokens.append_open_paren() + tokens.append(InstructionTextToken(InstructionTextTokenType.OperationToken, "maxs")) + tokens.append_open_paren() + self.perform_get_expr_text(instr.left, tokens, settings) + tokens.append(InstructionTextToken(InstructionTextTokenType.TextToken, ", ")) + self.perform_get_expr_text(instr.right, tokens, settings) + tokens.append_close_paren() + if parens: + tokens.append_close_paren() + elif instr.operation == HighLevelILOperation.HLIL_MINU: + parens = precedence > OperatorPrecedence.MemberAndFunctionOperatorPrecedence + if parens: + tokens.append_open_paren() + tokens.append(InstructionTextToken(InstructionTextTokenType.OperationToken, "minu")) + tokens.append_open_paren() + self.perform_get_expr_text(instr.left, tokens, settings) + tokens.append(InstructionTextToken(InstructionTextTokenType.TextToken, ", ")) + self.perform_get_expr_text(instr.right, tokens, settings) + tokens.append_close_paren() + if parens: + tokens.append_close_paren() + elif instr.operation == HighLevelILOperation.HLIL_MAXU: + parens = precedence > OperatorPrecedence.MemberAndFunctionOperatorPrecedence + if parens: + tokens.append_open_paren() + tokens.append(InstructionTextToken(InstructionTextTokenType.OperationToken, "maxu")) + tokens.append_open_paren() + self.perform_get_expr_text(instr.left, tokens, settings) + tokens.append(InstructionTextToken(InstructionTextTokenType.TextToken, ", ")) + self.perform_get_expr_text(instr.right, tokens, settings) + tokens.append_close_paren() + if parens: + tokens.append_close_paren() elif instr.operation == HighLevelILOperation.HLIL_ROUND_TO_INT: parens = precedence > OperatorPrecedence.MemberAndFunctionOperatorPrecedence if parens: diff --git a/python/highlevelil.py b/python/highlevelil.py index f990467c..d664232c 100644 --- a/python/highlevelil.py +++ b/python/highlevelil.py @@ -3862,6 +3862,66 @@ class HighLevelILFunction: """ return self.expr(HighLevelILOperation.HLIL_MULU_DP, a, b, size=size, source_location=loc) + def min_signed( + self, size: int, a: ExpressionIndex, b: ExpressionIndex, loc: Optional['ILSourceLocation'] = None + ) -> ExpressionIndex: + """ + ``min_signed`` signed minimum of expressions ``a`` and ``b`` returning an expression of ``size`` bytes + + :param int size: the size of the result in bytes + :param ExpressionIndex a: LHS expression + :param ExpressionIndex b: RHS expression + :param ILSourceLocation loc: location of returned expression + :return: The expression ``mins.<size>(a, b)`` + :rtype: ExpressionIndex + """ + return self.expr(HighLevelILOperation.HLIL_MINS, a, b, size=size, source_location=loc) + + def max_signed( + self, size: int, a: ExpressionIndex, b: ExpressionIndex, loc: Optional['ILSourceLocation'] = None + ) -> ExpressionIndex: + """ + ``max_signed`` signed maximum of expressions ``a`` and ``b`` returning an expression of ``size`` bytes + + :param int size: the size of the result in bytes + :param ExpressionIndex a: LHS expression + :param ExpressionIndex b: RHS expression + :param ILSourceLocation loc: location of returned expression + :return: The expression ``maxs.<size>(a, b)`` + :rtype: ExpressionIndex + """ + return self.expr(HighLevelILOperation.HLIL_MAXS, a, b, size=size, source_location=loc) + + def min_unsigned( + self, size: int, a: ExpressionIndex, b: ExpressionIndex, loc: Optional['ILSourceLocation'] = None + ) -> ExpressionIndex: + """ + ``min_unsigned`` unsigned minimum of expressions ``a`` and ``b`` returning an expression of ``size`` bytes + + :param int size: the size of the result in bytes + :param ExpressionIndex a: LHS expression + :param ExpressionIndex b: RHS expression + :param ILSourceLocation loc: location of returned expression + :return: The expression ``minu.<size>(a, b)`` + :rtype: ExpressionIndex + """ + return self.expr(HighLevelILOperation.HLIL_MINU, a, b, size=size, source_location=loc) + + def max_unsigned( + self, size: int, a: ExpressionIndex, b: ExpressionIndex, loc: Optional['ILSourceLocation'] = None + ) -> ExpressionIndex: + """ + ``max_unsigned`` unsigned maximum of expressions ``a`` and ``b`` returning an expression of ``size`` bytes + + :param int size: the size of the result in bytes + :param ExpressionIndex a: LHS expression + :param ExpressionIndex b: RHS expression + :param ILSourceLocation loc: location of returned expression + :return: The expression ``maxu.<size>(a, b)`` + :rtype: ExpressionIndex + """ + return self.expr(HighLevelILOperation.HLIL_MAXU, a, b, size=size, source_location=loc) + def div_signed( self, size: int, a: ExpressionIndex, b: ExpressionIndex, loc: Optional['ILSourceLocation'] = None ) -> ExpressionIndex: @@ -4014,6 +4074,93 @@ class HighLevelILFunction: """ return self.expr(HighLevelILOperation.HLIL_NOT, value, size=size, source_location=loc) + def byte_swap(self, size: int, value: ExpressionIndex, loc: Optional['ILSourceLocation'] = None) -> ExpressionIndex: + """ + ``byte_swap`` reverses the byte order of expression ``value`` of size ``size`` + + :param int size: the size of the result in bytes + :param ExpressionIndex value: the expression to byte swap + :param ILSourceLocation loc: location of returned expression + :return: The expression ``bswap.<size>(value)`` + :rtype: ExpressionIndex + """ + return self.expr(HighLevelILOperation.HLIL_BSWAP, value, size=size, source_location=loc) + + def population_count(self, size: int, value: ExpressionIndex, loc: Optional['ILSourceLocation'] = None) -> ExpressionIndex: + """ + ``population_count`` counts the number of set bits in expression ``value`` of size ``size`` + + :param int size: the size of the result in bytes + :param ExpressionIndex value: the expression to count set bits in + :param ILSourceLocation loc: location of returned expression + :return: The expression ``popcnt.<size>(value)`` + :rtype: ExpressionIndex + """ + return self.expr(HighLevelILOperation.HLIL_POPCNT, value, size=size, source_location=loc) + + def count_leading_zeros(self, size: int, value: ExpressionIndex, loc: Optional['ILSourceLocation'] = None) -> ExpressionIndex: + """ + ``count_leading_zeros`` counts the leading zero bits in expression ``value`` of size ``size``. The result is + ``8 * size`` when ``value`` is zero. + + :param int size: the size of the result in bytes + :param ExpressionIndex value: the expression to count leading zero bits in + :param ILSourceLocation loc: location of returned expression + :return: The expression ``clz.<size>(value)`` + :rtype: ExpressionIndex + """ + return self.expr(HighLevelILOperation.HLIL_CLZ, value, size=size, source_location=loc) + + def count_trailing_zeros(self, size: int, value: ExpressionIndex, loc: Optional['ILSourceLocation'] = None) -> ExpressionIndex: + """ + ``count_trailing_zeros`` counts the trailing zero bits in expression ``value`` of size ``size``. The result is + ``8 * size`` when ``value`` is zero. + + :param int size: the size of the result in bytes + :param ExpressionIndex value: the expression to count trailing zero bits in + :param ILSourceLocation loc: location of returned expression + :return: The expression ``ctz.<size>(value)`` + :rtype: ExpressionIndex + """ + return self.expr(HighLevelILOperation.HLIL_CTZ, value, size=size, source_location=loc) + + def reverse_bits(self, size: int, value: ExpressionIndex, loc: Optional['ILSourceLocation'] = None) -> ExpressionIndex: + """ + ``reverse_bits`` reverses the bit order of expression ``value`` of size ``size`` + + :param int size: the size of the result in bytes + :param ExpressionIndex value: the expression to reverse the bits of + :param ILSourceLocation loc: location of returned expression + :return: The expression ``rbit.<size>(value)`` + :rtype: ExpressionIndex + """ + return self.expr(HighLevelILOperation.HLIL_RBIT, value, size=size, source_location=loc) + + def count_leading_signs(self, size: int, value: ExpressionIndex, loc: Optional['ILSourceLocation'] = None) -> ExpressionIndex: + """ + ``count_leading_signs`` counts the leading sign bits in expression ``value`` of size ``size`` (the number of bits + below the sign bit that match it) + + :param int size: the size of the result in bytes + :param ExpressionIndex value: the expression to count leading sign bits in + :param ILSourceLocation loc: location of returned expression + :return: The expression ``cls.<size>(value)`` + :rtype: ExpressionIndex + """ + return self.expr(HighLevelILOperation.HLIL_CLS, value, size=size, source_location=loc) + + def absolute_value(self, size: int, value: ExpressionIndex, loc: Optional['ILSourceLocation'] = None) -> ExpressionIndex: + """ + ``absolute_value`` signed absolute value of expression ``value`` of size ``size`` + + :param int size: the size of the result in bytes + :param ExpressionIndex value: the expression to take the absolute value of + :param ILSourceLocation loc: location of returned expression + :return: The expression ``abs.<size>(value)`` + :rtype: ExpressionIndex + """ + return self.expr(HighLevelILOperation.HLIL_ABS, value, size=size, source_location=loc) + def sign_extend(self, size: int, value: ExpressionIndex, loc: Optional['ILSourceLocation'] = None) -> ExpressionIndex: """ ``sign_extend`` two's complement sign-extends the expression in ``value`` to ``size`` bytes diff --git a/python/lowlevelil.py b/python/lowlevelil.py index 9f601fd4..68143203 100644 --- a/python/lowlevelil.py +++ b/python/lowlevelil.py @@ -4177,6 +4177,13 @@ class LowLevelILFunction: LowLevelILOperation.LLIL_PUSH, LowLevelILOperation.LLIL_NEG, LowLevelILOperation.LLIL_NOT, + LowLevelILOperation.LLIL_BSWAP, + LowLevelILOperation.LLIL_POPCNT, + LowLevelILOperation.LLIL_CLZ, + LowLevelILOperation.LLIL_CTZ, + LowLevelILOperation.LLIL_RBIT, + LowLevelILOperation.LLIL_CLS, + LowLevelILOperation.LLIL_ABS, LowLevelILOperation.LLIL_SX, LowLevelILOperation.LLIL_ZX, LowLevelILOperation.LLIL_LOW_PART, @@ -4207,6 +4214,10 @@ class LowLevelILFunction: LowLevelILOperation.LLIL_ROL, LowLevelILOperation.LLIL_ROR, LowLevelILOperation.LLIL_MUL, + LowLevelILOperation.LLIL_MINS, + LowLevelILOperation.LLIL_MAXS, + LowLevelILOperation.LLIL_MINU, + LowLevelILOperation.LLIL_MAXU, LowLevelILOperation.LLIL_MULU_DP, LowLevelILOperation.LLIL_MULS_DP, LowLevelILOperation.LLIL_DIVU, @@ -5076,6 +5087,78 @@ class LowLevelILFunction: """ return self.expr(LowLevelILOperation.LLIL_MULU_DP, a, b, size=size, flags=flags, source_location=loc) + def min_signed( + self, size: int, a: ExpressionIndex, b: ExpressionIndex, flags: Optional['architecture.FlagWriteType'] = None, + loc: Optional['ILSourceLocation'] = None + ) -> ExpressionIndex: + """ + ``min_signed`` signed minimum of expressions ``a`` and ``b`` potentially setting flags ``flags`` and returning an + expression of ``size`` bytes. + + :param int size: the size of the result in bytes + :param ExpressionIndex a: LHS expression + :param ExpressionIndex b: RHS expression + :param FlagWriteType flags: optional, flag write type caused by this operation + :param ILSourceLocation loc: location of returned expression + :return: The expression ``mins.<size>{<flags>}(a, b)`` + :rtype: ExpressionIndex + """ + return self.expr(LowLevelILOperation.LLIL_MINS, a, b, size=size, flags=flags, source_location=loc) + + def max_signed( + self, size: int, a: ExpressionIndex, b: ExpressionIndex, flags: Optional['architecture.FlagWriteType'] = None, + loc: Optional['ILSourceLocation'] = None + ) -> ExpressionIndex: + """ + ``max_signed`` signed maximum of expressions ``a`` and ``b`` potentially setting flags ``flags`` and returning an + expression of ``size`` bytes. + + :param int size: the size of the result in bytes + :param ExpressionIndex a: LHS expression + :param ExpressionIndex b: RHS expression + :param FlagWriteType flags: optional, flag write type caused by this operation + :param ILSourceLocation loc: location of returned expression + :return: The expression ``maxs.<size>{<flags>}(a, b)`` + :rtype: ExpressionIndex + """ + return self.expr(LowLevelILOperation.LLIL_MAXS, a, b, size=size, flags=flags, source_location=loc) + + def min_unsigned( + self, size: int, a: ExpressionIndex, b: ExpressionIndex, flags: Optional['architecture.FlagWriteType'] = None, + loc: Optional['ILSourceLocation'] = None + ) -> ExpressionIndex: + """ + ``min_unsigned`` unsigned minimum of expressions ``a`` and ``b`` potentially setting flags ``flags`` and returning an + expression of ``size`` bytes. + + :param int size: the size of the result in bytes + :param ExpressionIndex a: LHS expression + :param ExpressionIndex b: RHS expression + :param FlagWriteType flags: optional, flag write type caused by this operation + :param ILSourceLocation loc: location of returned expression + :return: The expression ``minu.<size>{<flags>}(a, b)`` + :rtype: ExpressionIndex + """ + return self.expr(LowLevelILOperation.LLIL_MINU, a, b, size=size, flags=flags, source_location=loc) + + def max_unsigned( + self, size: int, a: ExpressionIndex, b: ExpressionIndex, flags: Optional['architecture.FlagWriteType'] = None, + loc: Optional['ILSourceLocation'] = None + ) -> ExpressionIndex: + """ + ``max_unsigned`` unsigned maximum of expressions ``a`` and ``b`` potentially setting flags ``flags`` and returning an + expression of ``size`` bytes. + + :param int size: the size of the result in bytes + :param ExpressionIndex a: LHS expression + :param ExpressionIndex b: RHS expression + :param FlagWriteType flags: optional, flag write type caused by this operation + :param ILSourceLocation loc: location of returned expression + :return: The expression ``maxu.<size>{<flags>}(a, b)`` + :rtype: ExpressionIndex + """ + return self.expr(LowLevelILOperation.LLIL_MAXU, a, b, size=size, flags=flags, source_location=loc) + def div_signed( self, size: int, a: ExpressionIndex, b: ExpressionIndex, flags: Optional['architecture.FlagWriteType'] = None, loc: Optional['ILSourceLocation'] = None @@ -5256,6 +5339,121 @@ class LowLevelILFunction: """ return self.expr(LowLevelILOperation.LLIL_NOT, value, size=size, flags=flags, source_location=loc) + def byte_swap( + self, size: int, value: ExpressionIndex, flags: Optional['architecture.FlagWriteType'] = None, + loc: Optional['ILSourceLocation'] = None + ) -> ExpressionIndex: + """ + ``byte_swap`` reverses the byte order of expression ``value`` of size ``size`` potentially setting flags + + :param int size: the size of the result in bytes + :param ExpressionIndex value: the expression to byte swap + :param FlagWriteType flags: optional, flag write type caused by this operation + :param ILSourceLocation loc: location of returned expression + :return: The expression ``bswap.<size>{<flags>}(value)`` + :rtype: ExpressionIndex + """ + return self.expr(LowLevelILOperation.LLIL_BSWAP, value, size=size, flags=flags, source_location=loc) + + def population_count( + self, size: int, value: ExpressionIndex, flags: Optional['architecture.FlagWriteType'] = None, + loc: Optional['ILSourceLocation'] = None + ) -> ExpressionIndex: + """ + ``population_count`` counts the number of set bits in expression ``value`` of size ``size`` potentially setting flags + + :param int size: the size of the result in bytes + :param ExpressionIndex value: the expression to count set bits in + :param FlagWriteType flags: optional, flag write type caused by this operation + :param ILSourceLocation loc: location of returned expression + :return: The expression ``popcnt.<size>{<flags>}(value)`` + :rtype: ExpressionIndex + """ + return self.expr(LowLevelILOperation.LLIL_POPCNT, value, size=size, flags=flags, source_location=loc) + + def count_leading_zeros( + self, size: int, value: ExpressionIndex, flags: Optional['architecture.FlagWriteType'] = None, + loc: Optional['ILSourceLocation'] = None + ) -> ExpressionIndex: + """ + ``count_leading_zeros`` counts the leading zero bits in expression ``value`` of size ``size`` potentially setting + flags. The result is ``8 * size`` when ``value`` is zero. + + :param int size: the size of the result in bytes + :param ExpressionIndex value: the expression to count leading zero bits in + :param FlagWriteType flags: optional, flag write type caused by this operation + :param ILSourceLocation loc: location of returned expression + :return: The expression ``clz.<size>{<flags>}(value)`` + :rtype: ExpressionIndex + """ + return self.expr(LowLevelILOperation.LLIL_CLZ, value, size=size, flags=flags, source_location=loc) + + def count_trailing_zeros( + self, size: int, value: ExpressionIndex, flags: Optional['architecture.FlagWriteType'] = None, + loc: Optional['ILSourceLocation'] = None + ) -> ExpressionIndex: + """ + ``count_trailing_zeros`` counts the trailing zero bits in expression ``value`` of size ``size`` potentially setting + flags. The result is ``8 * size`` when ``value`` is zero. + + :param int size: the size of the result in bytes + :param ExpressionIndex value: the expression to count trailing zero bits in + :param FlagWriteType flags: optional, flag write type caused by this operation + :param ILSourceLocation loc: location of returned expression + :return: The expression ``ctz.<size>{<flags>}(value)`` + :rtype: ExpressionIndex + """ + return self.expr(LowLevelILOperation.LLIL_CTZ, value, size=size, flags=flags, source_location=loc) + + def reverse_bits( + self, size: int, value: ExpressionIndex, flags: Optional['architecture.FlagWriteType'] = None, + loc: Optional['ILSourceLocation'] = None + ) -> ExpressionIndex: + """ + ``reverse_bits`` reverses the bit order of expression ``value`` of size ``size`` potentially setting flags + + :param int size: the size of the result in bytes + :param ExpressionIndex value: the expression to reverse the bits of + :param FlagWriteType flags: optional, flag write type caused by this operation + :param ILSourceLocation loc: location of returned expression + :return: The expression ``rbit.<size>{<flags>}(value)`` + :rtype: ExpressionIndex + """ + return self.expr(LowLevelILOperation.LLIL_RBIT, value, size=size, flags=flags, source_location=loc) + + def count_leading_signs( + self, size: int, value: ExpressionIndex, flags: Optional['architecture.FlagWriteType'] = None, + loc: Optional['ILSourceLocation'] = None + ) -> ExpressionIndex: + """ + ``count_leading_signs`` counts the leading sign bits in expression ``value`` of size ``size`` (the number of bits + below the sign bit that match it) potentially setting flags + + :param int size: the size of the result in bytes + :param ExpressionIndex value: the expression to count leading sign bits in + :param FlagWriteType flags: optional, flag write type caused by this operation + :param ILSourceLocation loc: location of returned expression + :return: The expression ``cls.<size>{<flags>}(value)`` + :rtype: ExpressionIndex + """ + return self.expr(LowLevelILOperation.LLIL_CLS, value, size=size, flags=flags, source_location=loc) + + def absolute_value( + self, size: int, value: ExpressionIndex, flags: Optional['architecture.FlagWriteType'] = None, + loc: Optional['ILSourceLocation'] = None + ) -> ExpressionIndex: + """ + ``absolute_value`` signed absolute value of expression ``value`` of size ``size`` potentially setting flags + + :param int size: the size of the result in bytes + :param ExpressionIndex value: the expression to take the absolute value of + :param FlagWriteType flags: optional, flag write type caused by this operation + :param ILSourceLocation loc: location of returned expression + :return: The expression ``abs.<size>{<flags>}(value)`` + :rtype: ExpressionIndex + """ + return self.expr(LowLevelILOperation.LLIL_ABS, value, size=size, flags=flags, source_location=loc) + def sign_extend( self, size: int, value: ExpressionIndex, flags: Optional['architecture.FlagWriteType'] = None, loc: Optional['ILSourceLocation'] = None diff --git a/python/mediumlevelil.py b/python/mediumlevelil.py index 018a817f..4d0d5834 100644 --- a/python/mediumlevelil.py +++ b/python/mediumlevelil.py @@ -4210,6 +4210,13 @@ class MediumLevelILFunction: if expr.operation in [ MediumLevelILOperation.MLIL_NEG, MediumLevelILOperation.MLIL_NOT, + MediumLevelILOperation.MLIL_BSWAP, + MediumLevelILOperation.MLIL_POPCNT, + MediumLevelILOperation.MLIL_CLZ, + MediumLevelILOperation.MLIL_CTZ, + MediumLevelILOperation.MLIL_RBIT, + MediumLevelILOperation.MLIL_CLS, + MediumLevelILOperation.MLIL_ABS, MediumLevelILOperation.MLIL_SX, MediumLevelILOperation.MLIL_ZX, MediumLevelILOperation.MLIL_LOW_PART, @@ -4243,6 +4250,10 @@ class MediumLevelILFunction: MediumLevelILOperation.MLIL_ROL, MediumLevelILOperation.MLIL_ROR, MediumLevelILOperation.MLIL_MUL, + MediumLevelILOperation.MLIL_MINS, + MediumLevelILOperation.MLIL_MAXS, + MediumLevelILOperation.MLIL_MINU, + MediumLevelILOperation.MLIL_MAXU, MediumLevelILOperation.MLIL_MULU_DP, MediumLevelILOperation.MLIL_MULS_DP, MediumLevelILOperation.MLIL_DIVU, @@ -5212,6 +5223,66 @@ class MediumLevelILFunction: """ return self.expr(MediumLevelILOperation.MLIL_MULU_DP, a, b, size=size, source_location=loc) + def min_signed( + self, size: int, a: ExpressionIndex, b: ExpressionIndex, loc: Optional['ILSourceLocation'] = None + ) -> ExpressionIndex: + """ + ``min_signed`` signed minimum of expressions ``a`` and ``b`` returning an expression of ``size`` bytes + + :param int size: the size of the result in bytes + :param ExpressionIndex a: LHS expression + :param ExpressionIndex b: RHS expression + :param ILSourceLocation loc: location of returned expression + :return: The expression ``mins.<size>(a, b)`` + :rtype: ExpressionIndex + """ + return self.expr(MediumLevelILOperation.MLIL_MINS, a, b, size=size, source_location=loc) + + def max_signed( + self, size: int, a: ExpressionIndex, b: ExpressionIndex, loc: Optional['ILSourceLocation'] = None + ) -> ExpressionIndex: + """ + ``max_signed`` signed maximum of expressions ``a`` and ``b`` returning an expression of ``size`` bytes + + :param int size: the size of the result in bytes + :param ExpressionIndex a: LHS expression + :param ExpressionIndex b: RHS expression + :param ILSourceLocation loc: location of returned expression + :return: The expression ``maxs.<size>(a, b)`` + :rtype: ExpressionIndex + """ + return self.expr(MediumLevelILOperation.MLIL_MAXS, a, b, size=size, source_location=loc) + + def min_unsigned( + self, size: int, a: ExpressionIndex, b: ExpressionIndex, loc: Optional['ILSourceLocation'] = None + ) -> ExpressionIndex: + """ + ``min_unsigned`` unsigned minimum of expressions ``a`` and ``b`` returning an expression of ``size`` bytes + + :param int size: the size of the result in bytes + :param ExpressionIndex a: LHS expression + :param ExpressionIndex b: RHS expression + :param ILSourceLocation loc: location of returned expression + :return: The expression ``minu.<size>(a, b)`` + :rtype: ExpressionIndex + """ + return self.expr(MediumLevelILOperation.MLIL_MINU, a, b, size=size, source_location=loc) + + def max_unsigned( + self, size: int, a: ExpressionIndex, b: ExpressionIndex, loc: Optional['ILSourceLocation'] = None + ) -> ExpressionIndex: + """ + ``max_unsigned`` unsigned maximum of expressions ``a`` and ``b`` returning an expression of ``size`` bytes + + :param int size: the size of the result in bytes + :param ExpressionIndex a: LHS expression + :param ExpressionIndex b: RHS expression + :param ILSourceLocation loc: location of returned expression + :return: The expression ``maxu.<size>(a, b)`` + :rtype: ExpressionIndex + """ + return self.expr(MediumLevelILOperation.MLIL_MAXU, a, b, size=size, source_location=loc) + def div_signed( self, size: int, a: ExpressionIndex, b: ExpressionIndex, loc: Optional['ILSourceLocation'] = None ) -> ExpressionIndex: @@ -5364,6 +5435,93 @@ class MediumLevelILFunction: """ return self.expr(MediumLevelILOperation.MLIL_NOT, value, size=size, source_location=loc) + def byte_swap(self, size: int, value: ExpressionIndex, loc: Optional['ILSourceLocation'] = None) -> ExpressionIndex: + """ + ``byte_swap`` reverses the byte order of expression ``value`` of size ``size`` + + :param int size: the size of the result in bytes + :param ExpressionIndex value: the expression to byte swap + :param ILSourceLocation loc: location of returned expression + :return: The expression ``bswap.<size>(value)`` + :rtype: ExpressionIndex + """ + return self.expr(MediumLevelILOperation.MLIL_BSWAP, value, size=size, source_location=loc) + + def population_count(self, size: int, value: ExpressionIndex, loc: Optional['ILSourceLocation'] = None) -> ExpressionIndex: + """ + ``population_count`` counts the number of set bits in expression ``value`` of size ``size`` + + :param int size: the size of the result in bytes + :param ExpressionIndex value: the expression to count set bits in + :param ILSourceLocation loc: location of returned expression + :return: The expression ``popcnt.<size>(value)`` + :rtype: ExpressionIndex + """ + return self.expr(MediumLevelILOperation.MLIL_POPCNT, value, size=size, source_location=loc) + + def count_leading_zeros(self, size: int, value: ExpressionIndex, loc: Optional['ILSourceLocation'] = None) -> ExpressionIndex: + """ + ``count_leading_zeros`` counts the leading zero bits in expression ``value`` of size ``size``. The result is + ``8 * size`` when ``value`` is zero. + + :param int size: the size of the result in bytes + :param ExpressionIndex value: the expression to count leading zero bits in + :param ILSourceLocation loc: location of returned expression + :return: The expression ``clz.<size>(value)`` + :rtype: ExpressionIndex + """ + return self.expr(MediumLevelILOperation.MLIL_CLZ, value, size=size, source_location=loc) + + def count_trailing_zeros(self, size: int, value: ExpressionIndex, loc: Optional['ILSourceLocation'] = None) -> ExpressionIndex: + """ + ``count_trailing_zeros`` counts the trailing zero bits in expression ``value`` of size ``size``. The result is + ``8 * size`` when ``value`` is zero. + + :param int size: the size of the result in bytes + :param ExpressionIndex value: the expression to count trailing zero bits in + :param ILSourceLocation loc: location of returned expression + :return: The expression ``ctz.<size>(value)`` + :rtype: ExpressionIndex + """ + return self.expr(MediumLevelILOperation.MLIL_CTZ, value, size=size, source_location=loc) + + def reverse_bits(self, size: int, value: ExpressionIndex, loc: Optional['ILSourceLocation'] = None) -> ExpressionIndex: + """ + ``reverse_bits`` reverses the bit order of expression ``value`` of size ``size`` + + :param int size: the size of the result in bytes + :param ExpressionIndex value: the expression to reverse the bits of + :param ILSourceLocation loc: location of returned expression + :return: The expression ``rbit.<size>(value)`` + :rtype: ExpressionIndex + """ + return self.expr(MediumLevelILOperation.MLIL_RBIT, value, size=size, source_location=loc) + + def count_leading_signs(self, size: int, value: ExpressionIndex, loc: Optional['ILSourceLocation'] = None) -> ExpressionIndex: + """ + ``count_leading_signs`` counts the leading sign bits in expression ``value`` of size ``size`` (the number of bits + below the sign bit that match it) + + :param int size: the size of the result in bytes + :param ExpressionIndex value: the expression to count leading sign bits in + :param ILSourceLocation loc: location of returned expression + :return: The expression ``cls.<size>(value)`` + :rtype: ExpressionIndex + """ + return self.expr(MediumLevelILOperation.MLIL_CLS, value, size=size, source_location=loc) + + def absolute_value(self, size: int, value: ExpressionIndex, loc: Optional['ILSourceLocation'] = None) -> ExpressionIndex: + """ + ``absolute_value`` signed absolute value of expression ``value`` of size ``size`` + + :param int size: the size of the result in bytes + :param ExpressionIndex value: the expression to take the absolute value of + :param ILSourceLocation loc: location of returned expression + :return: The expression ``abs.<size>(value)`` + :rtype: ExpressionIndex + """ + return self.expr(MediumLevelILOperation.MLIL_ABS, value, size=size, source_location=loc) + def sign_extend(self, size: int, value: ExpressionIndex, loc: Optional['ILSourceLocation'] = None) -> ExpressionIndex: """ ``sign_extend`` two's complement sign-extends the expression in ``value`` to ``size`` bytes |
