frida 16.7.14 → 16.7.16

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 (174) 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 +22 -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/assets/meson.build +13 -0
  15. package/src/frida_bindgen/__init__.py +0 -0
  16. package/src/frida_bindgen/__main__.py +4 -0
  17. package/src/frida_bindgen/__pycache__/__init__.cpython-312.pyc +0 -0
  18. package/src/frida_bindgen/__pycache__/__main__.cpython-312.pyc +0 -0
  19. package/src/frida_bindgen/__pycache__/cli.cpython-312.pyc +0 -0
  20. package/src/frida_bindgen/__pycache__/codegen.cpython-312.pyc +0 -0
  21. package/src/frida_bindgen/__pycache__/customization.cpython-312.pyc +0 -0
  22. package/src/frida_bindgen/__pycache__/loader.cpython-312.pyc +0 -0
  23. package/src/frida_bindgen/__pycache__/model.cpython-312.pyc +0 -0
  24. package/src/frida_bindgen/assets/codegen_helpers.c +1970 -0
  25. package/src/frida_bindgen/assets/codegen_helpers.ts +100 -0
  26. package/src/frida_bindgen/assets/codegen_prototypes.h +78 -0
  27. package/src/frida_bindgen/assets/codegen_types.h +57 -0
  28. package/src/frida_bindgen/assets/customization_facade.exports +13 -0
  29. package/src/frida_bindgen/assets/customization_facade.ts +157 -0
  30. package/src/frida_bindgen/assets/customization_helpers.imports +2 -0
  31. package/src/frida_bindgen/assets/customization_helpers.ts +396 -0
  32. package/src/frida_bindgen/cli.py +96 -0
  33. package/src/frida_bindgen/codegen.py +2233 -0
  34. package/src/frida_bindgen/customization.py +924 -0
  35. package/src/frida_bindgen/loader.py +60 -0
  36. package/src/frida_bindgen/model.py +1357 -0
  37. package/src/meson.build +94 -27
  38. package/{lib/build.py → src/tsc.py} +12 -12
  39. package/src/win_delay_load_hook.c +56 -0
  40. package/subprojects/frida-core.wrap +1 -1
  41. package/test/data/index.ts +2 -2
  42. package/test/device.ts +1 -2
  43. package/test/device_manager.ts +1 -2
  44. package/test/labrat.ts +2 -2
  45. package/test/script.ts +12 -12
  46. package/test/session.ts +3 -3
  47. package/tsconfig.json +6 -11
  48. package/dist/application.d.ts +0 -81
  49. package/dist/application.js +0 -2
  50. package/dist/authentication.d.ts +0 -3
  51. package/dist/authentication.js +0 -2
  52. package/dist/bus.d.ts +0 -16
  53. package/dist/bus.js +0 -23
  54. package/dist/cancellable.d.ts +0 -15
  55. package/dist/cancellable.js +0 -41
  56. package/dist/child.d.ts +0 -16
  57. package/dist/child.js +0 -9
  58. package/dist/crash.d.ts +0 -10
  59. package/dist/crash.js +0 -2
  60. package/dist/device.d.ts +0 -156
  61. package/dist/device.js +0 -188
  62. package/dist/device_manager.d.ts +0 -25
  63. package/dist/device_manager.js +0 -42
  64. package/dist/endpoint_parameters.d.ts +0 -26
  65. package/dist/endpoint_parameters.js +0 -24
  66. package/dist/icon.d.ts +0 -14
  67. package/dist/icon.js +0 -2
  68. package/dist/index.d.ts +0 -161
  69. package/dist/index.js +0 -170
  70. package/dist/iostream.d.ts +0 -13
  71. package/dist/iostream.js +0 -73
  72. package/dist/native.d.ts +0 -1
  73. package/dist/native.js +0 -11
  74. package/dist/portal_membership.d.ts +0 -6
  75. package/dist/portal_membership.js +0 -12
  76. package/dist/portal_service.d.ts +0 -48
  77. package/dist/portal_service.js +0 -52
  78. package/dist/process.d.ts +0 -47
  79. package/dist/process.js +0 -2
  80. package/dist/relay.d.ts +0 -22
  81. package/dist/relay.js +0 -32
  82. package/dist/script.d.ts +0 -70
  83. package/dist/script.js +0 -266
  84. package/dist/service.d.ts +0 -16
  85. package/dist/service.js +0 -26
  86. package/dist/session.d.ts +0 -45
  87. package/dist/session.js +0 -73
  88. package/dist/signals.d.ts +0 -20
  89. package/dist/signals.js +0 -40
  90. package/dist/socket_address.d.ts +0 -25
  91. package/dist/socket_address.js +0 -2
  92. package/dist/spawn.d.ts +0 -4
  93. package/dist/spawn.js +0 -2
  94. package/dist/system_parameters.d.ts +0 -84
  95. package/dist/system_parameters.js +0 -2
  96. package/lib/application.ts +0 -98
  97. package/lib/authentication.ts +0 -3
  98. package/lib/bus.ts +0 -30
  99. package/lib/cancellable.ts +0 -48
  100. package/lib/child.ts +0 -15
  101. package/lib/crash.ts +0 -11
  102. package/lib/device.ts +0 -331
  103. package/lib/device_manager.ts +0 -69
  104. package/lib/endpoint_parameters.ts +0 -56
  105. package/lib/icon.ts +0 -15
  106. package/lib/index.ts +0 -316
  107. package/lib/iostream.ts +0 -78
  108. package/lib/meson.build +0 -53
  109. package/lib/native.ts +0 -9
  110. package/lib/portal_membership.ts +0 -10
  111. package/lib/portal_service.ts +0 -105
  112. package/lib/process.ts +0 -57
  113. package/lib/relay.ts +0 -44
  114. package/lib/script.ts +0 -361
  115. package/lib/service.ts +0 -34
  116. package/lib/session.ts +0 -113
  117. package/lib/signals.ts +0 -45
  118. package/lib/socket_address.ts +0 -35
  119. package/lib/spawn.ts +0 -4
  120. package/lib/system_parameters.ts +0 -103
  121. package/meson.options +0 -11
  122. package/src/addon.cc +0 -78
  123. package/src/application.cc +0 -148
  124. package/src/application.h +0 -31
  125. package/src/authentication.cc +0 -174
  126. package/src/authentication.h +0 -24
  127. package/src/bus.cc +0 -167
  128. package/src/bus.h +0 -33
  129. package/src/cancellable.cc +0 -117
  130. package/src/cancellable.h +0 -31
  131. package/src/child.cc +0 -150
  132. package/src/child.h +0 -32
  133. package/src/crash.cc +0 -122
  134. package/src/crash.h +0 -30
  135. package/src/device.cc +0 -1350
  136. package/src/device.h +0 -56
  137. package/src/device_manager.cc +0 -362
  138. package/src/device_manager.h +0 -35
  139. package/src/endpoint_parameters.cc +0 -171
  140. package/src/endpoint_parameters.h +0 -28
  141. package/src/glib_context.cc +0 -62
  142. package/src/glib_context.h +0 -29
  143. package/src/glib_object.cc +0 -25
  144. package/src/glib_object.h +0 -37
  145. package/src/iostream.cc +0 -243
  146. package/src/iostream.h +0 -30
  147. package/src/operation.h +0 -94
  148. package/src/portal_membership.cc +0 -100
  149. package/src/portal_membership.h +0 -26
  150. package/src/portal_service.cc +0 -401
  151. package/src/portal_service.h +0 -40
  152. package/src/process.cc +0 -135
  153. package/src/process.h +0 -30
  154. package/src/relay.cc +0 -139
  155. package/src/relay.h +0 -31
  156. package/src/runtime.cc +0 -568
  157. package/src/runtime.h +0 -69
  158. package/src/script.cc +0 -301
  159. package/src/script.h +0 -36
  160. package/src/service.cc +0 -224
  161. package/src/service.h +0 -36
  162. package/src/session.cc +0 -860
  163. package/src/session.h +0 -42
  164. package/src/signals.cc +0 -334
  165. package/src/signals.h +0 -47
  166. package/src/spawn.cc +0 -95
  167. package/src/spawn.h +0 -27
  168. package/src/usage_monitor.h +0 -117
  169. package/src/uv_context.cc +0 -118
  170. package/src/uv_context.h +0 -40
  171. package/src/win_delay_load_hook.cc +0 -63
  172. package/subprojects/nan.wrap +0 -9
  173. package/subprojects/packagefiles/nan.patch +0 -13
  174. /package/{scripts → src/assets}/adjust-version.py +0 -0
