Skip to content

Commit f5ba22a

Browse files
committed
compiler: Expose platform and externals options
1 parent dccb681 commit f5ba22a

File tree

2 files changed

+63
-12
lines changed

2 files changed

+63
-12
lines changed

frida/_frida/extension.c

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,8 @@ static void PyCompiler_dealloc (PyCompiler * self);
533533
static PyObject * PyCompiler_build (PyCompiler * self, PyObject * args, PyObject * kw);
534534
static PyObject * PyCompiler_watch (PyCompiler * self, PyObject * args, PyObject * kw);
535535
static gboolean PyCompiler_set_options (FridaCompilerOptions * options, const gchar * project_root_value, const gchar * output_format_value,
536-
const gchar * bundle_format_value, const gchar * type_check_value, const gchar * source_maps_value, const gchar * compression_value);
536+
const gchar * bundle_format_value, const gchar * type_check_value, const gchar * source_maps_value, const gchar * compression_value,
537+
const gchar * platform_value, PyObject * externals_value);
537538

538539
static int PyPackageManager_init (PyPackageManager * self, PyObject * args, PyObject * kw);
539540
static void PyPackageManager_dealloc (PyPackageManager * self);
@@ -4904,26 +4905,28 @@ static PyObject *
49044905
PyCompiler_build (PyCompiler * self, PyObject * args, PyObject * kw)
49054906
{
49064907
PyObject * result;
4907-
static char * keywords[] =
4908-
{ "entrypoint", "project_root", "output_format", "bundle_format", "type_check", "source_maps", "compression", NULL };
4908+
static char * keywords[] = { "entrypoint", "project_root", "output_format", "bundle_format", "type_check", "source_maps", "compression",
4909+
"platform", "externals", NULL };
49094910
const char * entrypoint;
49104911
const char * project_root = NULL;
49114912
const char * output_format = NULL;
49124913
const char * bundle_format = NULL;
49134914
const char * type_check = NULL;
49144915
const char * source_maps = NULL;
49154916
const char * compression = NULL;
4917+
const char * platform = NULL;
4918+
PyObject * externals = NULL;
49164919
FridaBuildOptions * options;
49174920
GError * error = NULL;
49184921
gchar * bundle;
49194922

4920-
if (!PyArg_ParseTupleAndKeywords (args, kw, "s|ssssss", keywords, &entrypoint, &project_root, &output_format, &bundle_format, &type_check,
4921-
&source_maps, &compression))
4923+
if (!PyArg_ParseTupleAndKeywords (args, kw, "s|sssssssO", keywords, &entrypoint, &project_root, &output_format, &bundle_format,
4924+
&type_check, &source_maps, &compression, &platform, &externals))
49224925
return NULL;
49234926

49244927
options = frida_build_options_new ();
49254928
if (!PyCompiler_set_options (FRIDA_COMPILER_OPTIONS (options), project_root, output_format, bundle_format, type_check, source_maps,
4926-
compression))
4929+
compression, platform, externals))
49274930
goto invalid_option_value;
49284931

49294932
Py_BEGIN_ALLOW_THREADS
@@ -4950,25 +4953,27 @@ PyCompiler_build (PyCompiler * self, PyObject * args, PyObject * kw)
49504953
static PyObject *
49514954
PyCompiler_watch (PyCompiler * self, PyObject * args, PyObject * kw)
49524955
{
4953-
static char * keywords[] =
4954-
{ "entrypoint", "project_root", "output_format", "bundle_format", "type_check", "source_maps", "compression", NULL };
4956+
static char * keywords[] = { "entrypoint", "project_root", "output_format", "bundle_format", "type_check", "source_maps", "compression",
4957+
"platform", "externals", NULL };
49554958
const char * entrypoint;
49564959
const char * project_root = NULL;
49574960
const char * output_format = NULL;
49584961
const char * bundle_format = NULL;
49594962
const char * type_check = NULL;
49604963
const char * source_maps = NULL;
49614964
const char * compression = NULL;
4965+
const char * platform = NULL;
4966+
PyObject * externals = NULL;
49624967
FridaWatchOptions * options;
49634968
GError * error = NULL;
49644969

4965-
if (!PyArg_ParseTupleAndKeywords (args, kw, "s|ssssss", keywords, &entrypoint, &project_root, &output_format, &bundle_format, &type_check,
4966-
&source_maps, &compression))
4970+
if (!PyArg_ParseTupleAndKeywords (args, kw, "s|sssssssO", keywords, &entrypoint, &project_root, &output_format, &bundle_format,
4971+
&type_check, &source_maps, &compression, &platform, &externals))
49674972
return NULL;
49684973

49694974
options = frida_watch_options_new ();
49704975
if (!PyCompiler_set_options (FRIDA_COMPILER_OPTIONS (options), project_root, output_format, bundle_format, type_check, source_maps,
4971-
compression))
4976+
compression, platform, externals))
49724977
goto invalid_option_value;
49734978

