示例#1
0
        msgtype, key = key.split('.', 1)

        if key == 'color':
            current = _msgtype_prefixes[msgtype][0]
            _msgtype_prefixes[msgtype][0] = getattr(text, value, current)

        elif key == 'symbol':
            _msgtype_prefixes[msgtype][1] = value

        else:
            log.warn("Unknown configuration option %r in section %r" %
                     (key, 'log'))


register_config('log', read_log_config)

# the text decoration to use for spinners.  the spinners themselves can be found
# in the `pwnlib.term.spinners` module
_spinner_style = text.bold_blue


class Progress(object):
    """
    Progress logger used to generate log records associated with some running
    job.  Instances can be used as context managers which will automatically
    declare the running job a success upon exit or a failure upon a thrown
    exception.  After :meth:`success` or :meth:`failure` is called the status
    can no longer be updated.

    This class is intended for internal use.  Progress loggers should be created
示例#2
0
                disabled = True
            else:
                try:
                    value = int(value)
                except ValueError:
                    log.warn("Wrong value")
                else:
                    global update_freq
                    update_freq = datetime.timedelta(
                        days=value).total_seconds()
        else:
            log.warn("Unknown configuration option %r in section %r" %
                     (key, 'update'))


register_config('update', read_update_config)


def available_on_pypi(prerelease=current_version.is_prerelease):
    """Return True if an update is available on PyPI.

    >>> available_on_pypi() # doctest: +ELLIPSIS
    <Version('...')>
    >>> available_on_pypi(prerelease=False).is_prerelease
    False
    """
    versions = getattr(available_on_pypi, 'cached', None)
    if versions is None:
        client = ServerProxy('https://pypi.python.org/pypi')
        versions = client.package_releases('pwntools', True)
        available_on_pypi.cached = versions
示例#3
0
    log = getLogger(__name__)
    for key, value in section.items():
        if key not in ContextType.defaults:
            log.warn("Unknown configuration option %r in section %r" %
                     (key, 'context'))
            continue

        default = ContextType.defaults[key]

        if isinstance(
                default,
                six.string_types + six.integer_types + (tuple, list, dict)):
            value = safeeval.expr(value)
        else:
            log.warn("Unsupported configuration option %r in section %r" %
                     (key, 'context'))

        # Attempt to set the value, to see if it is value:
        try:
            with context.local(**{key: value}):
                value = getattr(context, key)
        except (ValueError, AttributeError) as e:
            log.warn("Could not set context.%s=%s via pwn.conf (%s)", key,
                     section[key], e)
            continue

        ContextType.defaults[key] = value


register_config('context', update_context_defaults)
示例#4
0
        i386
        >>> printArch(arch='arm')
        arm
    """
    @functools.wraps(function)
    def setter(*a, **kw):
        # Fast path to skip adding a Context frame
        if not kw:
            return function(*a)

        with context.local(**{k:kw.pop(k) for k,v in kw.items() if isinstance(getattr(ContextType, k, None), property)}):
            return function(*a, **kw)
    return setter

# Read configuration options from the context section
def update_context_defaults(section):
    # Circular imports FTW!
    from pwnlib.util import safeeval
    from pwnlib.log import getLogger
    log = getLogger(__name__)
    for key, value in section.items():
        if key not in ContextType.defaults:
            log.warn("Unknown configuration option %r in section %r" % (key, 'context'))
            continue
        if isinstance(ContextType.defaults[key], (str, unicode, tuple)):
            value = safeeval.expr(value)

        ContextType.defaults[key] = value

register_config('context', update_context_defaults)
示例#5
0
文件: log.py 项目: cxh852456/pwntools
            log.warn("Invalid configuration option %r in section %r" % (key, 'log'))
            continue

        msgtype, key = key.split('.', 1)

        if key == 'color':
            current = _msgtype_prefixes[msgtype][0]
            _msgtype_prefixes[msgtype][0] = getattr(text, value, current)

        elif key == 'symbol':
            _msgtype_prefixes[msgtype][1] = value

        else:
            log.warn("Unknown configuration option %r in section %r" % (key, 'log'))

register_config('log', read_log_config)

# the text decoration to use for spinners.  the spinners themselves can be found
# in the `pwnlib.term.spinners` module
_spinner_style = text.bold_blue

class Progress(object):
    """
    Progress logger used to generate log records associated with some running
    job.  Instances can be used as context managers which will automatically
    declare the running job a success upon exit or a failure upon a thrown
    exception.  After :meth:`success` or :meth:`failure` is called the status
    can no longer be updated.

    This class is intended for internal use.  Progress loggers should be created
    using :meth:`Logger.progress`.