@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,47 @@
1
+ /**
2
+ * Implements a Frida RPC client protocol for effect using the frida script
3
+ * exports.
4
+ *
5
+ * @since 1.0.0
6
+ */
7
+ import type * as Duration from "effect/Duration";
8
+ import type * as Scope from "effect/Scope";
9
+ import * as RpcClient from "@effect/rpc/RpcClient";
10
+ import * as RpcSerialization from "@effect/rpc/RpcSerialization";
11
+ import * as Effect from "effect/Effect";
12
+ import * as Layer from "effect/Layer";
13
+ /**
14
+ * @since 1.0.0
15
+ * @category Protocol
16
+ */
17
+ export declare const makeProtocolFrida: (options?: {
18
+ readonly generateExportName?: (() => string) | undefined;
19
+ readonly receivingStreamShareOptions?: {
20
+ readonly capacity: "unbounded";
21
+ readonly replay?: number | undefined;
22
+ readonly idleTimeToLive?: Duration.DurationInput | undefined;
23
+ } | {
24
+ readonly capacity: number;
25
+ readonly strategy?: "sliding" | "dropping" | "suspend" | undefined;
26
+ readonly replay?: number | undefined;
27
+ readonly idleTimeToLive?: Duration.DurationInput | undefined;
28
+ } | undefined;
29
+ } | undefined) => Effect.Effect<RpcClient.Protocol["Type"], never, RpcSerialization.RpcSerialization | Scope.Scope>;
30
+ /**
31
+ * @since 1.0.0
32
+ * @category Layers
33
+ */
34
+ export declare const layerProtocolFrida: (options?: {
35
+ readonly generateExportName?: (() => string) | undefined;
36
+ readonly receivingStreamShareOptions?: {
37
+ readonly capacity: "unbounded";
38
+ readonly replay?: number | undefined;
39
+ readonly idleTimeToLive?: Duration.DurationInput | undefined;
40
+ } | {
41
+ readonly capacity: number;
42
+ readonly strategy?: "sliding" | "dropping" | "suspend" | undefined;
43
+ readonly replay?: number | undefined;
44
+ readonly idleTimeToLive?: Duration.DurationInput | undefined;
45
+ } | undefined;
46
+ } | undefined) => Layer.Layer<RpcClient.Protocol, never, RpcSerialization.RpcSerialization>;
47
+ //# sourceMappingURL=FridaRpcClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FridaRpcClient.d.ts","sourceRoot":"","sources":["../../src/frida/FridaRpcClient.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAC;AAE3C,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAC;AACnD,OAAO,KAAK,gBAAgB,MAAM,8BAA8B,CAAC;AAIjE,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAUtC;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAC1B,UACM;IACI,QAAQ,CAA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G,SAAS,CAAC;QACnE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QACrC,QAAQ,CAAC,cAAc,CAAC,EAAE,QAAQ,CAAC,aAAa,GAAG,SAAS,CAAC;KAChE,GACD,SAAS,CAAC;CACnB,GACD,SAAS,KAChB,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,QAAQ,EAAE,KAAK,EAAE,gBAAgB,CAAC,gBAAgB,CACX,CAAC"}
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Implements a Frida RPC client protocol for effect using the frida script
3
+ * exports.
4
+ *
5
+ * @since 1.0.0
6
+ */
7
+ import * as RpcClient from "@effect/rpc/RpcClient";
8
+ import * as RpcSerialization from "@effect/rpc/RpcSerialization";
9
+ import * as FridaStream from "@efffrida/platform/Stream";
10
+ import * as Cause from "effect/Cause";
11
+ import * as Deferred from "effect/Deferred";
12
+ import * as Effect from "effect/Effect";
13
+ import * as Function from "effect/Function";
14
+ import * as Layer from "effect/Layer";
15
+ import * as Option from "effect/Option";
16
+ import * as ParseResult from "effect/ParseResult";
17
+ import * as Predicate from "effect/Predicate";
18
+ import * as Schema from "effect/Schema";
19
+ import * as Stream from "effect/Stream";
20
+ import * as constants from "../shared/constants.js";
21
+ import * as sharedPredicates from "../shared/predicates.js";
22
+ /**
23
+ * @since 1.0.0
24
+ * @category Protocol
25
+ */
26
+ export const makeProtocolFrida = options => RpcClient.Protocol.make(Effect.fnUntraced(function* (writeResponse) {
27
+ const serialization = yield* RpcSerialization.RpcSerialization;
28
+ const encoder = new TextEncoder();
29
+ const parser = serialization.unsafeMake();
30
+ /**
31
+ * Once the server has acknowledged our initiation request and sent
32
+ * use a client id to identify ourselves, this deferred will
33
+ * complete.
34
+ */
35
+ const clientIdDeferred = yield* Deferred.make();
36
+ /**
37
+ * Setup the receiving handler for the client id. We receive the
38
+ * client id over a script export instead of over the receiving
39
+ * stream since there could be multiple clients in this frida script
40
+ * and multiple could request client ids at the same time. This
41
+ * could be mitigated with a nonce of some kind in the request
42
+ * message, but receiving over a script export is full-proof so long
43
+ * as the exports are unique.
44
+ */
45
+ const exportName = options?.generateExportName?.() ?? constants.generateClientCallbackExportNameForServer();
46
+ yield* Effect.addFinalizer(() => Effect.sync(() => delete rpc.exports[exportName]));
47
+ rpc.exports[exportName] = maybeIncomingClientId => {
48
+ const parsedClientId = Schema.decodeUnknown(Schema.Number)(maybeIncomingClientId);
49
+ Deferred.unsafeDone(clientIdDeferred, parsedClientId);
50
+ };
51
+ /**
52
+ * Request a client id from the node side and wait for the response,
53
+ * handling any transient errors that might occur by retrying with
54
+ * the retry policy.
55
+ */
56
+ const connectionRequest = constants.nodeRpcClientMakeConnectionRequestForServer(exportName);
57
+ const connectionRequestTimeout = "1 second";
58
+ const clientId = yield* Effect.sync(() => send(connectionRequest)).pipe(Effect.flatMap(() => Deferred.await(clientIdDeferred)), Effect.timeout(connectionRequestTimeout), Effect.catchIf(ParseResult.isParseError, () => Effect.dieMessage("Failed to parse client ID")), Effect.catchIf(Cause.isTimeoutException, () => Effect.dieMessage("Timed out too many times")));
59
+ /**
60
+ * Attach to the receiving stream, where all future messages will
61
+ * come in at, and filter for only our messages.
62
+ */
63
+ const receivingPredicate = sharedPredicates.isTaggedForClient(clientId);
64
+ const receiveStream = yield* FridaStream.receiveStream(options?.receivingStreamShareOptions ?? {
65
+ replay: 100,
66
+ capacity: "unbounded"
67
+ });
68
+ /**
69
+ * For every response message received, decode it and send it the
70
+ * response back to the implementation.
71
+ */
72
+ yield* receiveStream.pipe(Stream.filterMap(unfiltered => {
73
+ if (receivingPredicate(unfiltered.message)) return Option.fromNullable(unfiltered.data);else return Option.none();
74
+ }), Stream.runForEach(filtered => {
75
+ try {
76
+ const responses = parser.decode(filtered);
77
+ if (responses.length === 0) return Effect.void;
78
+ let i = 0;
79
+ return Effect.whileLoop({
80
+ while: () => i < responses.length,
81
+ body: () => writeResponse(responses[i++]),
82
+ step: Function.constVoid
83
+ });
84
+ } catch (defect) {
85
+ return writeResponse({
86
+ _tag: "Defect",
87
+ defect
88
+ });
89
+ }
90
+ }), Effect.interruptible, Effect.forkScoped);
91
+ /**
92
+ * Sending messages is as simple as encoding them, then sending them
93
+ * to the node side tagged with our client id so it knows where to
94
+ * send them back to.
95
+ */
96
+ const sendHelper = Effect.fnUntraced(function* (message) {
97
+ const encoded = parser.encode(message);
98
+ if (Predicate.isUndefined(encoded)) return;
99
+ const transformed = typeof encoded === "string" ? encoder.encode(encoded) : encoded;
100
+ send({
101
+ clientId
102
+ }, transformed.buffer);
103
+ });
104
+ return {
105
+ send: sendHelper,
106
+ supportsAck: true,
107
+ supportsTransferables: false
108
+ };
109
+ }));
110
+ /**
111
+ * @since 1.0.0
112
+ * @category Layers
113
+ */
114
+ export const layerProtocolFrida = options => Layer.scoped(RpcClient.Protocol, makeProtocolFrida(options));
115
+ //# sourceMappingURL=FridaRpcClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FridaRpcClient.js","names":["RpcClient","RpcSerialization","FridaStream","Cause","Deferred","Effect","Function","Layer","Option","ParseResult","Predicate","Schema","Stream","constants","sharedPredicates","makeProtocolFrida","options","Protocol","make","fnUntraced","writeResponse","serialization","encoder","TextEncoder","parser","unsafeMake","clientIdDeferred","exportName","generateExportName","generateClientCallbackExportNameForServer","addFinalizer","sync","rpc","exports","maybeIncomingClientId","parsedClientId","decodeUnknown","Number","unsafeDone","connectionRequest","nodeRpcClientMakeConnectionRequestForServer","connectionRequestTimeout","clientId","send","pipe","flatMap","await","timeout","catchIf","isParseError","dieMessage","isTimeoutException","receivingPredicate","isTaggedForClient","receiveStream","receivingStreamShareOptions","replay","capacity","filterMap","unfiltered","message","fromNullable","data","none","runForEach","filtered","responses","decode","length","void","i","whileLoop","while","body","step","constVoid","defect","_tag","interruptible","forkScoped","sendHelper","encoded","encode","isUndefined","transformed","buffer","supportsAck","supportsTransferables","layerProtocolFrida","scoped"],"sources":["../../src/frida/FridaRpcClient.ts"],"sourcesContent":[null],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,UAAU;IAChBM,WAAW,EAAE,IAAI;IACjBC,qBAAqB,EAAE;GAC1B;AACL,CAAC,CAAC,CACL;AAEL;;;;AAIA,OAAO,MAAMC,kBAAkB,GAC3BxE,OAiBe,IAEfT,KAAK,CAACkF,MAAM,CAACzF,SAAS,CAACiB,QAAQ,EAAEF,iBAAiB,CAACC,OAAO,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Implements a Frida RPC server protocol for effect using the frida script
3
+ * exports.
4
+ *
5
+ * @since 1.0.0
6
+ */
7
+ import * as RpcSerialization from "@effect/rpc/RpcSerialization";
8
+ import * as RpcServer from "@effect/rpc/RpcServer";
9
+ import * as Effect from "effect/Effect";
10
+ import * as Layer from "effect/Layer";
11
+ /**
12
+ * @since 1.0.0
13
+ * @category Protocol
14
+ */
15
+ export declare const makeProtocolFrida: (options?: {
16
+ /** Generates server listener rpc exports for individual clients. */
17
+ readonly generateExportName?: ((clientId: number) => string) | undefined;
18
+ } | undefined) => Effect.Effect<{
19
+ readonly protocol: RpcServer.Protocol["Type"];
20
+ readonly rpcExport: () => Promise<number>;
21
+ }, never, RpcSerialization.RpcSerialization>;
22
+ /**
23
+ * @since 1.0.0
24
+ * @category Protocol
25
+ */
26
+ export declare const makeProtocolFridaWithExport: (options?: {
27
+ /**
28
+ * Name for the main rpc export that all clients start by
29
+ * connecting to.
30
+ */
31
+ readonly exportName?: string | undefined;
32
+ /** Generates server listener rpc exports for individual clients. */
33
+ readonly generateExportName?: ((clientId: number) => string) | undefined;
34
+ } | undefined) => Effect.Effect<RpcServer.Protocol["Type"], never, RpcSerialization.RpcSerialization>;
35
+ /**
36
+ * @since 1.0.0
37
+ * @category Layer
38
+ */
39
+ export declare const layerProtocolFrida: (options?: {
40
+ /**
41
+ * Name for the main rpc export that all clients start by
42
+ * connecting to.
43
+ */
44
+ readonly exportName?: string | undefined;
45
+ /** Generates server listener rpc exports for individual clients. */
46
+ readonly generateExportName?: ((clientId: number) => string) | undefined;
47
+ } | undefined) => Layer.Layer<RpcServer.Protocol, never, RpcSerialization.RpcSerialization>;
48
+ //# sourceMappingURL=FridaRpcServer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FridaRpcServer.d.ts","sourceRoot":"","sources":["../../src/frida/FridaRpcServer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,gBAAgB,MAAM,8BAA8B,CAAC;AACjE,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAC;AACnD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAMtC;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAC1B,UACM;IACI,oEAAoE;IACpE,QAAQ,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC,GAAG,SAAS,CAAC;CAC5E,GACD,SAAS,KAChB,MAAM,CAAC,MAAM,CACZ;IACI,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC9C,QAAQ,CAAC,SAAS,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;CAC7C,EACD,KAAK,EACL,gBAAgB,CAAC,gBAAgB,CAwF/B,CAAC;AAEP;;;GAGG;AACH,eAAO,MAAM,2BAA2B,GACpC,UACM;IACI;;;OAGG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAEzC,oEAAoE;IACpE,QAAQ,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC,GAAG,SAAS,CAAC;CAC5E,GACD,SAAS,KAChB,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,gBAAgB,CAAC,gBAAgB,CAK/E,CAAC;AAEP;;;GAGG;AACH,eAAO,MAAM,kBAAkB,GAC3B,UACM;IACI;;;OAGG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAEzC,oEAAoE;IACpE,QAAQ,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC,GAAG,SAAS,CAAC;CAC5E,GACD,SAAS,KAChB,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,QAAQ,EAAE,KAAK,EAAE,gBAAgB,CAAC,gBAAgB,CACD,CAAC"}
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Implements a Frida RPC server protocol for effect using the frida script
3
+ * exports.
4
+ *
5
+ * @since 1.0.0
6
+ */
7
+ import * as RpcMessage from "@effect/rpc/RpcMessage";
8
+ import * as RpcSerialization from "@effect/rpc/RpcSerialization";
9
+ import * as RpcServer from "@effect/rpc/RpcServer";
10
+ import * as Effect from "effect/Effect";
11
+ import * as Function from "effect/Function";
12
+ import * as Layer from "effect/Layer";
13
+ import * as Mailbox from "effect/Mailbox";
14
+ import * as Predicate from "effect/Predicate";
15
+ import * as constants from "../shared/constants.js";
16
+ /**
17
+ * @since 1.0.0
18
+ * @category Protocol
19
+ */
20
+ export const makeProtocolFrida = options => Effect.gen(function* () {
21
+ const encoder = new TextEncoder();
22
+ const disconnects = yield* Mailbox.make();
23
+ const serialization = yield* RpcSerialization.RpcSerialization;
24
+ let clientId = 0;
25
+ const clientIds = new Set();
26
+ const clients = new Map();
27
+ let writeRequest;
28
+ const exportName = options?.generateExportName ?? constants.generateServerExportNameForClient;
29
+ // Listen for new clients on the main rpc export
30
+ const rpcExport = Effect.gen(function* () {
31
+ const id = clientId++;
32
+ const parser = serialization.unsafeMake();
33
+ const writeRaw = data => {
34
+ const transformed = typeof data === "string" ? encoder.encode(data) : data;
35
+ return send({
36
+ clientId: id
37
+ }, transformed.buffer);
38
+ };
39
+ const write = response => {
40
+ try {
41
+ const encoded = parser.encode(response);
42
+ if (Predicate.isNotUndefined(encoded)) return writeRaw(encoded);
43
+ } catch (cause) {
44
+ const encoded = parser.encode(RpcMessage.ResponseDefectEncoded(cause));
45
+ return writeRaw(encoded);
46
+ }
47
+ };
48
+ clientIds.add(id);
49
+ clients.set(id, {
50
+ write
51
+ });
52
+ const onMessage = data => {
53
+ try {
54
+ const decoded = parser.decode(data);
55
+ if (decoded.length === 0) return Effect.void;
56
+ let i = 0;
57
+ return Effect.whileLoop({
58
+ while: () => i < decoded.length,
59
+ body() {
60
+ const message = decoded[i++];
61
+ return writeRequest(id, message);
62
+ },
63
+ step: Function.constVoid
64
+ });
65
+ } catch (cause) {
66
+ return Effect.sync(() => writeRaw(parser.encode(RpcMessage.ResponseDefectEncoded(cause))));
67
+ }
68
+ };
69
+ rpc.exports[exportName(clientId)] = data => Effect.runPromise(onMessage(data));
70
+ return clientId;
71
+ });
72
+ const protocol = yield* RpcServer.Protocol.make(writeRequest_ => {
73
+ writeRequest = writeRequest_;
74
+ return Effect.succeed({
75
+ disconnects,
76
+ send: (clientId, response) => {
77
+ const client = clients.get(clientId);
78
+ if (!client) return Effect.void;
79
+ return Effect.sync(() => client.write(response));
80
+ },
81
+ end(clientId) {
82
+ clientIds.delete(clientId); // TODO: Is this required?
83
+ clients.delete(clientId); // TODO: Is this required?
84
+ const exportName = options?.generateExportName ?? constants.generateServerExportNameForClient;
85
+ delete rpc.exports[exportName(clientId)];
86
+ return Effect.void;
87
+ },
88
+ clientIds: Effect.sync(() => clientIds),
89
+ initialMessage: Effect.succeedNone,
90
+ supportsAck: true,
91
+ supportsTransferables: false,
92
+ supportsSpanPropagation: true
93
+ });
94
+ });
95
+ return {
96
+ protocol,
97
+ rpcExport: () => Effect.runPromise(rpcExport)
98
+ };
99
+ });
100
+ /**
101
+ * @since 1.0.0
102
+ * @category Protocol
103
+ */
104
+ export const makeProtocolFridaWithExport = options => Effect.gen(function* () {
105
+ const {
106
+ protocol,
107
+ rpcExport
108
+ } = yield* makeProtocolFrida({
109
+ generateExportName: options?.generateExportName
110
+ });
111
+ rpc.exports[options?.exportName ?? constants.defaultServerMainExportName] = rpcExport;
112
+ return protocol;
113
+ });
114
+ /**
115
+ * @since 1.0.0
116
+ * @category Layer
117
+ */
118
+ export const layerProtocolFrida = options => Layer.effect(RpcServer.Protocol, makeProtocolFridaWithExport(options));
119
+ //# sourceMappingURL=FridaRpcServer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FridaRpcServer.js","names":["RpcMessage","RpcSerialization","RpcServer","Effect","Function","Layer","Mailbox","Predicate","constants","makeProtocolFrida","options","gen","encoder","TextEncoder","disconnects","make","serialization","clientId","clientIds","Set","clients","Map","writeRequest","exportName","generateExportName","generateServerExportNameForClient","rpcExport","id","parser","unsafeMake","writeRaw","data","transformed","encode","send","buffer","write","response","encoded","isNotUndefined","cause","ResponseDefectEncoded","add","set","onMessage","decoded","decode","length","void","i","whileLoop","while","body","message","step","constVoid","sync","rpc","exports","runPromise","protocol","Protocol","writeRequest_","succeed","client","get","end","delete","initialMessage","succeedNone","supportsAck","supportsTransferables","supportsSpanPropagation","makeProtocolFridaWithExport","defaultServerMainExportName","layerProtocolFrida","effect"],"sources":["../../src/frida/FridaRpcServer.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;AAOA,OAAO,KAAKA,UAAU,MAAM,wBAAwB;AACpD,OAAO,KAAKC,gBAAgB,MAAM,8BAA8B;AAChE,OAAO,KAAKC,SAAS,MAAM,uBAAuB;AAClD,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,QAAQ,MAAM,iBAAiB;AAC3C,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAKC,SAAS,MAAM,kBAAkB;AAE7C,OAAO,KAAKC,SAAS,MAAM,wBAAwB;AAEnD;;;;AAIA,OAAO,MAAMC,iBAAiB,GAC1BC,OAKe,IASfP,MAAM,CAACQ,GAAG,CAAC,aA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D,SAAS;EACrF,OAAOkC,QAAQ;AACnB,CAAC,CAAC;AAEN;;;;AAIA,OAAO,MAAMe,kBAAkB,GAC3BjE,OAWe,IAEfL,KAAK,CAACuE,MAAM,CAAC1E,SAAS,CAAC2D,QAAQ,EAAEY,2BAA2B,CAAC/D,OAAO,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+ /**
5
+ * Implements a Frida RPC client protocol for effect using the frida script
6
+ * exports.
7
+ *
8
+ * @since 1.0.0
9
+ */
10
+ export * as FridaRpcClient from "./FridaRpcClient.ts";
11
+ /**
12
+ * Implements a Frida RPC server protocol for effect using the frida script
13
+ * exports.
14
+ *
15
+ * @since 1.0.0
16
+ */
17
+ export * as FridaRpcServer from "./FridaRpcServer.ts";
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/frida/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;GAKG;AACH,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AAErD;;;;;GAKG;AACH,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA"}
@@ -1,15 +1,16 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
1
4
  /**
2
5
  * Implements a Frida RPC client protocol for effect using the frida script
3
- * exports. The reason we don't use the send/recv script channels is because
4
- * those are shared channels by everybody.
6
+ * exports.
5
7
  *
6
8
  * @since 1.0.0
7
9
  */