49744979
Py_BEGIN_ALLOW_THREADS
@@ -4991,7 +4996,8 @@ PyCompiler_watch (PyCompiler * self, PyObject * args, PyObject * kw)
49914996

49924997
static gboolean
49934998
PyCompiler_set_options (FridaCompilerOptions * options, const gchar * project_root_value, const gchar * output_format_value,
4994-
const gchar * bundle_format_value, const gchar * type_check_value, const gchar * source_maps_value, const gchar * compression_value)
4999+
const gchar * bundle_format_value, const gchar * type_check_value, const gchar * source_maps_value, const gchar * compression_value,
5000+
const gchar * platform_value, PyObject * externals_value)
49955001
{
49965002
if (project_root_value != NULL)
49975003
frida_compiler_options_set_project_root (options, project_root_value);
@@ -5046,6 +5052,43 @@ PyCompiler_set_options (FridaCompilerOptions * options, const gchar * project_ro
50465052
frida_compiler_options_set_compression (options, compression);
50475053
}
50485054

5055+
if (platform_value != NULL)
5056+
{
5057+
FridaJsPlatform platform;
5058+
5059+
if (!PyGObject_unmarshal_enum (platform_value, FRIDA_TYPE_JS_PLATFORM, &platform))
5060+
return FALSE;
5061+
5062+
frida_compiler_options_set_platform (options, platform);
5063+
}
5064+
5065+
if (externals_value != NULL)
5066+
{
5067+
gint n, i;
5068+
5069+
n = PySequence_Size (externals_value);
5070+
if (n == -1)
5071+
return FALSE;
5072+
5073+
for (i = 0; i != n; i++)
5074+
{
5075+
PyObject * element;
5076+
gchar * external = NULL;
5077+
5078+
element = PySequence_GetItem (externals_value, i);
5079+
if (element == NULL)
5080+
return FALSE;
5081+
PyGObject_unmarshal_string (element, &external);
5082+
Py_DecRef (element);
5083+
if (external == NULL)
5084+
return FALSE;
5085+
5086+
frida_compiler_options_add_external (options, external);
5087+
5088+
g_free (external);
5089+
}
5090+
}
5091+
50495092
return TRUE;
50505093
}
50515094

frida/core.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,6 +1572,8 @@ def build(
15721572
type_check: Optional[str] = None,
15731573
source_maps: Optional[str] = None,
15741574
compression: Optional[str] = None,
1575+
platform: Optional[str] = None,
1576+
externals: Optional[Sequence[str]] = None,
15751577
) -> str:
15761578
kwargs = {
15771579
"project_root": project_root,
@@ -1580,6 +1582,8 @@ def build(
15801582
"type_check": type_check,
15811583
"source_maps": source_maps,
15821584
"compression": compression,
1585+
"platform": platform,
1586+
"externals": externals,
15831587
}
15841588
_filter_missing_kwargs(kwargs)
15851589
return self._impl.build(entrypoint, **kwargs)
@@ -1594,6 +1598,8 @@ def watch(
15941598
type_check: Optional[str] = None,
15951599
source_maps: Optional[str] = None,
15961600
compression: Optional[str] = None,
1601+
platform: Optional[str] = None,
1602+
externals: Optional[Sequence[str]] = None,
15971603
) -> None:
15981604
kwargs = {
15991605
"project_root": project_root,
@@ -1602,6 +1608,8 @@ def watch(
16021608
"type_check": type_check,
16031609
"source_maps": source_maps,
16041610
"compression": compression,
1611+
"platform": platform,
1612+
"externals": externals,
16051613
}
16061614
_filter_missing_kwargs(kwargs)
16071615
return self._impl.watch(entrypoint, **kwargs)

0 commit comments

Comments
 (0)