@efffrida/rpc 0.0.14 → 0.0.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 (63) hide show
  1. package/dist/frida/FridaRpcClient.d.ts +48 -0
  2. package/dist/frida/FridaRpcClient.d.ts.map +1 -0
  3. package/dist/frida/FridaRpcClient.js +116 -0
  4. package/dist/frida/FridaRpcClient.js.map +1 -0
  5. package/dist/frida/FridaRpcServer.d.ts +49 -0
  6. package/dist/frida/FridaRpcServer.d.ts.map +1 -0
  7. package/dist/frida/FridaRpcServer.js +121 -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 +16 -6
  14. package/dist/node/FridaRpcClient.d.ts.map +1 -0
  15. package/dist/node/FridaRpcClient.js +83 -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 +61 -45
  34. package/src/frida/FridaRpcClient.ts +182 -0
  35. package/src/frida/FridaRpcServer.ts +172 -0
  36. package/src/frida/index.ts +19 -0
  37. package/src/node/FridaRpcClient.ts +141 -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
@@ -1,172 +0,0 @@
1
- /**
2
- * Implements a Frida RPC server 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.
5
- *
6
- * @since 1.0.0
7
- */
8
-
9
- import * as RpcMessage from "@effect/rpc/RpcMessage";
10
- import * as RpcSerialization from "@effect/rpc/RpcSerialization";
11
- import * as RpcServer from "@effect/rpc/RpcServer";
12
- import * as Array from "effect/Array";
13
- import * as Chunk from "effect/Chunk";
14
- import * as Effect from "effect/Effect";
15
- import * as Function from "effect/Function";
16
- import * as Layer from "effect/Layer";
17
- import * as Mailbox from "effect/Mailbox";
18
- import * as Predicate from "effect/Predicate";
19
- import * as Queue from "effect/Queue";
20
- import * as Runtime from "effect/Runtime";
21
- import * as Schema from "effect/Schema";
22
-
23
- /**
24
- * @since 1.0.0
25
- * @category Protocol
26
- */
27
- export const makeProtocolFrida: Effect.Effect<
28
- {
29
- protocol: RpcServer.Protocol["Type"];
30
- rpcExport: (request: string | Uint8Array) => Promise<string | ReadonlyArray<number>>;
31
- },
32
- never,
33
- RpcSerialization.RpcSerialization
34
- > = Effect.gen(function* () {
35
- const runtime = yield* Effect.runtime<never>();
36
- const disconnects = yield* Mailbox.make<number>();
37
- const serialization = yield* RpcSerialization.RpcSerialization;
38
-
39
- let clientId = 0;
40
- const clients = new Map<
41
- number,
42
- {
43
- readonly end: Effect.Effect<void, never, never>;
44
- readonly write: (bytes: RpcMessage.FromServerEncoded) => Effect.Effect<void>;
45
- }
46
- >();
47
- let writeRequest!: (clientId: number, message: RpcMessage.FromClientEncoded) => Effect.Effect<void>;
48
-
49
- const rpcExport = async function (request: string | Uint8Array): Promise<string | ReadonlyArray<number>> {
50
- const id = clientId++;
51
-
52
- const parser = serialization.unsafeMake();
53
- const schema = Schema.Union(Schema.String, Schema.Uint8Array);
54
- const encode = Function.compose(parser.encode, Schema.encodeSync(schema));
55
- const decode = Function.compose(Schema.decodeUnknownSync(schema), parser.decode);
56
-
57
- const latch = await Effect.makeLatch(false).pipe(Runtime.runPromise(runtime));
58
- const queue = await Queue.unbounded<RpcMessage.FromServerEncoded>().pipe(Runtime.runPromise(runtime));
59
-
60
- // When the implementation is done, do this with it's response
61
- clients.set(id, {
62
- end: Effect.void,
63
- write: (response: RpcMessage.FromServerEncoded): Effect.Effect<void, never, never> =>
64
- Effect.andThen(queue.offer(response), Predicate.isTagged(response, "Chunk") ? Effect.void : latch.open),
65
- });
66
-
67
- // Parse the request and send it to the implementation
68
- try {
69
- const decoded = decode(request) as ReadonlyArray<RpcMessage.FromClientEncoded>;
70
- if (decoded.length === 0) return "";
71
- let i = 0;
72
- await Runtime.runPromise(
73
- runtime,
74
- Effect.whileLoop({
75
- while: () => i < decoded.length,
76
- body: () => writeRequest(id, decoded[i++]),
77
- step: Function.constVoid,
78
- })
79
- );
80
- } catch (cause) {
81
- const message = RpcMessage.ResponseDefectEncoded(cause);
82
- const encoded = encode(message);
83
- return Promise.resolve(encoded);
84
- }
85
-
86
- // Wait for the implementation to respond
87
- const responses = await latch.await
88
- .pipe(Effect.andThen(queue.takeAll))
89
- .pipe(Effect.tap(queue.shutdown))
90
- .pipe(Effect.map(Chunk.toReadonlyArray))
91
- .pipe(Runtime.runPromise(runtime));
92
-
93
- // Encode the responses
94
- const chunks: Array<string | ReadonlyArray<number>> = [];
95
- for (const responseMessage of responses) {
96
- try {
97
- const encoded = encode(responseMessage);
98
- chunks.push(encoded);
99
- } catch (cause) {
100
- const message = RpcMessage.ResponseDefectEncoded(cause);
101
- const encoded = encode(message);
102
- return Promise.resolve(encoded);
103
- }
104
- }
105
-
106
- // Concatenate the responses
107
- const final = Predicate.isString(chunks[0])
108
- ? chunks.join("")
109
- : Array.flatten(chunks as Array<ReadonlyArray<number>>);
110
- return Promise.resolve(final);
111
- };
112
-
113
- const protocol = yield* RpcServer.Protocol.make((writeRequest_) => {
114
- writeRequest = writeRequest_;
115
- return Effect.succeed({
116
- disconnects,
117
- send: (clientId, response) => {
118
- const client = clients.get(clientId);
119
- if (!client) return Effect.void;
120
- return client.write(response);
121
- },
122
- end(clientId) {
123
- const client = clients.get(clientId);
124
- if (!client) return Effect.void;
125
- clients.delete(clientId);
126
- return client.end;
127
- },
128
- initialMessage: Effect.succeedNone,
129
- supportsAck: false,
130
- supportsTransferables: false,
131
- supportsSpanPropagation: false,
132
- });
133
- });
134
-
135
- return { protocol, rpcExport };
136
- });
137
-
138
- /**
139
- * @since 1.0.0
140
- * @category Protocol
141
- */
142
- export const makeProtocolFridaWithExport = (
143
- options?:
144
- | {
145
- readonly exportName?: string | undefined;
146
- readonly messageOnRpcAvailable?: string | undefined;
147
- }
148
- | undefined
149
- ): Effect.Effect<RpcServer.Protocol["Type"], never, RpcSerialization.RpcSerialization> =>
150
- Effect.gen(function* () {
151
- const { protocol, rpcExport } = yield* makeProtocolFrida;
152
- rpc.exports[options?.exportName ?? "rpc"] = rpcExport;
153
- const messageOnRpcAvailable = options?.messageOnRpcAvailable;
154
- if (Predicate.isNotUndefined(messageOnRpcAvailable)) {
155
- send(messageOnRpcAvailable);
156
- }
157
- return protocol;
158
- });
159
-
160
- /**
161
- * @since 1.0.0
162
- * @category Layer
163
- */
164
- export const layerProtocolFrida = (
165
- options?:
166
- | {
167
- readonly exportName?: string | undefined;
168
- readonly messageOnRpcAvailable?: string | undefined;
169
- }
170
- | undefined
171
- ): Layer.Layer<RpcServer.Protocol, never, RpcSerialization.RpcSerialization> =>
172
- Layer.effect(RpcServer.Protocol, makeProtocolFridaWithExport(options));
package/src/index.ts DELETED
@@ -1,17 +0,0 @@
1
- /**
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.
5
- *
6
- * @since 1.0.0
7
- */
8
- export * as FridaRpcClient from "./FridaRpcClient.js"
9
-
10
- /**
11
- * Implements a Frida RPC server protocol for effect using the frida script
12
- * exports. The reason we don't use the send/recv script channels is because
13
- * those are shared channels by everybody.
14
- *
15
- * @since 1.0.0
16
- */
17
- export * as FridaRpcServer from "./FridaRpcServer.js"