8
10
  export * as FridaRpcClient from "./FridaRpcClient.js";
9
11
  /**
10
12
  * Implements a Frida RPC server protocol for effect using the frida script
11
- * exports. The reason we don't use the send/recv script channels is because
12
- * those are shared channels by everybody.
13
+ * exports.
13
14
  *
14
15
  * @since 1.0.0
15
16
  */
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["FridaRpcClient","FridaRpcServer"],"sources":["../../src/frida/index.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAIA;;;;;;AAMA,OAAO,KAAKA,cAAc,MAAM,qBAAqB;AAErD;;;;;;AAMA,OAAO,KAAKC,cAAc,MAAM,qBAAqB","ignoreList":[]}
@@ -1,11 +1,11 @@
1
1
  /**
2
2
  * Implements a Frida RPC client protocol for effect using the frida script
3
- * exports. The reason we don't use the send/recv script channels is because
4
- * those are shared channels by everybody.
3
+ * exports.
5
4
  *
6
5
  * @since 1.0.0
7
6
  */
8
7
  import type * as FridaSessionError from "@efffrida/frida-tools/FridaSessionError";
8
+ import type * as Scope from "effect/Scope";
9
9
  import * as RpcClient from "@effect/rpc/RpcClient";
10
10
  import * as RpcSerialization from "@effect/rpc/RpcSerialization";
