Class: CFrida::Device

Inherits:
GObject show all
Defined in:
ext/c_frida/Device.c

Instance Method Summary collapse

Methods inherited from GObject

#off, #on

Instance Method Details

#attach(*args) ⇒ Object



870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
# File 'ext/c_frida/Device.c', line 870

static VALUE Device_attach(int argc, VALUE *argv, VALUE self)
{
    GET_GOBJECT_DATA();
    REQUIRE_GOBJECT_HANDLE();
    VALUE pid, kws;
    FridaSessionOptions *options;

    rb_scan_args(argc, argv, "1:", &pid, &kws);
    options = frida_session_options_new();
    if (!RB_TYPE_P(pid, T_FIXNUM)) {
        raise_argerror("pid must be a number.");
        return (Qnil);
    }
    if (!NIL_P(kws)) {
        VALUE realm;
        realm = rb_hash_aref(kws, ID2SYM(rb_intern("realm")));
        if (!NIL_P(realm)) {
            if (!RB_TYPE_P(realm, T_STRING)) {
                raise_argerror("realm must be a string.");
                return (Qnil);
            }
            FridaRealm grealm;
            if (!rbGObject_unmarshal_enum(StringValueCStr(realm), FRIDA_TYPE_REALM, &grealm)) {
                g_object_unref(options);
                raise_argerror("invalid realm.");
                return (Qnil);
            }
            frida_session_options_set_realm(options, grealm);
        }

        VALUE persist_timeout;
        persist_timeout = rb_hash_aref(kws, ID2SYM(rb_intern("persist_timeout")));
        if (!NIL_P(persist_timeout)) {
            if (!RB_TYPE_P(persist_timeout, T_STRING)) {
                raise_argerror("persist_timeout must be a number.");
                return (Qnil);
            }
        }
        frida_session_options_set_persist_timeout(options, NUM2UINT(persist_timeout));
    }
    attach_sync_proxy_args args = {
        .device_handle = d->handle,
        .pid = NUM2UINT(pid),
        .options = options
    };
    CALL_GVL_FREE_WITH_RET(FridaSession *session, attach_sync, &args);
    g_object_unref(options);
    return (Session_from_FridaSession(session));

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

#busObject



53
54
55
56
# File 'ext/c_frida/Device.c', line 53

static VALUE Device_bus(VALUE self)
{
    return (rb_ivar_get(self, rb_intern("bus")));
}

#disable_spawn_gatingObject



394
395
396
397
398
399
400
401
402
403
# File 'ext/c_frida/Device.c', line 394

static VALUE Device_disable_spawn_gating(VALUE self)
{
    GET_GOBJECT_DATA();
    REQUIRE_GOBJECT_HANDLE();

    CALL_GVL_FREE_WITH_RET(void *dummy, disable_spawn_gating_sync, d->handle);
    return (Qnil);

    GERROR_BLOCK
}

#enable_spawn_gatingObject



371
372
373
374
375
376
377
378
379
380
# File 'ext/c_frida/Device.c', line 371

static VALUE Device_enable_spawn_gating(VALUE self)
{
    GET_GOBJECT_DATA();
    REQUIRE_GOBJECT_HANDLE();

    CALL_GVL_FREE_WITH_RET(void *dummy, enable_spawn_gating_sync, d->handle);
    return (Qnil);

    GERROR_BLOCK
}

#enumerate_applications(*args) ⇒ Object



302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
# File 'ext/c_frida/Device.c', line 302

static VALUE Device_enumerate_applications(int argc, VALUE *argv, VALUE self)
{
    GET_GOBJECT_DATA();
    REQUIRE_GOBJECT_HANDLE();
    FridaApplicationQueryOptions *options;
    VALUE identifiers, scope = Qnil;
    VALUE kws;

    rb_scan_args(argc, argv, ":", &kws);
    options = frida_application_query_options_new();
    if (!NIL_P(kws)) {
        identifiers = rb_hash_aref(kws, ID2SYM(rb_intern("identifiers")));
        if (!NIL_P(identifiers)) {
            if (!RB_TYPE_P(identifiers, T_ARRAY) || !array_all_type(identifiers, T_STRING)) {
                raise_argerror("identifiers must be an array of strings.");
                return (Qnil);
            }
            long len = RARRAY_LEN(identifiers);
            VALUE id;
            for (uint i = 0; i < len; i++) {
                id = RARRAY_AREF(identifiers, i);
                frida_application_query_options_select_identifier(options, StringValueCStr(id));
            }
        }
        scope = rb_hash_aref(kws, ID2SYM(rb_intern("scope")));
        if (!NIL_P(scope)) {
            if (!RB_TYPE_P(scope, T_STRING)) {
                raise_argerror("scope must be a string.");
                return (Qnil);
            }
            FridaScope frida_scope;
            if (!rbGObject_unmarshal_enum(StringValueCStr(scope), FRIDA_TYPE_SCOPE, &frida_scope))
                goto error;
            frida_application_query_options_set_scope(options, frida_scope);
        }
    }
    enumerate_applications_proxy_args args = {
        .device_handle = d->handle,
        .options = options
    };
    CALL_GVL_FREE_WITH_RET(FridaApplicationList *apps, enumerate_applications_sync, &args);
    g_object_unref(options);
    int apps_count = frida_application_list_size(apps);
    VALUE apps_arr = rb_ary_new_capa(apps_count);
    for (gint i = 0; i < apps_count; i++) {
        rb_ary_store(apps_arr, i, Application_from_FridaApplication(frida_application_list_get(apps, i)));
    }
    g_object_unref(apps);
    return (apps_arr);

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

#enumerate_pending_childrenObject



834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
# File 'ext/c_frida/Device.c', line 834

static VALUE Device_enumerate_pending_children(VALUE self)
{
    GET_GOBJECT_DATA();
    REQUIRE_GOBJECT_HANDLE();
    guint child_list_size;
    VALUE child_list_array;

    CALL_GVL_FREE_WITH_RET(FridaChildList *child_list, enumerate_pending_children_sync, d->handle);
    child_list_size = frida_child_list_size(child_list);
    child_list_array = rb_ary_new_capa(child_list_size);
    for (uint i = 0; i < child_list_size; i++) {
        rb_ary_store(child_list_array, i, Child_from_FridaChild(frida_child_list_get(child_list, i)));
    }
    g_object_unref(child_list);
    goto done;

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

#enumerate_pending_spawnObject



798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
# File 'ext/c_frida/Device.c', line 798

static VALUE Device_enumerate_pending_spawn(VALUE self)
{
    GET_GOBJECT_DATA();
    REQUIRE_GOBJECT_HANDLE();
    guint spawn_list_size;
    VALUE spawn_list_array;

    CALL_GVL_FREE_WITH_RET(FridaSpawnList *spawn_list, enumerate_pending_spawn_sync, d->handle);
    spawn_list_size = frida_spawn_list_size(spawn_list);
    spawn_list_array = rb_ary_new_capa(spawn_list_size);
    for (uint i = 0; i < spawn_list_size; i++) {
        rb_ary_store(spawn_list_array, i, Spawn_from_FridaSpawn(frida_spawn_list_get(spawn_list, i)));
    }
    g_object_unref(spawn_list);
    goto done;

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

#enumerate_processes(*args) ⇒ Object



232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# File 'ext/c_frida/Device.c', line 232

static VALUE Device_enumerate_processes(int argc, VALUE *argv, VALUE self)
{
    GET_GOBJECT_DATA();
    REQUIRE_GOBJECT_HANDLE();
    FridaProcessQueryOptions *options;
    VALUE pids, scope = Qnil;
    VALUE kws;

    rb_scan_args(argc, argv, ":", &kws);
    options = frida_process_query_options_new();
    if (!NIL_P(kws)) {
        pids = rb_hash_aref(kws, ID2SYM(rb_intern("pids")));
        if (!NIL_P(pids)) {
            if (!RB_TYPE_P(pids, T_ARRAY) || !array_all_type(pids, T_FIXNUM)) {
                raise_argerror("pids must be an array of integers.");
                return (Qnil);
            }
            long len = RARRAY_LEN(pids);
            VALUE pid;
            for (uint i = 0; i < len; i++) {
                pid = RARRAY_AREF(pids, i);
                frida_process_query_options_select_pid(options, NUM2UINT(pid));
            }
        }
        scope = rb_hash_aref(kws, ID2SYM(rb_intern("scope")));
        if (!NIL_P(scope)) {
            if (!RB_TYPE_P(scope, T_STRING)) {
                raise_argerror("scope must be a string.");
                return (Qnil);
            }
            FridaScope frida_scope;
            if (!rbGObject_unmarshal_enum(StringValueCStr(scope), FRIDA_TYPE_SCOPE, &frida_scope))
                goto error;
            frida_process_query_options_set_scope(options, frida_scope);
        }
    }
    enumerate_processes_proxy_args args = {
        .device_handle = d->handle,
        .options = options
    };
    CALL_GVL_FREE_WITH_RET(FridaProcessList *procs, enumerate_processes_sync, &args);
    g_object_unref(options);
    int procs_count = frida_process_list_size(procs);
    VALUE procs_arr = rb_ary_new_capa(procs_count);
    for (gint i = 0; i < procs_count; i++) {
        rb_ary_store(procs_arr, i, Process_from_FridaProcess(frida_process_list_get(procs, i)));
    }
    g_object_unref(procs);
    return (procs_arr);

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

#get_frontmost_application(*args) ⇒ Object



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'ext/c_frida/Device.c', line 168

static VALUE Device_get_frontmost_application(int argc, VALUE *argv, VALUE self)
{
    GET_GOBJECT_DATA();
    REQUIRE_GOBJECT_HANDLE();
    FridaFrontmostQueryOptions *options;
    VALUE scope = Qnil;
    VALUE kws;

    rb_scan_args(argc, argv, ":", &kws);
    options = frida_frontmost_query_options_new();
    if (!NIL_P(kws)) {
        scope = rb_hash_aref(kws, ID2SYM(rb_intern("scope")));
        if (!NIL_P(scope)) {
            if (!RB_TYPE_P(scope, T_STRING)) {
                raise_argerror("scope must be a string.");
                return (Qnil);
            }
            FridaScope fscope;
            if (!rbGObject_unmarshal_enum(StringValueCStr(scope), FRIDA_TYPE_SCOPE, &fscope))
                goto invalid_argument;
            frida_frontmost_query_options_set_scope(options, scope);
        }
    }
    get_frontmost_application_proxy_args args = {
        .device_handle = d->handle,
        .options = options
    };
    CALL_GVL_FREE_WITH_RET(void *app, get_frontmost_application_sync, &args);
    g_object_unref (options);
    return (Application_from_FridaApplication(app));

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

#iconObject



62
63
64
65
# File 'ext/c_frida/Device.c', line 62

static VALUE Device_icon(VALUE self)
{
    return (rb_ivar_get(self, rb_intern("icon")));
}

#idObject



26
27
28
29
# File 'ext/c_frida/Device.c', line 26

static VALUE Device_id(VALUE self)
{
    return (rb_ivar_get(self, rb_intern("id")));
}

#inject_library_blob(pid, blob, entrypoint, data) ⇒ Object



745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
# File 'ext/c_frida/Device.c', line 745

static VALUE Device_inject_library_blob(VALUE self, VALUE pid, VALUE blob, VALUE entrypoint, VALUE data)
{
    GET_GOBJECT_DATA();
    REQUIRE_GOBJECT_HANDLE();
    GBytes *gblob;

    if (!RB_TYPE_P(pid, T_FIXNUM)) {
        raise_argerror("pid must be a number.");
        return (Qnil);
    }
    if (!RB_TYPE_P(blob, T_STRING)) {
        raise_argerror("blob must be a string.");
        return (Qnil);
    }
    if (!RB_TYPE_P(entrypoint, T_STRING)) {
        raise_argerror("entrypoint must be a string.");
        return (Qnil);
    }
    if (!RB_TYPE_P(data, T_STRING)) {
        raise_argerror("data must be a string.");
        return (Qnil);
    }
    gblob = g_bytes_new(RSTRING_PTR(blob), RSTRING_LEN(blob));
    inject_library_blob_sync_proxy_args args = {
        .device_handle = d->handle,
        .pid = NUM2UINT(pid),
        .blob = gblob,
        .entrypoint = StringValueCStr(entrypoint),
        .data = StringValueCStr(data)
    };
    CALL_GVL_FREE_WITH_RET(void *id, inject_library_file_sync, &args);
    g_bytes_unref(gblob);
    return (UINT2NUM((unsigned long long)id / sizeof(char)));

gerror:
    g_bytes_unref(gblob);
    raise_rerror(NULL, _gerr);
    return (Qnil);
}

#inject_library_file(pid, path, entrypoint, data) ⇒ Object



697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
# File 'ext/c_frida/Device.c', line 697

static VALUE Device_inject_library_file(VALUE self, VALUE pid, VALUE path, VALUE entrypoint, VALUE data)
{
    GET_GOBJECT_DATA();
    REQUIRE_GOBJECT_HANDLE();

    if (!RB_TYPE_P(pid, T_FIXNUM)) {
        raise_argerror("pid must be a number.");
        return (Qnil);
    }
    if (!RB_TYPE_P(path, T_STRING)) {
        raise_argerror("path must be a string.");
        return (Qnil);
    }
    if (!RB_TYPE_P(entrypoint, T_STRING)) {
        raise_argerror("entrypoint must be a string.");
        return (Qnil);
    }
    if (!RB_TYPE_P(data, T_STRING)) {
        raise_argerror("data must be a string.");
        return (Qnil);
    }
    inject_library_file_sync_proxy_args args = {
        .device_handle = d->handle,
        .pid = NUM2UINT(pid),
        .path = StringValueCStr(path),
        .entrypoint = StringValueCStr(entrypoint),
        .data = StringValueCStr(data)
    };
    CALL_GVL_FREE_WITH_RET(void *id, inject_library_file_sync, &args);
    return (UINT2NUM((unsigned long long)id / sizeof(char)));

    GERROR_BLOCK
}

#input(pid, buffer) ⇒ Object



594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
# File 'ext/c_frida/Device.c', line 594

static VALUE Device_input(VALUE self, VALUE pid, VALUE buffer)
{
    GET_GOBJECT_DATA();
    REQUIRE_GOBJECT_HANDLE();

    if (!RB_TYPE_P(pid, T_FIXNUM)) {
        raise_argerror("pid must be a number.");
        return (Qnil);
    }
    if (!RB_TYPE_P(buffer, T_STRING)) {
        raise_argerror("buffer must be a string.");
        return (Qnil);
    }
    GBytes *data;
    data = g_bytes_new(RSTRING_PTR(buffer), RSTRING_LEN(buffer));
    input_sync_proxy_args args = {
        .device_handle = d->handle,
        .pid = NUM2UINT(pid),
        .data = data
    };
    CALL_GVL_FREE_WITH_RET(void *dummy, input_sync, &args);
    goto done;

gerror:
    raise_rerror(NULL, _gerr);
done:
    g_bytes_unref(data);
    return (Qnil);
}

#inspectObject Also known as: to_s



67
68
69
70
71
72
73
74
75
76
# File 'ext/c_frida/Device.c', line 67

static VALUE Device_inspect(VALUE self)
{
    VALUE	s, id, name, type;

    id = rb_funcall(self, rb_intern("id"), 0, NULL);
    name = rb_funcall(self, rb_intern("name"), 0, NULL);
    type = rb_funcall(self, rb_intern("type"), 0, NULL);
    s = rb_sprintf("#<Device: id=%+"PRIsVALUE", name=%+"PRIsVALUE", type=%+"PRIsVALUE">", id, name, type);
    return (s);
}

#is_lostObject



122
123
124
125
126
127
128
129
130
# File 'ext/c_frida/Device.c', line 122

static VALUE Device_is_lost(VALUE self)
{
    GET_GOBJECT_DATA();
    REQUIRE_GOBJECT_HANDLE();
    CALL_GVL_FREE_WITH_RET(void *is_lost, is_lost, d->handle);
    return (is_lost ? Qtrue : Qfalse);

    UNREACHABLE_GERROR_BLOCK
}

#kill(pid) ⇒ Object



636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
# File 'ext/c_frida/Device.c', line 636

static VALUE Device_kill(VALUE self, VALUE pid)
{
    GET_GOBJECT_DATA();
    REQUIRE_GOBJECT_HANDLE();

    if (!RB_TYPE_P(pid, T_FIXNUM)) {
        raise_argerror("pid must be a number.");
        return (Qnil);
    }
    kill_sync_proxy_args args = {
        .device_handle = d->handle,
        .pid = NUM2UINT(pid)
    };
    CALL_GVL_FREE_WITH_RET(void *dummy, kill_sync, &args);
    goto done;
gerror:
    raise_rerror(NULL, _gerr);
done:
    return (Qnil);
}

#nameObject



35
36
37
38
# File 'ext/c_frida/Device.c', line 35

static VALUE Device_name(VALUE self)
{
    return (rb_ivar_get(self, rb_intern("name")));
}

#open_channel(address) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'ext/c_frida/Device.c', line 91

static VALUE Device_open_channel(VALUE self, VALUE address)
{
    GET_GOBJECT_DATA();
    REQUIRE_GOBJECT_HANDLE();
    if (!RB_TYPE_P(address, T_STRING)) {
        raise_argerror("address should be a string.");
        return (Qnil);
    }
    open_channel_proxy_args args = {
        .device_handle = d->handle,
        .address = StringValueCStr(address)
    };
    CALL_GVL_FREE_WITH_RET(GIOStream *stream, open_channel_sync, &args);
    return (IOStream_from_GIOStream(stream));

    GERROR_BLOCK
}

#query_system_parametersObject



145
146
147
148
149
150
151
152
153
# File 'ext/c_frida/Device.c', line 145

static VALUE Device_query_system_parameters(VALUE self)
{
    GET_GOBJECT_DATA();
    REQUIRE_GOBJECT_HANDLE();
    CALL_GVL_FREE_WITH_RET(void *params, query_system_parameters_sync, d->handle);
    return (rbGObject_marshal_dict(params));

    GERROR_BLOCK
}

#resume(pid) ⇒ Object



563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
# File 'ext/c_frida/Device.c', line 563

static VALUE Device_resume(VALUE self, VALUE pid)
{
    GET_GOBJECT_DATA();
    REQUIRE_GOBJECT_HANDLE();

    if (!RB_TYPE_P(pid, T_FIXNUM)) {
        raise_argerror("pid must be a number.");
        return (Qnil);
    }
    resume_sync_proxy_args args = {
        .device_handle = d->handle,
        .pid = NUM2UINT(pid)
    };
    CALL_GVL_FREE_WITH_RET(void *dummy, resume_sync, &args);
    return (Qnil);

    GERROR_BLOCK
}

#spawn(*args) ⇒ Object



519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
# File 'ext/c_frida/Device.c', line 519

static VALUE Device_spawn(int argc, VALUE *argv, VALUE self)
{
    GET_GOBJECT_DATA();
    REQUIRE_GOBJECT_HANDLE();
    VALUE program, kws;

    FridaSpawnOptions *options = frida_spawn_options_new();
    rb_scan_args(argc, argv, "1:", &program, &kws);
    if (!RB_TYPE_P(program, T_STRING)) {
        raise_argerror("program must be a string.");
        return (Qnil);
    }
    if (!NIL_P(kws)) {
        options = parse_spwan_options(options, kws);
        if (!options)
            return (g_object_unref(options), Qnil);
    }
    spawn_sync_proxy_args args = {
        .device_handle = d->handle,
        .program = StringValueCStr(program),
        .options = options
    };
    CALL_GVL_FREE_WITH_RET(void *pid, spawn_sync, &args);
    g_object_unref(options);
    return (UINT2NUM((unsigned long long)pid / sizeof(char)));

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

#typeObject



44
45
46
47
# File 'ext/c_frida/Device.c', line 44

static VALUE Device_type(VALUE self)
{
    return (rb_ivar_get(self, rb_intern("type")));
}

#unpairObject



669
670
671
672
673
674
675
676
677
678
679
680
681
# File 'ext/c_frida/Device.c', line 669

static VALUE Device_unpair(VALUE self)
{
    GET_GOBJECT_DATA();
    REQUIRE_GOBJECT_HANDLE();

    CALL_GVL_FREE_WITH_RET(void *dummy, unpair_sync, d->handle);
    goto done;

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