Skip to content

Commit 71dcaaa

Browse files
oleavrAbhiTheModder
authored andcommitted
Fix Script.enable_debugger() port default
Vala's default argument is absent from the .gir, so the generated facade made the port mandatory. Declare the default in the customizations, and let param_typings override the facade signature also when there is no custom logic.
1 parent 4daa699 commit 71dcaaa

3 files changed

Lines changed: 18 additions & 9 deletions

File tree

‎frida/frida_bindgen/codegen.py‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -649,9 +649,7 @@ def generate_py_sync_method(method: Method, model: Model) -> Optional[str]:
649649
if any(build_sync_param(param) is None for param in method.input_parameters):
650650
return None
651651

652-
signature = ["self"]
653-
for param in method.input_parameters:
654-
signature.append(facade_param(param, model))
652+
params = [facade_param(param, model) for param in method.input_parameters]
655653
names = ", ".join(param.name for param in method.input_parameters)
656654

657655
call = f"self._impl.{method.name}({names})"
@@ -660,10 +658,14 @@ def generate_py_sync_method(method: Method, model: Model) -> Optional[str]:
660658

661659
ret = "None" if method.return_value is None else pyi_type(method.return_value.type, model)
662660

663-
return f""" def {method.name}({", ".join(signature)}) -> {ret}:
661+
return f""" def {method.name}({facade_signature(method, params)}) -> {ret}:
664662
return {call}"""
665663

666664

665+
def facade_signature(method: Method, params: List[str]) -> str:
666+
return ", ".join(["self"] + (method.custom_facade_params or params))
667+
668+
667669
def facade_param(param, model: Model) -> str:
668670
annotation = pyi_type(param.type, model)
669671
if param.nullable:
@@ -691,7 +693,7 @@ def generate_py_async_method(method: Method, model: Model) -> Optional[str]:
691693

692694

693695
def build_facade_async_parts(method: Method, model: Model) -> Optional[Tuple[str, str]]:
694-
signature = ["self"]
696+
params = []
695697
args = []
696698
for param in method.input_parameters:
697699
if param.type.name == "Gio.Cancellable":
@@ -700,20 +702,20 @@ def build_facade_async_parts(method: Method, model: Model) -> Optional[Tuple[str
700702
return None
701703
options = resolve_options_type(param.type, model)
702704
if options is not None:
703-
signature.append("**kwargs")
705+
params.append("**kwargs")
704706
args.append(f"_make_options(_frida.{options.py_name}, kwargs, {build_option_selectors(options)})")
705707
elif resolve_input_object_type(param.type, model) is not None:
706-
signature.append(f"{param.name}: Optional[{pyi_type(param.type, model)}] = None")
708+
params.append(f"{param.name}: Optional[{pyi_type(param.type, model)}] = None")
707709
args.append(f"_unwrap({param.name})")
708710
else:
709-
signature.append(facade_param(param, model))
711+
params.append(facade_param(param, model))
710712
args.append(param.name)
711713

712714
if method.return_value is not None:
713715
if build_return_marshal(method.return_value.type, model) is None:
714716
return None
715717

716-
return ", ".join(signature), "".join(arg + ", " for arg in args)
718+
return facade_signature(method, params), "".join(arg + ", " for arg in args)
717719

718720

719721
def build_option_selectors(options: ObjectType) -> str:

‎frida/frida_bindgen/customization.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ def load_customizations() -> Customizations:
153153
param_typings=["message: Any", "data: Optional[bytes] = None"],
154154
custom_logic="json = _to_json(message)",
155155
),
156+
"enable_debugger": MethodCustomizations(param_typings=["port: int = 0"]),
156157
"is_destroyed": MethodCustomizations(as_property=True),
157158
},
158159
),

‎tests/test_bindgen.py‎

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

693+
def test_enable_debugger_defaults_to_any_port(self):
694+
import inspect
695+
696+
for script in [self.frida.Script, self.frida.aio.Script]:
697+
self.assertEqual(inspect.signature(script.enable_debugger).parameters["port"].default, 0)
698+
693699
def test_file_monitor_reports_changes(self):
694700
import os
695701
import tempfile

0 commit comments

Comments
 (0)