Skip to content

Commit 1122f97

Browse files
oleavrAbhiTheModder
authored andcommitted
Fix attach() linker_notifier_offsets kwarg
Its customization hardcoded an empty selector map instead of the one computed from the options type, so the plural kwarg was rejected. Let codegen build the options argument for custom facade methods that take **kwargs.
1 parent 71dcaaa commit 1122f97

4 files changed

Lines changed: 27 additions & 13 deletions

File tree

‎frida/frida_bindgen/codegen.py‎

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,11 +448,12 @@ def generate_custom_facade_method(
448448
method: Method, logic: Union[str, Tuple[str, str]], model: Model, awaitable: bool
449449
) -> str:
450450
signature = ", ".join(["self"] + method.custom_facade_params)
451+
args = facade_call_args(method, model)
451452
if method.is_async:
452-
invoke = f"_invoke(self._impl.{method.name}, ({method.facade_call_args}))"
453+
invoke = f"_invoke(self._impl.{method.name}, ({args}))"
453454
call = f"await {invoke}" if awaitable else invoke
454455
else:
455-
call = f"self._impl.{method.name}({method.facade_call_args})"
456+
call = f"self._impl.{method.name}({args})"
456457
if method.return_value is not None:
457458
call = wrap_result(call, method.return_value.type, model)
458459

@@ -468,6 +469,20 @@ def generate_custom_facade_method(
468469
return {call}"""
469470

470471

472+
def facade_call_args(method: Method, model: Model) -> str:
473+
takes_kwargs = any(param.split(":")[0].strip() == "**kwargs" for param in method.custom_facade_params)
474+
args = []
475+
for param in method.input_parameters:
476+
if param.type.name == "Gio.Cancellable":
477+
continue
478+
options = resolve_options_type(param.type, model)
479+
if options is not None and takes_kwargs:
480+
args.append(make_options_expr(options))
481+
else:
482+
args.append(param.name)
483+
return "".join(arg + ", " for arg in args)
484+
485+
471486
def generate_py_exception_reexports(model: Model) -> List[str]:
472487
names = [f"{name}Error" for _, name in error_members(model)]
473488
names.append("OperationCancelledError")
@@ -703,7 +718,7 @@ def build_facade_async_parts(method: Method, model: Model) -> Optional[Tuple[str
703718
options = resolve_options_type(param.type, model)
704719
if options is not None:
705720
params.append("**kwargs")
706-
args.append(f"_make_options(_frida.{options.py_name}, kwargs, {build_option_selectors(options)})")
721+
args.append(make_options_expr(options))
707722
elif resolve_input_object_type(param.type, model) is not None:
708723
params.append(f"{param.name}: Optional[{pyi_type(param.type, model)}] = None")
709724
args.append(f"_unwrap({param.name})")
@@ -718,6 +733,10 @@ def build_facade_async_parts(method: Method, model: Model) -> Optional[Tuple[str
718733
return facade_signature(method, params), "".join(arg + ", " for arg in args)
719734

720735

736+
def make_options_expr(options: ObjectType) -> str:
737+
return f"_make_options(_frida.{options.py_name}, kwargs, {build_option_selectors(options)})"
738+
739+
721740
def build_option_selectors(options: ObjectType) -> str:
722741
selectors = {}
723742
otype = options

‎frida/frida_bindgen/customization.py‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,7 @@ def load_customizations() -> Customizations:
131131
),
132132
"attach": MethodCustomizations(
133133
param_typings=["target: ProcessTarget", "**kwargs: Any"],
134-
custom_logic=(
135-
"pid = self._pid_of(target)\n" "options = _make_options(_frida.SessionOptions, kwargs, {})",
136-
"pid = await self._pid_of(target)\n"
137-
"options = _make_options(_frida.SessionOptions, kwargs, {})",
138-
),
134+
custom_logic=_RESOLVE_PID,
139135
),
140136
},
141137
custom_code=CustomCode(

‎frida/frida_bindgen/model.py‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,6 @@ def custom_logic(self) -> Optional[Union[str, Tuple[str, str]]]:
144144
custom = self.customizations
145145
return custom.custom_logic if custom is not None else None
146146

147-
@cached_property
148-
def facade_call_args(self) -> str:
149-
return "".join(f"{param.name}, " for param in self.input_parameters if param.type.name != "Gio.Cancellable")
150-
151-
152147
class Property(core.Property):
153148
pass
154149

‎tests/test_bindgen.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,10 @@ def test_create_script_from_bytes_positional_name(self):
690690
finally:
691691
session.detach()
692692

693+
def test_attach_accepts_linker_notifier_offsets(self):
694+
session = self.frida.get_local_device().attach(0, linker_notifier_offsets=[0x100])
695+
session.detach()
696+
693697
def test_enable_debugger_defaults_to_any_port(self):
694698
import inspect
695699

0 commit comments

Comments
 (0)