Exemplo n.º 1
0
    def evaluate_expression(self, expression, frame_idx=0):
        # XXX: cdb insists on using '->' to examine fields of structures,
        # as it appears to reserve '.' for other purposes.
        fixed_expr = expression.replace('.', '->')

        orig_scope_idx = self.client.Symbols.GetCurrentScopeFrameIndex()
        self.client.Symbols.SetScopeFrameByIndex(frame_idx)

        res = self.client.Control.Evaluate(fixed_expr)
        if res is not None:
          result, typename = self.client.Control.Evaluate(fixed_expr)
          could_eval = True
        else:
          result, typename = (None, None)
          could_eval = False

        self.client.Symbols.SetScopeFrameByIndex(orig_scope_idx)

        return ValueIR(
            expression=expression,
            value=str(result),
            type_name=typename,
            error_string="",
            could_evaluate=could_eval,
            is_optimized_away=False,
            is_irretrievable=not could_eval)
Exemplo n.º 2
0
    def evaluate_expression(self, expression, frame_idx=0) -> ValueIR:
        self.set_current_stack_frame(frame_idx)
        result = self._debugger.GetExpression(expression)
        self.set_current_stack_frame(0)
        value = result.Value

        is_optimized_away = any(s in value for s in [
            'Variable is optimized away and not available',
            'Value is not available, possibly due to optimization',
        ])

        is_irretrievable = any(s in value for s in [
            '???',
            '<Unable to read memory>',
        ])

        # an optimized away value is still counted as being able to be
        # evaluated.
        could_evaluate = (result.IsValidValue or is_optimized_away
                          or is_irretrievable)

        return ValueIR(
            expression=expression,
            value=value,
            type_name=result.Type,
            error_string=None,
            is_optimized_away=is_optimized_away,
            could_evaluate=could_evaluate,
            is_irretrievable=is_irretrievable,
        )
Exemplo n.º 3
0
 def eval(self, step_info):
     return {'DexExpectStepOrder': ValueIR(expression=str(step_info.current_location.lineno),
                   value=str(step_info.step_index), type_name=None,
                   error_string=None,
                   could_evaluate=True,
                   is_optimized_away=True,
                   is_irretrievable=False)}
Exemplo n.º 4
0
 def eval(self, step_info):
     # If we're ever called, at all, then we're evaluating a line that has
     # been marked as unreachable. Which means a failure.
     vir = ValueIR(expression="Unreachable",
                   value="True", type_name=None,
                   error_string=None,
                   could_evaluate=True,
                   is_optimized_away=True,
                   is_irretrievable=False)
     return {'DexUnreachable' : vir}
Exemplo n.º 5
0
    def evaluate_expression(self, expression, frame_idx=0) -> ValueIR:
        result = self._thread.GetFrameAtIndex(frame_idx).EvaluateExpression(
            expression)
        error_string = str(result.error)

        value = result.value
        could_evaluate = not any(s in error_string for s in [
            "Can't run the expression locally",
            "use of undeclared identifier",
            "no member named",
            "Couldn't lookup symbols",
            "reference to local variable",
            "invalid use of 'this' outside of a non-static member function",
        ])

        is_optimized_away = any(s in error_string for s in [
            'value may have been optimized out',
        ])

        is_irretrievable = any(s in error_string for s in [
            "couldn't get the value of variable",
            "couldn't read its memory",
            "couldn't read from memory",
            "Cannot access memory at address",
            "invalid address (fault address:",
        ])

        if could_evaluate and not is_irretrievable and not is_optimized_away:
            assert error_string == 'success', (error_string, expression, value)
            # assert result.value is not None, (result.value, expression)

        if error_string == 'success':
            error_string = None

        # attempt to find expression as a variable, if found, take the variable
        # obj's type information as it's 'usually' more accurate.
        var_result = self._thread.GetFrameAtIndex(frame_idx).FindVariable(
            expression)
        if str(var_result.error) == 'success':
            type_name = var_result.type.GetDisplayTypeName()
        else:
            type_name = result.type.GetDisplayTypeName()

        return ValueIR(
            expression=expression,
            value=value,
            type_name=type_name,
            error_string=error_string,
            could_evaluate=could_evaluate,
            is_optimized_away=is_optimized_away,
            is_irretrievable=is_irretrievable,
        )
Exemplo n.º 6
0
 def eval(self, debugger):
     step_info = debugger.get_step_info()
     loc = step_info.current_location
     return {
         'DexExpectStepOrder':
         ValueIR(expression=str(loc.lineno),
                 value=str(debugger.step_index),
                 type_name=None,
                 error_string=None,
                 could_evaluate=True,
                 is_optimized_away=True,
                 is_irretrievable=False)
     }
Exemplo n.º 7
0
    def evaluate_expression(self, expression):
        res = self.client.Control.Evaluate(expression)
        if res is not None:
            result, typename = self.client.Control.Evaluate(expression)
            could_eval = True
        else:
            result, typename = (None, None)
            could_eval = False

        return ValueIR(expression=expression,
                       value=str(result),
                       type_name=typename,
                       error_string="",
                       could_evaluate=could_eval,
                       is_optimized_away=False,
                       is_irretrievable=False)