diff --git a/examples/child_gating.py b/examples/child_gating.py index ce663ca..2006851 100644 --- a/examples/child_gating.py +++ b/examples/child_gating.py @@ -26,7 +26,7 @@ class Application: "BADGER": "badger-badger-badger", "SNAKE": "mushroom-mushroom", } - print("✔ spawn(argv={})".format(argv)) + print(f"✔ spawn(argv={argv})") pid = self._device.spawn(argv, env=env, stdio='pipe') self._instrument(pid) @@ -35,7 +35,7 @@ class Application: self._stop_requested.set() def _instrument(self, pid): - print("✔ attach(pid={})".format(pid)) + print(f"✔ attach(pid={pid})") session = self._device.attach(pid) session.on("detached", lambda reason: self._reactor.schedule(lambda: self._on_detached(pid, session, reason))) print("✔ enable_child_gating()") @@ -54,27 +54,27 @@ Interceptor.attach(Module.getExportByName(null, 'open'), { script.on("message", lambda message, data: self._reactor.schedule(lambda: self._on_message(pid, message))) print("✔ load()") script.load() - print("✔ resume(pid={})".format(pid)) + print(f"✔ resume(pid={pid})") self._device.resume(pid) self._sessions.add(session) def _on_child_added(self, child): - print("⚡ child_added: {}".format(child)) + print(f"⚡ child_added: {child}") self._instrument(child.pid) def _on_child_removed(self, child): - print("⚡ child_removed: {}".format(child)) + print(f"⚡ child_removed: {child}") def _on_output(self, pid, fd, data): - print("⚡ output: pid={}, fd={}, data={}".format(pid, fd, repr(data))) + print(f"⚡ output: pid={pid}, fd={fd}, data={repr(data)}") def _on_detached(self, pid, session, reason): - print("⚡ detached: pid={}, reason='{}'".format(pid, reason)) + print(f"⚡ detached: pid={pid}, reason='{reason}'") self._sessions.remove(session) self._reactor.schedule(self._stop_if_idle, delay=0.5) def _on_message(self, pid, message): - print("⚡ message: pid={}, payload={}".format(pid, message["payload"])) + print(f"⚡ message: pid={pid}, payload={message['payload']}") app = Application() diff --git a/examples/cpushark/Capture.py b/examples/cpushark/Capture.py index 492b673..1eee57a 100644 --- a/examples/cpushark/Capture.py +++ b/examples/cpushark/Capture.py @@ -126,7 +126,7 @@ class Capture(NSObject): self._delegate.captureRecvTotalDidChange() else: if not self.calls._handleStanza_(stanza): - print("Woot! Got stanza: %s from=%s" % (stanza['name'], stanza['from'])) + print(f"Woot! Got stanza: {stanza['name']} from={stanza['from']}") else: print("Unhandled message:", message) @@ -355,7 +355,7 @@ class FunctionCall(NSObject): self = self.init() self.func = func self.args = args - self.summary = "%s(%s)" % (func.name, ", ".join(args)) + self.summary = f"{func.name}({', '.join(args)})" return self SCRIPT_TEMPLATE = """ diff --git a/examples/enumerate_applications.py b/examples/enumerate_applications.py index 79b1b50..59480ae 100644 --- a/examples/enumerate_applications.py +++ b/examples/enumerate_applications.py @@ -17,8 +17,5 @@ for app in apps: params = dict(app.parameters) if 'icons' in params: params['icons'] = [trim_icon(icon) for icon in params['icons']] - print("Application(identifier=\"{}\", name=\"{}\", pid={}, parameters={})".format( - app.identifier, - app.name, - app.pid, - highlight(pformat(params), PythonLexer(), Terminal256Formatter()).rstrip())) + parameters = highlight(pformat(params), PythonLexer(), Terminal256Formatter()).rstrip() + print(f"Application(identifier=\"{app.identifier}\", name=\"{app.name}\", pid={app.pid}, parameters={parameters})") diff --git a/examples/enumerate_processes.py b/examples/enumerate_processes.py index 9cc6d23..588f35a 100644 --- a/examples/enumerate_processes.py +++ b/examples/enumerate_processes.py @@ -17,4 +17,4 @@ for proc in processes: params = dict(proc.parameters) if 'icons' in params: params['icons'] = [trim_icon(icon) for icon in params['icons']] - print("Process(pid={}, name=\"{}\", parameters={})".format(proc.pid, proc.name, highlight(pformat(params), PythonLexer(), Terminal256Formatter()).rstrip())) + print(f"Process(pid={proc.pid}, name=\"{proc.name}\", parameters={highlight(pformat(params), PythonLexer(), Terminal256Formatter()).rstrip()})") diff --git a/examples/get_frontmost_application.py b/examples/get_frontmost_application.py index 392e45c..04f512f 100644 --- a/examples/get_frontmost_application.py +++ b/examples/get_frontmost_application.py @@ -17,6 +17,6 @@ if app is not None: params = dict(app.parameters) if 'icons' in params: params['icons'] = [trim_icon(icon) for icon in params['icons']] - print("{}:".format(app.identifier), highlight(pformat(params), PythonLexer(), Terminal256Formatter())) + print(f"{app.identifier}:", highlight(pformat(params), PythonLexer(), Terminal256Formatter())) else: print("No frontmost application") diff --git a/examples/portal_client.py b/examples/portal_client.py index 9608536..1dbbc21 100644 --- a/examples/portal_client.py +++ b/examples/portal_client.py @@ -51,7 +51,7 @@ class Application: }) channel = text[6:] self._channel = channel - self._prompt = "{} > ".format(channel) + self._prompt = f"{channel} > " self._bus.post({ 'type': 'join', 'channel': channel @@ -80,19 +80,19 @@ class Application: self._print("*** Welcome! Available channels:", repr(message['channels'])) elif mtype == 'membership': self._print("*** Joined", message['channel']) - self._print("- Members:\n\t" + "\n\t".join(["{} (connected from {})".format(m['nick'], m['address']) for m in message['members']])) + self._print("- Members:\n\t" + "\n\t".join([f"{m['nick']} (connected from {m['address']})" for m in message['members']])) for item in message['history']: - self._print("<{}> {}".format(item['sender'], item['text'])) + self._print(f"<{item['sender']}> {item['text']}") elif mtype == 'join': user = message['user'] - self._print("👋 {} ({}) joined {}".format(user['nick'], user['address'], message['channel'])) + self._print(f"👋 {user['nick']} ({user['address']}) joined {message['channel']}") elif mtype == 'part': user = message['user'] - self._print("🚪 {} ({}) left {}".format(user['nick'], user['address'], message['channel'])) + self._print(f"🚪 {user['nick']} ({user['address']}) left {message['channel']}") elif mtype == 'chat': - self._print("<{}> {}".format(message['sender'], message['text'])) + self._print(f"<{message['sender']}> {message['text']}") elif mtype == 'announce': - self._print("📣 <{}> {}".format(message['sender'], message['text'])) + self._print(f"📣 <{message['sender']}> {message['text']}") else: self._print("Unhandled message:", message) diff --git a/examples/session_persist_timeout.py b/examples/session_persist_timeout.py index 87ec115..02c614f 100644 --- a/examples/session_persist_timeout.py +++ b/examples/session_persist_timeout.py @@ -68,10 +68,10 @@ function puts(s) { print("Unknown command") def _on_detached(self, reason, crash): - print("⚡ detached: reason={}, crash={}".format(reason, crash)) + print(f"⚡ detached: reason={reason}, crash={crash}") def _on_message(self, message, data): - print("⚡ message: {}".format(message)) + print(f"⚡ message: {message}") app = Application() diff --git a/frida/__init__.py b/frida/__init__.py index c1ad7e7..dc86a1d 100644 --- a/frida/__init__.py +++ b/frida/__init__.py @@ -7,7 +7,7 @@ except Exception as ex: print("Frida native extension not found") print("Please check your PYTHONPATH.") else: - print("Failed to load the Frida native extension: %s" % ex) + print(f"Failed to load the Frida native extension: {ex}") print("Please ensure that the extension was compiled correctly") print("***") print("") diff --git a/frida/core.py b/frida/core.py index bd74f28..6754864 100644 --- a/frida/core.py +++ b/frida/core.py @@ -121,9 +121,10 @@ class Device: if len(matching) == 1: return matching[0] elif len(matching) > 1: - raise _frida.ProcessNotFoundError("ambiguous name; it matches: %s" % ", ".join(["%s (pid: %d)" % (process.name, process.pid) for process in matching])) + matches_list = ", ".join([f"{process.name} (pid: {process.pid})" for process in matching]) + raise _frida.ProcessNotFoundError(f"ambiguous name; it matches: {matches_list}") else: - raise _frida.ProcessNotFoundError("unable to find process with name '%s'" % process_name) + raise _frida.ProcessNotFoundError(f"unable to find process with name '{process_name}'") @cancellable def enable_spawn_gating(self): diff --git a/meson.build b/meson.build index 0c9c280..49e626a 100644 --- a/meson.build +++ b/meson.build @@ -54,7 +54,7 @@ if python_incdir == '' endif result = run_command(python, '-c', - 'import sys; sys.stdout.write("%d.%d" % (sys.version_info[0], sys.version_info[1]))', + 'import sys; sys.stdout.write(f"{sys.version_info[0]}.{sys.version_info[1]}")', check: true) python_version = result.stdout() python_name = 'python' + python_version diff --git a/setup.py b/setup.py index 56a51bc..0c3fcf3 100755 --- a/setup.py +++ b/setup.py @@ -73,14 +73,14 @@ class FridaPrebuiltExt(build_ext): arch_name = 'armv7l' else: arch_name = machine - os_version = "{}-{}".format(os_name, arch_name) + os_version = f"{os_name}-{arch_name}" elif system == 'FreeBSD': os_version = "freebsd-" + platform.machine() else: raise NotImplementedError("unsupported OS") egg_path = os.path.expanduser( - "~{}frida-{}-py{}.{}-{}.egg".format(os.sep, frida_version, python_version[0], python_version[1], os_version)) + f"~{os.sep}frida-{frida_version}-py{python_version[0]}.{python_version[1]}-{os_version}.egg") print("looking for prebuilt extension in home directory, i.e.", egg_path) try: @@ -98,10 +98,7 @@ class FridaPrebuiltExt(build_ext): index_url = normalize_url(index_url) frida_url = urljoin(index_url, "frida/") # slash is necessary here timeout = 20 - errmsg = ( - "unable to download it within {} seconds; " - "please download it manually to {}" - ).format("{}", egg_path) + errmsg = "unable to download it within {} seconds; " f"please download it manually to {egg_path}" print("downloading package list from", frida_url) try: @@ -168,7 +165,7 @@ def get_index_url(): else: return index_url - print("using default index URL: {}".format(DEFAULT_INDEX_URL)) + print(f"using default index URL: {DEFAULT_INDEX_URL}") return DEFAULT_INDEX_URL @@ -241,9 +238,7 @@ def check_pep503_hash(bytes_io, url): hashname, hashvalue = fragment.split("=") if hashname not in {"md5", "sha1", "sha224", "sha256", "sha348", "sha512"}: - raise ValueError("Unsupported hash algorithm: {}, hashvalue={}".format( - hashname, hashvalue, - )) + raise ValueError(f"Unsupported hash algorithm: {hashname}, hashvalue={hashvalue}") h = hashlib.new(hashname) for block in iter(partial(bytes_io.read, 4096), b""): # iterate until EOF @@ -254,10 +249,7 @@ def check_pep503_hash(bytes_io, url): if digest == hashvalue: return else: - raise ValueError( - "`{}` hash checking failed! Expected: {}, but got: {}".format( - hashname, hashvalue, digest) - ) + raise ValueError(f"`{hashname}` hash checking failed! Expected: {hashvalue}, but got: {digest}") if __name__ == "__main__":