@efffrida/rpc 0.0.13 → 0.0.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 (63) hide show
  1. package/dist/frida/FridaRpcClient.d.ts +47 -0
  2. package/dist/frida/FridaRpcClient.d.ts.map +1 -0
  3. package/dist/frida/FridaRpcClient.js +115 -0
  4. package/dist/frida/FridaRpcClient.js.map +1 -0
  5. package/dist/frida/FridaRpcServer.d.ts +48 -0
  6. package/dist/frida/FridaRpcServer.d.ts.map +1 -0
  7. package/dist/frida/FridaRpcServer.js +119 -0
  8. package/dist/frida/FridaRpcServer.js.map +1 -0
  9. package/dist/frida/index.d.ts +18 -0
  10. package/dist/frida/index.d.ts.map +1 -0
  11. package/dist/{esm → frida}/index.js +5 -4
  12. package/dist/frida/index.js.map +1 -0
  13. package/dist/{dts → node}/FridaRpcClient.d.ts +4 -6
  14. package/dist/node/FridaRpcClient.d.ts.map +1 -0
  15. package/dist/node/FridaRpcClient.js +86 -0
  16. package/dist/node/FridaRpcClient.js.map +1 -0
  17. package/dist/node/FridaRpcServer.d.ts +16 -0
  18. package/dist/node/FridaRpcServer.d.ts.map +1 -0
  19. package/dist/node/FridaRpcServer.js +115 -0
  20. package/dist/node/FridaRpcServer.js.map +1 -0
  21. package/dist/node/index.d.ts +18 -0
  22. package/dist/node/index.d.ts.map +1 -0
  23. package/dist/{dts/index.d.ts → node/index.js} +6 -5
  24. package/dist/node/index.js.map +1 -0
  25. package/dist/shared/constants.d.ts +6 -0
  26. package/dist/shared/constants.d.ts.map +1 -0
  27. package/dist/shared/constants.js +7 -0
  28. package/dist/shared/constants.js.map +1 -0
  29. package/dist/shared/predicates.d.ts +10 -0
  30. package/dist/shared/predicates.d.ts.map +1 -0
  31. package/dist/shared/predicates.js +12 -0
  32. package/dist/shared/predicates.js.map +1 -0
  33. package/package.json +59 -45
  34. package/src/frida/FridaRpcClient.ts +180 -0
  35. package/src/frida/FridaRpcServer.ts +168 -0
  36. package/src/frida/index.ts +19 -0
  37. package/src/node/FridaRpcClient.ts +120 -0
  38. package/src/node/FridaRpcServer.ts +134 -0
  39. package/src/node/index.ts +19 -0
  40. package/src/shared/constants.ts +11 -0
  41. package/src/shared/predicates.ts +19 -0
  42. package/FridaRpcClient/package.json +0 -6
  43. package/FridaRpcServer/package.json +0 -6
  44. package/dist/cjs/FridaRpcClient.js +0 -77
  45. package/dist/cjs/FridaRpcClient.js.map +0 -1
  46. package/dist/cjs/FridaRpcServer.js +0 -135
  47. package/dist/cjs/FridaRpcServer.js.map +0 -1
  48. package/dist/cjs/index.js +0 -12
  49. package/dist/cjs/index.js.map +0 -1
  50. package/dist/dts/FridaRpcClient.d.ts.map +0 -1
  51. package/dist/dts/FridaRpcServer.d.ts +0 -36
  52. package/dist/dts/FridaRpcServer.d.ts.map +0 -1
  53. package/dist/dts/index.d.ts.map +0 -1
  54. package/dist/esm/FridaRpcClient.js +0 -67
  55. package/dist/esm/FridaRpcClient.js.map +0 -1
  56. package/dist/esm/FridaRpcServer.js +0 -125
  57. package/dist/esm/FridaRpcServer.js.map +0 -1
  58. package/dist/esm/index.js.map +0 -1
  59. package/dist/esm/package.json +0 -4
  60. package/index/package.json +0 -6
  61. package/src/FridaRpcClient.ts +0 -107
  62. package/src/FridaRpcServer.ts +0 -172
  63. package/src/index.ts +0 -17
