frida 16.7.14 → 16.7.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/README.md +1 -10
  2. package/build/BSDmakefile +6 -0
  3. package/build/Makefile +10 -0
  4. package/build/src/frida.d.ts +364 -0
  5. package/build/src/frida.js +962 -0
  6. package/build/src/frida_binding.d.ts +938 -0
  7. package/meson.build +34 -67
  8. package/package.json +30 -20
  9. package/scripts/fetch-abi-bits.py +15 -65
  10. package/scripts/install.js +5 -4
  11. package/src/addon.def +3 -0
  12. package/src/addon.symbols +2 -1
  13. package/src/addon.version +4 -0
  14. package/src/frida_bindgen/__init__.py +0 -0
  15. package/src/frida_bindgen/__main__.py +4 -0
  16. package/src/frida_bindgen/__pycache__/__init__.cpython-312.pyc +0 -0
  17. package/src/frida_bindgen/__pycache__/__main__.cpython-312.pyc +0 -0
  18. package/src/frida_bindgen/__pycache__/cli.cpython-312.pyc +0 -0
  19. package/src/frida_bindgen/__pycache__/codegen.cpython-312.pyc +0 -0
  20. package/src/frida_bindgen/__pycache__/customization.cpython-312.pyc +0 -0
  21. package/src/frida_bindgen/__pycache__/loader.cpython-312.pyc +0 -0
  22. package/src/frida_bindgen/__pycache__/model.cpython-312.pyc +0 -0
  23. package/src/frida_bindgen/assets/codegen_helpers.c +1970 -0
  24. package/src/frida_bindgen/assets/codegen_helpers.ts +100 -0
  25. package/src/frida_bindgen/assets/codegen_prototypes.h +78 -0
  26. package/src/frida_bindgen/assets/codegen_types.h +57 -0
  27. package/src/frida_bindgen/assets/customization_facade.exports +13 -0
  28. package/src/frida_bindgen/assets/customization_facade.ts +157 -0
  29. package/src/frida_bindgen/assets/customization_helpers.imports +2 -0
  30. package/src/frida_bindgen/assets/customization_helpers.ts +396 -0
  31. package/src/frida_bindgen/cli.py +96 -0
  32. package/src/frida_bindgen/codegen.py +2233 -0
  33. package/src/frida_bindgen/customization.py +924 -0
  34. package/src/frida_bindgen/loader.py +60 -0
  35. package/src/frida_bindgen/model.py +1357 -0
  36. package/src/meson.build +92 -27
  37. package/{lib/build.py → src/tsc.py} +12 -12
  38. package/src/win_delay_load_hook.c +56 -0
  39. package/subprojects/frida-core.wrap +1 -1
  40. package/test/data/index.ts +2 -2
  41. package/test/device.ts +1 -2
  42. package/test/device_manager.ts +1 -2
  43. package/test/labrat.ts +2 -2
  44. package/test/script.ts +12 -12
  45. package/test/session.ts +3 -3
  46. package/tsconfig.json +6 -11
  47. package/dist/application.d.ts +0 -81
  48. package/dist/application.js +0 -2
  49. package/dist/authentication.d.ts +0 -3
  50. package/dist/authentication.js +0 -2
  51. package/dist/bus.d.ts +0 -16
  52. package/dist/bus.js +0 -23
  53. package/dist/cancellable.d.ts +0 -15
  54. package/dist/cancellable.js +0 -41
  55. package/dist/child.d.ts +0 -16
  56. package/dist/child.js +0 -9
  57. package/dist/crash.d.ts +0 -10
  58. package/dist/crash.js +0 -2
  59. package/dist/device.d.ts +0 -156
  60. package/dist/device.js +0 -188
  61. package/dist/device_manager.d.ts +0 -25
  62. package/dist/device_manager.js +0 -42
  63. package/dist/endpoint_parameters.d.ts +0 -26
  64. package/dist/endpoint_parameters.js +0 -24
  65. package/dist/icon.d.ts +0 -14
  66. package/dist/icon.js +0 -2
  67. package/dist/index.d.ts +0 -161
  68. package/dist/index.js +0 -170
  69. package/dist/iostream.d.ts +0 -13
  70. package/dist/iostream.js +0 -73
  71. package/dist/native.d.ts +0 -1
  72. package/dist/native.js +0 -11
  73. package/dist/portal_membership.d.ts +0 -6
  74. package/dist/portal_membership.js +0 -12
  75. package/dist/portal_service.d.ts +0 -48
  76. package/dist/portal_service.js +0 -52
  77. package/dist/process.d.ts +0 -47
  78. package/dist/process.js +0 -2
  79. package/dist/relay.d.ts +0 -22
  80. package/dist/relay.js +0 -32
  81. package/dist/script.d.ts +0 -70
  82. package/dist/script.js +0 -266
  83. package/dist/service.d.ts +0 -16
  84. package/dist/service.js +0 -26
  85. package/dist/session.d.ts +0 -45
  86. package/dist/session.js +0 -73
  87. package/dist/signals.d.ts +0 -20
  88. package/dist/signals.js +0 -40
  89. package/dist/socket_address.d.ts +0 -25
  90. package/dist/socket_address.js +0 -2
  91. package/dist/spawn.d.ts +0 -4
  92. package/dist/spawn.js +0 -2
  93. package/dist/system_parameters.d.ts +0 -84
  94. package/dist/system_parameters.js +0 -2
  95. package/lib/application.ts +0 -98
  96. package/lib/authentication.ts +0 -3
  97. package/lib/bus.ts +0 -30
  98. package/lib/cancellable.ts +0 -48
  99. package/lib/child.ts +0 -15
  100. package/lib/crash.ts +0 -11
  101. package/lib/device.ts +0 -331
  102. package/lib/device_manager.ts +0 -69
  103. package/lib/endpoint_parameters.ts +0 -56
  104. package/lib/icon.ts +0 -15
  105. package/lib/index.ts +0 -316
  106. package/lib/iostream.ts +0 -78
  107. package/lib/meson.build +0 -53
  108. package/lib/native.ts +0 -9
  109. package/lib/portal_membership.ts +0 -10
  110. package/lib/portal_service.ts +0 -105
  111. package/lib/process.ts +0 -57
  112. package/lib/relay.ts +0 -44
  113. package/lib/script.ts +0 -361
  114. package/lib/service.ts +0 -34
  115. package/lib/session.ts +0 -113
  116. package/lib/signals.ts +0 -45
  117. package/lib/socket_address.ts +0 -35
  118. package/lib/spawn.ts +0 -4
  119. package/lib/system_parameters.ts +0 -103
  120. package/meson.options +0 -11
  121. package/src/addon.cc +0 -78
  122. package/src/application.cc +0 -148
  123. package/src/application.h +0 -31
  124. package/src/authentication.cc +0 -174
  125. package/src/authentication.h +0 -24
  126. package/src/bus.cc +0 -167
  127. package/src/bus.h +0 -33
  128. package/src/cancellable.cc +0 -117
  129. package/src/cancellable.h +0 -31
  130. package/src/child.cc +0 -150
  131. package/src/child.h +0 -32
  132. package/src/crash.cc +0 -122
  133. package/src/crash.h +0 -30
  134. package/src/device.cc +0 -1350
  135. package/src/device.h +0 -56
  136. package/src/device_manager.cc +0 -362
  137. package/src/device_manager.h +0 -35
  138. package/src/endpoint_parameters.cc +0 -171
  139. package/src/endpoint_parameters.h +0 -28
  140. package/src/glib_context.cc +0 -62
  141. package/src/glib_context.h +0 -29
  142. package/src/glib_object.cc +0 -25
  143. package/src/glib_object.h +0 -37
  144. package/src/iostream.cc +0 -243
  145. package/src/iostream.h +0 -30
  146. package/src/operation.h +0 -94
  147. package/src/portal_membership.cc +0 -100
  148. package/src/portal_membership.h +0 -26
  149. package/src/portal_service.cc +0 -401
  150. package/src/portal_service.h +0 -40
  151. package/src/process.cc +0 -135
  152. package/src/process.h +0 -30
  153. package/src/relay.cc +0 -139
  154. package/src/relay.h +0 -31
  155. package/src/runtime.cc +0 -568
  156. package/src/runtime.h +0 -69
  157. package/src/script.cc +0 -301
  158. package/src/script.h +0 -36
  159. package/src/service.cc +0 -224
  160. package/src/service.h +0 -36
  161. package/src/session.cc +0 -860
  162. package/src/session.h +0 -42
  163. package/src/signals.cc +0 -334
  164. package/src/signals.h +0 -47
  165. package/src/spawn.cc +0 -95
  166. package/src/spawn.h +0 -27
  167. package/src/usage_monitor.h +0 -117
  168. package/src/uv_context.cc +0 -118
  169. package/src/uv_context.h +0 -40
  170. package/src/win_delay_load_hook.cc +0 -63
  171. package/subprojects/nan.wrap +0 -9
  172. package/subprojects/packagefiles/nan.patch +0 -13
