@efffrida/frida-tools 0.0.17 → 0.0.18

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@efffrida/frida-tools",
3
- "version": "0.0.17",
3
+ "version": "0.0.18",
4
4
  "description": "Frida with effect-ts",
5
5
  "keywords": [
6
6
  "frida.re",
@@ -4,6 +4,7 @@
4
4
  * @since 1.0.0
5
5
  */
6
6
 
7
+ import type * as FileSystem from "@effect/platform/FileSystem";
7
8
  import type * as Path from "@effect/platform/Path";
8
9
  import type * as Context from "effect/Context";
9
10
  import type * as Deferred from "effect/Deferred";
@@ -151,3 +152,29 @@ export const layer: {
151
152
  options?: LoadOptions | undefined
152
153
  ): (entrypoint: URL) => Layer.Layer<FridaScript, FridaSessionError.FridaSessionError, FridaSession.FridaSession>;
153
154
  } = internal.layer;
155
+
156
+ /**
157
+ * @since 1.0.0
158
+ * @category Frida
159
+ */
160
+ export const watch: {
161
+ <A, E, R>(
162
+ effect: Effect.Effect<A, E, R>,
163
+ entrypoint: URL,
164
+ options?: LoadOptions | undefined
165
+ ): Effect.Effect<
166
+ void,
167
+ E | FridaSessionError.FridaSessionError,
168
+ FileSystem.FileSystem | FridaSession.FridaSession | Exclude<R, FridaScript>
169
+ >;
170
+ (
171
+ entrypoint: URL,
172
+ options?: LoadOptions | undefined
173
+ ): <A, E, R>(
174
+ effect: Effect.Effect<A, E, R>
175
+ ) => Effect.Effect<
176
+ void,
177
+ E | FridaSessionError.FridaSessionError,
178
+ FileSystem.FileSystem | FridaSession.FridaSession | Exclude<R, FridaScript>
179
+ >;
180
+ } = internal.watch;
@@ -34,7 +34,18 @@ export const isFridaSessionError = (u: unknown): u is FridaSessionError =>
34
34
  */
35
35
  export class FridaSessionError extends PlatformError.TypeIdError(FridaSessionErrorTypeId, "FridaSessionError")<{
36
36
  cause: unknown;
37
- when: "spawn" | "kill" | "attach" | "detach" | "compile" | "load" | "unload" | "resume" | "message" | "rpcCall";
37
+ when:
38
+ | "spawn"
39
+ | "kill"
40
+ | "attach"
41
+ | "detach"
42
+ | "compile"
43
+ | "watch"
44
+ | "load"
45
+ | "unload"
46
+ | "resume"
47
+ | "message"
48
+ | "rpcCall";
38
49
  }> {
39
50
  override get message() {
40
51
  return `A Frida session error occurred on ${this.when}`;
@@ -234,7 +234,7 @@ export const acquireAndroidEmulatorDevice = Effect.fn("acquireAndroidEmulatorDev
234
234
  new FridaDeviceAcquisitionError.FridaDeviceAcquisitionError({
235
235
  attempts: 1,
236
236
  acquisitionMethod: "android-emulator",
237
- cause: new Error(`ADB wait-for-device failed with exit code ${code}`),
237
+ cause: `ADB wait-for-device failed with exit code ${code}`,
238
238
  })
239
239
  )
240
240
  );
@@ -248,7 +248,7 @@ export const acquireAndroidEmulatorDevice = Effect.fn("acquireAndroidEmulatorDev
248
248
  new FridaDeviceAcquisitionError.FridaDeviceAcquisitionError({
249
249
  attempts: 1,
250
250
  acquisitionMethod: "android-emulator",
251
- cause: new Error(`ADB root failed with exit code ${code}`),
251
+ cause: `ADB root failed with exit code ${code}`,
252
252
  })
253
253
  )
254
254
  );
@@ -274,7 +274,7 @@ export const acquireAndroidEmulatorDevice = Effect.fn("acquireAndroidEmulatorDev
274
274
  new FridaDeviceAcquisitionError.FridaDeviceAcquisitionError({
275
275
  attempts: 1,
276
276
  acquisitionMethod: "android-emulator",
277
- cause: new Error("Timeout while acquiring Android emulator device"),
277
+ cause: "Timeout while acquiring Android emulator device",
278
278
  }),
279
279
  }),
280
280
  Effect.catchIf(
@@ -1,6 +1,7 @@
1
1
  import type * as Scope from "effect/Scope";
2
2
  import type * as FridaScript from "../FridaScript.ts";
3
3
 
4
+ import * as FileSystem from "@effect/platform/FileSystem";
4
5
  import * as Path from "@effect/platform/Path";
5
6
  import * as Cause from "effect/Cause";
6
7
  import * as Context from "effect/Context";
@@ -375,3 +376,65 @@ export const layer = Function.dual<
375
376
  (entrypoint: URL, options?: FridaScript.LoadOptions | undefined) =>
376
377
  Layer.scoped(Tag, load(entrypoint, options)).pipe(Layer.provide(Path.layer))
377
378
  );
379
+
380
+ /** @internal */
381
+ export const watch = Function.dual<
382
+ (
383
+ entrypoint: URL,
384
+ options?: FridaScript.LoadOptions | undefined
385
+ ) => <A, E, R>(
386
+ effect: Effect.Effect<A, E, R>
387
+ ) => Effect.Effect<
388
+ void,
389
+ E | FridaSessionError.FridaSessionError,
390
+ FileSystem.FileSystem | FridaSession.FridaSession | Exclude<R, FridaScript.FridaScript>
391
+ >,
392
+ <A, E, R>(
393
+ effect: Effect.Effect<A, E, R>,
394
+ entrypoint: URL,
395
+ options?: FridaScript.LoadOptions | undefined
396
+ ) => Effect.Effect<
397
+ void,
398
+ E | FridaSessionError.FridaSessionError,
399
+ FileSystem.FileSystem | FridaSession.FridaSession | Exclude<R, FridaScript.FridaScript>
400
+ >
401
+ >(
402
+ (arguments_) => Effect.isEffect(arguments_[0]),
403
+ <A, E, R>(
404
+ effect: Effect.Effect<A, E, R>,
405
+ entrypoint: URL,
406
+ options?: FridaScript.LoadOptions | undefined
407
+ ): Effect.Effect<
408
+ void,
409
+ E | FridaSessionError.FridaSessionError,
410
+ FileSystem.FileSystem | FridaSession.FridaSession | Exclude<R, FridaScript.FridaScript>
411
+ > =>
412
+ Effect.gen(function* () {
413
+ const path = yield* Path.Path;
414
+ const fileSystem = yield* FileSystem.FileSystem;
415
+
416
+ const pathString = yield* Effect.mapError(
417
+ path.fromFileUrl(entrypoint),
418
+ (cause) =>
419
+ new FridaSessionError.FridaSessionError({
420
+ when: "watch",
421
+ cause,
422
+ })
423
+ );
424
+
425
+ const provideFridaScript = Effect.provideServiceEffect(Tag, load(entrypoint, options));
426
+ const sink = Sink.forEach((_: void) => provideFridaScript(effect).pipe(Effect.scoped));
427
+ const stream = fileSystem.watch(pathString).pipe(
428
+ Stream.filter((event) => event._tag === "Update"),
429
+ Stream.mapError(
430
+ (cause) =>
431
+ new FridaSessionError.FridaSessionError({
432
+ when: "watch",
433
+ cause,
434
+ })
435
+ )
436
+ );
437
+
438
+ return yield* Stream.run(stream, sink);
439
+ }).pipe(Effect.provide(Path.layer))
440
+ );