Class: CFrida::Compiler

Inherits:
GObject
  • Object
show all
Defined in:
ext/c_frida/Compiler.c

Instance Method Summary collapse

Constructor Details

#initialize(dvmgr) ⇒ Object



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'ext/c_frida/Compiler.c', line 182

static VALUE Compiler_initialize(VALUE self, VALUE dvmgr)
{
    GET_GOBJECT_DATA();

    if (dvmgr == Qfalse)
        return (self);
    if (!rb_obj_is_instance_of(dvmgr, cDeviceManager)) {
        raise_argerror("argument should be a DeviceManager instance.");
        return (Qnil);
    }
    VALUE dvmgr_self;
    dvmgr_self = dvmgr;
    GET_DATA_EX(GObject, dvmgr_self, dvmgr_d);
    d->handle = frida_compiler_new(dvmgr_d->handle);
    d->destroy = frida_unref;
    return (self);
}

Instance Method Details

#build(*args) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'ext/c_frida/Compiler.c', line 30

static VALUE Compiler_build(int argc, VALUE *argv, VALUE self)
{
    GET_GOBJECT_DATA();
    REQUIRE_GOBJECT_HANDLE();

    VALUE entrypoint, kws;
    FridaBuildOptions *options;
    FridaCompilerOptions *coptions;

    rb_scan_args(argc, argv, "1:", &entrypoint, &kws);
    if (!RB_TYPE_P(entrypoint, T_STRING)) {
        raise_argerror("entrypoint must be a string.");
        return (Qnil);
    }
    options = frida_build_options_new();
    coptions = FRIDA_COMPILER_OPTIONS(options);
    if (!NIL_P(kws)) {
        VALUE project_root = rb_hash_aref(kws, ID2SYM(rb_intern("project_root")));
        if (!NIL_P(project_root)) {
            if (!RB_TYPE_P(project_root, T_STRING)) {
                raise_argerror("project_root must be a string.");
                return (Qnil);
            }
            frida_compiler_options_set_project_root(coptions, StringValueCStr(project_root));
        }
        VALUE source_maps = rb_hash_aref(kws, ID2SYM(rb_intern("source_maps")));
        if (!NIL_P(source_maps)) {
            if (!RB_TYPE_P(source_maps, T_STRING)) {
                raise_argerror("source_maps must be a string.");
                return (Qnil);
            }
            FridaSourceMaps gsource_maps;
            if (!rbGObject_unmarshal_enum(StringValueCStr(source_maps), FRIDA_TYPE_SOURCE_MAPS, &gsource_maps)) {
                raise_argerror("invalid source_maps.");
                return (Qnil);
            }
            frida_compiler_options_set_source_maps(coptions, gsource_maps);
        }
        VALUE compression = rb_hash_aref(kws, ID2SYM(rb_intern("compression")));
        if (!NIL_P(compression)) {
            if (!RB_TYPE_P(compression, T_STRING)) {
                raise_argerror("compression must be a string.");
                return (Qnil);
            }
            FridaJsCompression gcompression;
            if (!rbGObject_unmarshal_enum(StringValueCStr(compression), FRIDA_TYPE_JS_COMPRESSION, &gcompression)) {
                raise_argerror("invalid compression.");
                return (Qnil);
            }
            frida_compiler_options_set_compression(coptions, gcompression);
        }
    }
    build_sync_proxy_args args = {
        .handle = d->handle,
        .entrypoint = StringValueCStr(entrypoint),
        .options = options
    };
    CALL_GVL_FREE_WITH_RET(char *bundle, build_sync, &args);
    g_object_unref(options);
    VALUE rbundle = rb_str_new_cstr(bundle);
    g_free(bundle);
    return (rbundle);

gerror:
    g_object_unref(options);
    raise_rerror(NULL, _gerr);
    return (Qnil);
}

#watch(*args) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'ext/c_frida/Compiler.c', line 111

static VALUE Compiler_watch(int argc, VALUE *argv, VALUE self)
{
    GET_GOBJECT_DATA();
    REQUIRE_GOBJECT_HANDLE();

    VALUE entrypoint, kws;
    FridaWatchOptions *options;
    FridaCompilerOptions *coptions;

    rb_scan_args(argc, argv, "1:", &entrypoint, &kws);
    if (!RB_TYPE_P(entrypoint, T_STRING)) {
        raise_argerror("entrypoint must be a string.");
        return (Qnil);
    }
    options = frida_watch_options_new();
    coptions = FRIDA_COMPILER_OPTIONS(options);
    if (!NIL_P(kws)) {
        VALUE project_root = rb_hash_aref(kws, ID2SYM(rb_intern("project_root")));
        if (!NIL_P(project_root)) {
            if (!RB_TYPE_P(project_root, T_STRING)) {
                raise_argerror("project_root must be a string.");
                return (Qnil);
            }
            frida_compiler_options_set_project_root(coptions, StringValueCStr(project_root));
        }
        VALUE source_maps = rb_hash_aref(kws, ID2SYM(rb_intern("source_maps")));
        if (!NIL_P(source_maps)) {
            if (!RB_TYPE_P(source_maps, T_STRING)) {
                raise_argerror("source_maps must be a string.");
                return (Qnil);
            }
            FridaSourceMaps gsource_maps;
            if (!rbGObject_unmarshal_enum(StringValueCStr(source_maps), FRIDA_TYPE_SOURCE_MAPS, &gsource_maps)) {
                raise_argerror("invalid source_maps.");
                return (Qnil);
            }
            frida_compiler_options_set_source_maps(coptions, gsource_maps);
        }
        VALUE compression = rb_hash_aref(kws, ID2SYM(rb_intern("compression")));
        if (!NIL_P(compression)) {
            if (!RB_TYPE_P(compression, T_STRING)) {
                raise_argerror("compression must be a string.");
                return (Qnil);
            }
            FridaJsCompression gcompression;
            if (!rbGObject_unmarshal_enum(StringValueCStr(compression), FRIDA_TYPE_JS_COMPRESSION, &gcompression)) {
                raise_argerror("invalid compression.");
                return (Qnil);
            }
            frida_compiler_options_set_compression(coptions, gcompression);
        }
    }
    watch_sync_proxy_args args = {
        .handle = d->handle,
        .entrypoint = StringValueCStr(entrypoint),
        .options = options
    };
    CALL_GVL_FREE_WITH_RET(char *dummy, watch_sync, &args);
    goto done;

gerror:
    raise_rerror(NULL, _gerr);
done:
    g_object_unref(options);
    return (Qnil);
}