package/src/device.h DELETED
@@ -1,56 +0,0 @@
1
- #ifndef FRIDANODE_DEVICE_H
2
- #define FRIDANODE_DEVICE_H
3
-
4
- #include "glib_object.h"
5
-
6
- #include <frida-core.h>
7
-
8
- namespace frida {
9
-
10
- class Device : public GLibObject {
11
- public:
12
- static void Init(v8::Local<v8::Object> exports, Runtime* runtime);
13
- static v8::Local<v8::Object> New(gpointer handle, Runtime* runtime);
14
-
15
- private:
16
- Device(FridaDevice* handle, Runtime* runtime);
17
- ~Device();
18
-
19
- static NAN_METHOD(New);
20
-
21
- static NAN_PROPERTY_GETTER(GetId);
22
- static NAN_PROPERTY_GETTER(GetName);
23
- static NAN_PROPERTY_GETTER(GetIcon);
24
- static NAN_PROPERTY_GETTER(GetType);
25
- static NAN_PROPERTY_GETTER(GetBus);
26
- static NAN_PROPERTY_GETTER(IsLost);
27
-
28
- static NAN_METHOD(QuerySystemParameters);
29
- static NAN_METHOD(GetFrontmostApplication);
30
- static NAN_METHOD(EnumerateApplications);
31
- static NAN_METHOD(EnumerateProcesses);
32
- static NAN_METHOD(EnableSpawnGating);
33
- static NAN_METHOD(DisableSpawnGating);
34
- static NAN_METHOD(EnumeratePendingSpawn);
35
- static NAN_METHOD(EnumeratePendingChildren);
36
- static NAN_METHOD(Spawn);
37
- static NAN_METHOD(Input);
38
- static NAN_METHOD(Resume);
39
- static NAN_METHOD(Kill);
40
- static NAN_METHOD(Attach);
41
- static NAN_METHOD(InjectLibraryFile);
42
- static NAN_METHOD(InjectLibraryBlob);
43
- static NAN_METHOD(OpenChannel);
44
- static NAN_METHOD(OpenService);
45
- static NAN_METHOD(Unpair);
46
-
47
- static v8::Local<v8::Value> TransformSignal(const gchar* name, guint index,
48
- const GValue* value, gpointer user_data);
49
- static void OnConnect(const gchar* signal, gpointer user_data);
50
- static void OnDisconnect(const gchar* signal, gpointer user_data);
51
- static bool ShouldStayAliveToEmit(const gchar* signal);
52
- };
53
-
54
- }
55
-
56
- #endif
@@ -1,362 +0,0 @@
1
- #include "device_manager.h"
2
-
3
- #include "device.h"
4
- #include "operation.h"
5
- #include "signals.h"
6
-
7
- #include <cstring>
8
-
9
- #define DEVICE_MANAGER_DATA_WRAPPERS "device_manager:wrappers"
10
-
11
- using std::strcmp;
12
- using v8::Array;
13
- using v8::Isolate;
14
- using v8::Local;
15
- using v8::Object;
16
- using v8::String;
17
- using v8::Value;
18
-
19
- namespace frida {
20
-
21
- DeviceManager::DeviceManager(FridaDeviceManager* handle, Runtime* runtime)
22
- : GLibObject(handle, runtime) {
23
- g_object_ref(handle_);
24
-
25
- runtime_->SetDataPointer(DEVICE_MANAGER_DATA_WRAPPERS, g_slist_prepend(
26
- static_cast<GSList*>(
27
- runtime_->GetDataPointer(DEVICE_MANAGER_DATA_WRAPPERS)), this));
28
- }
29
-
30
- DeviceManager::~DeviceManager() {
31
- runtime_->SetDataPointer(DEVICE_MANAGER_DATA_WRAPPERS, g_slist_remove(
32
- static_cast<GSList*>(
33
- runtime_->GetDataPointer(DEVICE_MANAGER_DATA_WRAPPERS)), this));
34
-
35
- frida_unref(handle_);
36
- }
37
-
38
- void DeviceManager::Init(Local<Object> exports, Runtime* runtime) {
39
- Local<String> name = Nan::New("DeviceManager").ToLocalChecked();
40
-
41
- auto tpl = CreateTemplate(name, DeviceManager::New, runtime);
42
-
43
- Nan::SetPrototypeMethod(tpl, "close", Close);
44
- Nan::SetPrototypeMethod(tpl, "enumerateDevices", EnumerateDevices);
45
- Nan::SetPrototypeMethod(tpl, "addRemoteDevice", AddRemoteDevice);
46
- Nan::SetPrototypeMethod(tpl, "removeRemoteDevice", RemoveRemoteDevice);
47
-
48
- Nan::Set(exports, name, Nan::GetFunction(tpl).ToLocalChecked());
49
- }
50
-
51
- void DeviceManager::Dispose(Runtime* runtime) {
52
- auto wrappers = static_cast<GSList*>(
53
- runtime->GetDataPointer(DEVICE_MANAGER_DATA_WRAPPERS));
54
- while (wrappers != NULL) {
55
- auto wrapper = static_cast<DeviceManager*>(wrappers->data);
56
- frida_device_manager_close_sync(wrapper->GetHandle<FridaDeviceManager>(),
57
- NULL, NULL);
58
- wrappers = g_slist_delete_link(wrappers, wrappers);
59
- }
60
- runtime->SetDataPointer(DEVICE_MANAGER_DATA_WRAPPERS, NULL);
61
- }
62
-
63
- NAN_METHOD(DeviceManager::New) {
64
- if (!info.IsConstructCall()) {
65
- Nan::ThrowError("Use the `new` keyword to create a new instance");
66
- return;
67
- }
68
-
69
- auto runtime = GetRuntimeFromConstructorArgs(info);
70
-
71
- auto handle = frida_device_manager_new();
72
-
73
- auto wrapper = new DeviceManager(handle, runtime);
74
- auto obj = info.This();
75
- wrapper->Wrap(obj);
76
-
77
- auto signals_obj = Signals::New(handle, runtime, TransformDeviceSignals,
78
- runtime);
79
- Nan::Set(obj, Nan::New("signals").ToLocalChecked(), signals_obj);
80
-
81
- g_object_unref(handle);
82
-
83
- auto signals_wrapper = ObjectWrap::Unwrap<Signals>(signals_obj);
84
- signals_wrapper->SetConnectCallback(OnConnect, runtime);
85
- signals_wrapper->SetDisconnectCallback(OnDisconnect, runtime);
86
-
87
- info.GetReturnValue().Set(obj);
88
- }
89
-
90
- namespace {
91
-
92
- class CloseOperation : public Operation<FridaDeviceManager> {
93
- protected:
94
- void Begin() {
95
- frida_device_manager_close(handle_, cancellable_, OnReady, this);
96
- }
97
-
98
- void End(GAsyncResult* result, GError** error) {
99
- frida_device_manager_close_finish(handle_, result, error);
100
- }
101
-
102
- Local<Value> Result(Isolate* isolate) {
103
- return Nan::Undefined();
104
- }
105
- };
106
-
107
- }
108
-
109
- NAN_METHOD(DeviceManager::Close) {
110
- auto isolate = info.GetIsolate();
111
- auto wrapper = ObjectWrap::Unwrap<DeviceManager>(info.Holder());
112
-
113
- auto operation = new CloseOperation();
114
- operation->Schedule(isolate, wrapper, info);
115
-
116
- info.GetReturnValue().Set(operation->GetPromise(isolate));
117
- }
118
-
119
- namespace {
120
-
121
- class EnumerateDevicesOperation : public Operation<FridaDeviceManager> {
122
- protected:
123
- void Begin() {
124
- frida_device_manager_enumerate_devices(handle_, cancellable_, OnReady,
125
- this);
126
- }
127
-
128
- void End(GAsyncResult* result, GError** error) {
129
- devices_ = frida_device_manager_enumerate_devices_finish(handle_, result,
130
- error);
131
- }
132
-
133
- Local<Value> Result(Isolate* isolate) {
134
- auto size = frida_device_list_size(devices_);
135
- Local<Array> devices = Nan::New<Array>(size);
136
- for (auto i = 0; i != size; i++) {
137
- auto handle = frida_device_list_get(devices_, i);
138
- auto device = Device::New(handle, runtime_);
139
- Nan::Set(devices, i, device);
140
- g_object_unref(handle);
141
- }
142
-
143
- frida_unref(devices_);
144
-
145
- return devices;
146
- }
147
-
148
- private:
149
- FridaDeviceList* devices_;
150
- };
151
-
152
- }
153
-
154
- NAN_METHOD(DeviceManager::EnumerateDevices) {
155
- auto isolate = info.GetIsolate();
156
- auto wrapper = ObjectWrap::Unwrap<DeviceManager>(info.Holder());
157
-
158
- auto operation = new EnumerateDevicesOperation();
159
- operation->Schedule(isolate, wrapper, info);
160
-
161
- info.GetReturnValue().Set(operation->GetPromise(isolate));
162
- }
163
-
164
- namespace {
165
-
166
- class AddRemoteDeviceOperation : public Operation<FridaDeviceManager> {
167
- public:
168
- AddRemoteDeviceOperation(gchar* address, FridaRemoteDeviceOptions* options)
169
- : address_(address),
170
- options_(options) {
171
- }
172
-
173
- ~AddRemoteDeviceOperation() {
174
- g_object_unref(options_);
175
- g_free(address_);
176
- }
177
-
178
- protected:
179
- void Begin() {
180
- frida_device_manager_add_remote_device(handle_, address_, options_,
181
- cancellable_, OnReady, this);
182
- }
183
-
184
- void End(GAsyncResult* result, GError** error) {
185
- device_ = frida_device_manager_add_remote_device_finish(handle_, result,
186
- error);
187
- }
188
-
189
- Local<Value> Result(Isolate* isolate) {
190
- auto wrapper = Device::New(device_, runtime_);
191
- g_object_unref(device_);
192
- return wrapper;
193
- }
194
-
195
- private:
196
- gchar* address_;
197
- FridaRemoteDeviceOptions* options_;
198
- FridaDevice* device_;
199
- };
200
-
201
- }
202
-
203
- NAN_METHOD(DeviceManager::AddRemoteDevice) {
204
- auto isolate = info.GetIsolate();
205
- auto wrapper = ObjectWrap::Unwrap<DeviceManager>(info.Holder());
206
-
207
- if (info.Length() < 5) {
208
- Nan::ThrowTypeError("Missing one or more arguments");
209
- return;
210
- }
211
-
212
- auto address_value = info[0];
213
- auto certificate_value = info[1];
214
- auto origin_value = info[2];
215
- auto token_value = info[3];
216
- auto keepalive_interval_value = info[4];
217
-
218
- if (!address_value->IsString()) {
219
- Nan::ThrowTypeError("Bad argument, 'address' must be a string");
220
- return;
221
- }
222
- Nan::Utf8String address(address_value);
223
-
224
- auto options = frida_remote_device_options_new();
225
- bool valid = true;
226
-
227
- if (!certificate_value->IsNull()) {
228
- GTlsCertificate* certificate;
229
- valid = Runtime::ValueToCertificate(certificate_value, &certificate);
230
- if (valid) {
231
- frida_remote_device_options_set_certificate(options, certificate);
232
- g_object_unref(certificate);
233
- }
234
- }
235
-
236
- if (valid && !origin_value->IsNull()) {
237
- if (origin_value->IsString()) {
238
- Nan::Utf8String origin(origin_value);
239
- frida_remote_device_options_set_origin(options, *origin);
240
- } else {
241
- Nan::ThrowTypeError("Bad argument, 'origin' must be a string");
242
- valid = false;
243
- }
244
- }
245
-
246
- if (valid && !token_value->IsNull()) {
247
- if (token_value->IsString()) {
248
- Nan::Utf8String token(token_value);
249
- frida_remote_device_options_set_token(options, *token);
250
- } else {
251
- Nan::ThrowTypeError("Bad argument, 'token' must be a string");
252
- valid = false;
253
- }
254
- }
255
-
256
- if (valid && !keepalive_interval_value->IsNull()) {
257
- if (keepalive_interval_value->IsNumber()) {
258
- auto keepalive_interval =
259
- Nan::To<int32_t>(keepalive_interval_value).FromMaybe(-1);
260
- if (keepalive_interval >= -1) {
261
- frida_remote_device_options_set_keepalive_interval(options,
262
- keepalive_interval);
263
- } else {
264
- Nan::ThrowTypeError("Bad argument, invalid 'keepaliveInterval'");
265
- valid = false;
266
- }
267
- } else {
268
- Nan::ThrowTypeError("Bad argument, 'keepaliveInterval' must be a number");
269
- valid = false;
270
- }
271
- }
272
-
273
- if (!valid) {
274
- g_object_unref(options);
275
- return;
276
- }
277
-
278
- auto operation = new AddRemoteDeviceOperation(g_strdup(*address), options);
279
- operation->Schedule(isolate, wrapper, info);
280
-
281
- info.GetReturnValue().Set(operation->GetPromise(isolate));
282
- }
283
-
284
- namespace {
285
-
286
- class RemoveRemoteDeviceOperation : public Operation<FridaDeviceManager> {
287
- public:
288
- RemoveRemoteDeviceOperation(gchar* address) : address_(address) {
289
- }
290
-
291
- ~RemoveRemoteDeviceOperation() {
292
- g_free(address_);
293
- }
294
-
295
- protected:
296
- void Begin() {
297
- frida_device_manager_remove_remote_device(handle_, address_, cancellable_,
298
- OnReady, this);
299
- }
300
-
301
- void End(GAsyncResult* result, GError** error) {
302
- frida_device_manager_remove_remote_device_finish(handle_, result, error);
303
- }
304
-
305
- Local<Value> Result(Isolate* isolate) {
306
- return Nan::Undefined();
307
- }
308
-
309
- private:
310
- gchar* address_;
311
- };
312
-
313
- }
314
-
315
- NAN_METHOD(DeviceManager::RemoveRemoteDevice) {
316
- auto isolate = info.GetIsolate();
317
- auto wrapper = ObjectWrap::Unwrap<DeviceManager>(info.Holder());
318
-
319
- if (info.Length() < 1 || !info[0]->IsString()) {
320
- Nan::ThrowTypeError("Expected an address");
321
- return;
322
- }
323
-
324
- Nan::Utf8String address(info[0]);
325
-
326
- auto operation = new RemoveRemoteDeviceOperation(g_strdup(*address));
327
- operation->Schedule(isolate, wrapper, info);
328
-
329
- info.GetReturnValue().Set(operation->GetPromise(isolate));
330
- }
331
-
332
- Local<Value> DeviceManager::TransformDeviceSignals(const gchar* name,
333
- guint index, const GValue* value, gpointer user_data) {
334
- if (index == 0 && (strcmp(name, "added") == 0 ||
335
- strcmp(name, "removed") == 0)) {
336
- auto runtime = static_cast<Runtime*>(user_data);
337
- return Device::New(g_value_get_object(value), runtime);
338
- }
339
- return Local<Value>();
340
- }
341
-
342
- void DeviceManager::OnConnect(const gchar* name, gpointer user_data) {
343
- auto runtime = static_cast<Runtime*>(user_data);
344
-
345
- if (ShouldStayAliveToEmit(name))
346
- runtime->GetUVContext()->IncreaseUsage();
347
- }
348
-
349
- void DeviceManager::OnDisconnect(const gchar* name, gpointer user_data) {
350
- auto runtime = static_cast<Runtime*>(user_data);
351
-
352
- if (ShouldStayAliveToEmit(name))
353
- runtime->GetUVContext()->DecreaseUsage();
354
- }
355
-
356
- bool DeviceManager::ShouldStayAliveToEmit(const gchar* name) {
357
- return strcmp(name, "added") == 0 ||
358
- strcmp(name, "removed") == 0 ||
359
- strcmp(name, "changed") == 0;
360
- }
361
-
362
- }
@@ -1,35 +0,0 @@
1
- #ifndef FRIDANODE_DEVICE_MANAGER_H
2
- #define FRIDANODE_DEVICE_MANAGER_H
3
-
4
- #include "glib_object.h"
5
-
6
- #include <frida-core.h>
7
-
8
- namespace frida {
9
-
10
- class DeviceManager : public GLibObject {
11
- public:
12
- static void Init(v8::Local<v8::Object> exports, Runtime* runtime);
13
- static void Dispose(Runtime* runtime);
14
-
15
- private:
16
- DeviceManager(FridaDeviceManager* handle, Runtime* runtime);
17
- ~DeviceManager();
18
-
19
- static NAN_METHOD(New);
20
-
21
- static NAN_METHOD(Close);
22
- static NAN_METHOD(EnumerateDevices);
23
- static NAN_METHOD(AddRemoteDevice);
24
- static NAN_METHOD(RemoveRemoteDevice);
25
-
26
- static v8::Local<v8::Value> TransformDeviceSignals(const gchar* name,
27
- guint index, const GValue* value, gpointer user_data);
28
- static void OnConnect(const gchar* signal, gpointer user_data);
29
- static void OnDisconnect(const gchar* signal, gpointer user_data);
30
- static bool ShouldStayAliveToEmit(const gchar* signal);
31
- };
32
-
33
- }
34
-
35
- #endif
@@ -1,171 +0,0 @@
1
- #include "endpoint_parameters.h"
2
-
3
- #include "authentication.h"
4
-
5
- #define ENDPOINT_PARAMETERS_DATA_TEMPLATE "endpoint_parameters:tpl"
6
-
7
- using v8::Function;
8
- using v8::FunctionTemplate;
9
- using v8::Isolate;
10
- using v8::Local;
11
- using v8::Object;
12
- using v8::Persistent;
13
- using v8::Value;
14
-
15
- namespace frida {
16
-
17
- EndpointParameters::EndpointParameters(FridaEndpointParameters* handle,
18
- Runtime* runtime)
19
- : GLibObject(handle, runtime) {
20
- g_object_ref(handle_);
21
- }
22
-
23
- EndpointParameters::~EndpointParameters() {
24
- g_object_unref(handle_);
25
- }
26
-
27
- void EndpointParameters::Init(Local<Object> exports, Runtime* runtime) {
28
- auto isolate = Isolate::GetCurrent();
29
-
30
- auto name = Nan::New("EndpointParameters").ToLocalChecked();
31
- auto tpl = CreateTemplate(name, EndpointParameters::New, runtime);
32
-
33
- auto ctor = Nan::GetFunction(tpl).ToLocalChecked();
34
- Nan::Set(exports, name, ctor);
35
- runtime->SetDataPointer(ENDPOINT_PARAMETERS_DATA_TEMPLATE,
36
- new Persistent<FunctionTemplate>(isolate, tpl));
37
- }
38
-
39
- FridaEndpointParameters* EndpointParameters::TryParse(Local<Value> value,
40
- Runtime* runtime) {
41
- if (!value->IsObject())
42
- return NULL;
43
-
44
- auto impl = Nan::Get(value.As<Object>(), Nan::New("impl").ToLocalChecked())
45
- .ToLocalChecked();
46
- if (!HasInstance(impl, runtime))
47
- return NULL;
48
-
49
- return ObjectWrap::Unwrap<EndpointParameters>(
50
- impl.As<Object>())->GetHandle<FridaEndpointParameters>();
51
- }
52
-
53
- bool EndpointParameters::HasInstance(Local<Value> value, Runtime* runtime) {
54
- auto tpl = Nan::New<FunctionTemplate>(
55
- *static_cast<Persistent<FunctionTemplate>*>(
56
- runtime->GetDataPointer(ENDPOINT_PARAMETERS_DATA_TEMPLATE)));
57
- return tpl->HasInstance(value);
58
- }
59
-
60
- NAN_METHOD(EndpointParameters::New) {
61
- if (!info.IsConstructCall()) {
62
- Nan::ThrowError("Use the `new` keyword to create a new instance");
63
- return;
64
- }
65
-
66
- if (info.Length() < 7) {
67
- Nan::ThrowTypeError("Missing one or more arguments");
68
- return;
69
- }
70
-
71
- auto runtime = GetRuntimeFromConstructorArgs(info);
72
-
73
- auto address_value = info[0];
74
- auto port_value = info[1];
75
- auto certificate_value = info[2];
76
- auto origin_value = info[3];
77
- auto auth_token_value = info[4];
78
- auto auth_callback_value = info[5];
79
- auto asset_root_value = info[6];
80
-
81
- gchar* address = NULL;
82
- guint16 port = 0;
83
- GTlsCertificate* certificate = NULL;
84
- gchar* origin = NULL;
85
- FridaAuthenticationService* auth_service = NULL;
86
- GFile* asset_root = NULL;
87
- bool valid = true;
88
-
89
- if (!address_value->IsNull()) {
90
- if (address_value->IsString()) {
91
- Nan::Utf8String str(address_value);
92
- address = g_strdup(*str);
93
- } else {
94
- Nan::ThrowTypeError("Bad argument, 'address' must be a string");
95
- valid = false;
96
- }
97
- }
98
-
99
- if (valid && !port_value->IsNull()) {
100
- auto val = Nan::To<int32_t>(port_value).FromMaybe(-1);
101
- if (val >= 0 && val <= 65535) {
102
- port = val;
103
- } else {
104
- Nan::ThrowTypeError("Bad argument, 'port' must be a valid port number");
105
- valid = false;
106
- }
107
- }
108
-
109
- if (valid && !certificate_value->IsNull()) {
110
- valid = Runtime::ValueToCertificate(certificate_value, &certificate);
111
- }
112
-
113
- if (valid && !origin_value->IsNull()) {
114
- if (origin_value->IsString()) {
115
- Nan::Utf8String str(origin_value);
116
- origin = g_strdup(*str);
117
- } else {
118
- Nan::ThrowTypeError("Bad argument, 'origin' must be a string");
119
- valid = false;
120
- }
121
- }
122
-
123
- if (valid && !auth_token_value->IsNull()) {
124
- if (auth_token_value->IsString()) {
125
- Nan::Utf8String auth_token(auth_token_value);
126
- auth_service = FRIDA_AUTHENTICATION_SERVICE(
127
- frida_static_authentication_service_new(*auth_token));
128
- } else {
129
- Nan::ThrowTypeError("Bad argument, 'authToken' must be a string");
130
- valid = false;
131
- }
132
- } else if (valid && !auth_callback_value->IsNull()) {
133
- if (auth_callback_value->IsFunction()) {
134
- auto auth_callback = Local<Function>::Cast(auth_callback_value);
135
- auth_service =
136
- frida_node_authentication_service_new(auth_callback, runtime);
137
- } else {
138
- Nan::ThrowTypeError("Bad argument, 'authCallback' must be a function");
139
- valid = false;
140
- }
141
- }
142
-
143
- if (valid && !asset_root_value->IsNull()) {
144
- if (asset_root_value->IsString()) {
145
- Nan::Utf8String str(asset_root_value);
146
- asset_root = g_file_new_for_path(*str);
147
- } else {
148
- Nan::ThrowTypeError("Bad argument, 'assetRoot' must be a string");
149
- valid = false;
150
- }
151
- }
152
-
153
- if (valid) {
154
- auto handle = frida_endpoint_parameters_new(address, port, certificate,
155
- origin, auth_service, asset_root);
156
- auto wrapper = new EndpointParameters(handle, runtime);
157
- g_object_unref(handle);
158
- auto obj = info.This();
159
- wrapper->Wrap(obj);
160
-
161
- info.GetReturnValue().Set(obj);
162
- }
163
-
164
- g_clear_object(&asset_root);
165
- g_clear_object(&auth_service);
166
- g_free(origin);
167
- g_clear_object(&certificate);
168
- g_free(address);
169
- }
170
-
171
- }
@@ -1,28 +0,0 @@
1
- #ifndef FRIDANODE_ENDPOINT_PARAMETERS_H
2
- #define FRIDANODE_ENDPOINT_PARAMETERS_H
3
-
4
- #include "glib_object.h"
5
-
6
- #include <frida-core.h>
7
-
8
- namespace frida {
9
-
10
- class EndpointParameters : public GLibObject {
11
- public:
12
- static void Init(v8::Local<v8::Object> exports, Runtime* runtime);
13
-
14
- static FridaEndpointParameters* TryParse(v8::Local<v8::Value> value,
15
- Runtime* runtime);
16
- static bool HasInstance(v8::Local<v8::Value> value, Runtime* runtime);
17
-
18
- private:
19
- explicit EndpointParameters(FridaEndpointParameters* handle,
20
- Runtime* runtime);
21
- ~EndpointParameters();
22
-
23
- static NAN_METHOD(New);
24
- };
25
-
26
- }
27
-
28
- #endif
@@ -1,62 +0,0 @@
1
- #include "glib_context.h"
2
-
3
- #define GLIB_CONTEXT_LOCK() g_mutex_lock(&mutex_)
4
- #define GLIB_CONTEXT_UNLOCK() g_mutex_unlock(&mutex_)
5
- #define GLIB_CONTEXT_WAIT() g_cond_wait(&cond_, &mutex_)
6
- #define GLIB_CONTEXT_SIGNAL() g_cond_signal(&cond_)
7
-
8
- namespace frida {
9
-
10
- GLibContext::GLibContext(GMainContext* main_context) : main_context_(main_context) {
11
- g_mutex_init(&mutex_);
12
- g_cond_init(&cond_);
13
- }
14
-
15
- GLibContext::~GLibContext() {
16
- g_cond_clear(&cond_);
17
- g_mutex_clear(&mutex_);
18
- }
19
-
20
- void GLibContext::Schedule(std::function<void ()> f) {
21
- auto source = g_idle_source_new();
22
- g_source_set_callback(source, InvokeCallback, new std::function<void ()>(f),
23
- DestroyCallback);
24
- g_source_attach(source, main_context_);
25
- g_source_unref(source);
26
- }
27
-
28
- void GLibContext::Perform(std::function<void ()> f) {
29
- volatile bool finished = false;
30
-
31
- auto work = new std::function<void ()>([this, f, &finished]() {
32
- f();
33
-
34
- GLIB_CONTEXT_LOCK();
35
- finished = true;
36
- GLIB_CONTEXT_SIGNAL();
37
- GLIB_CONTEXT_UNLOCK();
38
- });
39
-
40
- auto source = g_idle_source_new();
41
- g_source_set_callback(source, InvokeCallback, work, DestroyCallback);
42
- g_source_attach(source, main_context_);
43
- g_source_unref(source);
44
-
45
- GLIB_CONTEXT_LOCK();
46
- while (!finished)
47
- GLIB_CONTEXT_WAIT();
48
- GLIB_CONTEXT_UNLOCK();
49
- }
50
-
51
- gboolean GLibContext::InvokeCallback(gpointer data) {
52
- auto f = static_cast<std::function<void ()>*>(data);
53
- (*f)();
54
- return FALSE;
55
- }
56
-
57
- void GLibContext::DestroyCallback(gpointer data) {
58
- auto f = static_cast<std::function<void ()>*>(data);
59
- delete f;
60
- }
61
-
62
- }