Skip to content

Commit e35a085

Browse files
committed
bindgen: Restore remaining public names
Reinstate the cancellable decorator, RPCResult, make_rpc_call_request and make_auth_callback, and expose ScriptExportsAsync from frida.core via a new facade_epilogues customization.
1 parent d1716f4 commit e35a085

10 files changed

Lines changed: 95 additions & 1 deletion

‎frida/frida_bindgen/assets/facade_cancellable_helpers.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,20 @@ def __enter__(self) -> int:
2121

2222
def __exit__(self, *exc: Any) -> None:
2323
self.release()
24+
25+
26+
P = ParamSpec("P")
27+
R = TypeVar("R", covariant=True)
28+
29+
30+
def cancellable(f: Callable[P, R]) -> Callable[P, R]:
31+
@functools.wraps(f)
32+
def wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
33+
cancellable = kwargs.pop("cancellable", None)
34+
if cancellable is not None:
35+
with cast(Cancellable, cancellable):
36+
return f(*args, **kwargs)
37+
38+
return f(*args, **kwargs)
39+
40+
return wrapper

‎frida/frida_bindgen/assets/facade_cancellable_helpers_aio.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,20 @@ def __enter__(self) -> int:
2121

2222
def __exit__(self, *exc: Any) -> None:
2323
self.release()
24+
25+
26+
P = ParamSpec("P")
27+
R = TypeVar("R", covariant=True)
28+
29+
30+
def cancellable(f: Callable[P, R]) -> Callable[P, R]:
31+
@functools.wraps(f)
32+
def wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
33+
cancellable = kwargs.pop("cancellable", None)
34+
if cancellable is not None:
35+
with cast(Cancellable, cancellable):
36+
return f(*args, **kwargs)
37+
38+
return f(*args, **kwargs)
39+
40+
return wrapper
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ScriptExportsAsync = aio._ScriptExports

‎frida/frida_bindgen/assets/facade_rpc_helpers.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,20 @@ def __dir__(self) -> List[str]:
4040

4141
ScriptExportsSync = _ScriptExports
4242
ScriptExports = ScriptExportsSync
43+
44+
45+
@dataclasses.dataclass
46+
class RPCResult:
47+
finished: bool = False
48+
value: Any = None
49+
error: Optional[Exception] = None
50+
51+
52+
def make_rpc_call_request(js_name: str, args: Sequence[Any]) -> Tuple[List[Any], Optional[bytes]]:
53+
if args and isinstance(args[-1], bytes):
54+
raw_args = args[:-1]
55+
data = args[-1]
56+
else:
57+
raw_args = args
58+
data = None
59+
return (["call", js_name, raw_args], data)

‎frida/frida_bindgen/assets/facade_rpc_helpers_aio.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,20 @@ def method(*args: Any) -> Any:
3636

3737

3838
ScriptExportsAsync = _ScriptExports
39+
40+
41+
@dataclasses.dataclass
42+
class RPCResult:
43+
finished: bool = False
44+
value: Any = None
45+
error: Optional[Exception] = None
46+
47+
48+
def make_rpc_call_request(js_name: str, args: Sequence[Any]) -> Tuple[List[Any], Optional[bytes]]:
49+
if args and isinstance(args[-1], bytes):
50+
raw_args = args[:-1]
51+
data = args[-1]
52+
else:
53+
raw_args = args
54+
data = None
55+
return (["call", js_name, raw_args], data)

‎frida/frida_bindgen/assets/facade_toplevel.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,11 @@ def inject_library_blob(target: ProcessTarget, blob: bytes, entrypoint: str, dat
6969

7070
def shutdown() -> None:
7171
get_device_manager().close()
72+
73+
74+
def make_auth_callback(callback: Callable[[str], Any]) -> Callable[[Any], str]:
75+
def authenticate(token: str) -> str:
76+
session_info = callback(token)
77+
return json.dumps(session_info)
78+
79+
return authenticate

‎frida/frida_bindgen/assets/facade_toplevel_aio.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,11 @@ async def inject_library_blob(target: ProcessTarget, blob: bytes, entrypoint: st
7070

7171
async def shutdown() -> None:
7272
await get_device_manager().close()
73+
74+
75+
def make_auth_callback(callback: Callable[[str], Any]) -> Callable[[Any], str]:
76+
def authenticate(token: str) -> str:
77+
session_info = callback(token)
78+
return json.dumps(session_info)
79+
80+
return authenticate

‎frida/frida_bindgen/codegen.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def read_asset(name: str) -> str:
3636

3737
FACADE_TYPING_IMPORTS = (
3838
"from typing import (Any, Callable, Dict, List, Literal, Mapping, NotRequired, Optional, Tuple, TypedDict, "
39-
"Union, overload)"
39+
"Sequence, Union, ParamSpec, TypeVar, cast, overload)"
4040
)
4141

4242

@@ -244,7 +244,9 @@ def generate_all(model: Model) -> Dict[str, str]:
244244
def generate_py(model: Model) -> str:
245245
lines = [
246246
"from . import _frida",
247+
"import dataclasses",
247248
"import fnmatch",
249+
"import functools",
248250
"import inspect",
249251
"import time",
250252
"import json",
@@ -280,6 +282,9 @@ def generate_py(model: Model) -> str:
280282
lines.append("")
281283
lines.append("")
282284
lines.append("from . import aio")
285+
for asset in model.customizations.facade_epilogues:
286+
lines.append("")
287+
lines.append(read_asset(asset).strip())
283288
lines.append("")
284289
lines.append("core = sys.modules[__name__]")
285290
lines.append('sys.modules[__name__ + ".core"] = core')
@@ -312,7 +317,9 @@ def generate_aio(model: Model) -> str:
312317
"import asyncio",
313318
"import contextvars",
314319
"import time",
320+
"import dataclasses",
315321
"import fnmatch",
322+
"import functools",
316323
"import inspect",
317324
"import json",
318325
"import sys",

‎frida/frida_bindgen/customization.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,4 +399,5 @@ def load_customizations() -> Customizations:
399399
return Customizations(
400400
type_customizations=type_customizations,
401401
facade_preludes=("facade_types.py",),
402+
facade_epilogues=("facade_epilogue.py",),
402403
)

‎frida/frida_bindgen/model.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ def customizations(self) -> Optional[EnumerationMemberCustomizations]:
201201
class Customizations:
202202
type_customizations: Mapping[str, TypeCustomizations] = field(default_factory=OrderedDict)
203203
facade_preludes: Tuple[str, ...] = ()
204+
facade_epilogues: Tuple[str, ...] = ()
204205

205206

206207
@dataclass

0 commit comments

Comments
 (0)