11
11
  import * as FridaScript from "@efffrida/frida-tools/FridaScript";
@@ -15,16 +15,14 @@ import * as Layer from "effect/Layer";
15
15
  * @since 1.0.0
16
16
  * @category Protocol
17
17
  */
18
- export declare const makeProtocolFrida: (script: FridaScript.FridaScript, options?: {
18
+ export declare const makeProtocolFrida: (options?: {
19
19
  readonly exportName?: string | undefined;
20
- readonly rpcIsAvailableWhen?: ((message: string) => boolean) | undefined;
21
- } | undefined) => Effect.Effect<RpcClient.Protocol["Type"], FridaSessionError.FridaSessionError, RpcSerialization.RpcSerialization>;
20
+ } | undefined) => Effect.Effect<RpcClient.Protocol["Type"], FridaSessionError.FridaSessionError, RpcSerialization.RpcSerialization | FridaScript.FridaScript | Scope.Scope>;
22
21
  /**
23
22
  * @since 1.0.0
24
23
  * @category Layers
25
24
  */
26
25
  export declare const layerProtocolFrida: (options?: {
27
26
  readonly exportName?: string | undefined;
28
- readonly rpcIsAvailableWhen?: ((message: string) => boolean) | undefined;
29
27
  } | undefined) => Layer.Layer<RpcClient.Protocol, FridaSessionError.FridaSessionError, RpcSerialization.RpcSerialization | FridaScript.FridaScript>;
