From f5ba22ad36fe3ac7a9e58147e354afd31863352a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Andr=C3=A9=20Vadla=20Ravn=C3=A5s?= Date: Tue, 4 Nov 2025 10:22:27 +0100 Subject: [PATCH] compiler: Expose platform and externals options --- frida/_frida/extension.c | 67 +++++++++++++++++++++++++++++++++------- frida/core.py | 8 +++++ 2 files changed, 63 insertions(+), 12 deletions(-) diff --git a/frida/_frida/extension.c b/frida/_frida/extension.c index 6f2c0fa..c6fd1fc 100644 --- a/frida/_frida/extension.c +++ b/frida/_frida/extension.c @@ -533,7 +533,8 @@ static void PyCompiler_dealloc (PyCompiler * self); static PyObject * PyCompiler_build (PyCompiler * self, PyObject * args, PyObject * kw); static PyObject * PyCompiler_watch (PyCompiler * self, PyObject * args, PyObject * kw); static gboolean PyCompiler_set_options (FridaCompilerOptions * options, const gchar * project_root_value, const gchar * output_format_value, - const gchar * bundle_format_value, const gchar * type_check_value, const gchar * source_maps_value, const gchar * compression_value); + const gchar * bundle_format_value, const gchar * type_check_value, const gchar * source_maps_value, const gchar * compression_value, + const gchar * platform_value, PyObject * externals_value); static int PyPackageManager_init (PyPackageManager * self, PyObject * args, PyObject * kw); static void PyPackageManager_dealloc (PyPackageManager * self); @@ -4904,8 +4905,8 @@ static PyObject * PyCompiler_build (PyCompiler * self, PyObject * args, PyObject * kw) { PyObject * result; - static char * keywords[] = - { "entrypoint", "project_root", "output_format", "bundle_format", "type_check", "source_maps", "compression", NULL }; + static char * keywords[] = { "entrypoint", "project_root", "output_format", "bundle_format", "type_check", "source_maps", "compression", + "platform", "externals", NULL }; const char * entrypoint; const char * project_root = NULL; const char * output_format = NULL; @@ -4913,17 +4914,19 @@ PyCompiler_build (PyCompiler * self, PyObject * args, PyObject * kw) const char * type_check = NULL; const char * source_maps = NULL; const char * compression = NULL; + const char * platform = NULL; + PyObject * externals = NULL; FridaBuildOptions * options; GError * error = NULL; gchar * bundle; - if (!PyArg_ParseTupleAndKeywords (args, kw, "s|ssssss", keywords, &entrypoint, &project_root, &output_format, &bundle_format, &type_check, - &source_maps, &compression)) + if (!PyArg_ParseTupleAndKeywords (args, kw, "s|sssssssO", keywords, &entrypoint, &project_root, &output_format, &bundle_format, + &type_check, &source_maps, &compression, &platform, &externals)) return NULL; options = frida_build_options_new (); if (!PyCompiler_set_options (FRIDA_COMPILER_OPTIONS (options), project_root, output_format, bundle_format, type_check, source_maps, - compression)) + compression, platform, externals)) goto invalid_option_value; Py_BEGIN_ALLOW_THREADS @@ -4950,8 +4953,8 @@ invalid_option_value: static PyObject * PyCompiler_watch (PyCompiler * self, PyObject * args, PyObject * kw) { - static char * keywords[] = - { "entrypoint", "project_root", "output_format", "bundle_format", "type_check", "source_maps", "compression", NULL }; + static char * keywords[] = { "entrypoint", "project_root", "output_format", "bundle_format", "type_check", "source_maps", "compression", + "platform", "externals", NULL }; const char * entrypoint; const char * project_root = NULL; const char * output_format = NULL; @@ -4959,16 +4962,18 @@ PyCompiler_watch (PyCompiler * self, PyObject * args, PyObject * kw) const char * type_check = NULL; const char * source_maps = NULL; const char * compression = NULL; + const char * platform = NULL; + PyObject * externals = NULL; FridaWatchOptions * options; GError * error = NULL; - if (!PyArg_ParseTupleAndKeywords (args, kw, "s|ssssss", keywords, &entrypoint, &project_root, &output_format, &bundle_format, &type_check, - &source_maps, &compression)) + if (!PyArg_ParseTupleAndKeywords (args, kw, "s|sssssssO", keywords, &entrypoint, &project_root, &output_format, &bundle_format, + &type_check, &source_maps, &compression, &platform, &externals)) return NULL; options = frida_watch_options_new (); if (!PyCompiler_set_options (FRIDA_COMPILER_OPTIONS (options), project_root, output_format, bundle_format, type_check, source_maps, - compression)) + compression, platform, externals)) goto invalid_option_value; Py_BEGIN_ALLOW_THREADS @@ -4991,7 +4996,8 @@ invalid_option_value: static gboolean PyCompiler_set_options (FridaCompilerOptions * options, const gchar * project_root_value, const gchar * output_format_value, - const gchar * bundle_format_value, const gchar * type_check_value, const gchar * source_maps_value, const gchar * compression_value) + const gchar * bundle_format_value, const gchar * type_check_value, const gchar * source_maps_value, const gchar * compression_value, + const gchar * platform_value, PyObject * externals_value) { if (project_root_value != NULL) frida_compiler_options_set_project_root (options, project_root_value); @@ -5046,6 +5052,43 @@ PyCompiler_set_options (FridaCompilerOptions * options, const gchar * project_ro frida_compiler_options_set_compression (options, compression); } + if (platform_value != NULL) + { + FridaJsPlatform platform; + + if (!PyGObject_unmarshal_enum (platform_value, FRIDA_TYPE_JS_PLATFORM, &platform)) + return FALSE; + + frida_compiler_options_set_platform (options, platform); + } + + if (externals_value != NULL) + { + gint n, i; + + n = PySequence_Size (externals_value); + if (n == -1) + return FALSE; + + for (i = 0; i != n; i++) + { + PyObject * element; + gchar * external = NULL; + + element = PySequence_GetItem (externals_value, i); + if (element == NULL) + return FALSE; + PyGObject_unmarshal_string (element, &external); + Py_DecRef (element); + if (external == NULL) + return FALSE; + + frida_compiler_options_add_external (options, external); + + g_free (external); + } + } + return TRUE; } diff --git a/frida/core.py b/frida/core.py index 830ccee..5d5ac65 100644 --- a/frida/core.py +++ b/frida/core.py @@ -1572,6 +1572,8 @@ class Compiler: type_check: Optional[str] = None, source_maps: Optional[str] = None, compression: Optional[str] = None, + platform: Optional[str] = None, + externals: Optional[Sequence[str]] = None, ) -> str: kwargs = { "project_root": project_root, @@ -1580,6 +1582,8 @@ class Compiler: "type_check": type_check, "source_maps": source_maps, "compression": compression, + "platform": platform, + "externals": externals, } _filter_missing_kwargs(kwargs) return self._impl.build(entrypoint, **kwargs) @@ -1594,6 +1598,8 @@ class Compiler: type_check: Optional[str] = None, source_maps: Optional[str] = None, compression: Optional[str] = None, + platform: Optional[str] = None, + externals: Optional[Sequence[str]] = None, ) -> None: kwargs = { "project_root": project_root, @@ -1602,6 +1608,8 @@ class Compiler: "type_check": type_check, "source_maps": source_maps, "compression": compression, + "platform": platform, + "externals": externals, } _filter_missing_kwargs(kwargs) return self._impl.watch(entrypoint, **kwargs)