frida 16.7.14 → 16.7.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/README.md +1 -10
  2. package/build/BSDmakefile +6 -0
  3. package/build/Makefile +10 -0
  4. package/build/src/frida.d.ts +364 -0
  5. package/build/src/frida.js +962 -0
  6. package/build/src/frida_binding.d.ts +938 -0
  7. package/meson.build +34 -67
  8. package/package.json +30 -20
  9. package/scripts/fetch-abi-bits.py +15 -65
  10. package/scripts/install.js +5 -4
  11. package/src/addon.def +3 -0
  12. package/src/addon.symbols +2 -1
  13. package/src/addon.version +4 -0
  14. package/src/frida_bindgen/__init__.py +0 -0
  15. package/src/frida_bindgen/__main__.py +4 -0
  16. package/src/frida_bindgen/__pycache__/__init__.cpython-312.pyc +0 -0
  17. package/src/frida_bindgen/__pycache__/__main__.cpython-312.pyc +0 -0
  18. package/src/frida_bindgen/__pycache__/cli.cpython-312.pyc +0 -0
  19. package/src/frida_bindgen/__pycache__/codegen.cpython-312.pyc +0 -0
  20. package/src/frida_bindgen/__pycache__/customization.cpython-312.pyc +0 -0
  21. package/src/frida_bindgen/__pycache__/loader.cpython-312.pyc +0 -0
  22. package/src/frida_bindgen/__pycache__/model.cpython-312.pyc +0 -0
  23. package/src/frida_bindgen/assets/codegen_helpers.c +1970 -0
  24. package/src/frida_bindgen/assets/codegen_helpers.ts +100 -0
  25. package/src/frida_bindgen/assets/codegen_prototypes.h +78 -0
  26. package/src/frida_bindgen/assets/codegen_types.h +57 -0
  27. package/src/frida_bindgen/assets/customization_facade.exports +13 -0
  28. package/src/frida_bindgen/assets/customization_facade.ts +157 -0
  29. package/src/frida_bindgen/assets/customization_helpers.imports +2 -0
  30. package/src/frida_bindgen/assets/customization_helpers.ts +396 -0
  31. package/src/frida_bindgen/cli.py +96 -0
  32. package/src/frida_bindgen/codegen.py +2233 -0
  33. package/src/frida_bindgen/customization.py +924 -0
  34. package/src/frida_bindgen/loader.py +60 -0
  35. package/src/frida_bindgen/model.py +1357 -0
  36. package/src/meson.build +92 -27
  37. package/{lib/build.py → src/tsc.py} +12 -12
  38. package/src/win_delay_load_hook.c +56 -0
  39. package/subprojects/frida-core.wrap +1 -1
  40. package/test/data/index.ts +2 -2
  41. package/test/device.ts +1 -2
  42. package/test/device_manager.ts +1 -2
  43. package/test/labrat.ts +2 -2
  44. package/test/script.ts +12 -12
  45. package/test/session.ts +3 -3
  46. package/tsconfig.json +6 -11
  47. package/dist/application.d.ts +0 -81
  48. package/dist/application.js +0 -2
  49. package/dist/authentication.d.ts +0 -3
  50. package/dist/authentication.js +0 -2
  51. package/dist/bus.d.ts +0 -16
  52. package/dist/bus.js +0 -23
  53. package/dist/cancellable.d.ts +0 -15
  54. package/dist/cancellable.js +0 -41
  55. package/dist/child.d.ts +0 -16
  56. package/dist/child.js +0 -9
  57. package/dist/crash.d.ts +0 -10
  58. package/dist/crash.js +0 -2
  59. package/dist/device.d.ts +0 -156
  60. package/dist/device.js +0 -188
  61. package/dist/device_manager.d.ts +0 -25
  62. package/dist/device_manager.js +0 -42
  63. package/dist/endpoint_parameters.d.ts +0 -26
  64. package/dist/endpoint_parameters.js +0 -24
  65. package/dist/icon.d.ts +0 -14
  66. package/dist/icon.js +0 -2
  67. package/dist/index.d.ts +0 -161
  68. package/dist/index.js +0 -170
  69. package/dist/iostream.d.ts +0 -13
  70. package/dist/iostream.js +0 -73
  71. package/dist/native.d.ts +0 -1
  72. package/dist/native.js +0 -11
  73. package/dist/portal_membership.d.ts +0 -6
  74. package/dist/portal_membership.js +0 -12
  75. package/dist/portal_service.d.ts +0 -48
  76. package/dist/portal_service.js +0 -52
  77. package/dist/process.d.ts +0 -47
  78. package/dist/process.js +0 -2
  79. package/dist/relay.d.ts +0 -22
  80. package/dist/relay.js +0 -32
  81. package/dist/script.d.ts +0 -70
  82. package/dist/script.js +0 -266
  83. package/dist/service.d.ts +0 -16
  84. package/dist/service.js +0 -26
  85. package/dist/session.d.ts +0 -45
  86. package/dist/session.js +0 -73
  87. package/dist/signals.d.ts +0 -20
  88. package/dist/signals.js +0 -40
  89. package/dist/socket_address.d.ts +0 -25
  90. package/dist/socket_address.js +0 -2
  91. package/dist/spawn.d.ts +0 -4
  92. package/dist/spawn.js +0 -2
  93. package/dist/system_parameters.d.ts +0 -84
  94. package/dist/system_parameters.js +0 -2
  95. package/lib/application.ts +0 -98
  96. package/lib/authentication.ts +0 -3
  97. package/lib/bus.ts +0 -30
  98. package/lib/cancellable.ts +0 -48
  99. package/lib/child.ts +0 -15
  100. package/lib/crash.ts +0 -11
  101. package/lib/device.ts +0 -331
  102. package/lib/device_manager.ts +0 -69
  103. package/lib/endpoint_parameters.ts +0 -56
  104. package/lib/icon.ts +0 -15
  105. package/lib/index.ts +0 -316
  106. package/lib/iostream.ts +0 -78
  107. package/lib/meson.build +0 -53
  108. package/lib/native.ts +0 -9
  109. package/lib/portal_membership.ts +0 -10
  110. package/lib/portal_service.ts +0 -105
  111. package/lib/process.ts +0 -57
  112. package/lib/relay.ts +0 -44
  113. package/lib/script.ts +0 -361
  114. package/lib/service.ts +0 -34
  115. package/lib/session.ts +0 -113
  116. package/lib/signals.ts +0 -45
  117. package/lib/socket_address.ts +0 -35
  118. package/lib/spawn.ts +0 -4
  119. package/lib/system_parameters.ts +0 -103
  120. package/meson.options +0 -11
  121. package/src/addon.cc +0 -78
  122. package/src/application.cc +0 -148
  123. package/src/application.h +0 -31
  124. package/src/authentication.cc +0 -174
  125. package/src/authentication.h +0 -24
  126. package/src/bus.cc +0 -167
  127. package/src/bus.h +0 -33
  128. package/src/cancellable.cc +0 -117
  129. package/src/cancellable.h +0 -31
  130. package/src/child.cc +0 -150
  131. package/src/child.h +0 -32
  132. package/src/crash.cc +0 -122
  133. package/src/crash.h +0 -30
  134. package/src/device.cc +0 -1350
  135. package/src/device.h +0 -56
  136. package/src/device_manager.cc +0 -362
  137. package/src/device_manager.h +0 -35
  138. package/src/endpoint_parameters.cc +0 -171
  139. package/src/endpoint_parameters.h +0 -28
  140. package/src/glib_context.cc +0 -62
  141. package/src/glib_context.h +0 -29
  142. package/src/glib_object.cc +0 -25
  143. package/src/glib_object.h +0 -37
  144. package/src/iostream.cc +0 -243
  145. package/src/iostream.h +0 -30
  146. package/src/operation.h +0 -94
  147. package/src/portal_membership.cc +0 -100
  148. package/src/portal_membership.h +0 -26
  149. package/src/portal_service.cc +0 -401
  150. package/src/portal_service.h +0 -40
  151. package/src/process.cc +0 -135
  152. package/src/process.h +0 -30
  153. package/src/relay.cc +0 -139
  154. package/src/relay.h +0 -31
  155. package/src/runtime.cc +0 -568
  156. package/src/runtime.h +0 -69
  157. package/src/script.cc +0 -301
  158. package/src/script.h +0 -36
  159. package/src/service.cc +0 -224
  160. package/src/service.h +0 -36
  161. package/src/session.cc +0 -860
  162. package/src/session.h +0 -42
  163. package/src/signals.cc +0 -334
  164. package/src/signals.h +0 -47
  165. package/src/spawn.cc +0 -95
  166. package/src/spawn.h +0 -27
  167. package/src/usage_monitor.h +0 -117
  168. package/src/uv_context.cc +0 -118
  169. package/src/uv_context.h +0 -40
  170. package/src/win_delay_load_hook.cc +0 -63
  171. package/subprojects/nan.wrap +0 -9
  172. package/subprojects/packagefiles/nan.patch +0 -13