@@ -0,0 +1,168 @@
1
+ /**
2
+ * Implements a Frida RPC server protocol for effect using the frida script
3
+ * exports.
4
+ *
5
+ * @since 1.0.0
6
+ */
7
+
8
+ import * as RpcMessage from "@effect/rpc/RpcMessage";
9
+ import * as RpcSerialization from "@effect/rpc/RpcSerialization";
10
+ import * as RpcServer from "@effect/rpc/RpcServer";
11
+ import * as Effect from "effect/Effect";
12
+ import * as Function from "effect/Function";
13
+ import * as Layer from "effect/Layer";
14
+ import * as Mailbox from "effect/Mailbox";
15
+ import * as Predicate from "effect/Predicate";
16
+
17
+ import * as constants from "../shared/constants.ts";
18
+
19
+ /**
20
+ * @since 1.0.0
21
+ * @category Protocol
22
+ */
23
+ export const makeProtocolFrida = (
24
+ options?:
25
+ | {
26
+ /** Generates server listener rpc exports for individual clients. */
27
+ readonly generateExportName?: ((clientId: number) => string) | undefined;
28
+ }
29
+ | undefined
30
+ ): Effect.Effect<
31
+ {
32
+ readonly protocol: RpcServer.Protocol["Type"];
33
+ readonly rpcExport: () => Promise<number>;
34
+ },
35
+ never,
36
+ RpcSerialization.RpcSerialization
37
+ > =>
38
+ Effect.gen(function* () {
39
+ const encoder = new TextEncoder();
40
+ const disconnects = yield* Mailbox.make<number>();
41
+ const serialization = yield* RpcSerialization.RpcSerialization;
42
+
43
+ let clientId = 0;
44
+ const clientIds = new Set<number>();
45
+ const clients = new Map<number, { readonly write: (bytes: RpcMessage.FromServerEncoded) => void }>();
46
+
47
+ let writeRequest!: (clientId: number, message: RpcMessage.FromClientEncoded) => Effect.Effect<void>;
48
+ const exportName = options?.generateExportName ?? constants.generateServerExportNameForClient;
49
+
50
+ // Listen for new clients on the main rpc export
51
+ const rpcExport = Effect.gen(function* () {
52
+ const id = clientId++;
53
+ const parser = serialization.unsafeMake();
54
+
55
+ const writeRaw = (data: string | Uint8Array): void => {
56
+ const transformed = typeof data === "string" ? encoder.encode(data) : data;
57
+ return send({ clientId: id }, (transformed as Uint8Array<ArrayBuffer>).buffer);
58
+ };
59
+ const write = (response: RpcMessage.FromServerEncoded): void => {
60
+ try {
61
+ const encoded = parser.encode(response);
62
+ if (Predicate.isNotUndefined(encoded)) return writeRaw(encoded);
63
+ } catch (cause) {
64
+ const encoded = parser.encode(RpcMessage.ResponseDefectEncoded(cause))!;
65
+ return writeRaw(encoded);
66
+ }
67
+ };
68
+
69
+ clientIds.add(id);
70
+ clients.set(id, { write });
71
+
72
+ const onMessage = (data: string | Uint8Array): Effect.Effect<void, never, never> => {
73
+ try {
74
+ const decoded = parser.decode(data) as ReadonlyArray<RpcMessage.FromClientEncoded>;
75
+ if (decoded.length === 0) return Effect.void;
76
+ let i = 0;
77
+ return Effect.whileLoop({
78
+ while: () => i < decoded.length,
79
+ body() {
80
+ const message = decoded[i++];
81
+ return writeRequest(id, message);
82
+ },
83
+ step: Function.constVoid,
84
+ });
85
+ } catch (cause) {
86
+ return Effect.sync(() => writeRaw(parser.encode(RpcMessage.ResponseDefectEncoded(cause))!));
87
+ }
88
+ };
89
+
90
+ rpc.exports[exportName(clientId)] = (data: string | Uint8Array): Promise<void> =>
91
+ Effect.runPromise(onMessage(data));
92
+
93
+ return clientId;
94
+ });
95
+
96
+ const protocol = yield* RpcServer.Protocol.make((writeRequest_) => {
97
+ writeRequest = writeRequest_;
98
+ return Effect.succeed({
99
+ disconnects,
100
+ send: (clientId, response) => {
101
+ const client = clients.get(clientId);
102
+ if (!client) return Effect.void;
103
+ return Effect.sync(() => client.write(response));
104
+ },
105
+ end(clientId) {
106
+ clientIds.delete(clientId); // TODO: Is this required?
107
+ clients.delete(clientId); // TODO: Is this required?
108
+ const exportName = options?.generateExportName ?? constants.generateServerExportNameForClient;
109
+ delete rpc.exports[exportName(clientId)];
110
+ return Effect.void;
111
+ },
112
+ clientIds: Effect.sync(() => clientIds),
113
+ initialMessage: Effect.succeedNone,
114
+ supportsAck: true,
115
+ supportsTransferables: false,
116
+ supportsSpanPropagation: true,
117
+ });
118
+ });
119
+
120
+ return {
121
+ protocol,
122
+ rpcExport: () => Effect.runPromise(rpcExport),
123
+ };
124
+ });
125
+
126
+ /**
127
+ * @since 1.0.0
128
+ * @category Protocol
129
+ */
130
+ export const makeProtocolFridaWithExport = (
131
+ options?:
132
+ | {
133
+ /**
134
+ * Name for the main rpc export that all clients start by
135
+ * connecting to.
136
+ */
137
+ readonly exportName?: string | undefined;
138
+
139
+ /** Generates server listener rpc exports for individual clients. */
140
+ readonly generateExportName?: ((clientId: number) => string) | undefined;
141
+ }
142
+ | undefined
143
+ ): Effect.Effect<RpcServer.Protocol["Type"], never, RpcSerialization.RpcSerialization> =>
144
+ Effect.gen(function* () {
145
+ const { protocol, rpcExport } = yield* makeProtocolFrida({ generateExportName: options?.generateExportName });
146
+ rpc.exports[options?.exportName ?? constants.defaultServerMainExportName] = rpcExport;
147
+ return protocol;
148
+ });
149
+
150
+ /**
151
+ * @since 1.0.0
152
+ * @category Layer
153
+ */
154
+ export const layerProtocolFrida = (
155
+ options?:
156
+ | {
157
+ /**
158
+ * Name for the main rpc export that all clients start by
159
+ * connecting to.
160
+ */
161
+ readonly exportName?: string | undefined;
162
+
163
+ /** Generates server listener rpc exports for individual clients. */
164
+ readonly generateExportName?: ((clientId: number) => string) | undefined;
165
+ }
166
+ | undefined
167
+ ): Layer.Layer<RpcServer.Protocol, never, RpcSerialization.RpcSerialization> =>
168
+ Layer.effect(RpcServer.Protocol, makeProtocolFridaWithExport(options));
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+
5
+ /**
6
+ * Implements a Frida RPC client protocol for effect using the frida script
7
+ * exports.
8
+ *
9
+ * @since 1.0.0
10
+ */
11
+ export * as FridaRpcClient from "./FridaRpcClient.ts"
12
+
13
+ /**
14
+ * Implements a Frida RPC server protocol for effect using the frida script
15
+ * exports.
16
+ *
17
+ * @since 1.0.0
18
+ */
19
+ export * as FridaRpcServer from "./FridaRpcServer.ts"
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Implements a Frida RPC client protocol for effect using the frida script
3
+ * exports.
4
+ *
5
+ * @since 1.0.0
6
+ */
7
+
8
+ import type * as RpcMessage from "@effect/rpc/RpcMessage";
9
+ import type * as FridaSessionError from "@efffrida/frida-tools/FridaSessionError";
10
+ import type * as Scope from "effect/Scope";
11
+
12
+ import * as RpcClient from "@effect/rpc/RpcClient";
13
+ import * as RpcSerialization from "@effect/rpc/RpcSerialization";
14
+ import * as FridaScript from "@efffrida/frida-tools/FridaScript";
15
+ import * as Effect from "effect/Effect";
16
+ import * as Function from "effect/Function";
17
+ import * as Layer from "effect/Layer";
18
+ import * as Option from "effect/Option";
19
+ import * as ParseResult from "effect/ParseResult";
20
+ import * as Predicate from "effect/Predicate";
21
+ import * as Schema from "effect/Schema";
22
+ import * as Stream from "effect/Stream";
23
+
24
+ import * as shared from "../shared/constants.ts";
25
+
26
+ /**
27
+ * @since 1.0.0
28
+ * @category Protocol
29
+ */
30
+ export const makeProtocolFrida = (
31
+ options?: { readonly exportName?: string | undefined } | undefined
32
+ ): Effect.Effect<
33
+ RpcClient.Protocol["Type"],
34
+ FridaSessionError.FridaSessionError,
35
+ RpcSerialization.RpcSerialization | FridaScript.FridaScript | Scope.Scope
36
+ > =>
37
+ RpcClient.Protocol.make(
38
+ Effect.fnUntraced(function* (writeResponse) {
39
+ const script = yield* FridaScript.FridaScript;
40
+ const serialization = yield* RpcSerialization.RpcSerialization;
41
+
42
+ const encoder = new TextEncoder();
43
+ const parser = serialization.unsafeMake();
44
+ const exportName = options?.exportName ?? shared.defaultServerMainExportName;
45
+
46
+ /**
47
+ * Obtain a client id from the frida script export, this will allow
48
+ * us to filter future messages for ours since the script channels
49
+ * are shared.
50
+ */
51
+ const clientId = yield* Effect.catchIf(
52
+ script.callExport(exportName, Schema.Number)(),
53
+ ParseResult.isParseError,
54
+ () => Effect.dieMessage("Failed to obtain client ID from Frida script export")
55
+ );
56
+
57
+ const isClientId = Predicate.compose(Predicate.isNumber, (id) => id === clientId);
58
+ const receivingPredicate = Predicate.compose(
59
+ Predicate.isUnknown,
60
+ Predicate.struct({ clientId: isClientId })
61
+ );
62
+
63
+ /**
64
+ * Start listening for responses to our requests, decode them, and
65
+ * send the responses back to the implementation.
66
+ */
67
+ yield* script.stream.pipe(
68
+ Stream.filterMap((unfiltered) => {
69
+ if (receivingPredicate(unfiltered.message)) return unfiltered.data;
70
+ else return Option.none<Buffer<ArrayBufferLike>>();
71
+ }),
72
+ Stream.runForEach((filtered) => {
73
+ try {
74
+ const responses = parser.decode(filtered) as Array<RpcMessage.FromServerEncoded>;
75
+ if (responses.length === 0) return Effect.void;
76
+ let i = 0;
77
+ return Effect.whileLoop({
78
+ while: () => i < responses.length,
79
+ body: () => writeResponse(responses[i++]),
80
+ step: Function.constVoid,
81
+ });
82
+ } catch (defect) {
83
+ return writeResponse({ _tag: "Defect", defect });
84
+ }
85
+ }),
86
+ Effect.interruptible,
87
+ Effect.forkScoped
88
+ );
89
+
90
+ /**
91
+ * Sending messages is as simple as encoding them, then posting them
92
+ * to the frida side tagged with our client id so it knows where to
93
+ * send them back to.
94
+ */
95
+ const send = Effect.fnUntraced(function* (message: RpcMessage.FromClientEncoded) {
96
+ const encoded = parser.encode(message);
97
+ if (Predicate.isUndefined(encoded)) return;
98
+ const transformed = typeof encoded === "string" ? encoder.encode(encoded) : encoded;
99
+ script.script.post({ clientId }, Buffer.from(transformed));
100
+ });
101
+
102
+ return {
103
+ send,
104
+ supportsAck: true,
105
+ supportsTransferables: false,
106
+ };
107
+ })
108
+ );
109
+
110
+ /**
111
+ * @since 1.0.0
112
+ * @category Layers
113
+ */
114
+ export const layerProtocolFrida = (
115
+ options?: { readonly exportName?: string | undefined } | undefined
116
+ ): Layer.Layer<
117
+ RpcClient.Protocol,
118
+ FridaSessionError.FridaSessionError,
119
+ RpcSerialization.RpcSerialization | FridaScript.FridaScript
120
+ > => Layer.scoped(RpcClient.Protocol, makeProtocolFrida(options));
@@ -0,0 +1,134 @@
1
+ /**
2
+ * Implements a Frida RPC server protocol for effect using the frida script
3
+ * exports.
4
+ *
5
+ * @since 1.0.0
6
+ */
7
+
8
+ import type * as Scope from "effect/Scope";
9
+
10
+ import * as RpcMessage from "@effect/rpc/RpcMessage";
11
+ import * as RpcSerialization from "@effect/rpc/RpcSerialization";
12
+ import * as RpcServer from "@effect/rpc/RpcServer";
13
+ import * as FridaScript from "@efffrida/frida-tools/FridaScript";
14
+ import * as Console from "effect/Console";
15
+ import * as Effect from "effect/Effect";
16
+ import * as Function from "effect/Function";
17
+ import * as Mailbox from "effect/Mailbox";
18
+ import * as Option from "effect/Option";
19
+ import * as Predicate from "effect/Predicate";
20
+ import * as Schema from "effect/Schema";
21
+ import * as Stream from "effect/Stream";
22
+ import * as String from "effect/String";
23
+ import * as Tuple from "effect/Tuple";
24
+
25
+ import * as constants from "../shared/constants.ts";
26
+ import * as predicates from "../shared/predicates.ts";
27
+
28
+ /**
29
+ * @since 1.0.0
30
+ * @category Protocol
31
+ */
32
+ export const makeProtocolFrida = (): Effect.Effect<
33
+ unknown,
34
+ never,
35
+ FridaScript.FridaScript | RpcSerialization.RpcSerialization | Scope.Scope
36
+ > =>
37
+ Effect.gen(function* () {
38
+ const encoder = new TextEncoder();
39
+ const script = yield* FridaScript.FridaScript;
40
+ const serialization = yield* RpcSerialization.RpcSerialization;
41
+
42
+ let clientId = 0;
43
+ const clientIds = new Set<number>();
44
+ const parser = serialization.unsafeMake();
45
+ const disconnects = yield* Mailbox.make<number>();
46
+
47
+ let writeRequest!: (clientId: number, message: RpcMessage.FromClientEncoded) => Effect.Effect<void>;
48
+
49
+ // Listen for new clients
50
+ yield* script.stream.pipe(
51
+ Stream.filterMap(({ message }) => {
52
+ if (predicates.newClientPredicate(message)) {
53
+ const stripPrefix = String.replace(constants.nodeRpcClientConnectionRequestMessagePrefix, "");
54
+ return Option.some(stripPrefix(message));
55
+ } else {
56
+ return Option.none();
57
+ }
58
+ }),
59
+ Stream.runForEach((exportName) => {
60
+ const id = clientId++;
61
+ clientIds.add(id);
62
+ return script.callExport(exportName, Schema.Void)(clientId++);
63
+ }),
64
+ Stream.tapError(Console.error),
65
+ Stream.runDrain,
66
+ Effect.forkScoped
67
+ );
68
+
69
+ // Listen for messages from connected clients
70
+ yield* script.stream.pipe(
71
+ Stream.filterMap(({ data: maybeData, message }) => {
72
+ if (predicates.isTaggedForAnyClient(message)) {
73
+ return Option.map(maybeData, (data) => Tuple.make(message.clientId, data));
74
+ } else {
75
+ return Option.none();
76
+ }
77
+ }),
78
+ Stream.runForEach(([clientId, data]) => {
79
+ try {
80
+ const decoded = parser.decode(data) as ReadonlyArray<RpcMessage.FromClientEncoded>;
81
+ if (decoded.length === 0) return Effect.void;
82
+ let i = 0;
83
+ return Effect.whileLoop({
84
+ while: () => i < decoded.length,
85
+ body() {
86
+ const message = decoded[i++];
87
+ return writeRequest(clientId, message);
88
+ },
89
+ step: Function.constVoid,
90
+ });
91
+ } catch (cause) {
92
+ return Effect.sync(() => {
93
+ const encoded = parser.encode(RpcMessage.ResponseDefectEncoded(cause))!;
94
+ const transformed = typeof encoded === "string" ? encoder.encode(encoded) : encoded;
95
+ script.script.post({ clientId }, Buffer.from(transformed));
96
+ });
97
+ }
98
+ }),
99
+ Stream.tapError(Console.error),
100
+ Stream.runDrain,
101
+ Effect.forkScoped
102
+ );
103
+
104
+ return yield* RpcServer.Protocol.make((_writeRequest) => {
105
+ writeRequest = _writeRequest;
106
+ return Effect.succeed({
107
+ disconnects,
108
+ send: (clientId, response) => {
109
+ const writeRaw = (data: string | Uint8Array) => {
110
+ const transformed = typeof data === "string" ? encoder.encode(data) : data;
111
+ script.script.post({ clientId }, Buffer.from(transformed));
112
+ return Effect.void;
113
+ };
114
+
115
+ try {
116
+ const encoded = parser.encode(response);
117
+ if (Predicate.isNotUndefined(encoded)) return writeRaw(encoded);
118
+ else return Effect.void;
119
+ } catch (cause) {
120
+ const encoded = parser.encode(RpcMessage.ResponseDefectEncoded(cause))!;
121
+ return writeRaw(encoded);
122
+ }
123
+ },
124
+ end(_clientId) {
125
+ return Effect.void;
126
+ },
127
+ clientIds: Effect.sync(() => clientIds),
128
+ initialMessage: Effect.succeedNone,
129
+ supportsAck: true,
130
+ supportsTransferables: false,
131
+ supportsSpanPropagation: true,
132
+ });
133
+ });
134
+ });
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+
5
+ /**
6
+ * Implements a Frida RPC client protocol for effect using the frida script
7
+ * exports.
8
+ *
9
+ * @since 1.0.0
10
+ */
11
+ export * as FridaRpcClient from "./FridaRpcClient.ts"
12
+
13
+ /**
14
+ * Implements a Frida RPC server protocol for effect using the frida script
15
+ * exports.
16
+ *
17
+ * @since 1.0.0
18
+ */
19
+ export * as FridaRpcServer from "./FridaRpcServer.ts"
@@ -0,0 +1,11 @@
1
+ export const defaultServerMainExportName = "rpc";
2
+ export const generateServerExportNameForClient = (clientId: number): string =>
3
+ `@efffrida/rpc/FridaServerRpcListenerForClient/${clientId}`;
4
+
5
+ let exportIdForClientCallback: number = 0;
6
+ export const generateClientCallbackExportNameForServer = (): string =>
7
+ `@efffrida/rpc/FridaClientRpcCallback/${exportIdForClientCallback++}`;
8
+
9
+ export const nodeRpcClientConnectionRequestMessagePrefix = "client id request message";
10
+ export const nodeRpcClientMakeConnectionRequestForServer = (exportName: string) =>
11
+ `${nodeRpcClientConnectionRequestMessagePrefix}:${exportName}`;
@@ -0,0 +1,19 @@
1
+ import * as Predicate from "effect/Predicate";
2
+ import * as String from "effect/String";
3
+
4
+ import * as constants from "./constants.ts";
5
+
6
+ export const isClientId = (clientId: number) => Predicate.compose(Predicate.isNumber, (id) => id === clientId);
7
+
8
+ export const isTaggedForClient = (clientId: number) =>
9
+ Predicate.compose(Predicate.isUnknown, Predicate.struct({ clientId: isClientId(clientId) }));
10
+
11
+ export const isTaggedForAnyClient = Predicate.compose(
12
+ Predicate.isUnknown,
13
+ Predicate.struct({ clientId: Predicate.isNumber })
14
+ );
15
+
16
+ export const newClientPredicate = Predicate.compose(
17
+ Predicate.isString,
18
+ String.startsWith(constants.nodeRpcClientConnectionRequestMessagePrefix)
19
+ );
@@ -1,6 +0,0 @@
1
- {
2
- "sideEffects": [],
3
- "main": "../dist/cjs/FridaRpcClient.js",
4
- "module": "../dist/esm/FridaRpcClient.js",
5
- "types": "../dist/dts/FridaRpcClient.d.ts"
6
- }
@@ -1,6 +0,0 @@
1
- {
2
- "sideEffects": [],
3
- "main": "../dist/cjs/FridaRpcServer.js",
4
- "module": "../dist/esm/FridaRpcServer.js",
5
- "types": "../dist/dts/FridaRpcServer.d.ts"
6
- }
@@ -1,77 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.makeProtocolFrida = exports.layerProtocolFrida = void 0;
7
- var RpcClient = _interopRequireWildcard(require("@effect/rpc/RpcClient"));
8
- var RpcSerialization = _interopRequireWildcard(require("@effect/rpc/RpcSerialization"));
9
- var FridaScript = _interopRequireWildcard(require("@efffrida/frida-tools/FridaScript"));
10
- var Effect = _interopRequireWildcard(require("effect/Effect"));
11
- var Function = _interopRequireWildcard(require("effect/Function"));
12
- var Layer = _interopRequireWildcard(require("effect/Layer"));
13
- var Predicate = _interopRequireWildcard(require("effect/Predicate"));
14
- var Schema = _interopRequireWildcard(require("effect/Schema"));
15
- var Stream = _interopRequireWildcard(require("effect/Stream"));
16
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
17
- /**
18
- * Implements a Frida RPC client protocol for effect using the frida script
19
- * exports. The reason we don't use the send/recv script channels is because
20
- * those are shared channels by everybody.
21
- *
22
- * @since 1.0.0
23
- */
24
-
25
- /**
26
- * @since 1.0.0
27
- * @category Protocol
28
- */
29
- const makeProtocolFrida = (script, options) => RpcClient.Protocol.make(Effect.fnUntraced(function* (writeResponse) {
30
- const serialization = yield* RpcSerialization.RpcSerialization;
31
- const exportName = options?.exportName ?? "rpc";
32
- const rpcIsAvailableWhen = options?.rpcIsAvailableWhen;
33
- const send = request => {
34
- if (request._tag !== "Request") {
35
- return Effect.void;
36
- }
37
- const parser = serialization.unsafeMake();
38
- const schema = Schema.Union(Schema.String, Schema.Uint8Array);
39
- const encode = Function.compose(parser.encode, Schema.encode(schema));
40
- const decode = Function.compose(Schema.decodeUnknownSync(schema), parser.decode);
41
- return encode(request).pipe(Effect.flatMap(script.callExport(exportName))).pipe(Effect.orDie).pipe(Effect.flatMap(incoming => {
42
- try {
43
- const responses = decode(incoming);
44
- if (responses.length === 0) return Effect.void;
45
- let i = 0;
46
- return Effect.whileLoop({
47
- while: () => i < responses.length,
48
- body: () => writeResponse(responses[i++]),
49
- step: Function.constVoid
50
- });
51
- } catch (defect) {
52
- return writeResponse({
53
- _tag: "Defect",
54
- defect
55
- });
56
- }
57
- }));
58
- };
59
- if (Predicate.isNotUndefined(rpcIsAvailableWhen)) {
60
- yield* script.stream.pipe(Stream.map(({
61
- message
62
- }) => message)).pipe(Stream.filter(Predicate.isString)).pipe(Stream.takeUntil(rpcIsAvailableWhen)).pipe(Stream.runDrain);
63
- }
64
- return {
65
- send,
66
- supportsAck: false,
67
- supportsTransferables: false
68
- };
69
- }));
70
- /**
71
- * @since 1.0.0
72
- * @category Layers
73
- */
74
- exports.makeProtocolFrida = makeProtocolFrida;
75
- const layerProtocolFrida = options => Layer.effect(RpcClient.Protocol, Effect.flatMap(FridaScript.FridaScript, script => makeProtocolFrida(script, options)));
76
- exports.layerProtocolFrida = layerProtocolFrida;
77
- //# sourceMappingURL=FridaRpcClient.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FridaRpcClient.js","names":["RpcClient","_interopRequireWildcard","require","RpcSerialization","FridaScript","Effect","Function","Layer","Predicate","Schema","Stream","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","makeProtocolFrida","script","options","Protocol","make","fnUntraced","writeResponse","serialization","exportName","rpcIsAvailableWhen","send","request","_tag","void","parser","unsafeMake","schema","Union","String","Uint8Array","encode","compose","decode","decodeUnknownSync","pipe","flatMap","callExport","orDie","incoming","responses","length","whileLoop","while","body","step","constVoid","defect","isNotUndefined","stream","map","message","filter","isString","takeUntil","runDrain","supportsAck","supportsTransferables","exports","layerProtocolFrida","effect"],"sources":["../../src/FridaRpcClient.ts"],"sourcesContent":[null],"mappings":";;;;;;AAWA,IAAAA,SAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAF,uBAAA,CAAAC,OAAA;AACA,IAAAE,WAAA,GAAAH,uBAAA,CAAAC,OAAA;AACA,IAAAG,MAAA,GAAAJ,uBAAA,CAAAC,OAAA;AACA,IAAAI,QAAA,GAAAL,uBAAA,CAAAC,OAAA;AACA,IAAAK,KAAA,GAAAN,uBAAA,CAAAC,OAAA;AACA,IAAAM,SAAA,GAAAP,uBAAA,CAAAC,OAAA;AACA,IAAAO,MAAA,GAAAR,uBAAA,CAAAC,OAAA;AACA,IAAAQ,MAAA,GAAAT,uBAAA,CAAAC,OAAA;AAAuC,SAAAD,wBAAAU,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAZ,uBAAA,YAAAA,CAAAU,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA,gBAAAP,CAAA,IAAAD,CAAA,gBAAAC,CAAA,OAAAa,cAAA,CAAAC,IAAA,CAAAf,CAAA,EAAAC,CAAA,OAAAM,CAAA,IAAAD,CAAA,GAAAU,MAAA,CAAAC,cAAA,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