Fix stylistic inconsistencies

This commit is contained in:
Ole André Vadla Ravnås committed 2026-03-25 18:01:36 +01:00
1 parent 8c077b7d8c
commit 83a76a3719
7 files changed
+83 -82

No files matched your search

+1 -3
View File
@@ -168,9 +168,7 @@ class Time(Magic):
const _endTime = Date.now();
console.log('Time: ' + (_endTime - _startTime) + ' ms.');
return _result;
}})();""".format(
expression=json.dumps(" ".join(args))
),
}})();""".format(expression=json.dumps(" ".join(args))),
)
+2 -2
View File
@@ -154,7 +154,7 @@ def inject(gadget_so: str, lib_dir: str, config: Dict[str, Dict[str, str]], outp
def get_gadget_arch(gadget: BinaryIO) -> str:
ELF_HEADER = struct.Struct("<B3sB13xH")
(m1, m2, bits, machine) = ELF_HEADER.unpack(gadget.read(ELF_HEADER.size))
m1, m2, bits, machine = ELF_HEADER.unpack(gadget.read(ELF_HEADER.size))
if m1 != 0x7F or m2 != b"ELF":
raise ValueError("gadget is not an ELF file")
@@ -218,7 +218,7 @@ class ChunkHeader:
def __init__(self, stream: BufferedReader, consume_data: bool = True) -> None:
self.stream = stream
data = self.stream.peek(struct.calcsize(self.FORMAT))
(self.type, self.header_size, self.size) = struct.unpack_from(self.FORMAT, data)
self.type, self.header_size, self.size = struct.unpack_from(self.FORMAT, data)
if consume_data:
self.chunk_data = self.stream.read(self.size)
else:
+7 -19
View File
@@ -42,7 +42,7 @@ class CreatorApplication(ConsoleApplication):
return False
def _start(self) -> None:
(assets, message) = self._generate()
assets, message = self._generate()
outdir = self._outdir
for name, data in assets.items():
@@ -66,9 +66,7 @@ class CreatorApplication(ConsoleApplication):
def _generate_agent(self) -> Tuple[Dict[str, str], str]:
assets = {}
assets[
"package.json"
] = f"""{{
assets["package.json"] = f"""{{
"name": "{self._project_name}-agent",
"version": "1.0.0",
"description": "Frida agent written in TypeScript",
@@ -87,9 +85,7 @@ class CreatorApplication(ConsoleApplication):
}}
"""
assets[
"tsconfig.json"
] = """\
assets["tsconfig.json"] = """\
{
"compilerOptions": {
"target": "ES2022",
@@ -103,9 +99,7 @@ class CreatorApplication(ConsoleApplication):
"""
assets[
"agent/index.ts"
] = """\
assets["agent/index.ts"] = """\
import { log } from "./logger.js";
const header = Memory.alloc(16);
@@ -130,9 +124,7 @@ Interceptor.attach(Module.findGlobalExportByName("open")!, {
});
"""
assets[
"agent/logger.ts"
] = """\
assets["agent/logger.ts"] = """\
export function log(message: string): void {
console.log(message);
}
@@ -155,9 +147,7 @@ Tip: Use an editor like Visual Studio Code for code completion, inline docs,
def _generate_cmodule(self) -> Tuple[Dict[str, str], str]:
assets = {}
assets[
"meson.build"
] = f"""\
assets["meson.build"] = f"""\
project('{self._project_name}', 'c',
default_options: 'buildtype=release',
)
@@ -168,9 +158,7 @@ shared_module('{self._project_name}', '{self._project_name}.c',
)
"""
assets[
self._project_name + ".c"
] = """\
assets[self._project_name + ".c"] = """\
#include <gum/guminterceptor.h>
static void frida_log (const char * format, ...);
+1 -1
View File
@@ -55,7 +55,7 @@ class Reactor:
previous_pending_length = -1
with self._lock:
for item in self._pending:
(f, when) = item
f, when = item
if now >= when:
work = f
self._pending.remove(item)
+10 -10
View File
@@ -109,7 +109,11 @@ class REPLApplication(ConsoleApplication):
default=False,
)
parser.add_argument(
"-t", "--timeout", help="seconds to wait before terminating in quiet mode (or 'inf' to run forever)", dest="timeout", default=0
"-t",
"--timeout",
help="seconds to wait before terminating in quiet mode (or 'inf' to run forever)",
dest="timeout",
default=0,
)
parser.add_argument(
"--pause",
@@ -477,7 +481,7 @@ class REPLApplication(ConsoleApplication):
def _exec_and_print(self, exec: Callable[[T], Tuple[str, bytes]], arg: T) -> bool:
success = False
try:
(t, value) = self._perform_on_reactor_thread(lambda: exec(arg))
t, value = self._perform_on_reactor_thread(lambda: exec(arg))
if t in ("function", "undefined", "null"):
output = t
elif t == "binary":
@@ -504,8 +508,7 @@ class REPLApplication(ConsoleApplication):
return success
def _print_startup_message(self) -> None:
self._print(
"""\
self._print("""\
____
/ _ | Frida {version} - A world-class dynamic instrumentation toolkit
| (_| |
@@ -514,10 +517,7 @@ class REPLApplication(ConsoleApplication):
. . . . object? -> Display information about 'object'
. . . . exit/quit -> Exit
. . . .
. . . . More info at https://frida.re/docs/home/""".format(
version=frida.__version__
)
)
. . . . More info at https://frida.re/docs/home/""".format(version=frida.__version__))
def _print_help(self, expression: str) -> None:
# TODO: Figure out docstrings and implement here. This is real jankaty right now.
@@ -526,7 +526,7 @@ class REPLApplication(ConsoleApplication):
expression = expression[:-2] + "?"
obj_to_identify = [x for x in expression.split(" ") if x.endswith("?")][0][:-1]
(obj_type, obj_value) = self._evaluate_expression(obj_to_identify)
obj_type, obj_value = self._evaluate_expression(obj_to_identify)
if obj_type == "function":
signature = self._evaluate_expression("%s.toString()" % obj_to_identify)[1]
@@ -1091,7 +1091,7 @@ class FridaCompleter(Completer):
def _get_keys(self, code):
repl = self._repl
with repl._reactor.io_cancellable:
(t, value) = repl._evaluate_expression(code)
t, value = repl._evaluate_expression(code)
if t == "error":
return []
+58 -39
View File
@@ -133,10 +133,20 @@ class StraceApplication(ConsoleApplication):
"-u", "--user", action="append", dest="users", help="Trace processes owned by USER (repeatable)"
)
parser.add_argument("--uid", action="append", type=int, dest="uids", help="Trace UID (repeatable)")
parser.add_argument("-x", "--exclude", action="append", dest="exclude",
help="Exclude syscall by name (repeatable), e.g. --exclude openat")
parser.add_argument("-i", "--include", action="append", dest="include",
help="Only trace syscall by name (repeatable), e.g. --include openat")
parser.add_argument(
"-x",
"--exclude",
action="append",
dest="exclude",
help="Exclude syscall by name (repeatable), e.g. --exclude openat",
)
parser.add_argument(
"-i",
"--include",
action="append",
dest="include",
help="Only trace syscall by name (repeatable), e.g. --include openat",
)
parser.add_argument("--limit", type=int, default=5000, help="Max events kept in UI (default: 5000)")
def _initialize(self, parser, options, args) -> None:
@@ -188,7 +198,9 @@ class StraceApplication(ConsoleApplication):
targets_req["uids"] = self._uids
try:
self._tracer.start(self._device, targets_req, self._excluded_names_requested, self._included_names_requested)
self._tracer.start(
self._device, targets_req, self._excluded_names_requested, self._included_names_requested
)
except Exception as e:
self._state = "stopping"
self._ready.set()
@@ -500,30 +512,32 @@ class StraceApplication(ConsoleApplication):
filter=Condition(lambda: self._search_editing),
)
help_text = "\n".join([
"",
" Navigation",
" j/k ↑/↓ move selection",
" PgUp/PgDn page up/down",
" ^D/^U half-page down/up",
" Home End t top / tail",
" ←/→ 0 scroll / reset",
"",
" Search & Filter",
" / search",
" n/N next/prev match",
" f promote search to filter",
" ^L clear filter",
"",
" Actions",
" Enter resolve selected stack",
" x exclude syscall",
" w export view to JSON",
" d toggle detail pane",
"",
" ? close this help q/^C quit",
"",
])
help_text = "\n".join(
[
"",
" Navigation",
" j/k ↑/↓ move selection",
" PgUp/PgDn page up/down",
" ^D/^U half-page down/up",
" Home End t top / tail",
" ←/→ 0 scroll / reset",
"",
" Search & Filter",
" / search",
" n/N next/prev match",
" f promote search to filter",
" ^L clear filter",
"",
" Actions",
" Enter resolve selected stack",
" x exclude syscall",
" w export view to JSON",
" d toggle detail pane",
"",
" ? close this help q/^C quit",
"",
]
)
help_win = Window(
content=FormattedTextControl(text=help_text),
wrap_lines=False,
@@ -889,11 +903,16 @@ class StraceApplication(ConsoleApplication):
def _serialize_event(self, ev: SyscallEvent) -> dict:
d: dict = {
"id": ev.id, "phase": ev.phase,
"pid": ev.pid, "tid": ev.tid, "abi": ev.abi,
"nr": ev.nr, "name": ev.name,
"id": ev.id,
"phase": ev.phase,
"pid": ev.pid,
"tid": ev.tid,
"abi": ev.abi,
"nr": ev.nr,
"name": ev.name,
"time_ns": ev.time_ns,
"merged": ev.merged, "failed": ev.failed,
"merged": ev.merged,
"failed": ev.failed,
}
if ev.enter_args is not None:
@@ -1130,7 +1149,7 @@ class StraceApplication(ConsoleApplication):
path, *extra = modules[mod_index]
base = path.rsplit("/", 1)[-1]
out.append(f" {base}+0x{offset:x}")
for addr in stack[len(entries):]:
for addr in stack[len(entries) :]:
out.append(f" 0x{addr:x}")
return out
@@ -1267,11 +1286,11 @@ class SyscallTracer:
self._platform = platform
def start(
self,
device: frida.core.Device,
targets_req: Dict[str, Any],
excluded_by_name: Optional[list[str]],
included_by_name: Optional[list[str]] = None,
self,
device: frida.core.Device,
targets_req: Dict[str, Any],
excluded_by_name: Optional[list[str]],
included_by_name: Optional[list[str]] = None,
) -> None:
self._service = device.open_service("syscall-trace")
+4 -8
View File
@@ -853,9 +853,7 @@ class Repository:
defineHandler(function (log, args, state) {
log(`%(display_name)s hit! sp=${this.context.sp}`);
});
""" % {
"display_name": target.display_name
}
""" % {"display_name": target.display_name}
def _create_stub_native_handler(self, target: TraceTarget, decorate: bool) -> str:
if target.flavor == "objc":
@@ -963,9 +961,7 @@ defineHandler({
}
}
});
""" % {
"display_name": target.display_name
}
""" % {"display_name": target.display_name}
def _generate_cstyle_argument_logging_code(self, target: TraceTarget) -> List[str]:
if self._manpages is None:
@@ -1165,7 +1161,7 @@ class FileRepository(Repository):
def ensure_handler(self, target: TraceTarget) -> str:
entry = self._handler_by_id.get(target.identifier)
if entry is not None:
(target, handler, handler_file) = entry
target, handler, handler_file = entry
return handler
handler = None
@@ -1250,7 +1246,7 @@ class FileRepository(Repository):
changes = self._changed_files.copy()
self._changed_files.clear()
for changed_handler_file in changes:
(target, old_handler, handler_file) = self._handler_by_file[changed_handler_file]
target, old_handler, handler_file = self._handler_by_file[changed_handler_file]
new_handler = self._load_handler(handler_file)
if new_handler != old_handler:
entry = (target, new_handler, handler_file)