@@ -0,0 +1,924 @@
1
+ from __future__ import annotations
2
+
3
+ from pathlib import Path
4
+ from typing import List, Mapping
5
+
6
+ from .model import (ConstructorCustomizations, CustomCode, CustomDeclaration,
7
+ Customizations, CustomMethod, CustomType, CustomTypeKind,
8
+ EnumerationCustomizations, EnumerationMemberCustomizations,
9
+ KeepAliveCustomization, MethodCustomizations,
10
+ ObjectTypeCustomizations, PropertyCustomizations,
11
+ SignalCustomizations, TypeCustomizations)
12
+
13
+ ASSETS_DIR = Path(__file__).resolve().parent / "assets"
14
+ CUSTOMIZATION_FACADE_EXPORTS = (
15
+ (ASSETS_DIR / "customization_facade.exports")
16
+ .read_text(encoding="utf-8")
17
+ .strip()
18
+ .split("\n")
19
+ )
20
+ CUSTOMIZATION_FACADE_TS = (ASSETS_DIR / "customization_facade.ts").read_text(
21
+ encoding="utf-8"
22
+ )
23
+ CUSTOMIZATION_HELPERS_IMPORTS = (
24
+ (ASSETS_DIR / "customization_helpers.imports")
25
+ .read_text(encoding="utf-8")
26
+ .strip()
27
+ .split("\n")
28
+ )
29
+ CUSTOMIZATION_HELPERS_TS = (ASSETS_DIR / "customization_helpers.ts").read_text(
30
+ encoding="utf-8"
31
+ )
32
+
33
+
34
+ def load_customizations() -> Customizations:
35
+ custom_types: List[CustomType] = {
36
+ "TargetProcess": CustomType(CustomTypeKind.TYPE, "ProcessID | ProcessName"),
37
+ "ProcessID": CustomType(CustomTypeKind.TYPE, "number"),
38
+ "InjecteeID": CustomType(CustomTypeKind.TYPE, "number"),
39
+ "FileDescriptor": CustomType(CustomTypeKind.TYPE, "number"),
40
+ "ProcessName": CustomType(CustomTypeKind.TYPE, "string"),
41
+ "SystemParameters": CustomType(
42
+ CustomTypeKind.INTERFACE,
43
+ """
44
+ /**
45
+ * Operating System details.
46
+ */
47
+ os: {
48
+ /**
49
+ * ID, e.g.: windows, macos, linux, ios, android, qnx, fedora, ubuntu, etc.
50
+ */
51
+ id: string;
52
+
53
+ /**
54
+ * Human-readable name, e.g. `"macOS"`.
55
+ */
56
+ name: string;
57
+
58
+ /**
59
+ * Human-readable version string, e.g. `"11.2.2"`.
60
+ */
61
+ version?: string;
62
+
63
+ /**
64
+ * Build version, e.g. `"21B91"`.
65
+ */
66
+ build?: string;
67
+ }
68
+
69
+ /**
70
+ * Platform, same as `Process.platform` in GumJS.
71
+ */
72
+ platform: "windows" | "darwin" | "linux" | "freebsd" | "qnx";
73
+
74
+ /**
75
+ * Architecture, same as `Process.arch` in GumJS.
76
+ */
77
+ arch: "ia32" | "x64" | "arm" | "arm64" | "mips";
78
+
79
+ /**
80
+ * Hardware details.
81
+ */
82
+ hardware?: {
83
+ /**
84
+ * Product type, e.g. `"iPad6,3"`.
85
+ */
86
+ product?: string;
87
+
88
+ /**
89
+ * Hardware platform, e.g. `"t8010"`.
90
+ */
91
+ platform?: string;
92
+
93
+ /**
94
+ * Hardware model, e.g. `"J71bAP"`.
95
+ */
96
+ model?: string;
97
+ }
98
+
99
+ /**
100
+ * Level of access.
101
+ */
102
+ access: "full" | "jailed";
103
+
104
+ /**
105
+ * System name, e.g. `"Ole André’s iPhone"`.
106
+ */
107
+ name?: string;
108
+
109
+ /**
110
+ * iOS UDID (Unique Device ID).
111
+ */
112
+ udid?: string;
113
+
114
+ /**
115
+ * Details about cellular and networking interfaces.
116
+ */
117
+ interfaces?: SystemInterface[];
118
+
119
+ /**
120
+ * Android API level, e.g.: `30`.
121
+ */
122
+ apiLevel?: number;
123
+
124
+ [name: string]: any;
125
+ """,
126
+ ),
127
+ "SystemInterface": CustomType(
128
+ CustomTypeKind.TYPE, "NetworkInterface | CellularInterface"
129
+ ),
130
+ "NetworkInterface": CustomType(
131
+ CustomTypeKind.INTERFACE,
132
+ """
133
+ type: "ethernet" | "wifi" | "bluetooth";
134
+
135
+ /**
136
+ * MAC address, e.g.: `"aa:bb:cc:dd:ee:ff"`.
137
+ */
138
+ address: string;
139
+ """,
140
+ ),
141
+ "CellularInterface": CustomType(
142
+ CustomTypeKind.INTERFACE,
143
+ """
144
+ type: "cellular";
145
+
146
+ /**
147
+ * Phone number, e.g. `"+47 123 45 678"`.
148
+ */
149
+ phoneNumber: string;
150
+ """,
151
+ ),
152
+ "SpawnOptions": CustomType(
153
+ CustomTypeKind.INTERFACE,
154
+ """
155
+ argv?: string[];
156
+ envp?: { [name: string]: string };
157
+ env?: { [name: string]: string };
158
+ cwd?: string;
159
+ stdio?: Stdio;
160
+
161
+ [name: string]: any;
162
+ """,
163
+ ),
164
+ "RelayProperties": CustomType(
165
+ CustomTypeKind.INTERFACE,
166
+ """
167
+ address: string;
168
+ username: string;
169
+ password: string;
170
+ kind: RelayKind;
171
+ """,
172
+ ),
173
+ "Message": CustomType(CustomTypeKind.TYPE, "SendMessage | ErrorMessage"),
174
+ "MessageType": CustomType(
175
+ CustomTypeKind.ENUM,
176
+ """
177
+ Send = "send",
178
+ Error = "error"
179
+ """,
180
+ ),
181
+ "SendMessage": CustomType(
182
+ CustomTypeKind.INTERFACE,
183
+ """
184
+ type: MessageType.Send;
185
+ payload: any;
186
+ """,
187
+ ),
188
+ "ErrorMessage": CustomType(
189
+ CustomTypeKind.INTERFACE,
190
+ """
191
+ type: MessageType.Error;
192
+ description: string;
193
+ stack?: string;
194
+ fileName?: string;
195
+ lineNumber?: number;
196
+ columnNumber?: number;
197
+ """,
198
+ ),
199
+ "ScriptLogHandler": CustomType(
200
+ CustomTypeKind.TYPE, "(level: LogLevel, text: string) => void"
201
+ ),
202
+ "ScriptExports": CustomType(
203
+ CustomTypeKind.INTERFACE,
204
+ """
205
+ [name: string]: (...args: any[]) => Promise<any>;
206
+ """,
207
+ ),
208
+ "LogLevel": CustomType(
209
+ CustomTypeKind.ENUM,
210
+ """
211
+ Info = "info",
212
+ Warning = "warning",
213
+ Error = "error",
214
+ """,
215
+ ),
216
+ "EnableDebuggerOptions": CustomType(
217
+ CustomTypeKind.INTERFACE,
218
+ """
219
+ port?: number;
220
+ """,
221
+ ),
222
+ "PortalServiceOptions": CustomType(
223
+ CustomTypeKind.INTERFACE,
224
+ """
225
+ clusterParams?: EndpointParameters;
226
+ controlParams?: EndpointParameters;
227
+ """,
228
+ ),
229
+ "PortalConnectionId": CustomType(CustomTypeKind.TYPE, "number"),
230
+ "PortalConnectionTag": CustomType(CustomTypeKind.TYPE, "string"),
231
+ "EndpointParametersSubset": CustomType(
232
+ CustomTypeKind.INTERFACE,
233
+ """
234
+ address?: string;
235
+ port?: number;
236
+ certificate?: string;
237
+ origin?: string;
238
+ authentication?: AuthenticationScheme;
239
+ assetRoot?: string;
240
+ """,
241
+ ),
242
+ "AuthenticationScheme": CustomType(
243
+ CustomTypeKind.TYPE,
244
+ "TokenAuthenticationScheme | CallbackAuthenticationScheme",
245
+ ),
246
+ "TokenAuthenticationScheme": CustomType(
247
+ CustomTypeKind.INTERFACE,
248
+ """
249
+ scheme: "token";
250
+ token: string;
251
+ """,
252
+ ),
253
+ "CallbackAuthenticationScheme": CustomType(
254
+ CustomTypeKind.INTERFACE,
255
+ """
256
+ scheme: "callback";
257
+ callback: AuthenticationCallback;
258
+ """,
259
+ ),
260
+ "AuthenticationCallback": CustomType(
261
+ CustomTypeKind.TYPE,
262
+ "(token: string) => Promise<AuthenticatedSessionInfo>",
263
+ ),
264
+ "AuthenticatedSessionInfo": CustomType(
265
+ CustomTypeKind.INTERFACE,
266
+ """
267
+ [key: string]: any;
268
+ """,
269
+ ),
270
+ "SocketAddress": CustomType(
271
+ CustomTypeKind.TYPE,
272
+ "IPV4SocketAddress | IPV6SocketAddress | AnonymousUnixSocketAddress | PathUnixSocketAddress | AbstractUnixSocketAddress",
273
+ ),
274
+ "IPV4SocketAddress": CustomType(
275
+ CustomTypeKind.INTERFACE,
276
+ """
277
+ family: "ipv4";
278
+ address: string;
279
+ port: number;
280
+ """,
281
+ ),
282
+ "IPV6SocketAddress": CustomType(
283
+ CustomTypeKind.INTERFACE,
284
+ """
285
+ family: "ipv6";
286
+ address: string;
287
+ port: number;
288
+ flowlabel: number;
289
+ scopeid: number;
290
+ """,
291
+ ),
292
+ "AnonymousUnixSocketAddress": CustomType(
293
+ CustomTypeKind.INTERFACE,
294
+ """
295
+ family: "unix:anonymous";
296
+ """,
297
+ ),
298
+ "PathUnixSocketAddress": CustomType(
299
+ CustomTypeKind.INTERFACE,
300
+ """
301
+ family: "unix:path";
302
+ path: string;
303
+ """,
304
+ ),
305
+ "AbstractUnixSocketAddress": CustomType(
306
+ CustomTypeKind.INTERFACE,
307
+ """
308
+ family: "unix:abstract";
309
+ path: Buffer;
310
+ """,
311
+ ),
312
+ "Variant": CustomType(
313
+ CustomTypeKind.TYPE, "VariantValue | [type: symbol, value: VariantValue]"
314
+ ),
315
+ "VariantValue": CustomType(
316
+ CustomTypeKind.TYPE,
317
+ """
318
+ | boolean
319
+ | number
320
+ | string
321
+ | Buffer
322
+ | Variant[]
323
+ | VariantDict
324
+ """,
325
+ ),
326
+ "VariantDict": CustomType(
327
+ CustomTypeKind.INTERFACE,
328
+ """
329
+ [key: string]: Variant;
330
+ """,
331
+ ),
332
+ }
333
+
334
+ type_customizations: Mapping[str, TypeCustomizations] = {
335
+ "DeviceManager": ObjectTypeCustomizations(
336
+ signals={
337
+ "added": SignalCustomizations(behavior="FDN_SIGNAL_KEEP_ALIVE"),
338
+ "removed": SignalCustomizations(behavior="FDN_SIGNAL_KEEP_ALIVE"),
339
+ "changed": SignalCustomizations(behavior="FDN_SIGNAL_KEEP_ALIVE"),
340
+ },
341
+ cleanup="close",
342
+ ),
343
+ "Device": ObjectTypeCustomizations(
344
+ methods={
345
+ "query_system_parameters": MethodCustomizations(
346
+ return_typing="Promise<SystemParameters>",
347
+ return_wrapper="as SystemParameters",
348
+ ),
349
+ "spawn": MethodCustomizations(
350
+ param_typings=[
351
+ "programOrArgv: string | string[]",
352
+ "opts?: SpawnOptions",
353
+ "cancellable?: Cancellable | null",
354
+ ],
355
+ return_typing="Promise<ProcessID>",
356
+ custom_logic="""
357
+ const options: RawSpawnOptions = {};
358
+
359
+ let program: string;
360
+ let argv;
361
+ if (typeof programOrArgv === "string") {
362
+ program = programOrArgv;
363
+ argv = opts?.argv;
364
+ } else {
365
+ program = programOrArgv[0];
366
+ argv = programOrArgv;
367
+ if (argv.length === 1) {
368
+ argv = undefined;
369
+ }
370
+ }
371
+ if (argv !== undefined) {
372
+ options.argv = argv;
373
+ }
374
+
375
+ if (opts !== undefined) {
376
+ const envp = opts.envp;
377
+ if (envp !== undefined) {
378
+ options.envp = objectToStrv(envp);
379
+ }
380
+
381
+ const env = opts.env;
382
+ if (env !== undefined) {
383
+ options.env = objectToStrv(env);
384
+ }
385
+
386
+ const cwd = opts.cwd;
387
+ if (cwd !== undefined) {
388
+ options.cwd = cwd;
389
+ }
390
+
391
+ options.aux = Object.fromEntries(Object.entries(opts).filter(([k, v]) => !STANDARD_SPAWN_OPTION_NAMES.has(k)));
392
+ }
393
+ """,
394
+ ),
395
+ "input": MethodCustomizations(
396
+ param_typings=[
397
+ "target: TargetProcess",
398
+ "data: Buffer",
399
+ "cancellable?: Cancellable | null",
400
+ ],
401
+ custom_logic="const pid = await this.#getPid(target, cancellable);",
402
+ ),
403
+ "resume": MethodCustomizations(
404
+ param_typings=[
405
+ "target: TargetProcess",
406
+ "cancellable?: Cancellable | null",
407
+ ],
408
+ custom_logic="const pid = await this.#getPid(target, cancellable);",
409
+ ),
410
+ "kill": MethodCustomizations(
411
+ param_typings=[
412
+ "target: TargetProcess",
413
+ "cancellable?: Cancellable | null",
414
+ ],
415
+ custom_logic="const pid = await this.#getPid(target, cancellable);",
416
+ ),
417
+ "attach": MethodCustomizations(
418
+ param_typings=[
419
+ "target: TargetProcess",
420
+ "options?: SessionOptions",
421
+ "cancellable?: Cancellable | null",
422
+ ],
423
+ custom_logic="const pid = await this.#getPid(target, cancellable);",
424
+ ),
425
+ "inject_library_file": MethodCustomizations(
426
+ param_typings=[
427
+ "target: TargetProcess",
428
+ "path: string",
429
+ "entrypoint: string",
430
+ "data: string",
431
+ "cancellable?: Cancellable | null",
432
+ ],
433
+ return_typing="Promise<InjecteeID>",
434
+ custom_logic="const pid = await this.#getPid(target, cancellable);",
435
+ ),
436
+ "inject_library_blob": MethodCustomizations(
437
+ param_typings=[
438
+ "target: TargetProcess",
439
+ "blob: Buffer",
440
+ "entrypoint: string",
441
+ "data: string",
442
+ "cancellable?: Cancellable | null",
443
+ ],
444
+ return_typing="Promise<InjecteeID>",
445
+ custom_logic="const pid = await this.#getPid(target, cancellable);",
446
+ ),
447
+ "open_channel": MethodCustomizations(
448
+ return_typing="Promise<NodeJS.ReadWriteStream>",
449
+ return_wrapper="new IOStreamAdapter",
450
+ ),
451
+ },
452
+ properties={
453
+ "dtype": PropertyCustomizations(
454
+ js_name="type",
455
+ ),
456
+ },
457
+ signals={
458
+ "spawn-added": SignalCustomizations(behavior="FDN_SIGNAL_KEEP_ALIVE"),
459
+ "spawn-removed": SignalCustomizations(behavior="FDN_SIGNAL_KEEP_ALIVE"),
460
+ "child-added": SignalCustomizations(behavior="FDN_SIGNAL_KEEP_ALIVE"),
461
+ "child-removed": SignalCustomizations(behavior="FDN_SIGNAL_KEEP_ALIVE"),
462
+ "process-crashed": SignalCustomizations(
463
+ behavior="FDN_SIGNAL_KEEP_ALIVE"
464
+ ),
465
+ "output": SignalCustomizations(
466
+ behavior="FDN_SIGNAL_KEEP_ALIVE",
467
+ transform={
468
+ 0: ("pid: ProcessID", None),
469
+ 1: ("fd: FileDescriptor", None),
470
+ },
471
+ ),
472
+ "uninjected": SignalCustomizations(
473
+ behavior="FDN_SIGNAL_KEEP_ALIVE",
474
+ transform={
475
+ 0: ("id: InjecteeID", None),
476
+ },
477
+ ),
478
+ },
479
+ custom_code=CustomCode(
480
+ methods=[
481
+ CustomMethod(
482
+ typing="getProcess(name: string, options?: ProcessMatchOptions, cancellable?: Cancellable | null): Promise<Process>",
483
+ code="""
484
+ async getProcess(name: string, options: ProcessMatchOptions = {}, cancellable?: Cancellable | null): Promise<Process> {
485
+ const {
486
+ scope = Scope.Minimal,
487
+ } = options;
488
+ const processes = await this.enumerateProcesses({ scope }, cancellable);
489
+ const mm = new Minimatch(name.toLowerCase());
490
+ const matching = processes.filter(process => mm.match(process.name.toLowerCase()));
491
+ if (matching.length === 1) {
492
+ return matching[0];
493
+ } else if (matching.length > 1) {
494
+ throw new Error("Ambiguous name; it matches: " + matching.map(process => `${process.name} (pid: ${process.pid})`).join(", "));
495
+ } else {
496
+ throw new Error("Process not found");
497
+ }
498
+ }
499
+ """,
500
+ ),
501
+ CustomMethod(
502
+ typing=None,
503
+ code="""
504
+ async #getPid(target: TargetProcess, cancellable?: Cancellable | null): Promise<ProcessID> {
505
+ if (typeof target === "number") {
506
+ return target;
507
+ }
508
+
509
+ const process = await this.getProcess(target, {}, cancellable);
510
+ return process.pid;
511
+ }
512
+ """,
513
+ ),
514
+ ],
515
+ ),
516
+ ),
517
+ "SpawnOptions": ObjectTypeCustomizations(js_name="RawSpawnOptions"),
518
+ "Bus": ObjectTypeCustomizations(
519
+ methods={
520
+ "post": MethodCustomizations(
521
+ param_typings=[
522
+ "message: any",
523
+ "data?: Buffer | null",
524
+ ],
525
+ custom_logic="const json = JSON.stringify(message);",
526
+ ),
527
+ },
528
+ signals={
529
+ "detached": SignalCustomizations(behavior="FDN_SIGNAL_KEEP_ALIVE"),
530
+ "message": SignalCustomizations(
531
+ behavior="FDN_SIGNAL_KEEP_ALIVE",
532
+ transform={
533
+ 0: ("message: any", "JSON.parse"),
534
+ },
535
+ ),
536
+ },
537
+ ),
538
+ "Service": ObjectTypeCustomizations(
539
+ keep_alive=KeepAliveCustomization(
540
+ is_destroyed_function="is_closed", destroy_signal_name="close"
541
+ ),
542
+ ),
543
+ "Relay": ObjectTypeCustomizations(
544
+ constructor=ConstructorCustomizations(
545
+ param_typings=[
546
+ "properties: RelayProperties",
547
+ ],
548
+ custom_logic="const { address, username, password, kind } = properties;",
549
+ ),
550
+ ),
551
+ "RelayKind": EnumerationCustomizations(
552
+ members={
553
+ "turn_udp": EnumerationMemberCustomizations(js_name="TurnUDP"),
554
+ "turn_tcp": EnumerationMemberCustomizations(js_name="TurnTCP"),
555
+ "turn_tls": EnumerationMemberCustomizations(js_name="TurnTLS"),
556
+ },
557
+ ),
558
+ "Script": ObjectTypeCustomizations(
559
+ methods={
560
+ "is_destroyed": MethodCustomizations(hide=True),
561
+ "post": MethodCustomizations(
562
+ param_typings=[
563
+ "message: any",
564
+ "data?: Buffer | null",
565
+ ],
566
+ custom_logic="const json = JSON.stringify(message);",
567
+ ),
568
+ "enable_debugger": MethodCustomizations(
569
+ param_typings=[
570
+ "options?: EnableDebuggerOptions",
571
+ "cancellable?: Cancellable | null",
572
+ ],
573
+ custom_logic="const port = options?.port ?? 0;",
574
+ ),
575
+ },
576
+ signals={
577
+ "message": SignalCustomizations(
578
+ transform={
579
+ 0: ("message: Message", "JSON.parse"),
580
+ },
581
+ intercept="this.#services.handleMessageIntercept",
582
+ ),
583
+ },
584
+ custom_code=CustomCode(
585
+ declarations=[
586
+ CustomDeclaration(
587
+ typing=None, code="#services = new ScriptServices(this);"
588
+ ),
589
+ CustomDeclaration(
590
+ typing="logHandler: ScriptLogHandler",
591
+ code="logHandler: ScriptLogHandler = log;",
592
+ ),
593
+ ],
594
+ methods=[
595
+ CustomMethod(
596
+ typing="readonly isDestroyed: boolean",
597
+ code="""
598
+ get isDestroyed(): boolean {
599
+ return this._isDestroyed();
600
+ }
601
+ """,
602
+ ),
603
+ CustomMethod(
604
+ typing="readonly exports: ScriptExports",
605
+ code="""
606
+ get exports(): ScriptExports {
607
+ return this.#services.exportsProxy;
608
+ }
609
+ """,
610
+ ),
611
+ CustomMethod(
612
+ typing="readonly defaultLogHandler: ScriptLogHandler",
613
+ code="""
614
+ get defaultLogHandler(): ScriptLogHandler {
615
+ return log;
616
+ }
617
+ """,
618
+ ),
619
+ ],
620
+ ),
621
+ keep_alive=KeepAliveCustomization(
622
+ is_destroyed_function="is_destroyed", destroy_signal_name="destroyed"
623
+ ),
624
+ ),
625
+ "ScriptRuntime": EnumerationCustomizations(
626
+ members={
627
+ "qjs": EnumerationMemberCustomizations(js_name="QJS"),
628
+ },
629
+ ),
630
+ "ControlService": ObjectTypeCustomizations(
631
+ methods={
632
+ "start": MethodCustomizations(ref_keep_alive=True),
633
+ "stop": MethodCustomizations(unref_keep_alive=True),
634
+ "get_endpoint_params": MethodCustomizations(drop=True),
635
+ },
636
+ properties={
637
+ "endpoint-params": PropertyCustomizations(drop=True),
638
+ },
639
+ ),
640
+ "PortalService": ObjectTypeCustomizations(
641
+ constructor=ConstructorCustomizations(
642
+ param_typings=[
643
+ "options?: PortalServiceOptions",
644
+ ],
645
+ custom_logic="""
646
+ const clusterParams = options?.clusterParams ?? new EndpointParameters();
647
+ const controlParams = options?.controlParams ?? null;
648
+ """,
649
+ ),
650
+ methods={
651
+ "start": MethodCustomizations(ref_keep_alive=True),
652
+ "stop": MethodCustomizations(unref_keep_alive=True),
653
+ "kick": MethodCustomizations(
654
+ param_typings=[
655
+ "connectionId: PortalConnectionId",
656
+ ],
657
+ ),
658
+ "post": MethodCustomizations(
659
+ param_typings=[
660
+ "connectionId: PortalConnectionId",
661
+ "message: any",
662
+ "data?: Buffer | null",
663
+ ],
664
+ custom_logic="const json = JSON.stringify(message);",
665
+ ),
666
+ "narrowcast": MethodCustomizations(
667
+ param_typings=[
668
+ "tag: string",
669
+ "message: any",
670
+ "data?: Buffer | null",
671
+ ],
672
+ custom_logic="const json = JSON.stringify(message);",
673
+ ),
674
+ "broadcast": MethodCustomizations(
675
+ param_typings=[
676
+ "message: any",
677
+ "data?: Buffer | null",
678
+ ],
679
+ custom_logic="const json = JSON.stringify(message);",
680
+ ),
681
+ "enumerate_tags": MethodCustomizations(
682
+ param_typings=[
683
+ "connectionId: PortalConnectionId",
684
+ ],
685
+ ),
686
+ "tag": MethodCustomizations(
687
+ param_typings=[
688
+ "connectionId: PortalConnectionId",
689
+ "tag: string",
690
+ ],
691
+ ),
692
+ "untag": MethodCustomizations(
693
+ param_typings=[
694
+ "connectionId: PortalConnectionId",
695
+ "tag: string",
696
+ ],
697
+ ),
698
+ },
699
+ signals={
700
+ "node-connected": SignalCustomizations(
701
+ transform={
702
+ 0: ("connectionId: PortalConnectionId", None),
703
+ 1: ("remoteAddress: SocketAddress", "parseSocketAddress"),
704
+ },
705
+ ),
706
+ "node-joined": SignalCustomizations(
707
+ transform={
708
+ 0: ("connectionId: PortalConnectionId", None),
709
+ },
710
+ ),
711
+ "node-left": SignalCustomizations(
712
+ transform={
713
+ 0: ("connectionId: PortalConnectionId", None),
714
+ },
715
+ ),
716
+ "node-disconnected": SignalCustomizations(
717
+ transform={
718
+ 0: ("connectionId: PortalConnectionId", None),
719
+ 1: ("remoteAddress: SocketAddress", "parseSocketAddress"),
720
+ },
721
+ ),
722
+ "controller-connected": SignalCustomizations(
723
+ transform={
724
+ 0: ("connectionId: PortalConnectionId", None),
725
+ 1: ("remoteAddress: SocketAddress", "parseSocketAddress"),
726
+ },
727
+ ),
728
+ "controller-disconnected": SignalCustomizations(
729
+ transform={
730
+ 0: ("connectionId: PortalConnectionId", None),
731
+ 1: ("remoteAddress: SocketAddress", "parseSocketAddress"),
732
+ },
733
+ ),
734
+ "authenticated": SignalCustomizations(
735
+ transform={
736
+ 0: ("connectionId: PortalConnectionId", None),
737
+ 1: ("sessionInfo: AuthenticatedSessionInfo", "JSON.parse"),
738
+ },
739
+ ),
740
+ "subscribe": SignalCustomizations(
741
+ transform={
742
+ 0: ("connectionId: PortalConnectionId", None),
743
+ },
744
+ ),
745
+ "message": SignalCustomizations(
746
+ transform={
747
+ 0: ("connectionId: PortalConnectionId", None),
748
+ 1: ("message: any", "JSON.parse"),
749
+ },
750
+ ),
751
+ },
752
+ ),
753
+ "EndpointParameters": ObjectTypeCustomizations(
754
+ constructor=ConstructorCustomizations(
755
+ param_typings=[
756
+ "params?: EndpointParametersSubset",
757
+ ],
758
+ custom_logic="""
759
+ const address = params?.address ?? null;
760
+ const port = params?.port ?? 0;
761
+ const certificate = params?.certificate ?? null;
762
+ const origin = params?.origin ?? null;
763
+
764
+ let authService: AuthenticationService | null = null;
765
+ const auth = params?.authentication;
766
+ if (auth !== undefined) {
767
+ if (auth.scheme === "token") {
768
+ authService = new StaticAuthenticationService(auth.token);
769
+ } else {
770
+ authService = new CallbackAuthenticationService(auth.callback);
771
+ }
772
+ }
773
+
774
+ const assetRoot = params?.assetRoot ?? null;
775
+ """,
776
+ ),
777
+ ),
778
+ "Injector": ObjectTypeCustomizations(drop=True),
779
+ "RpcClient": ObjectTypeCustomizations(drop=True),
780
+ "RpcPeer": ObjectTypeCustomizations(drop=True),
781
+ "Cancellable": ObjectTypeCustomizations(
782
+ methods={
783
+ "is_cancelled": MethodCustomizations(hide=True),
784
+ "set_error_if_cancelled": MethodCustomizations(
785
+ js_name="throwIfCancelled",
786
+ return_typing="void",
787
+ ),
788
+ "make_pollfd": MethodCustomizations(drop=True),
789
+ "release_fd": MethodCustomizations(drop=True),
790
+ "source_new": MethodCustomizations(drop=True),
791
+ },
792
+ custom_code=CustomCode(
793
+ methods=[
794
+ CustomMethod(
795
+ typing="readonly isCancelled: boolean",
796
+ code="""
797
+ get isCancelled(): boolean {
798
+ return this._isCancelled();
799
+ }
800
+ """,
801
+ ),
802
+ ],
803
+ ),
804
+ ),
805
+ "IOStream": ObjectTypeCustomizations(
806
+ methods={
807
+ "close": MethodCustomizations(drop=True),
808
+ "close_async": MethodCustomizations(js_name="close"),
809
+ "splice_async": MethodCustomizations(drop=True),
810
+ "has_pending": MethodCustomizations(drop=True),
811
+ "set_pending": MethodCustomizations(drop=True),
812
+ "clear_pending": MethodCustomizations(drop=True),
813
+ },
814
+ ),
815
+ "InputStream": ObjectTypeCustomizations(
816
+ methods={
817
+ "close": MethodCustomizations(drop=True),
818
+ "close_async": MethodCustomizations(js_name="close"),
819
+ "read": MethodCustomizations(drop=True),
820
+ "read_async": MethodCustomizations(drop=True),
821
+ "read_all": MethodCustomizations(drop=True),
822
+ "read_all_async": MethodCustomizations(drop=True),
823
+ "read_bytes": MethodCustomizations(drop=True),
824
+ "read_bytes_async": MethodCustomizations(js_name="read"),
825
+ "skip": MethodCustomizations(drop=True),
826
+ "skip_async": MethodCustomizations(js_name="skip"),
827
+ "is_closed": MethodCustomizations(drop=True),
828
+ "has_pending": MethodCustomizations(drop=True),
829
+ "set_pending": MethodCustomizations(drop=True),
830
+ "clear_pending": MethodCustomizations(drop=True),
831
+ },
832
+ ),
833
+ "OutputStream": ObjectTypeCustomizations(
834
+ methods={
835
+ "close": MethodCustomizations(drop=True),
836
+ "close_async": MethodCustomizations(js_name="close"),
837
+ "flush": MethodCustomizations(drop=True),
838
+ "flush_async": MethodCustomizations(js_name="flush"),
839
+ "write": MethodCustomizations(drop=True),
840
+ "write_async": MethodCustomizations(drop=True),
841
+ "write_all": MethodCustomizations(drop=True),
842
+ "write_all_async": MethodCustomizations(drop=True),
843
+ "write_bytes": MethodCustomizations(drop=True),
844
+ "write_bytes_async": MethodCustomizations(js_name="write"),
845
+ "writev": MethodCustomizations(drop=True),
846
+ "writev_async": MethodCustomizations(drop=True),
847
+ "writev_all": MethodCustomizations(drop=True),
848
+ "writev_all_async": MethodCustomizations(drop=True),
849
+ "splice": MethodCustomizations(drop=True),
850
+ "splice_async": MethodCustomizations(drop=True),
851
+ "is_closing": MethodCustomizations(drop=True),
852
+ "is_closed": MethodCustomizations(drop=True),
853
+ "has_pending": MethodCustomizations(drop=True),
854
+ "set_pending": MethodCustomizations(drop=True),
855
+ "clear_pending": MethodCustomizations(drop=True),
856
+ },
857
+ ),
858
+ "UnixSocketAddress": ObjectTypeCustomizations(
859
+ methods={
860
+ "get_path": MethodCustomizations(
861
+ return_typing="Buffer",
862
+ return_cconversion="fdn_buffer_to_value (env, (const guint8 *) retval, g_unix_socket_address_get_path_len (handle))",
863
+ ),
864
+ "get_path_len": MethodCustomizations(drop=True),
865
+ "get_is_abstract": MethodCustomizations(drop=True),
866
+ },
867
+ properties={
868
+ "path": PropertyCustomizations(typing="path: Buffer"),
869
+ "abstract": PropertyCustomizations(drop=True),
870
+ "path-as-array": PropertyCustomizations(drop=True),
871
+ },
872
+ ),
873
+ "SocketAddress": ObjectTypeCustomizations(
874
+ js_name="BaseSocketAddress",
875
+ constructor=ConstructorCustomizations(drop=True),
876
+ methods={
877
+ "to_native": MethodCustomizations(drop=True),
878
+ },
879
+ ),
880
+ "SocketConnectable": ObjectTypeCustomizations(drop_abstract_base=True),
881
+ "InetAddress": ObjectTypeCustomizations(
882
+ properties={
883
+ "bytes": PropertyCustomizations(drop=True),
884
+ },
885
+ ),
886
+ "Object": ObjectTypeCustomizations(
887
+ js_name="BaseObject",
888
+ methods={
889
+ "is_floating": MethodCustomizations(drop=True),
890
+ "ref": MethodCustomizations(drop=True),
891
+ "ref_sink": MethodCustomizations(drop=True),
892
+ "unref": MethodCustomizations(drop=True),
893
+ "getv": MethodCustomizations(drop=True),
894
+ "get_property": MethodCustomizations(drop=True),
895
+ "set_property": MethodCustomizations(drop=True),
896
+ "notify_by_pspec": MethodCustomizations(drop=True),
897
+ "freeze_notify": MethodCustomizations(drop=True),
898
+ "thaw_notify": MethodCustomizations(drop=True),
899
+ "bind_property": MethodCustomizations(drop=True),
900
+ "bind_property_full": MethodCustomizations(drop=True),
901
+ "bind_property_with_closures": MethodCustomizations(drop=True),
902
+ "force_floating": MethodCustomizations(drop=True),
903
+ "get_data": MethodCustomizations(drop=True),
904
+ "get_qdata": MethodCustomizations(drop=True),
905
+ "run_dispose": MethodCustomizations(drop=True),
906
+ "set_data": MethodCustomizations(drop=True),
907
+ "steal_data": MethodCustomizations(drop=True),
908
+ "steal_qdata": MethodCustomizations(drop=True),
909
+ "watch_closure": MethodCustomizations(drop=True),
910
+ },
911
+ signals={
912
+ "notify": SignalCustomizations(drop=True),
913
+ },
914
+ ),
915
+ }
916
+
917
+ return Customizations(
918
+ custom_types,
919
+ type_customizations,
920
+ CUSTOMIZATION_FACADE_EXPORTS,
921
+ CUSTOMIZATION_FACADE_TS,
922
+ CUSTOMIZATION_HELPERS_IMPORTS,
923
+ CUSTOMIZATION_HELPERS_TS,
924
+ )