appium-ios-remotexpc 0.0.3 → 0.0.5

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 (213) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/build/src/base-plist-service.d.ts +51 -0
  3. package/build/src/base-plist-service.d.ts.map +1 -0
  4. package/build/src/base-plist-service.js +61 -0
  5. package/build/src/base-socket-service.d.ts +15 -0
  6. package/build/src/base-socket-service.d.ts.map +1 -0
  7. package/build/src/base-socket-service.js +46 -0
  8. package/build/src/index.d.ts +9 -0
  9. package/build/src/index.d.ts.map +1 -0
  10. package/build/src/index.js +7 -0
  11. package/build/src/lib/apple-tv/constants.d.ts +77 -0
  12. package/build/src/lib/apple-tv/constants.d.ts.map +1 -0
  13. package/build/src/lib/apple-tv/constants.js +106 -0
  14. package/build/src/lib/apple-tv/encryption/chacha20-poly1305.d.ts +22 -0
  15. package/build/src/lib/apple-tv/encryption/chacha20-poly1305.d.ts.map +1 -0
  16. package/build/src/lib/apple-tv/encryption/chacha20-poly1305.js +97 -0
  17. package/build/src/lib/apple-tv/encryption/ed25519.d.ts +16 -0
  18. package/build/src/lib/apple-tv/encryption/ed25519.d.ts.map +1 -0
  19. package/build/src/lib/apple-tv/encryption/ed25519.js +93 -0
  20. package/build/src/lib/apple-tv/encryption/hkdf.d.ts +18 -0
  21. package/build/src/lib/apple-tv/encryption/hkdf.d.ts.map +1 -0
  22. package/build/src/lib/apple-tv/encryption/hkdf.js +73 -0
  23. package/build/src/lib/apple-tv/encryption/index.d.ts +5 -0
  24. package/build/src/lib/apple-tv/encryption/index.d.ts.map +1 -0
  25. package/build/src/lib/apple-tv/encryption/index.js +4 -0
  26. package/build/src/lib/apple-tv/encryption/opack2.d.ts +57 -0
  27. package/build/src/lib/apple-tv/encryption/opack2.d.ts.map +1 -0
  28. package/build/src/lib/apple-tv/encryption/opack2.js +203 -0
  29. package/build/src/lib/apple-tv/errors.d.ts +17 -0
  30. package/build/src/lib/apple-tv/errors.d.ts.map +1 -0
  31. package/build/src/lib/apple-tv/errors.js +30 -0
  32. package/build/src/lib/apple-tv/tlv/decoder.d.ts +19 -0
  33. package/build/src/lib/apple-tv/tlv/decoder.d.ts.map +1 -0
  34. package/build/src/lib/apple-tv/tlv/decoder.js +49 -0
  35. package/build/src/lib/apple-tv/tlv/encoder.d.ts +10 -0
  36. package/build/src/lib/apple-tv/tlv/encoder.d.ts.map +1 -0
  37. package/build/src/lib/apple-tv/tlv/encoder.js +20 -0
  38. package/build/src/lib/apple-tv/tlv/index.d.ts +4 -0
  39. package/build/src/lib/apple-tv/tlv/index.d.ts.map +1 -0
  40. package/build/src/lib/apple-tv/tlv/index.js +3 -0
  41. package/build/src/lib/apple-tv/tlv/pairing-tlv.d.ts +14 -0
  42. package/build/src/lib/apple-tv/tlv/pairing-tlv.d.ts.map +1 -0
  43. package/build/src/lib/apple-tv/tlv/pairing-tlv.js +27 -0
  44. package/build/src/lib/apple-tv/types.d.ts +36 -0
  45. package/build/src/lib/apple-tv/types.d.ts.map +1 -0
  46. package/build/src/lib/apple-tv/types.js +1 -0
  47. package/build/src/lib/apple-tv/utils/buffer-utils.d.ts +40 -0
  48. package/build/src/lib/apple-tv/utils/buffer-utils.d.ts.map +1 -0
  49. package/build/src/lib/apple-tv/utils/buffer-utils.js +76 -0
  50. package/build/src/lib/apple-tv/utils/index.d.ts +3 -0
  51. package/build/src/lib/apple-tv/utils/index.d.ts.map +1 -0
  52. package/build/src/lib/apple-tv/utils/index.js +2 -0
  53. package/build/src/lib/apple-tv/utils/uuid-generator.d.ts +9 -0
  54. package/build/src/lib/apple-tv/utils/uuid-generator.d.ts.map +1 -0
  55. package/build/src/lib/apple-tv/utils/uuid-generator.js +36 -0
  56. package/build/src/lib/lockdown/index.d.ts +87 -0
  57. package/build/src/lib/lockdown/index.d.ts.map +1 -0
  58. package/build/src/lib/lockdown/index.js +324 -0
  59. package/build/src/lib/pair-record/index.d.ts +3 -0
  60. package/build/src/lib/pair-record/index.d.ts.map +1 -0
  61. package/build/src/lib/pair-record/index.js +2 -0
  62. package/build/src/lib/pair-record/pair-record.d.ts +48 -0
  63. package/build/src/lib/pair-record/pair-record.d.ts.map +1 -0
  64. package/build/src/lib/pair-record/pair-record.js +85 -0
  65. package/build/src/lib/plist/binary-plist-creator.d.ts +14 -0
  66. package/build/src/lib/plist/binary-plist-creator.d.ts.map +1 -0
  67. package/build/src/lib/plist/binary-plist-creator.js +475 -0
  68. package/build/src/lib/plist/binary-plist-parser.d.ts +14 -0
  69. package/build/src/lib/plist/binary-plist-parser.d.ts.map +1 -0
  70. package/build/src/lib/plist/binary-plist-parser.js +449 -0
  71. package/build/src/lib/plist/constants.d.ts +36 -0
  72. package/build/src/lib/plist/constants.d.ts.map +1 -0
  73. package/build/src/lib/plist/constants.js +43 -0
  74. package/build/src/lib/plist/index.d.ts +14 -0
  75. package/build/src/lib/plist/index.d.ts.map +1 -0
  76. package/build/src/lib/plist/index.js +16 -0
  77. package/build/src/lib/plist/length-based-splitter.d.ts +43 -0
  78. package/build/src/lib/plist/length-based-splitter.d.ts.map +1 -0
  79. package/build/src/lib/plist/length-based-splitter.js +228 -0
  80. package/build/src/lib/plist/plist-creator.d.ts +8 -0
  81. package/build/src/lib/plist/plist-creator.d.ts.map +1 -0
  82. package/build/src/lib/plist/plist-creator.js +33 -0
  83. package/build/src/lib/plist/plist-decoder.d.ts +25 -0
  84. package/build/src/lib/plist/plist-decoder.d.ts.map +1 -0
  85. package/build/src/lib/plist/plist-decoder.js +103 -0
  86. package/build/src/lib/plist/plist-encoder.d.ts +10 -0
  87. package/build/src/lib/plist/plist-encoder.d.ts.map +1 -0
  88. package/build/src/lib/plist/plist-encoder.js +27 -0
  89. package/build/src/lib/plist/plist-parser.d.ts +9 -0
  90. package/build/src/lib/plist/plist-parser.d.ts.map +1 -0
  91. package/build/src/lib/plist/plist-parser.js +109 -0
  92. package/build/src/lib/plist/plist-service.d.ts +86 -0
  93. package/build/src/lib/plist/plist-service.d.ts.map +1 -0
  94. package/build/src/lib/plist/plist-service.js +180 -0
  95. package/build/src/lib/plist/unified-plist-creator.d.ts +9 -0
  96. package/build/src/lib/plist/unified-plist-creator.d.ts.map +1 -0
  97. package/build/src/lib/plist/unified-plist-creator.js +14 -0
  98. package/build/src/lib/plist/unified-plist-parser.d.ts +8 -0
  99. package/build/src/lib/plist/unified-plist-parser.d.ts.map +1 -0
  100. package/build/src/lib/plist/unified-plist-parser.js +23 -0
  101. package/build/src/lib/plist/utils.d.ts +97 -0
  102. package/build/src/lib/plist/utils.d.ts.map +1 -0
  103. package/build/src/lib/plist/utils.js +287 -0
  104. package/build/src/lib/remote-xpc/constants.d.ts +20 -0
  105. package/build/src/lib/remote-xpc/constants.d.ts.map +1 -0
  106. package/build/src/lib/remote-xpc/constants.js +21 -0
  107. package/build/src/lib/remote-xpc/handshake-frames.d.ts +74 -0
  108. package/build/src/lib/remote-xpc/handshake-frames.d.ts.map +1 -0
  109. package/build/src/lib/remote-xpc/handshake-frames.js +285 -0
  110. package/build/src/lib/remote-xpc/handshake.d.ts +14 -0
  111. package/build/src/lib/remote-xpc/handshake.d.ts.map +1 -0
  112. package/build/src/lib/remote-xpc/handshake.js +95 -0
  113. package/build/src/lib/remote-xpc/remote-xpc-connection.d.ts +55 -0
  114. package/build/src/lib/remote-xpc/remote-xpc-connection.d.ts.map +1 -0
  115. package/build/src/lib/remote-xpc/remote-xpc-connection.js +365 -0
  116. package/build/src/lib/remote-xpc/xpc-protocol.d.ts +22 -0
  117. package/build/src/lib/remote-xpc/xpc-protocol.d.ts.map +1 -0
  118. package/build/src/lib/remote-xpc/xpc-protocol.js +368 -0
  119. package/build/src/lib/tunnel/index.d.ts +69 -0
  120. package/build/src/lib/tunnel/index.d.ts.map +1 -0
  121. package/build/src/lib/tunnel/index.js +205 -0
  122. package/build/src/lib/tunnel/packet-stream-client.d.ts +46 -0
  123. package/build/src/lib/tunnel/packet-stream-client.d.ts.map +1 -0
  124. package/build/src/lib/tunnel/packet-stream-client.js +152 -0
  125. package/build/src/lib/tunnel/packet-stream-server.d.ts +37 -0
  126. package/build/src/lib/tunnel/packet-stream-server.d.ts.map +1 -0
  127. package/build/src/lib/tunnel/packet-stream-server.js +109 -0
  128. package/build/src/lib/tunnel/tunnel-api-client.d.ts +85 -0
  129. package/build/src/lib/tunnel/tunnel-api-client.d.ts.map +1 -0
  130. package/build/src/lib/tunnel/tunnel-api-client.js +207 -0
  131. package/build/src/lib/tunnel/tunnel-registry-server.d.ts +68 -0
  132. package/build/src/lib/tunnel/tunnel-registry-server.d.ts.map +1 -0
  133. package/build/src/lib/tunnel/tunnel-registry-server.js +351 -0
  134. package/build/src/lib/types.d.ts +238 -0
  135. package/build/src/lib/types.d.ts.map +1 -0
  136. package/build/src/lib/types.js +4 -0
  137. package/build/src/lib/usbmux/index.d.ts +177 -0
  138. package/build/src/lib/usbmux/index.d.ts.map +1 -0
  139. package/build/src/lib/usbmux/index.js +490 -0
  140. package/build/src/lib/usbmux/usbmux-decoder.d.ts +19 -0
  141. package/build/src/lib/usbmux/usbmux-decoder.d.ts.map +1 -0
  142. package/build/src/lib/usbmux/usbmux-decoder.js +38 -0
  143. package/build/src/lib/usbmux/usbmux-encoder.d.ts +12 -0
  144. package/build/src/lib/usbmux/usbmux-encoder.d.ts.map +1 -0
  145. package/build/src/lib/usbmux/usbmux-encoder.js +32 -0
  146. package/build/src/service-connection.d.ts +34 -0
  147. package/build/src/service-connection.d.ts.map +1 -0
  148. package/build/src/service-connection.js +51 -0
  149. package/build/src/services/index.d.ts +6 -0
  150. package/build/src/services/index.d.ts.map +1 -0
  151. package/build/src/services/index.js +5 -0
  152. package/build/src/services/ios/base-service.d.ts +35 -0
  153. package/build/src/services/ios/base-service.d.ts.map +1 -0
  154. package/build/src/services/ios/base-service.js +55 -0
  155. package/build/src/services/ios/diagnostic-service/index.d.ts +46 -0
  156. package/build/src/services/ios/diagnostic-service/index.d.ts.map +1 -0
  157. package/build/src/services/ios/diagnostic-service/index.js +169 -0
  158. package/build/src/services/ios/diagnostic-service/keys.d.ts +5 -0
  159. package/build/src/services/ios/diagnostic-service/keys.d.ts.map +1 -0
  160. package/build/src/services/ios/diagnostic-service/keys.js +770 -0
  161. package/build/src/services/ios/syslog-service/index.d.ts +91 -0
  162. package/build/src/services/ios/syslog-service/index.d.ts.map +1 -0
  163. package/build/src/services/ios/syslog-service/index.js +323 -0
  164. package/build/src/services/ios/tunnel-service/index.d.ts +17 -0
  165. package/build/src/services/ios/tunnel-service/index.d.ts.map +1 -0
  166. package/build/src/services/ios/tunnel-service/index.js +57 -0
  167. package/build/src/services.d.ts +14 -0
  168. package/build/src/services.d.ts.map +1 -0
  169. package/build/src/services.js +48 -0
  170. package/package.json +12 -3
  171. package/src/lib/apple-tv/constants.ts +42 -0
  172. package/src/lib/apple-tv/encryption/chacha20-poly1305.ts +147 -0
  173. package/src/lib/apple-tv/encryption/ed25519.ts +126 -0
  174. package/src/lib/apple-tv/encryption/hkdf.ts +95 -0
  175. package/src/lib/apple-tv/encryption/index.ts +11 -0
  176. package/src/lib/apple-tv/encryption/opack2.ts +257 -0
  177. package/.github/dependabot.yml +0 -38
  178. package/.github/workflows/format-check.yml +0 -43
  179. package/.github/workflows/lint-and-build.yml +0 -40
  180. package/.github/workflows/pr-title.yml +0 -16
  181. package/.github/workflows/publish.js.yml +0 -43
  182. package/.github/workflows/test-validation.yml +0 -40
  183. package/.mocharc.json +0 -8
  184. package/.prettierignore +0 -3
  185. package/.prettierrc +0 -17
  186. package/.releaserc +0 -48
  187. package/assets/images/ios-arch.png +0 -0
  188. package/eslint.config.js +0 -45
  189. package/npm-shrinkwrap.json +0 -2711
  190. package/test/integration/diagnostics-test.ts +0 -44
  191. package/test/integration/read-pair-record-test.ts +0 -39
  192. package/test/integration/tunnel-test.ts +0 -104
  193. package/test/unit/apple-tv/tlv/decoder.spec.ts +0 -144
  194. package/test/unit/apple-tv/tlv/encoder.spec.ts +0 -91
  195. package/test/unit/apple-tv/tlv/pairing-tlv.spec.ts +0 -101
  196. package/test/unit/apple-tv/tlv/tlv-integration.spec.ts +0 -146
  197. package/test/unit/apple-tv/utils/buffer-utils.spec.ts +0 -74
  198. package/test/unit/apple-tv/utils/uuid-generator.spec.ts +0 -39
  199. package/test/unit/fixtures/index.ts +0 -88
  200. package/test/unit/fixtures/usbmuxconnectmessage.bin +0 -0
  201. package/test/unit/fixtures/usbmuxlistdevicemessage.bin +0 -0
  202. package/test/unit/plist/error-handling.spec.ts +0 -101
  203. package/test/unit/plist/fixtures/sample.binary.plist +0 -0
  204. package/test/unit/plist/fixtures/sample.xml.plist +0 -38
  205. package/test/unit/plist/plist-parser.spec.ts +0 -283
  206. package/test/unit/plist/plist.spec.ts +0 -205
  207. package/test/unit/plist/tag-position-handling.spec.ts +0 -90
  208. package/test/unit/plist/unified-plist-parser.spec.ts +0 -227
  209. package/test/unit/plist/utils.spec.ts +0 -249
  210. package/test/unit/plist/xml-cleaning.spec.ts +0 -60
  211. package/test/unit/tunnel/tunnel-registry-server.spec.ts +0 -194
  212. package/test/unit/usbmux/usbmux-specs.ts +0 -71
  213. package/tsconfig.json +0 -36
