@@ -110,17 +110,25 @@ def _to_envp(value):
110110
111111def _make_options(cls, values, selectors):
112112 options = cls()
113+ _apply_settings(options, values, selectors)
114+ return options
115+
116+
117+ def _apply_settings(impl, values, selectors):
113118 for name, value in values.items():
114119 if value is None:
115120 continue
116121 select = selectors.get(name)
117122 if select is None:
118- setattr(options, name, value)
123+ setattr(impl, name, _unwrap(value))
124+ elif isinstance(value, dict):
125+ add = getattr(impl, select)
126+ for key, element in value.items():
127+ add(key, _unwrap(element))
119128 else:
120- add = getattr(options , select)
129+ add = getattr(impl , select)
121130 for element in value:
122- add(element)
123- return options
131+ add(_unwrap(element))
124132
125133
126134_current_cancellable = threading.local()
@@ -204,17 +212,25 @@ def _to_envp(value):
204212
205213def _make_options(cls, values, selectors):
206214 options = cls()
215+ _apply_settings(options, values, selectors)
216+ return options
217+
218+
219+ def _apply_settings(impl, values, selectors):
207220 for name, value in values.items():
208221 if value is None:
209222 continue
210223 select = selectors.get(name)
211224 if select is None:
212- setattr(options, name, value)
225+ setattr(impl, name, _unwrap(value))
226+ elif isinstance(value, dict):
227+ add = getattr(impl, select)
228+ for key, element in value.items():
229+ add(key, _unwrap(element))
213230 else:
214- add = getattr(options , select)
231+ add = getattr(impl , select)
215232 for element in value:
216- add(element)
217- return options
233+ add(_unwrap(element))
218234
219235
220236_current_cancellable: contextvars.ContextVar = contextvars.ContextVar("frida_current_cancellable", default=None)
@@ -538,10 +554,8 @@ def generate_facade_init(otype: ObjectType) -> str:
538554{ body } """
539555
540556 return f""" def __init__(self, *args, **kwargs):
541- self._impl = _frida.{ otype .py_name } (
542- *[_unwrap(a) for a in args],
543- **{{k: _unwrap(v) for k, v in kwargs.items()}},
544- )
557+ self._impl = _frida.{ otype .py_name } (*[_unwrap(a) for a in args])
558+ _apply_settings(self._impl, kwargs, { build_option_selectors (otype )} )
545559 setup = getattr(self, "_setup", None)
546560 if setup is not None:
547561 setup()"""
@@ -665,7 +679,7 @@ def generate_py_sync_method(method: Method, model: Model) -> Optional[str]:
665679 return None
666680
667681 params = [facade_param (param , model ) for param in method .input_parameters ]
668- names = ", " .join (param . name for param in method .input_parameters )
682+ names = ", " .join (facade_argument ( param , model ) for param in method .input_parameters )
669683
670684 call = f"self._impl.{ method .name } ({ names } )"
671685 if method .return_value is not None :
@@ -681,6 +695,12 @@ def facade_signature(method: Method, params: List[str]) -> str:
681695 return ", " .join (["self" ] + (method .custom_facade_params or params ))
682696
683697
698+ def facade_argument (param , model : Model ) -> str :
699+ if resolve_input_object_type (param .type , model ) is not None :
700+ return f"_unwrap({ param .name } )"
701+ return param .name
702+
703+
684704def facade_param (param , model : Model ) -> str :
685705 annotation = pyi_type (param .type , model )
686706 if param .nullable :
@@ -1862,6 +1882,16 @@ def build_sync_param(param: Parameter) -> Optional["SyncParam"]:
18621882 cleanup = f"g_clear_pointer (&{ name } , g_variant_unref);" ,
18631883 )
18641884
1885+ if resolve_input_object_type (param .type , param .object_type .model ) is not None :
1886+ return SyncParam (
1887+ decl = f"PyObject * { name } _obj;\n { param .type .c } { name } = NULL;" ,
1888+ fmt = "O" ,
1889+ parse_args = [f"&{ name } _obj" ],
1890+ pre = f"""if ({ name } _obj != Py_None)
1891+ { name } = ({ param .type .c } ) PY_GOBJECT_HANDLE ({ name } _obj);""" ,
1892+ call_arg = name ,
1893+ )
1894+
18651895 return None
18661896
18671897
0 commit comments