From 9ace73a97703043fc4769cf47bba41b4609364ec Mon Sep 17 00:00:00 2001 From: Zach Riggle Date: Tue, 17 Jan 2017 15:10:25 -0500 Subject: [PATCH] Replace broken function-decorator context.quiet with working context.quietfunc Fixes: ae6a0745f --- pwnlib/adb/adb.py | 38 +++++++++++++++++++------------------- pwnlib/context/__init__.py | 11 ++++++----- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/pwnlib/adb/adb.py b/pwnlib/adb/adb.py index c91d58bb1..14c0b5027 100644 --- a/pwnlib/adb/adb.py +++ b/pwnlib/adb/adb.py @@ -88,7 +88,7 @@ def adb(argv, *a, **kw): return tubes.process.process(context.adb + argv, *a, **kw).recvall() -@context.quiet +@context.quietfunc def devices(serial=None): """Returns a list of ``Device`` objects corresponding to the connected devices.""" with Client() as c: @@ -552,7 +552,7 @@ def push(local_path, remote_path): return c.write(remote_path, misc.read(local_path), callback=_create_adb_push_pull_callback(w)) -@context.quiet +@context.quietfunc @with_device def read(path, target=None, callback=None): """Download a file from the device, and extract its contents. @@ -584,7 +584,7 @@ def read(path, target=None, callback=None): return data -@context.quiet +@context.quietfunc @with_device def write(path, data=''): """Create a file on the device with the provided contents. @@ -602,7 +602,7 @@ def write(path, data=''): misc.write(temp.name, data) push(temp.name, path) -@context.quiet +@context.quietfunc @with_device def mkdir(path): """Create a directory on the target device. @@ -645,7 +645,7 @@ def mkdir(path): if result: log.error(result) -@context.quiet +@context.quietfunc @with_device def makedirs(path): """Create a directory and all parent directories on the target device. @@ -664,7 +664,7 @@ def makedirs(path): mkdir(path) -@context.quiet +@context.quietfunc @with_device def exists(path): """Return :const:`True` if ``path`` exists on the target device. @@ -681,7 +681,7 @@ def exists(path): with Client() as c: return bool(c.stat(path)) -@context.quiet +@context.quietfunc @with_device def isdir(path): """Return :const:`True` if ``path`` is a on the target device. @@ -699,7 +699,7 @@ def isdir(path): st = c.stat(path) return bool(st and stat.S_ISDIR(st['mode'])) -@context.quiet +@context.quietfunc @with_device def unlink(path, recursive=False): """Unlinks a file or directory on the target device. @@ -816,7 +816,7 @@ def forward(port): start_forwarding = adb(['forward', tcp_port, tcp_port]) atexit.register(lambda: adb(['forward', '--remove', tcp_port])) -@context.quiet +@context.quietfunc @with_device def logcat(stream=False): """Reads the system log file. @@ -952,7 +952,7 @@ def address(self): return self.symbols['_text'] @property - @context.quiet + @context.quietfunc def symbols(self): """Returns a dictionary of kernel symbols""" result = {} @@ -964,7 +964,7 @@ def symbols(self): return result @property - @context.quiet + @context.quietfunc def kallsyms(self): """Returns the raw output of kallsyms""" if not self._kallsyms: @@ -975,20 +975,20 @@ def kallsyms(self): return self._kallsyms @property - @context.quiet + @context.quietfunc def version(self): """Returns the kernel version of the device.""" root() return read('/proc/version').strip() @property - @context.quiet + @context.quietfunc def cmdline(self): root() return read('/proc/cmdline').strip() @property - @context.quiet + @context.quietfunc def lastmsg(self): root() if 'last_kmsg' in listdir('/proc'): @@ -1240,15 +1240,15 @@ def readlink(path): class Partitions(object): @property - @context.quiet + @context.quietfunc def by_name_dir(self): return next(find('/dev/block/platform','by-name')) - @context.quiet + @context.quietfunc def __dir__(self): return list(self) - @context.quiet + @context.quietfunc @with_device def __iter__(self): root() @@ -1257,7 +1257,7 @@ def __iter__(self): for name in listdir(self.by_name_dir): yield name - @context.quiet + @context.quietfunc @with_device def __getattr__(self, attr): for name in self: @@ -1327,7 +1327,7 @@ def uninstall(package, *arguments): with context.quiet: return process(['pm','uninstall',package] + list(arguments)).recvall() -@context.quiet +@context.quietfunc def packages(): """Returns a list of packages installed on the system""" packages = process(['pm', 'list', 'packages']).recvall() diff --git a/pwnlib/context/__init__.py b/pwnlib/context/__init__.py index ede5cf567..32bac9d6b 100644 --- a/pwnlib/context/__init__.py +++ b/pwnlib/context/__init__.py @@ -530,12 +530,13 @@ def silent(self, function=None): def quiet(self, function=None): """Disables all non-error logging within the enclosed scope, *unless* the debugging level is set to 'debug' or lower.""" - if not function: - level = 'error' - if context.log_level <= logging.DEBUG: - level = None - return self.local(function, log_level=level) + level = 'error' + if context.log_level <= logging.DEBUG: + level = None + return self.local(function, log_level=level) + def quietfunc(self, function): + """Similar to :attr:`quiet`, but wraps a whole function.""" @functools.wraps(function) def wrapper(*a, **kw): level = 'error'