30
28
  //# sourceMappingURL=FridaRpcClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FridaRpcClient.d.ts","sourceRoot":"","sources":["../../src/node/FridaRpcClient.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,KAAK,iBAAiB,MAAM,yCAAyC,CAAC;AAClF,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAC;AAE3C,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAC;AACnD,OAAO,KAAK,gBAAgB,MAAM,8BAA8B,CAAC;AACjE,OAAO,KAAK,WAAW,MAAM,mCAAmC,CAAC;AACjE,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAStC;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAC1B,UAAU;IAAE,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,GAAG,SAAS,KACnE,MAAM,CAAC,MAAM,CACZ,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,EAC1B,iBAAiB,CAAC,iBAAiB,EACnC,gBAAgB,CAAC,gBAAgB,GAAG,WAAW,CAAC,WAAW,GAAG,KAAK,CAAC,KAAK,CAyExE,CAAC;AAEN;;;GAGG;AACH,eAAO,MAAM,kBAAkB,GAC3B,UAAU;IAAE,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,GAAG,SAAS,KACnE,KAAK,CAAC,KAAK,CACV,SAAS,CAAC,QAAQ,EAClB,iBAAiB,CAAC,iBAAiB,EACnC,gBAAgB,CAAC,gBAAgB,GAAG,WAAW,CAAC,WAAW,CACE,CAAC"}
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Implements a Frida RPC client protocol for effect using the frida script
3
+ * exports.
4
+ *
5
+ * @since 1.0.0
6
+ */
7
+ import * as RpcClient from "@effect/rpc/RpcClient";
8
+ import * as RpcSerialization from "@effect/rpc/RpcSerialization";
9
+ import * as FridaScript from "@efffrida/frida-tools/FridaScript";
10
+ import * as Effect from "effect/Effect";
11
+ import * as Function from "effect/Function";
12
+ import * as Layer from "effect/Layer";
13
+ import * as Option from "effect/Option";
14
+ import * as ParseResult from "effect/ParseResult";
15
+ import * as Predicate from "effect/Predicate";
16
+ import * as Schema from "effect/Schema";
17
+ import * as Stream from "effect/Stream";
18
+ import * as shared from "../shared/constants.js";
19
+ /**
20
+ * @since 1.0.0
21
+ * @category Protocol
22
+ */
23
+ export const makeProtocolFrida = options => RpcClient.Protocol.make(Effect.fnUntraced(function* (writeResponse) {
24
+ const script = yield* FridaScript.FridaScript;
25
+ const serialization = yield* RpcSerialization.RpcSerialization;
26
+ const encoder = new TextEncoder();
27
+ const parser = serialization.unsafeMake();
28
+ const exportName = options?.exportName ?? shared.defaultServerMainExportName;
29
+ /**
30
+ * Obtain a client id from the frida script export, this will allow
31
+ * us to filter future messages for ours since the script channels
32
+ * are shared.
33
+ */
34
+ const clientId = yield* Effect.catchIf(script.callExport(exportName, Schema.Number)(), ParseResult.isParseError, () => Effect.dieMessage("Failed to obtain client ID from Frida script export"));
35
+ const isClientId = Predicate.compose(Predicate.isNumber, id => id === clientId);
36
+ const receivingPredicate = Predicate.compose(Predicate.isUnknown, Predicate.struct({
37
+ clientId: isClientId
38
+ }));
39
+ /**
40
+ * Start listening for responses to our requests, decode them, and
41
+ * send the responses back to the implementation.
42
+ */
43
+ yield* script.stream.pipe(Stream.filterMap(unfiltered => {
44
+ if (receivingPredicate(unfiltered.message)) return unfiltered.data;else return Option.none();
45
+ }), Stream.runForEach(filtered => {
46
+ try {
47
+ const responses = parser.decode(filtered);
48
+ if (responses.length === 0) return Effect.void;
49
+ let i = 0;
50
+ return Effect.whileLoop({
51
+ while: () => i < responses.length,
52
+ body: () => writeResponse(responses[i++]),
53
+ step: Function.constVoid
54
+ });
55
+ } catch (defect) {
56
+ return writeResponse({
57
+ _tag: "Defect",
58
+ defect
59
+ });
60
+ }
61
+ }), Effect.interruptible, Effect.forkScoped);
62
+ /**
63
+ * Sending messages is as simple as encoding them, then posting them
64
+ * to the frida side tagged with our client id so it knows where to
65
+ * send them back to.
66
+ */
67
+ const send = Effect.fnUntraced(function* (message) {
68
+ const encoded = parser.encode(message);
69
+ if (Predicate.isUndefined(encoded)) return;
70
+ const transformed = typeof encoded === "string" ? encoder.encode(encoded) : encoded;
71
+ script.script.post({
72
+ clientId
73
+ }, Buffer.from(transformed));
74
+ });
75
+ return {
76
+ send,
77
+ supportsAck: true,
78
+ supportsTransferables: false
79
+ };
80
+ }));
81
+ /**
82
+ * @since 1.0.0
83
+ * @category Layers
84
+ */
85
+ export const layerProtocolFrida = options => Layer.scoped(RpcClient.Protocol, makeProtocolFrida(options));
86
+ //# sourceMappingURL=FridaRpcClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FridaRpcClient.js","names":["RpcClient","RpcSerialization","FridaScript","Effect","Function","Layer","Option","ParseResult","Predicate","Schema","Stream","shared","makeProtocolFrida","options","Protocol","make","fnUntraced","writeResponse","script","serialization","encoder","TextEncoder","parser","unsafeMake","exportName","defaultServerMainExportName","clientId","catchIf","callExport","Number","isParseError","dieMessage","isClientId","compose","isNumber","id","receivingPredicate","isUnknown","struct","stream","pipe","filterMap","unfiltered","message","data","none","runForEach","filtered","responses","decode","length","void","i","whileLoop","while","body","step","constVoid","defect","_tag","interruptible","forkScoped","send","encoded","encode","isUndefined","transformed","post","Buffer","from","supportsAck","supportsTransferables","layerProtocolFrida","scoped"],"sources":["../../src/node/FridaRpcClient.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;AAWA,OAAO,KAAKA,SAAS,MAAM,uBAAuB;AAClD,OAAO,KAAKC,gBAAgB,MAAM,8BAA8B;AAChE,OAAO,KAAKC,WAAW,MAAM,mCAAmC;AAChE,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,QAAQ,MAAM,iBAAiB;AAC3C,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,WAAW,MAAM,oBAAoB;AACj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AC;EAEF,OAAO;IACHJ,IAAI;IACJQ,WAAW,EAAE,IAAI;IACjBC,qBAAqB,EAAE;GAC1B;AACL,CAAC,CAAC,CACL;AAEL;;;;AAIA,OAAO,MAAMC,kBAAkB,GAC3B3D,OAAkE,IAKjER,KAAK,CAACoE,MAAM,CAACzE,SAAS,CAACc,QAAQ,EAAEF,iBAAiB,CAACC,OAAO,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Implements a Frida RPC server protocol for effect using the frida script
3
+ * exports.
4
+ *
5
+ * @since 1.0.0
6
+ */
7
+ import type * as Scope from "effect/Scope";
8
+ import * as RpcSerialization from "@effect/rpc/RpcSerialization";
9
+ import * as FridaScript from "@efffrida/frida-tools/FridaScript";
10
+ import * as Effect from "effect/Effect";
11
+ /**
12
+ * @since 1.0.0
13
+ * @category Protocol
14
+ */
15
+ export declare const makeProtocolFrida: () => Effect.Effect<unknown, never, FridaScript.FridaScript | RpcSerialization.RpcSerialization | Scope.Scope>;
16
+ //# sourceMappingURL=FridaRpcServer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FridaRpcServer.d.ts","sourceRoot":"","sources":["../../src/node/FridaRpcServer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAC;AAG3C,OAAO,KAAK,gBAAgB,MAAM,8BAA8B,CAAC;AAEjE,OAAO,KAAK,WAAW,MAAM,mCAAmC,CAAC;AAEjE,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAaxC;;;GAGG;AACH,eAAO,MAAM,iBAAiB,QAAO,MAAM,CAAC,MAAM,CAC9C,OAAO,EACP,KAAK,EACL,WAAW,CAAC,WAAW,GAAG,gBAAgB,CAAC,gBAAgB,GAAG,KAAK,CAAC,KAAK,CAmGvE,CAAC"}