@@ -1,401 +0,0 @@
1
- #include "portal_service.h"
2
-
3
- #include "application.h"
4
- #include "device.h"
5
- #include "endpoint_parameters.h"
6
- #include "operation.h"
7
- #include "signals.h"
8
-
9
- #include <cstring>
10
-
11
- using std::strcmp;
12
- using v8::DEFAULT;
13
- using v8::Function;
14
- using v8::FunctionTemplate;
15
- using v8::Isolate;
16
- using v8::Local;
17
- using v8::Object;
18
- using v8::Persistent;
19
- using v8::ReadOnly;
20
- using v8::Value;
21
-
22
- namespace frida {
23
-
24
- PortalService::PortalService(FridaPortalService* handle,
25
- Runtime* runtime)
26
- : GLibObject(handle, runtime) {
27
- g_object_ref(handle_);
28
- }
29
-
30
- PortalService::~PortalService() {
31
- frida_unref(handle_);
32
- }
33
-
34
- void PortalService::Init(Local<Object> exports, Runtime* runtime) {
35
- auto name = Nan::New("PortalService").ToLocalChecked();
36
- auto tpl = CreateTemplate(name, PortalService::New, runtime);
37
-
38
- auto instance_tpl = tpl->InstanceTemplate();
39
- auto data = Local<Value>();
40
- Nan::SetAccessor(instance_tpl, Nan::New("device").ToLocalChecked(), GetDevice,
41
- 0, data, DEFAULT, ReadOnly);
42
-
43
- Nan::SetPrototypeMethod(tpl, "start", Start);
44
- Nan::SetPrototypeMethod(tpl, "stop", Stop);
45
- Nan::SetPrototypeMethod(tpl, "post", Post);
46
- Nan::SetPrototypeMethod(tpl, "narrowcast", Narrowcast);
47
- Nan::SetPrototypeMethod(tpl, "broadcast", Broadcast);
48
- Nan::SetPrototypeMethod(tpl, "enumerateTags", EnumerateTags);
49
- Nan::SetPrototypeMethod(tpl, "tag", Tag);
50
- Nan::SetPrototypeMethod(tpl, "untag", Untag);
51
-
52
- auto ctor = Nan::GetFunction(tpl).ToLocalChecked();
53
- Nan::Set(exports, name, ctor);
54
- }
55
-
56
- NAN_METHOD(PortalService::New) {
57
- if (!info.IsConstructCall()) {
58
- Nan::ThrowError("Use the `new` keyword to create a new instance");
59
- return;
60
- }
61
-
62
- if (info.Length() < 2) {
63
- Nan::ThrowTypeError("Missing one or more arguments");
64
- return;
65
- }
66
-
67
- auto runtime = GetRuntimeFromConstructorArgs(info);
68
-
69
- auto cluster_params_value = info[0];
70
- auto control_params_value = info[1];
71
-
72
- FridaEndpointParameters* cluster_params = NULL;
73
- FridaEndpointParameters* control_params = NULL;
74
- bool valid = true;
75
-
76
- if (!cluster_params_value->IsNull()) {
77
- cluster_params =
78
- EndpointParameters::TryParse(cluster_params_value, runtime);
79
- if (cluster_params != NULL) {
80
- g_object_ref(cluster_params);
81
- } else {
82
- Nan::ThrowTypeError("Bad argument, 'clusterParams' type mismatch");
83
- valid = false;
84
- }
85
- } else {
86
- cluster_params =
87
- frida_endpoint_parameters_new(NULL, 0, NULL, NULL, NULL, NULL);
88
- }
89
-
90
- if (valid && !control_params_value->IsNull()) {
91
- control_params =
92
- EndpointParameters::TryParse(control_params_value, runtime);
93
- if (control_params != NULL) {
94
- g_object_ref(control_params);
95
- } else {
96
- Nan::ThrowTypeError("Bad argument, 'controlParams' type mismatch");
97
- valid = false;
98
- }
99
- }
100
-
101
- if (valid) {
102
- auto handle = frida_portal_service_new(cluster_params, control_params);
103
- auto wrapper = new PortalService(handle, runtime);
104
- g_object_unref(handle);
105
- auto obj = info.This();
106
- wrapper->Wrap(obj);
107
- Nan::Set(obj, Nan::New("signals").ToLocalChecked(),
108
- Signals::New(handle, runtime, TransformSignal, runtime));
109
-
110
- info.GetReturnValue().Set(obj);
111
- }
112
-
113
- g_clear_object(&control_params);
114
- g_clear_object(&cluster_params);
115
- }
116
-
117
- NAN_PROPERTY_GETTER(PortalService::GetDevice) {
118
- auto wrapper = ObjectWrap::Unwrap<PortalService>(info.Holder());
119
- auto handle = wrapper->GetHandle<FridaPortalService>();
120
-
121
- info.GetReturnValue().Set(
122
- Device::New(frida_portal_service_get_device(handle), wrapper->runtime_));
123
- }
124
-
125
- namespace {
126
-
127
- class StartOperation : public Operation<FridaPortalService> {
128
- protected:
129
- void Begin() {
130
- frida_portal_service_start(handle_, cancellable_, OnReady, this);
131
- }
132
-
133
- void End(GAsyncResult* result, GError** error) {
134
- frida_portal_service_start_finish(handle_, result, error);
135
- }
136
-
137
- Local<Value> Result(Isolate* isolate) {
138
- runtime_->GetUVContext()->IncreaseUsage();
139
- return Nan::Undefined();
140
- }
141
- };
142
-
143
- }
144
-
145
- NAN_METHOD(PortalService::Start) {
146
- auto isolate = info.GetIsolate();
147
- auto wrapper = ObjectWrap::Unwrap<PortalService>(info.Holder());
148
-
149
- auto operation = new StartOperation();
150
- operation->Schedule(isolate, wrapper, info);
151
-
152
- info.GetReturnValue().Set(operation->GetPromise(isolate));
153
- }
154
-
155
- namespace {
156
-
157
- class StopOperation : public Operation<FridaPortalService> {
158
- protected:
159
- void Begin() {
160
- frida_portal_service_stop(handle_, cancellable_, OnReady, this);
161
- }
162
-
163
- void End(GAsyncResult* result, GError** error) {
164
- frida_portal_service_stop_finish(handle_, result, error);
165
- }
166
-
167
- Local<Value> Result(Isolate* isolate) {
168
- runtime_->GetUVContext()->DecreaseUsage();
169
- return Nan::Undefined();
170
- }
171
- };
172
-
173
- }
174
-
175
- NAN_METHOD(PortalService::Stop) {
176
- auto isolate = info.GetIsolate();
177
- auto wrapper = ObjectWrap::Unwrap<PortalService>(info.Holder());
178
-
179
- auto operation = new StopOperation();
180
- operation->Schedule(isolate, wrapper, info);
181
-
182
- info.GetReturnValue().Set(operation->GetPromise(isolate));
183
- }
184
-
185
- NAN_METHOD(PortalService::Post) {
186
- auto wrapper = ObjectWrap::Unwrap<PortalService>(info.Holder());
187
-
188
- auto num_args = info.Length();
189
- if (num_args < 3) {
190
- Nan::ThrowTypeError("Missing one or more arguments");
191
- return;
192
- }
193
-
194
- guint connection_id;
195
- if (!ValueToConnectionId(info[0], &connection_id))
196
- return;
197
-
198
- Nan::Utf8String message(wrapper->runtime_->ValueToJson(info[1]));
199
-
200
- GBytes* data = NULL;
201
- auto buffer = info[2];
202
- if (!buffer->IsNull()) {
203
- if (!node::Buffer::HasInstance(buffer)) {
204
- Nan::ThrowTypeError("Expected a buffer");
205
- return;
206
- }
207
- data = g_bytes_new(node::Buffer::Data(buffer),
208
- node::Buffer::Length(buffer));
209
- }
210
-
211
- frida_portal_service_post(wrapper->GetHandle<FridaPortalService>(),
212
- connection_id, *message, data);
213
-
214
- g_bytes_unref(data);
215
- }
216
-
217
- NAN_METHOD(PortalService::Narrowcast) {
218
- auto wrapper = ObjectWrap::Unwrap<PortalService>(info.Holder());
219
-
220
- auto num_args = info.Length();
221
- if (num_args < 3) {
222
- Nan::ThrowTypeError("Missing one or more arguments");
223
- return;
224
- }
225
-
226
- Nan::Utf8String tag(info[0]);
227
-
228
- Nan::Utf8String message(wrapper->runtime_->ValueToJson(info[1]));
229
-
230
- GBytes* data = NULL;
231
- auto buffer = info[2];
232
- if (!buffer->IsNull()) {
233
- if (!node::Buffer::HasInstance(buffer)) {
234
- Nan::ThrowTypeError("Expected a buffer");
235
- return;
236
- }
237
- data = g_bytes_new(node::Buffer::Data(buffer),
238
- node::Buffer::Length(buffer));
239
- }
240
-
241
- frida_portal_service_narrowcast(wrapper->GetHandle<FridaPortalService>(),
242
- *tag, *message, data);
243
-
244
- g_bytes_unref(data);
245
- }
246
-
247
- NAN_METHOD(PortalService::Broadcast) {
248
- auto wrapper = ObjectWrap::Unwrap<PortalService>(info.Holder());
249
-
250
- auto num_args = info.Length();
251
- if (num_args < 2) {
252
- Nan::ThrowTypeError("Missing one or more arguments");
253
- return;
254
- }
255
-
256
- Nan::Utf8String message(wrapper->runtime_->ValueToJson(info[0]));
257
-
258
- GBytes* data = NULL;
259
- auto buffer = info[1];
260
- if (!buffer->IsNull()) {
261
- if (!node::Buffer::HasInstance(buffer)) {
262
- Nan::ThrowTypeError("Expected a buffer");
263
- return;
264
- }
265
- data = g_bytes_new(node::Buffer::Data(buffer),
266
- node::Buffer::Length(buffer));
267
- }
268
-
269
- frida_portal_service_broadcast(wrapper->GetHandle<FridaPortalService>(),
270
- *message, data);
271
-
272
- g_bytes_unref(data);
273
- }
274
-
275
- namespace {
276
-
277
- class EnumerateTagsOperation : public Operation<FridaPortalService> {
278
- public:
279
- EnumerateTagsOperation(guint connection_id)
280
- : connection_id_(connection_id),
281
- tags_(NULL),
282
- n_(0) {
283
- }
284
-
285
- ~EnumerateTagsOperation() {
286
- g_strfreev(tags_);
287
- }
288
-
289
- protected:
290
- void Begin() {
291
- tags_ = frida_portal_service_enumerate_tags(handle_, connection_id_, &n_);
292
- OnReady(G_OBJECT(handle_), NULL, this);
293
- }
294
-
295
- void End(GAsyncResult* result, GError** error) {
296
- }
297
-
298
- Local<Value> Result(Isolate* isolate) {
299
- return Runtime::ValueFromStrv(tags_, n_);
300
- }
301
-
302
- private:
303
- guint connection_id_;
304
- gchar** tags_;
305
- gint n_;
306
- };
307
-
308
- }
309
-
310
- NAN_METHOD(PortalService::EnumerateTags) {
311
- auto isolate = info.GetIsolate();
312
- auto wrapper = ObjectWrap::Unwrap<PortalService>(info.Holder());
313
-
314
- if (info.Length() < 1) {
315
- Nan::ThrowTypeError("Bad argument, expected a connection ID");
316
- return;
317
- }
318
-
319
- guint connection_id;
320
- if (!ValueToConnectionId(info[0], &connection_id))
321
- return;
322
-
323
- auto operation = new EnumerateTagsOperation(connection_id);
324
- operation->Schedule(isolate, wrapper, info);
325
-
326
- info.GetReturnValue().Set(operation->GetPromise(isolate));
327
- }
328
-
329
- NAN_METHOD(PortalService::Tag) {
330
- auto wrapper = ObjectWrap::Unwrap<PortalService>(info.Holder());
331
-
332
- auto num_args = info.Length();
333
- if (num_args < 2) {
334
- Nan::ThrowTypeError("Missing one or more arguments");
335
- return;
336
- }
337
-
338
- guint connection_id;
339
- if (!ValueToConnectionId(info[0], &connection_id))
340
- return;
341
-
342
- Nan::Utf8String tag(info[1]);
343
-
344
- frida_portal_service_tag(wrapper->GetHandle<FridaPortalService>(),
345
- connection_id, *tag);
346
- }
347
-
348
- NAN_METHOD(PortalService::Untag) {
349
- auto wrapper = ObjectWrap::Unwrap<PortalService>(info.Holder());
350
-
351
- auto num_args = info.Length();
352
- if (num_args < 2) {
353
- Nan::ThrowTypeError("Missing one or more arguments");
354
- return;
355
- }
356
-
357
- guint connection_id;
358
- if (!ValueToConnectionId(info[0], &connection_id))
359
- return;
360
-
361
- Nan::Utf8String tag(info[1]);
362
-
363
- frida_portal_service_untag(wrapper->GetHandle<FridaPortalService>(),
364
- connection_id, *tag);
365
- }
366
-
367
- bool PortalService::ValueToConnectionId(Local<Value> value,
368
- guint* connection_id) {
369
- if (!value->IsNumber()) {
370
- Nan::ThrowTypeError("Expected a connection ID");
371
- return false;
372
- }
373
-
374
- auto id = Nan::To<uint32_t>(value).FromMaybe(0);
375
- if (id == 0) {
376
- Nan::ThrowTypeError("Expected a connection ID");
377
- return false;
378
- }
379
-
380
- *connection_id = id;
381
- return true;
382
- }
383
-
384
- Local<Value> PortalService::TransformSignal(const gchar* name, guint index,
385
- const GValue* value, gpointer user_data) {
386
- auto runtime = static_cast<Runtime*>(user_data);
387
-
388
- if (index == 1 && (strcmp(name, "node-joined") == 0 ||
389
- strcmp(name, "node-left") == 0))
390
- return Application::New(g_value_get_object(value), runtime);
391
-
392
- if (index == 1 && (strcmp(name, "authenticated") == 0 ||
393
- strcmp(name, "message") == 0)) {
394
- auto json = Nan::New(g_value_get_string(value)).ToLocalChecked();
395
- return runtime->ValueFromJson(json);
396
- }
397
-
398
- return Local<Value>();
399
- }
400
-
401
- }
@@ -1,40 +0,0 @@
1
- #ifndef FRIDANODE_PORTAL_SERVICE_H
2
- #define FRIDANODE_PORTAL_SERVICE_H
3
-
4
- #include "glib_object.h"
5
-
6
- #include <frida-core.h>
7
-
8
- namespace frida {
9
-
10
- class PortalService : public GLibObject {
11
- public:
12
- static void Init(v8::Local<v8::Object> exports, Runtime* runtime);
13
-
14
- private:
15
- explicit PortalService(FridaPortalService* handle, Runtime* runtime);
16
- ~PortalService();
17
-
18
- static NAN_METHOD(New);
19
-
20
- static NAN_PROPERTY_GETTER(GetDevice);
21
-
22
- static NAN_METHOD(Start);
23
- static NAN_METHOD(Stop);
24
- static NAN_METHOD(Post);
25
- static NAN_METHOD(Narrowcast);
26
- static NAN_METHOD(Broadcast);
27
- static NAN_METHOD(EnumerateTags);
28
- static NAN_METHOD(Tag);
29
- static NAN_METHOD(Untag);
30
-
31
- static bool ValueToConnectionId(v8::Local<v8::Value> value,
32
- guint* connection_id);
33
-
34
- static v8::Local<v8::Value> TransformSignal(const gchar* name, guint index,
35
- const GValue* value, gpointer user_data);
36
- };
37
-
38
- }
39
-
40
- #endif
package/src/process.cc DELETED
@@ -1,135 +0,0 @@
1
- #include "process.h"
2
-
3
- #include <cstring>
4
-
5
- #define PROCESS_DATA_CONSTRUCTOR "process:ctor"
6
-
7
- using std::strcmp;
8
- using v8::DEFAULT;
9
- using v8::External;
10
- using v8::Function;
11
- using v8::Integer;
12
- using v8::Isolate;
13
- using v8::Local;
14
- using v8::Object;
15
- using v8::Persistent;
16
- using v8::ReadOnly;
17
- using v8::String;
18
- using v8::Value;
19
-
20
- namespace frida {
21
-
22
- Process::Process(FridaProcess* handle, Runtime* runtime)
23
- : GLibObject(handle, runtime) {
24
- g_object_ref(handle_);
25
- }
26
-
27
- Process::~Process() {
28
- g_object_unref(handle_);
29
- }
30
-
31
- void Process::Init(Local<Object> exports, Runtime* runtime) {
32
- auto isolate = Isolate::GetCurrent();
33
-
34
- auto name = Nan::New("Process").ToLocalChecked();
35
- auto tpl = CreateTemplate(name, Process::New, runtime);
36
-
37
- auto instance_tpl = tpl->InstanceTemplate();
38
- auto data = Local<Value>();
39
- Nan::SetAccessor(instance_tpl, Nan::New("parameters").ToLocalChecked(),
40
- GetParameters, 0, data, DEFAULT, ReadOnly);
41
- Nan::SetAccessor(instance_tpl, Nan::New("name").ToLocalChecked(),
42
- GetName, 0, data, DEFAULT, ReadOnly);
43
- Nan::SetAccessor(instance_tpl, Nan::New("pid").ToLocalChecked(),
44
- GetPid, 0, data, DEFAULT, ReadOnly);
45
-
46
- auto ctor = Nan::GetFunction(tpl).ToLocalChecked();
47
- Nan::Set(exports, name, ctor);
48
- runtime->SetDataPointer(PROCESS_DATA_CONSTRUCTOR,
49
- new Persistent<Function>(isolate, ctor));
50
- }
51
-
52
- Local<Object> Process::New(gpointer handle, Runtime* runtime) {
53
- auto ctor = Nan::New<Function>(
54
- *static_cast<Persistent<Function>*>(
55
- runtime->GetDataPointer(PROCESS_DATA_CONSTRUCTOR)));
56
- const int argc = 1;
57
- Local<Value> argv[argc] = { Nan::New<External>(handle) };
58
- return Nan::NewInstance(ctor, argc, argv).ToLocalChecked();
59
- }
60
-
61
- NAN_METHOD(Process::New) {
62
- if (!info.IsConstructCall()) {
63
- Nan::ThrowError("Use the `new` keyword to create a new instance");
64
- return;
65
- }
66
-
67
- if (info.Length() != 1 || !info[0]->IsExternal()) {
68
- Nan::ThrowTypeError("Bad argument, expected raw handle");
69
- return;
70
- }
71
-
72
- auto runtime = GetRuntimeFromConstructorArgs(info);
73
-
74
- auto handle = static_cast<FridaProcess*>(
75
- Local<External>::Cast(info[0])->Value());
76
- auto wrapper = new Process(handle, runtime);
77
- auto obj = info.This();
78
- wrapper->Wrap(obj);
79
-
80
- info.GetReturnValue().Set(obj);
81
- }
82
-
83
- NAN_PROPERTY_GETTER(Process::GetPid) {
84
- auto handle = ObjectWrap::Unwrap<Process>(
85
- info.Holder())->GetHandle<FridaProcess>();
86
-
87
- info.GetReturnValue().Set(Nan::New<Integer>(frida_process_get_pid(handle)));
88
- }
89
-
90
- NAN_PROPERTY_GETTER(Process::GetName) {
91
- auto handle = ObjectWrap::Unwrap<Process>(
92
- info.Holder())->GetHandle<FridaProcess>();
93
-
94
- info.GetReturnValue().Set(
95
- Nan::New(frida_process_get_name(handle)).ToLocalChecked());
96
- }
97
-
98
- NAN_PROPERTY_GETTER(Process::GetParameters) {
99
- auto wrapper = ObjectWrap::Unwrap<Process>(info.Holder());
100
- auto handle = wrapper->GetHandle<FridaProcess>();
101
-
102
- GHashTable* parameters = frida_process_get_parameters(handle);
103
- info.GetReturnValue().Set(ParseParameters(parameters));
104
- }
105
-
106
- Local<Value> Process::ParseParameters(GHashTable* dict) {
107
- auto result = Nan::New<Object>();
108
-
109
- GHashTableIter iter;
110
- gpointer raw_key, raw_value;
111
-
112
- g_hash_table_iter_init(&iter, dict);
113
-
114
- while (g_hash_table_iter_next(&iter, &raw_key, &raw_value)) {
115
- char* canonicalized_key =
116
- Runtime::ParameterNameFromC(static_cast<char*>(raw_key));
117
- GVariant* var_value = static_cast<GVariant*>(raw_value);
118
-
119
- Local<String> key = Nan::New(canonicalized_key).ToLocalChecked();
120
- Local<Value> value;
121
- if (strcmp(canonicalized_key, "started") == 0 &&
122
- g_variant_is_of_type(var_value, G_VARIANT_TYPE_STRING)) {
123
- value = Runtime::ValueFromDatetime(g_variant_get_string(var_value, NULL));
124
- } else {
125
- value = Runtime::ValueFromVariant(var_value);
126
- }
127
- Nan::Set(result, key, value);
128
-
129
- g_free(canonicalized_key);
130
- }
131
-
132
- return result;
133
- }
134
-
135
- }
package/src/process.h DELETED
@@ -1,30 +0,0 @@
1
- #ifndef FRIDANODE_PROCESS_H
2
- #define FRIDANODE_PROCESS_H
3
-
4
- #include "glib_object.h"
5
-
6
- #include <frida-core.h>
7
-
8
- namespace frida {
9
-
10
- class Process : 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
- explicit Process(FridaProcess* handle, Runtime* runtime);
17
- ~Process();
18
-
19
- static NAN_METHOD(New);
20
-
21
- static NAN_PROPERTY_GETTER(GetPid);
22
- static NAN_PROPERTY_GETTER(GetName);
23
- static NAN_PROPERTY_GETTER(GetParameters);
24
-
25
- static v8::Local<v8::Value> ParseParameters(GHashTable* dict);
26
- };
27
-
28
- }
29
-
30
- #endif