92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
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
177
178
179
180
181
182
|
# File 'ext/c_frida/EndpointParameters.c', line 92
static VALUE EndpointParameters_initialize(int argc, VALUE *argv, VALUE self)
{
GET_GOBJECT_DATA();
GTlsCertificate *certificate = NULL;
FridaAuthenticationService *auth_service = NULL;
GFile *asset_root = NULL;
unsigned short port = 0;
char *address = NULL, *origin = NULL, *auth_token = NULL;
VALUE kws;
rb_scan_args(argc, argv, ":", &kws);
if (!NIL_P(kws)) {
VALUE raddress = rb_hash_aref(kws, ID2SYM(rb_intern("address")));
if (!NIL_P(raddress)) {
if (!RB_TYPE_P(raddress, T_STRING)) {
raise_argerror("address must be a string.");
goto invalid_arg;
}
address = StringValueCStr(raddress);
}
VALUE rport = rb_hash_aref(kws, ID2SYM(rb_intern("port")));
if (!NIL_P(rport)) {
if (!RB_TYPE_P(rport, T_FIXNUM)) {
raise_argerror("port must be a number.");
goto invalid_arg;
}
port = (unsigned short)NUM2USHORT(rport);
}
VALUE rcert = rb_hash_aref(kws, ID2SYM(rb_intern("certificate")));
if (!NIL_P(rcert)) {
if (!RB_TYPE_P(rcert, T_STRING)) {
raise_argerror("certificate must be a string.");
goto invalid_arg;
}
char *cert = StringValueCStr(rcert);
if (!rbGObject_unmarshal_certificate(cert, &certificate)) {
raise_argerror("invalid certificate.");
goto invalid_arg;
}
}
VALUE rorigin = rb_hash_aref(kws, ID2SYM(rb_intern("origin")));
if (!NIL_P(rorigin)) {
if (!RB_TYPE_P(rorigin, T_STRING)) {
raise_argerror("origin must be a string.");
goto invalid_arg;
}
origin = StringValueCStr(rorigin);
}
VALUE rauth_token = rb_hash_aref(kws, ID2SYM(rb_intern("auth_token")));
if (!NIL_P(rauth_token)) {
if (!RB_TYPE_P(rauth_token, T_STRING)) {
raise_argerror("auth_token must be a string.");
goto invalid_arg;
}
auth_token = StringValueCStr(rauth_token);
}
VALUE rauth_callback = rb_hash_aref(kws, ID2SYM(rb_intern("auth_callback")));
if (!NIL_P(rauth_callback)) {
// currently support only methods.
if (rb_obj_is_kind_of(rauth_callback, rb_const_get(rb_cObject, rb_intern("Method"))) == Qfalse || \
NUM2INT(rb_funcall(rauth_callback, rb_intern("arity"), 0, NULL)) != 1) {
raise_argerror("auth_callback must be a method with one argument.");
goto invalid_arg;
}
// don't GC
rb_ivar_set(self, rb_intern("auth_callback"), rauth_callback);
}
if (auth_token)
auth_service = FRIDA_AUTHENTICATION_SERVICE(frida_static_authentication_service_new(auth_token));
else if (rauth_callback != Qnil)
auth_service = FRIDA_AUTHENTICATION_SERVICE(frida_rb_authentication_service_new(rauth_callback));
VALUE rasset_root = rb_hash_aref(kws, ID2SYM(rb_intern("asset_root")));
if (!NIL_P(rasset_root)) {
if (!RB_TYPE_P(rasset_root, T_STRING)) {
raise_argerror("asset_root must be a string.");
goto invalid_arg;
}
asset_root = g_file_new_for_path(StringValueCStr(rasset_root));
}
} else
return (self);
d->handle = frida_endpoint_parameters_new(address, port, certificate, origin, auth_service, asset_root);
d->destroy = g_object_unref;
return (self);
invalid_arg:
g_clear_object(&asset_root);
g_clear_object(&auth_service);
g_clear_object(&certificate);
return (Qnil);
}
|