@@ -0,0 +1,180 @@
1
+ import { logger } from '@appium/support';
2
+ import { Socket } from 'net';
3
+ import { TLSSocket } from 'tls';
4
+ import { LengthBasedSplitter } from './length-based-splitter.js';
5
+ import { PlistServiceDecoder } from './plist-decoder.js';
6
+ import { PlistServiceEncoder } from './plist-encoder.js';
7
+ const log = logger.getLogger('Plist');
8
+ const errorLog = logger.getLogger('PlistError');
9
+ const config = {
10
+ verboseErrorLogging: false,
11
+ };
12
+ /**
13
+ * Service for communication using plist protocol
14
+ */
15
+ export class PlistService {
16
+ /**
17
+ * Enable verbose error logging
18
+ */
19
+ static enableVerboseErrorLogging() {
20
+ config.verboseErrorLogging = true;
21
+ errorLog.debug('Verbose plist error logging enabled');
22
+ }
23
+ /**
24
+ * Disable verbose error logging
25
+ */
26
+ static disableVerboseErrorLogging() {
27
+ config.verboseErrorLogging = false;
28
+ }
29
+ /**
30
+ * Check if verbose error logging is enabled
31
+ * @returns True if verbose error logging is enabled
32
+ */
33
+ static isVerboseErrorLoggingEnabled() {
34
+ return config.verboseErrorLogging;
35
+ }
36
+ /**
37
+ * Gets the underlying socket
38
+ * @returns The socket used by this service
39
+ */
40
+ getSocket() {
41
+ return this._socket;
42
+ }
43
+ _socket;
44
+ _splitter;
45
+ _decoder;
46
+ _encoder;
47
+ _messageQueue;
48
+ /**
49
+ * Creates a new PlistService instance
50
+ * @param socket The socket to use for communication
51
+ * @param options Configuration options
52
+ */
53
+ constructor(socket, options = {}) {
54
+ this._socket = socket;
55
+ // Set up transformers
56
+ this._splitter = new LengthBasedSplitter({
57
+ maxFrameLength: options.maxFrameLength ?? 100 * 1024 * 1024, // Default to 100MB
58
+ });
59
+ this._decoder = new PlistServiceDecoder();
60
+ this._encoder = new PlistServiceEncoder();
61
+ // Set up the pipeline
62
+ this.setupPipeline();
63
+ // Message queue for async receiving
64
+ this._messageQueue = [];
65
+ this._decoder.on('data', (data) => this._messageQueue.push(data));
66
+ // Handle errors
67
+ this.setupErrorHandlers();
68
+ }
69
+ /**
70
+ * Send a plist message and receive a response
71
+ * @param data Message to send
72
+ * @param timeout Response timeout in ms
73
+ * @returns Promise resolving to the received message
74
+ */
75
+ async sendPlistAndReceive(data, timeout = 5000) {
76
+ this.sendPlist(data);
77
+ return this.receivePlist(timeout);
78
+ }
79
+ /**
80
+ * Send a plist message
81
+ * @param data Message to send
82
+ * @throws Error if data is null or undefined
83
+ */
84
+ sendPlist(data) {
85
+ if (!data) {
86
+ throw new Error('Cannot send null or undefined data');
87
+ }
88
+ this._encoder.write(data);
89
+ }
90
+ /**
91
+ * Receive a plist message with timeout
92
+ * @param timeout Timeout in ms
93
+ * @returns Promise resolving to the received message
94
+ * @throws Error if timeout is reached before receiving a message
95
+ */
96
+ async receivePlist(timeout = 5000) {
97
+ return new Promise((resolve, reject) => {
98
+ // Check if we already have a message
99
+ const message = this._messageQueue.shift();
100
+ if (message) {
101
+ return resolve(message);
102
+ }
103
+ // Set up a check interval
104
+ const checkInterval = setInterval(() => {
105
+ const message = this._messageQueue.shift();
106
+ if (message) {
107
+ clearInterval(checkInterval);
108
+ clearTimeout(timeoutId);
109
+ resolve(message);
110
+ }
111
+ }, 50);
112
+ // Set up timeout
113
+ const timeoutId = setTimeout(() => {
114
+ clearInterval(checkInterval);
115
+ reject(new Error(`Timed out waiting for plist response after ${timeout}ms`));
116
+ }, timeout);
117
+ });
118
+ }
119
+ /**
120
+ * Close the connection and clean up resources
121
+ */
122
+ close() {
123
+ try {
124
+ // Remove all data listeners to prevent parsing during close
125
+ this._splitter.removeAllListeners();
126
+ this._decoder.removeAllListeners();
127
+ // Clear the message queue to prevent processing during close
128
+ this._messageQueue = [];
129
+ // Unpipe the transformers to prevent data flow during close
130
+ try {
131
+ this._socket.unpipe(this._splitter);
132
+ this._splitter.unpipe(this._decoder);
133
+ }
134
+ catch (unpipeError) {
135
+ log.debug(`Non-critical error during unpipe: ${unpipeError instanceof Error ? unpipeError.message : String(unpipeError)}`);
136
+ }
137
+ // End the socket
138
+ this._socket.end();
139
+ }
140
+ catch (error) {
141
+ // Log the error but don't rethrow it to ensure cleanup completes
142
+ log.error(`Error closing socket: ${error instanceof Error ? error.message : String(error)}`);
143
+ // If ending fails, destroy the socket
144
+ this._socket.destroy();
145
+ }
146
+ }
147
+ /**
148
+ * Sets up the data pipeline between socket and transformers
149
+ */
150
+ setupPipeline() {
151
+ this._socket.pipe(this._splitter);
152
+ this._splitter.pipe(this._decoder);
153
+ this._encoder.pipe(this._socket);
154
+ }
155
+ /**
156
+ * Sets up error handlers for socket and transformers
157
+ */
158
+ setupErrorHandlers() {
159
+ this._socket.on('error', this.handleError.bind(this));
160
+ this._encoder.on('error', this.handleError.bind(this));
161
+ this._decoder.on('error', this.handleError.bind(this));
162
+ this._splitter.on('error', this.handleError.bind(this));
163
+ }
164
+ /**
165
+ * Handles errors from any component
166
+ * @param error The error that occurred
167
+ */
168
+ handleError(error) {
169
+ // Only log detailed errors if verbose logging is enabled
170
+ if (!config.verboseErrorLogging) {
171
+ return;
172
+ }
173
+ errorLog.debug(`PlistService Error: ${error.message}`);
174
+ // If this is an XML parsing error, it might be a binary plist
175
+ if (error.message.includes('Invalid XML') ||
176
+ error.message.includes('XML parsing')) {
177
+ errorLog.debug('This might be a binary plist with a non-standard format');
178
+ }
179
+ }
180
+ }
@@ -0,0 +1,9 @@
1
+ import type { PlistDictionary } from '../types.js';
2
+ /**
3
+ * Unified plist creator that can create both XML and binary plists
4
+ * @param obj - The JavaScript object to convert to a plist
5
+ * @param binary - Whether to create a binary plist (true) or XML plist (false)
6
+ * @returns The plist data as a string (XML) or Buffer (binary)
7
+ */
8
+ export declare function createPlist(obj: PlistDictionary, binary?: boolean): string | Buffer;
9
+ //# sourceMappingURL=unified-plist-creator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unified-plist-creator.d.ts","sourceRoot":"","sources":["../../../../src/lib/plist/unified-plist-creator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAInD;;;;;GAKG;AACH,wBAAgB,WAAW,CACzB,GAAG,EAAE,eAAe,EACpB,MAAM,GAAE,OAAe,GACtB,MAAM,GAAG,MAAM,CAKjB"}
@@ -0,0 +1,14 @@
1
+ import { createBinaryPlist } from './binary-plist-creator.js';
2
+ import { createPlist as createXmlPlist } from './plist-creator.js';
3
+ /**
4
+ * Unified plist creator that can create both XML and binary plists
5
+ * @param obj - The JavaScript object to convert to a plist
6
+ * @param binary - Whether to create a binary plist (true) or XML plist (false)
7
+ * @returns The plist data as a string (XML) or Buffer (binary)
8
+ */
9
+ export function createPlist(obj, binary = false) {
10
+ if (binary) {
11
+ return createBinaryPlist(obj);
12
+ }
13
+ return createXmlPlist(obj);
14
+ }
@@ -0,0 +1,8 @@
1
+ import type { PlistValue } from '../types.js';
2
+ /**
3
+ * Unified plist parser that can handle both XML and binary plists
4
+ * @param data - The plist data as a string or Buffer
5
+ * @returns The parsed JavaScript object
6
+ */
7
+ export declare function parsePlist(data: string | Buffer): PlistValue;
8
+ //# sourceMappingURL=unified-plist-parser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unified-plist-parser.d.ts","sourceRoot":"","sources":["../../../../src/lib/plist/unified-plist-parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAK9C;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,UAAU,CAc5D"}
@@ -0,0 +1,23 @@
1
+ import { isBinaryPlist, parseBinaryPlist } from './binary-plist-parser.js';
2
+ import { parsePlist as parseXmlPlist } from './plist-parser.js';
3
+ import { ensureString } from './utils.js';
4
+ /**
5
+ * Unified plist parser that can handle both XML and binary plists
6
+ * @param data - The plist data as a string or Buffer
7
+ * @returns The parsed JavaScript object
8
+ */
9
+ export function parsePlist(data) {
10
+ try {
11
+ // Check if it's a binary plist (only if data is a Buffer)
12
+ if (Buffer.isBuffer(data) && isBinaryPlist(data)) {
13
+ return parseBinaryPlist(data);
14
+ }
15
+ else {
16
+ // Otherwise, assume it's an XML plist
17
+ return parseXmlPlist(ensureString(data));
18
+ }
19
+ }
20
+ catch (error) {
21
+ throw new Error(`Failed to parse plist: ${error instanceof Error ? error.message : String(error)}`);
22
+ }
23
+ }
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Represents a tag position in XML
3
+ */
4
+ export interface TagPosition {
5
+ start: number;
6
+ end: number;
7
+ isOpening: boolean;
8
+ tagName: string;
9
+ }
10
+ /**
11
+ * Represents the result of finding tags around a position
12
+ */
13
+ export interface TagsAroundPosition {
14
+ beforeTag: TagPosition | null;
15
+ afterTag: TagPosition | null;
16
+ }
17
+ /**
18
+ * Ensures data is a string for string operations
19
+ *
20
+ * @param data - The data to convert, can be a string or Buffer
21
+ * @returns The data as a string
22
+ */
23
+ export declare function ensureString(data: string | Buffer): string;
24
+ /**
25
+ * Finds the position of the first Unicode replacement character in the data.
26
+ *
27
+ * @param data - The data to check, can be a string or Buffer
28
+ * @returns The position of the first replacement character, or -1 if not found
29
+ */
30
+ export declare function findFirstReplacementCharacter(data: string | Buffer): number;
31
+ /**
32
+ * Checks if the provided data contains Unicode replacement characters (�),
33
+ * which might indicate encoding issues.
34
+ *
35
+ * @param data - The data to check, can be a string or Buffer
36
+ * @returns True if replacement characters are found, false otherwise
37
+ */
38
+ export declare function hasUnicodeReplacementCharacter(data: string | Buffer): boolean;
39
+ /**
40
+ * Finds the XML declaration and trims any preceding content
41
+ *
42
+ * @param data - The data to process, can be a string or Buffer
43
+ * @returns The trimmed data as a string
44
+ */
45
+ export declare function trimBeforeXmlDeclaration(data: string | Buffer): string;
46
+ /**
47
+ * Checks for multiple XML declarations and fixes the data by keeping only the first one
48
+ *
49
+ * @param data - The data to check and fix, can be a string or Buffer
50
+ * @returns The fixed data as a string, or the original data if no fix was needed
51
+ */
52
+ export declare function fixMultipleXmlDeclarations(data: string | Buffer): string;
53
+ /**
54
+ * Removes extra content after the closing plist tag
55
+ *
56
+ * @param data - The data to clean, can be a string or Buffer
57
+ * @returns The cleaned data as a string
58
+ */
59
+ export declare function removeExtraContentAfterPlist(data: string | Buffer): string;
60
+ /**
61
+ * Checks if the data is valid XML (contains at least one tag)
62
+ *
63
+ * @param data - The data to check, can be a string or Buffer
64
+ * @returns True if the data is valid XML, false otherwise
65
+ */
66
+ export declare function isValidXml(data: string | Buffer): boolean;
67
+ /**
68
+ * Escapes special XML characters in a string
69
+ *
70
+ * @param str - The string to escape
71
+ * @returns The escaped string
72
+ */
73
+ export declare function escapeXml(str: string): string;
74
+ /**
75
+ * Checks if the data contains XML plist content by detecting XML declaration or plist tags
76
+ *
77
+ * @param data - The data to check, can be a string or Buffer
78
+ * @returns True if the data contains XML plist content, false otherwise
79
+ */
80
+ export declare function isXmlPlistContent(data: string | Buffer): boolean;
81
+ /**
82
+ * Finds XML tags around a specific position
83
+ *
84
+ * @param xmlString - The XML string to search
85
+ * @param position - The position to search around
86
+ * @returns An object with the nearest tags before and after the position
87
+ */
88
+ export declare function findTagsAroundPosition(xmlString: string, position: number): TagsAroundPosition;
89
+ /**
90
+ * Intelligently cleans XML with Unicode replacement characters
91
+ *
92
+ * @param xmlString - The XML string to clean
93
+ * @param badCharPos - The position of the replacement character
94
+ * @returns The cleaned XML string
95
+ */
96
+ export declare function cleanXmlWithReplacementChar(xmlString: string, badCharPos: number): string;
97
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/lib/plist/utils.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,WAAW,GAAG,IAAI,CAAC;IAC9B,QAAQ,EAAE,WAAW,GAAG,IAAI,CAAC;CAC9B;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAE1D;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAG3E;AAED;;;;;;GAMG;AACH,wBAAgB,8BAA8B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAI7E;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAStE;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAaxE;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAU1E;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAGzD;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAkB7C;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAKhE;AA6FD;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,GACf,kBAAkB,CAKpB;AAgFD;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CACzC,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,GACjB,MAAM,CAmBR"}
@@ -0,0 +1,287 @@
1
+ import { UTF8_ENCODING } from './constants.js';
2
+ /**
3
+ * Ensures data is a string for string operations
4
+ *
5
+ * @param data - The data to convert, can be a string or Buffer
6
+ * @returns The data as a string
7
+ */
8
+ export function ensureString(data) {
9
+ return typeof data === 'string' ? data : data.toString(UTF8_ENCODING);
10
+ }
11
+ /**
12
+ * Finds the position of the first Unicode replacement character in the data.
13
+ *
14
+ * @param data - The data to check, can be a string or Buffer
15
+ * @returns The position of the first replacement character, or -1 if not found
16
+ */
17
+ export function findFirstReplacementCharacter(data) {
18
+ const strData = ensureString(data);
19
+ return strData.indexOf('�');
20
+ }
21
+ /**
22
+ * Checks if the provided data contains Unicode replacement characters (�),
23
+ * which might indicate encoding issues.
24
+ *
25
+ * @param data - The data to check, can be a string or Buffer
26
+ * @returns True if replacement characters are found, false otherwise
27
+ */
28
+ export function hasUnicodeReplacementCharacter(data) {
29
+ const strData = ensureString(data);
30
+ return strData.includes('�');
31
+ }
32
+ /**
33
+ * Finds the XML declaration and trims any preceding content
34
+ *
35
+ * @param data - The data to process, can be a string or Buffer
36
+ * @returns The trimmed data as a string
37
+ */
38
+ export function trimBeforeXmlDeclaration(data) {
39
+ const strData = ensureString(data);
40
+ const xmlDeclIndex = strData.indexOf('<?xml');
41
+ if (xmlDeclIndex > 0) {
42
+ return strData.slice(xmlDeclIndex);
43
+ }
44
+ return strData;
45
+ }
46
+ /**
47
+ * Checks for multiple XML declarations and fixes the data by keeping only the first one
48
+ *
49
+ * @param data - The data to check and fix, can be a string or Buffer
50
+ * @returns The fixed data as a string, or the original data if no fix was needed
51
+ */
52
+ export function fixMultipleXmlDeclarations(data) {
53
+ const strData = ensureString(data);
54
+ const xmlDeclMatches = strData.match(/(<\?xml[^>]*\?>)/g) || [];
55
+ const xmlDeclCount = xmlDeclMatches.length;
56
+ if (xmlDeclCount > 1) {
57
+ const firstDeclEnd = strData.indexOf('?>') + 2;
58
+ const restOfXml = strData.substring(firstDeclEnd);
59
+ const cleanedRest = restOfXml.replace(/<\?xml[^>]*\?>/g, '');
60
+ return strData.substring(0, firstDeclEnd) + cleanedRest;
61
+ }
62
+ return strData;
63
+ }
64
+ /**
65
+ * Removes extra content after the closing plist tag
66
+ *
67
+ * @param data - The data to clean, can be a string or Buffer
68
+ * @returns The cleaned data as a string
69
+ */
70
+ export function removeExtraContentAfterPlist(data) {
71
+ const strData = ensureString(data);
72
+ const closingPlistIndex = strData.lastIndexOf('</plist>');
73
+ if (closingPlistIndex > 0) {
74
+ return strData.substring(0, closingPlistIndex + 8);
75
+ }
76
+ return strData;
77
+ }
78
+ /**
79
+ * Checks if the data is valid XML (contains at least one tag)
80
+ *
81
+ * @param data - The data to check, can be a string or Buffer
82
+ * @returns True if the data is valid XML, false otherwise
83
+ */
84
+ export function isValidXml(data) {
85
+ const strData = ensureString(data);
86
+ return Boolean(strData) && Boolean(strData.trim()) && strData.includes('<');
87
+ }
88
+ /**
89
+ * Escapes special XML characters in a string
90
+ *
91
+ * @param str - The string to escape
92
+ * @returns The escaped string
93
+ */
94
+ export function escapeXml(str) {
95
+ return str.replace(/[<>&"']/g, function (c) {
96
+ switch (c) {
97
+ case '<':
98
+ return '&lt;';
99
+ case '>':
100
+ return '&gt;';
101
+ case '&':
102
+ return '&amp;';
103
+ case '"':
104
+ return '&quot;';
105
+ // eslint-disable-next-line quotes -- Prettier uses double quotes here to avoid escaping the single quote character
106
+ case `'`:
107
+ return '&apos;';
108
+ default:
109
+ return c;
110
+ }
111
+ });
112
+ }
113
+ /**
114
+ * Checks if the data contains XML plist content by detecting XML declaration or plist tags
115
+ *
116
+ * @param data - The data to check, can be a string or Buffer
117
+ * @returns True if the data contains XML plist content, false otherwise
118
+ */
119
+ export function isXmlPlistContent(data) {
120
+ return (data.toString(UTF8_ENCODING).includes('<?xml') ||
121
+ data.toString(UTF8_ENCODING).includes('<plist'));
122
+ }
123
+ /**
124
+ * Parses a tag content to extract tag name and determine if it's an opening tag
125
+ *
126
+ * @param tagContent - The content between < and > in an XML tag
127
+ * @returns An object with tag name and whether it's an opening tag
128
+ */
129
+ function parseTagContent(tagContent) {
130
+ const isClosing = tagContent.startsWith('/');
131
+ const tagName = isClosing
132
+ ? tagContent.substring(1).trim().split(/\s+/)[0]
133
+ : tagContent.trim().split(/\s+/)[0];
134
+ return {
135
+ tagName,
136
+ isOpening: !isClosing,
137
+ };
138
+ }
139
+ /**
140
+ * Creates a TagPosition object from tag positions and content
141
+ *
142
+ * @param startPos - Start position of the tag
143
+ * @param endPos - End position of the tag
144
+ * @param tagContent - Content between < and > in the tag
145
+ * @returns A TagPosition object
146
+ */
147
+ function createTagPosition(startPos, endPos, tagContent) {
148
+ const { tagName, isOpening } = parseTagContent(tagContent);
149
+ return {
150
+ start: startPos,
151
+ end: endPos + 1,
152
+ isOpening,
153
+ tagName,
154
+ };
155
+ }
156
+ /**
157
+ * Finds the tag before a specific position in XML
158
+ *
159
+ * @param xmlString - The XML string to search
160
+ * @param position - The position to search before
161
+ * @returns The tag position or null if not found
162
+ */
163
+ function findTagBefore(xmlString, position) {
164
+ const tagEndPos = xmlString.lastIndexOf('>', position);
165
+ if (tagEndPos < 0) {
166
+ return null;
167
+ }
168
+ const tagStartPos = xmlString.lastIndexOf('<', tagEndPos);
169
+ if (tagStartPos < 0) {
170
+ return null;
171
+ }
172
+ const tagContent = xmlString.substring(tagStartPos + 1, tagEndPos);
173
+ return createTagPosition(tagStartPos, tagEndPos, tagContent);
174
+ }
175
+ /**
176
+ * Finds the tag after a specific position in XML
177
+ *
178
+ * @param xmlString - The XML string to search
179
+ * @param position - The position to search after
180
+ * @returns The tag position or null if not found
181
+ */
182
+ function findTagAfter(xmlString, position) {
183
+ const tagStartPos = xmlString.indexOf('<', position);
184
+ if (tagStartPos < 0) {
185
+ return null;
186
+ }
187
+ const tagEndPos = xmlString.indexOf('>', tagStartPos);
188
+ if (tagEndPos < 0) {
189
+ return null;
190
+ }
191
+ const tagContent = xmlString.substring(tagStartPos + 1, tagEndPos);
192
+ return createTagPosition(tagStartPos, tagEndPos, tagContent);
193
+ }
194
+ /**
195
+ * Finds XML tags around a specific position
196
+ *
197
+ * @param xmlString - The XML string to search
198
+ * @param position - The position to search around
199
+ * @returns An object with the nearest tags before and after the position
200
+ */
201
+ export function findTagsAroundPosition(xmlString, position) {
202
+ return {
203
+ beforeTag: findTagBefore(xmlString, position),
204
+ afterTag: findTagAfter(xmlString, position),
205
+ };
206
+ }
207
+ /**
208
+ * Removes content between two positions in an XML string
209
+ *
210
+ * @param xmlString - The XML string to modify
211
+ * @param startPos - The start position to remove from
212
+ * @param endPos - The end position to remove to
213
+ * @returns The modified XML string
214
+ */
215
+ function removeContentBetween(xmlString, startPos, endPos) {
216
+ return xmlString.substring(0, startPos) + xmlString.substring(endPos);
217
+ }
218
+ /**
219
+ * Handles the case where a replacement character is between complete tags
220
+ *
221
+ * @param xmlString - The XML string to clean
222
+ * @param beforeTag - The tag before the replacement character
223
+ * @param afterTag - The tag after the replacement character
224
+ * @returns The cleaned XML string
225
+ */
226
+ function cleanBetweenTags(xmlString, beforeTag, afterTag) {
227
+ return removeContentBetween(xmlString, beforeTag.end, afterTag.start);
228
+ }
229
+ /**
230
+ * Handles the case where a replacement character is inside a tag
231
+ *
232
+ * @param xmlString - The XML string to clean
233
+ * @param beforeTag - The tag containing the replacement character
234
+ * @param afterTag - The tag after the replacement character
235
+ * @returns The cleaned XML string or null if can't be cleaned
236
+ */
237
+ function cleanInsideTag(xmlString, beforeTag, afterTag) {
238
+ const prevCompleteTag = xmlString.lastIndexOf('>', beforeTag.start);
239
+ if (prevCompleteTag < 0) {
240
+ return null;
241
+ }
242
+ return removeContentBetween(xmlString, prevCompleteTag + 1, afterTag.start);
243
+ }
244
+ /**
245
+ * Fallback cleaning method when tags aren't available on both sides
246
+ *
247
+ * @param xmlString - The XML string to clean
248
+ * @returns The cleaned XML string
249
+ */
250
+ function fallbackCleaning(xmlString) {
251
+ const xmlDeclIndex = xmlString.indexOf('<?xml');
252
+ if (xmlDeclIndex > 0) {
253
+ return xmlString.slice(xmlDeclIndex);
254
+ }
255
+ const plistTagIndex = xmlString.indexOf('<plist');
256
+ if (plistTagIndex > 0) {
257
+ return xmlString.slice(plistTagIndex);
258
+ }
259
+ const anyTagIndex = xmlString.indexOf('<');
260
+ if (anyTagIndex > 0) {
261
+ return xmlString.slice(anyTagIndex);
262
+ }
263
+ return xmlString;
264
+ }
265
+ /**
266
+ * Intelligently cleans XML with Unicode replacement characters
267
+ *
268
+ * @param xmlString - The XML string to clean
269
+ * @param badCharPos - The position of the replacement character
270
+ * @returns The cleaned XML string
271
+ */
272
+ export function cleanXmlWithReplacementChar(xmlString, badCharPos) {
273
+ const { beforeTag, afterTag } = findTagsAroundPosition(xmlString, badCharPos);
274
+ if (!beforeTag || !afterTag) {
275
+ return fallbackCleaning(xmlString);
276
+ }
277
+ if (beforeTag.end <= badCharPos && badCharPos < afterTag.start) {
278
+ return cleanBetweenTags(xmlString, beforeTag, afterTag);
279
+ }
280
+ if (beforeTag.start <= badCharPos && badCharPos < beforeTag.end) {
281
+ const cleaned = cleanInsideTag(xmlString, beforeTag, afterTag);
282
+ if (cleaned) {
283
+ return cleaned;
284
+ }
285
+ }
286
+ return removeContentBetween(xmlString, beforeTag.start, afterTag.start);
287
+ }
@@ -0,0 +1,20 @@
1
+ export declare const Http2Constants: {
2
+ readonly HTTP2_MAGIC: Buffer<ArrayBuffer>;
3
+ readonly FRAME_HEADER_SIZE: 9;
4
+ readonly ROOT_CHANNEL: 1;
5
+ readonly REPLY_CHANNEL: 3;
6
+ readonly FLAG_END_HEADERS: 4;
7
+ readonly FLAG_ACK: 1;
8
+ readonly DEFAULT_SETTINGS_MAX_CONCURRENT_STREAMS: 100;
9
+ readonly DEFAULT_SETTINGS_INITIAL_WINDOW_SIZE: 1048576;
10
+ readonly DEFAULT_WIN_SIZE_INCR: 983041;
11
+ readonly SETTINGS_MAX_CONCURRENT_STREAMS: 3;
12
+ readonly SETTINGS_INITIAL_WINDOW_SIZE: 4;
13
+ };
14
+ export declare const XpcConstants: {
15
+ readonly XPC_FLAGS_INIT_HANDSHAKE: 4194304;
16
+ readonly XPC_FLAGS_ALWAYS_SET: 1;
17
+ readonly XPC_FLAGS_DATA_PRESENT: 256;
18
+ readonly XPC_FLAGS_WANTING_REPLY: 65536;
19
+ };
20
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../src/lib/remote-xpc/constants.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,cAAc;;;;;;;;;;;;CAYjB,CAAC;AAGX,eAAO,MAAM,YAAY;;;;;CAKf,CAAC"}
@@ -0,0 +1,21 @@
1
+ // HTTP/2 Constants
2
+ export const Http2Constants = {
3
+ HTTP2_MAGIC: Buffer.from('PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n', 'ascii'),
4
+ FRAME_HEADER_SIZE: 9,
5
+ ROOT_CHANNEL: 1,
6
+ REPLY_CHANNEL: 3,
7
+ FLAG_END_HEADERS: 0x4,
8
+ FLAG_ACK: 0x1,
9
+ DEFAULT_SETTINGS_MAX_CONCURRENT_STREAMS: 100,
10
+ DEFAULT_SETTINGS_INITIAL_WINDOW_SIZE: 1048576,
11
+ DEFAULT_WIN_SIZE_INCR: 983041,
12
+ SETTINGS_MAX_CONCURRENT_STREAMS: 0x03,
13
+ SETTINGS_INITIAL_WINDOW_SIZE: 0x04,
14
+ };
15
+ // XPC Constants
16
+ export const XpcConstants = {
17
+ XPC_FLAGS_INIT_HANDSHAKE: 0x00400000,
18
+ XPC_FLAGS_ALWAYS_SET: 0x00000001,
19
+ XPC_FLAGS_DATA_PRESENT: 0x00000100,
20
+ XPC_FLAGS_WANTING_REPLY: 0x00010000,
21
+ };