コード例 #1
0
 def visit_UnaryOpCode(self, node):
     if SInstructions.is_arithmetic_op(node) and isinstance(node.operand, (structural_nodes.Int, structural_nodes.Bytes)):
         if not formats.is_strict_num(int(node.operand)):
             msg = 'Input value to %s is longer than 4 bytes: 0x%x' % (node.name, node.operand)
             if self.options.strict_num:
                 self.error(msg, node.lineno)
                 raise IRStrictNumError(msg)
             else:
                 self.warning(msg, node.lineno)
     return_value = self.visit(node.operand)
     op = types.opcode_by_name(node.name)()
     return return_value + [op]
コード例 #2
0
    def visit_BinOpCode(self, node):
        # Check for values longer than 4 bytes.
        if SInstructions.is_arithmetic_op(node):
            operands = [node.left, node.right]
            if all(isinstance(i, (structural_nodes.Int, structural_nodes.Bytes)) for i in operands):
                valid = [formats.is_strict_num(int(i)) for i in operands]
                if False in valid:
                    msg = 'Input value to %s is longer than 4 bytes: 0x%x' % (node.name, operands[valid.index(False)])
                    if self.options.strict_num:
                        self.error(msg, node.lineno)
                        raise IRStrictNumError(msg)
                    else:
                        self.warning(msg, node.lineno)

        return_value = self.visit(node.left)
        return_value.extend(self.visit(node.right))
        op = types.opcode_by_name(node.name)()
        return return_value + [op]
コード例 #3
0
    def check_types(self, node):
        """Check the operand types of node."""
        if not isinstance(node, structural_nodes.OpCode):
            return
        args = node.get_args()
        if any(isinstance(arg, structural_nodes.Symbol) for arg in args):
            self.require_symbol_table('process operands')
        for i, arg in enumerate(args):
            if isinstance(arg, structural_nodes.Symbol):
                args[i] = self.symbol_table.lookup(arg.name).value

        if SInstructions.is_arithmetic_op(node):
            for arg in args:
                if isinstance(arg, structural_nodes.Bytes):
                    msg = 'Byte array %s used in arithmetic operation' % (arg)
                    self.warning(msg, node.lineno)
        elif SInstructions.is_byte_string_op(node):
            for arg in args:
                if isinstance(arg, structural_nodes.Int):
                    msg = 'Integer %s used in byte string operation' % (arg)
                    self.error(msg, node.lineno)
                    raise IRTypeError(msg, node.lineno)