Exemple #1
0
def eval_input(prompt='', float=True):
    """eval_input(prompt='', float=True)

    Replacement for the built-in python 2 - style ``input`` using
    ``pwnlib`` readline implementation, and `pwnlib.util.safeeval.expr`
    instead of ``eval`` (!).

    Arguments:
        prompt(str): The prompt to show to the user.
        float(bool): If set to ``True``, prompt and input will float to the
                     bottom of the screen when `term.term_mode` is enabled.

    Example:

        >>> try:
        ...     saved = sys.stdin, pwnlib.term.term_mode
        ...     pwnlib.term.term_mode = False
        ...     sys.stdin = io.TextIOWrapper(io.BytesIO(b"{'a': 20}"))
        ...     eval_input("Favorite object? ")['a']
        ... finally:
        ...     sys.stdin, pwnlib.term.term_mode = saved
        Favorite object? 20
    """
    from pwnlib.util import safeeval
    return safeeval.const(readline(-1, prompt, float))
Exemple #2
0
    def input(prompt = '', float = True):
        """input(prompt = '', float = True)

        Replacement for the built-in `input` using ``pwnlib``s readline
        implementation, and `pwnlib.util.safeeval.expr` instead of `eval` (!).

        Arguments:
            prompt(str): The prompt to show to the user.
            float(bool): If set to `True`, prompt and input will float to the
                         bottom of the screen when `term.term_mode` is enabled.
        """
        return safeeval.const(readline(None, prompt, float))
Exemple #3
0
    def input(prompt='', float=True):
        """input(prompt = '', float = True)

        Replacement for the built-in `input` using ``pwnlib``s readline
        implementation, and `pwnlib.util.safeeval.expr` instead of `eval` (!).

        Arguments:
            prompt(str): The prompt to show to the user.
            float(bool): If set to `True`, prompt and input will float to the
                         bottom of the screen when `term.term_mode` is enabled.
        """
        return safeeval.const(readline(None, prompt, float))
Exemple #4
0
def line2code(line, consts, names, varnames, labels, code):
    kwdargs = line.split()
    kwd, args = kwdargs[0], kwdargs[1:]
    if not args and kwd.endswith(':'):
        lbl = kwd[:-1]
        pos = len(code)
        labels[lbl] = pos
        for off in labels.pop(kwd, ()):
            eoff = off+(ARGMASKLEN>>3)
            posx = pos
            if code[off-1] in dis.hasjrel:
                posx -= eoff
            code[off:eoff] = basic_op(0, posx)[1:]
        return b''
    op = dis.opmap[kwd]
    if op < dis.HAVE_ARGUMENT:
        assert not args
        return simple_op(op)
    if op in dis.hasconst:
        co = safeeval.const(' '.join(args))
        arg = find(co, consts)
    elif op in dis.hasname:
        arg, = args
        arg = find(arg, names)
    elif op in dis.haslocal:
        arg, = args
        arg = find(arg, varnames)
    elif op in dis.hasjabs + dis.hasjrel:
        arg, = args
        if arg in labels:
            arg = labels[arg]
            if op in dis.hasjrel:
                arg -= len(code)+1+(ARGMASKLEN>>3)
        else:
            labels.setdefault(arg+':', []).append(len(code)+1)
            arg = ARGMASK
    elif op in dis.hascompare:
        arg, = args
        arg = dis.cmp_op.index(arg)
    else:
        arg, = args
        arg = int(arg, 0)
    return basic_op(op, arg)