Skip to content

Commit 51501ce

Browse files
committed
Add support for the new Compiler options
I.e. `output_format`, `bundle_format`, and `type_check`.
1 parent ef45347 commit 51501ce

File tree

2 files changed

+74
-12
lines changed

2 files changed

+74
-12
lines changed

frida/_frida/extension.c

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,8 @@ static void frida_python_authentication_service_do_authenticate (GTask * task, F
500500
static int PyCompiler_init (PyCompiler * self, PyObject * args, PyObject * kw);
501501
static PyObject * PyCompiler_build (PyCompiler * self, PyObject * args, PyObject * kw);
502502
static PyObject * PyCompiler_watch (PyCompiler * self, PyObject * args, PyObject * kw);
503-
static gboolean PyCompiler_set_options (FridaCompilerOptions * options, const gchar * project_root_value, const gchar * source_maps_value,
504-
const gchar * compression_value);
503+
static gboolean PyCompiler_set_options (FridaCompilerOptions * options, const gchar * project_root_value, const gchar * output_format_value,
504+
const gchar * bundle_format_value, const gchar * type_check_value, const gchar * source_maps_value, const gchar * compression_value);
505505

506506
static int PyFileMonitor_init (PyFileMonitor * self, PyObject * args, PyObject * kw);
507507
static PyObject * PyFileMonitor_enable (PyFileMonitor * self);
@@ -4768,20 +4768,26 @@ static PyObject *
47684768
PyCompiler_build (PyCompiler * self, PyObject * args, PyObject * kw)
47694769
{
47704770
PyObject * result;
4771-
static char * keywords[] = { "entrypoint", "project_root", "source_maps", "compression", NULL };
4771+
static char * keywords[] =
4772+
{ "entrypoint", "project_root", "output_format", "bundle_format", "type_check", "source_maps", "compression", NULL };
47724773
const char * entrypoint;
47734774
const char * project_root = NULL;
4775+
const char * output_format = NULL;
4776+
const char * bundle_format = NULL;
4777+
const char * type_check = NULL;
47744778
const char * source_maps = NULL;
47754779
const char * compression = NULL;
47764780
FridaBuildOptions * options;
47774781
GError * error = NULL;
47784782
gchar * bundle;
47794783

4780-
if (!PyArg_ParseTupleAndKeywords (args, kw, "s|sss", keywords, &entrypoint, &project_root, &source_maps, &compression))
4784+
if (!PyArg_ParseTupleAndKeywords (args, kw, "s|ssssss", keywords, &entrypoint, &project_root, &output_format, &bundle_format, &type_check,
4785+
&source_maps, &compression))
47814786
return NULL;
47824787

47834788
options = frida_build_options_new ();
4784-
if (!PyCompiler_set_options (FRIDA_COMPILER_OPTIONS (options), project_root, source_maps, compression))
4789+
if (!PyCompiler_set_options (FRIDA_COMPILER_OPTIONS (options), project_root, output_format, bundle_format, type_check, source_maps,
4790+
compression))
47854791
goto invalid_option_value;
47864792

47874793
Py_BEGIN_ALLOW_THREADS
@@ -4808,19 +4814,25 @@ PyCompiler_build (PyCompiler * self, PyObject * args, PyObject * kw)
48084814
static PyObject *
48094815
PyCompiler_watch (PyCompiler * self, PyObject * args, PyObject * kw)
48104816
{
4811-
static char * keywords[] = { "entrypoint", "project_root", "source_maps", "compression", NULL };
4817+
static char * keywords[] =
4818+
{ "entrypoint", "project_root", "output_format", "bundle_format", "type_check", "source_maps", "compression", NULL };
48124819
const char * entrypoint;
48134820
const char * project_root = NULL;
4821+
const char * output_format = NULL;
4822+
const char * bundle_format = NULL;
4823+
const char * type_check = NULL;
48144824
const char * source_maps = NULL;
48154825
const char * compression = NULL;
48164826
FridaWatchOptions * options;
48174827
GError * error = NULL;
48184828

4819-
if (!PyArg_ParseTupleAndKeywords (args, kw, "s|sss", keywords, &entrypoint, &project_root, &source_maps, &compression))
4829+
if (!PyArg_ParseTupleAndKeywords (args, kw, "s|ssssss", keywords, &entrypoint, &project_root, &output_format, &bundle_format, &type_check,
4830+
&source_maps, &compression))
48204831
return NULL;
48214832

48224833
options = frida_watch_options_new ();
4823-
if (!PyCompiler_set_options (FRIDA_COMPILER_OPTIONS (options), project_root, source_maps, compression))
4834+
if (!PyCompiler_set_options (FRIDA_COMPILER_OPTIONS (options), project_root, output_format, bundle_format, type_check, source_maps,
4835+
compression))
48244836
goto invalid_option_value;
48254837

48264838
Py_BEGIN_ALLOW_THREADS
@@ -4842,12 +4854,42 @@ PyCompiler_watch (PyCompiler * self, PyObject * args, PyObject * kw)
48424854
}
48434855

48444856
static gboolean
4845-
PyCompiler_set_options (FridaCompilerOptions * options, const gchar * project_root_value, const gchar * source_maps_value,
4846-
const gchar * compression_value)
4857+
PyCompiler_set_options (FridaCompilerOptions * options, const gchar * project_root_value, const gchar * output_format_value,
4858+
const gchar * bundle_format_value, const gchar * type_check_value, const gchar * source_maps_value, const gchar * compression_value)
48474859
{
48484860
if (project_root_value != NULL)
48494861
frida_compiler_options_set_project_root (options, project_root_value);
48504862

4863+
if (output_format_value != NULL)
4864+
{
4865+
FridaOutputFormat output_format;
4866+
4867+
if (!PyGObject_unmarshal_enum (output_format_value, FRIDA_TYPE_OUTPUT_FORMAT, &output_format))
4868+
return FALSE;
4869+
4870+
frida_compiler_options_set_output_format (options, output_format);
4871+
}
4872+
4873+
if (bundle_format_value != NULL)
4874+
{
4875+
FridaBundleFormat bundle_format;
4876+
4877+
if (!PyGObject_unmarshal_enum (bundle_format_value, FRIDA_TYPE_BUNDLE_FORMAT, &bundle_format))
4878+
return FALSE;
4879+
4880+
frida_compiler_options_set_bundle_format (options, bundle_format);
4881+
}
4882+
4883+
if (type_check_value != NULL)
4884+
{
4885+
FridaTypeCheckMode type_check;
4886+
4887+
if (!PyGObject_unmarshal_enum (type_check_value, FRIDA_TYPE_TYPE_CHECK_MODE, &type_check))
4888+
return FALSE;
4889+
4890+
frida_compiler_options_set_type_check (options, type_check);
4891+
}
4892+
48514893
if (source_maps_value != NULL)
48524894
{
48534895
FridaSourceMaps source_maps;

frida/core.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,10 +1567,20 @@ def build(
15671567
self,
15681568
entrypoint: str,
15691569
project_root: Optional[str] = None,
1570+
output_format: Optional[str] = None,
1571+
bundle_format: Optional[str] = None,
1572+
type_check: Optional[str] = None,
15701573
source_maps: Optional[str] = None,
15711574
compression: Optional[str] = None,
15721575
) -> str:
1573-
kwargs = {"project_root": project_root, "source_maps": source_maps, "compression": compression}
1576+
kwargs = {
1577+
"project_root": project_root,
1578+
"output_format": output_format,
1579+
"bundle_format": bundle_format,
1580+
"type_check": type_check,
1581+
"source_maps": source_maps,
1582+
"compression": compression,
1583+
}
15741584
_filter_missing_kwargs(kwargs)
15751585
return self._impl.build(entrypoint, **kwargs)
15761586

@@ -1579,10 +1589,20 @@ def watch(
15791589
self,
15801590
entrypoint: str,
15811591
project_root: Optional[str] = None,
1592+
output_format: Optional[str] = None,
1593+
bundle_format: Optional[str] = None,
1594+
type_check: Optional[str] = None,
15821595
source_maps: Optional[str] = None,
15831596
compression: Optional[str] = None,
15841597
) -> None:
1585-
kwargs = {"project_root": project_root, "source_maps": source_maps, "compression": compression}
1598+
kwargs = {
1599+
"project_root": project_root,
1600+
"output_format": output_format,
1601+
"bundle_format": bundle_format,
1602+
"type_check": type_check,
1603+
"source_maps": source_maps,
1604+
"compression": compression,
1605+
}
15861606
_filter_missing_kwargs(kwargs)
15871607
return self._impl.watch(entrypoint, **kwargs)
15881608

0 commit comments

Comments
 (0)