react-native-update-cli 2.24.1 → 2.25.0

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 (95) hide show
  1. package/README.md +11 -4
  2. package/README.zh-CN.md +11 -4
  3. package/cli.json +7 -1
  4. package/lib/api.d.ts +2 -0
  5. package/lib/api.js +63 -18
  6. package/lib/app.js +25 -3
  7. package/lib/bin.js +39 -45
  8. package/lib/bundle-runner.d.ts +27 -0
  9. package/lib/bundle-runner.js +240 -21
  10. package/lib/bundle.d.ts +1 -1
  11. package/lib/bundle.js +19 -6
  12. package/lib/commands.d.ts +6 -0
  13. package/lib/commands.js +65 -0
  14. package/lib/locales/en.d.ts +5 -14
  15. package/lib/locales/en.js +5 -14
  16. package/lib/locales/zh.d.ts +5 -13
  17. package/lib/locales/zh.js +5 -13
  18. package/lib/package.js +4 -0
  19. package/lib/provider.d.ts +1 -1
  20. package/lib/provider.js +3 -1
  21. package/lib/symbolicate.js +11 -3
  22. package/lib/types.d.ts +1 -0
  23. package/lib/user.js +6 -0
  24. package/lib/utils/add-gitignore.js +7 -1
  25. package/lib/utils/dep-versions.d.ts +7 -0
  26. package/lib/utils/dep-versions.js +78 -26
  27. package/lib/utils/git.js +9 -6
  28. package/lib/utils/hermes-base.js +2 -1
  29. package/lib/utils/i18n.d.ts +5 -0
  30. package/lib/utils/i18n.js +14 -1
  31. package/lib/utils/index.d.ts +2 -1
  32. package/lib/utils/index.js +9 -4
  33. package/lib/utils/latest-version/index.js +8 -0
  34. package/lib/utils/runtime.d.ts +21 -0
  35. package/lib/utils/runtime.js +138 -5
  36. package/lib/utils/slim-sourcemap.d.ts +11 -0
  37. package/lib/utils/slim-sourcemap.js +22 -0
  38. package/lib/utils/zip-range.js +3 -2
  39. package/lib/versions.js +16 -15
  40. package/package.json +4 -2
  41. package/lib/index.d.ts +0 -1
  42. package/lib/index.js +0 -17
  43. package/src/api.ts +0 -470
  44. package/src/app.ts +0 -241
  45. package/src/auto-update.ts +0 -647
  46. package/src/bin-cresc.ts +0 -8
  47. package/src/bin.ts +0 -115
  48. package/src/bundle-pack.ts +0 -61
  49. package/src/bundle-runner.ts +0 -1430
  50. package/src/bundle.ts +0 -371
  51. package/src/cache.ts +0 -20
  52. package/src/diff.ts +0 -1010
  53. package/src/exports.ts +0 -17
  54. package/src/index.ts +0 -1
  55. package/src/install.ts +0 -50
  56. package/src/locales/en.ts +0 -257
  57. package/src/locales/zh.ts +0 -234
  58. package/src/native-package.ts +0 -338
  59. package/src/package.ts +0 -482
  60. package/src/provider.ts +0 -294
  61. package/src/symbolicate.ts +0 -159
  62. package/src/types.ts +0 -150
  63. package/src/user.ts +0 -39
  64. package/src/utils/add-gitignore.ts +0 -35
  65. package/src/utils/app-info-parser/aab.ts +0 -241
  66. package/src/utils/app-info-parser/apk.ts +0 -92
  67. package/src/utils/app-info-parser/app.ts +0 -7
  68. package/src/utils/app-info-parser/index.ts +0 -54
  69. package/src/utils/app-info-parser/ipa.ts +0 -109
  70. package/src/utils/app-info-parser/resource-finder.ts +0 -508
  71. package/src/utils/app-info-parser/utils.ts +0 -161
  72. package/src/utils/app-info-parser/xml-parser/binary.ts +0 -693
  73. package/src/utils/app-info-parser/xml-parser/manifest.ts +0 -228
  74. package/src/utils/app-info-parser/zip.ts +0 -108
  75. package/src/utils/check-lockfile.ts +0 -93
  76. package/src/utils/check-plugin.ts +0 -38
  77. package/src/utils/command-result.ts +0 -24
  78. package/src/utils/constants.ts +0 -25
  79. package/src/utils/dep-versions.ts +0 -83
  80. package/src/utils/git.ts +0 -71
  81. package/src/utils/hbcTransform.ts +0 -649
  82. package/src/utils/hermes-base.ts +0 -1137
  83. package/src/utils/http-helper.ts +0 -152
  84. package/src/utils/i18n.ts +0 -39
  85. package/src/utils/index.ts +0 -698
  86. package/src/utils/latest-version/index.ts +0 -573
  87. package/src/utils/options.ts +0 -78
  88. package/src/utils/plugin-config.ts +0 -32
  89. package/src/utils/runtime.ts +0 -187
  90. package/src/utils/slim-sourcemap.ts +0 -83
  91. package/src/utils/zip-entries.ts +0 -209
  92. package/src/utils/zip-options.ts +0 -178
  93. package/src/utils/zip-range.ts +0 -727
  94. package/src/utils/zip-raw-writer.ts +0 -247
  95. package/src/versions.ts +0 -894
@@ -1,693 +0,0 @@
1
- // From https://github.com/openstf/adbkit-apkreader
2
- const NodeType = {
3
- ELEMENT_NODE: 1,
4
- ATTRIBUTE_NODE: 2,
5
- CDATA_SECTION_NODE: 4,
6
- };
7
-
8
- const ChunkType = {
9
- NULL: 0x0000,
10
- STRING_POOL: 0x0001,
11
- TABLE: 0x0002,
12
- XML: 0x0003,
13
- XML_FIRST_CHUNK: 0x0100,
14
- XML_START_NAMESPACE: 0x0100,
15
- XML_END_NAMESPACE: 0x0101,
16
- XML_START_ELEMENT: 0x0102,
17
- XML_END_ELEMENT: 0x0103,
18
- XML_CDATA: 0x0104,
19
- XML_LAST_CHUNK: 0x017f,
20
- XML_RESOURCE_MAP: 0x0180,
21
- TABLE_PACKAGE: 0x0200,
22
- TABLE_TYPE: 0x0201,
23
- TABLE_TYPE_SPEC: 0x0202,
24
- };
25
-
26
- const StringFlags = {
27
- SORTED: 1 << 0,
28
- UTF8: 1 << 8,
29
- };
30
-
31
- // Taken from android.util.TypedValue
32
- const TypedValue = {
33
- COMPLEX_MANTISSA_MASK: 0x00ffffff,
34
- COMPLEX_MANTISSA_SHIFT: 0x00000008,
35
- COMPLEX_RADIX_0p23: 0x00000003,
36
- COMPLEX_RADIX_16p7: 0x00000001,
37
- COMPLEX_RADIX_23p0: 0x00000000,
38
- COMPLEX_RADIX_8p15: 0x00000002,
39
- COMPLEX_RADIX_MASK: 0x00000003,
40
- COMPLEX_RADIX_SHIFT: 0x00000004,
41
- COMPLEX_UNIT_DIP: 0x00000001,
42
- COMPLEX_UNIT_FRACTION: 0x00000000,
43
- COMPLEX_UNIT_FRACTION_PARENT: 0x00000001,
44
- COMPLEX_UNIT_IN: 0x00000004,
45
- COMPLEX_UNIT_MASK: 0x0000000f,
46
- COMPLEX_UNIT_MM: 0x00000005,
47
- COMPLEX_UNIT_PT: 0x00000003,
48
- COMPLEX_UNIT_PX: 0x00000000,
49
- COMPLEX_UNIT_SHIFT: 0x00000000,
50
- COMPLEX_UNIT_SP: 0x00000002,
51
- DENSITY_DEFAULT: 0x00000000,
52
- DENSITY_NONE: 0x0000ffff,
53
- TYPE_ATTRIBUTE: 0x00000002,
54
- TYPE_DIMENSION: 0x00000005,
55
- TYPE_FIRST_COLOR_INT: 0x0000001c,
56
- TYPE_FIRST_INT: 0x00000010,
57
- TYPE_FLOAT: 0x00000004,
58
- TYPE_FRACTION: 0x00000006,
59
- TYPE_INT_BOOLEAN: 0x00000012,
60
- TYPE_INT_COLOR_ARGB4: 0x0000001e,
61
- TYPE_INT_COLOR_ARGB8: 0x0000001c,
62
- TYPE_INT_COLOR_RGB4: 0x0000001f,
63
- TYPE_INT_COLOR_RGB8: 0x0000001d,
64
- TYPE_INT_DEC: 0x00000010,
65
- TYPE_INT_HEX: 0x00000011,
66
- TYPE_LAST_COLOR_INT: 0x0000001f,
67
- TYPE_LAST_INT: 0x0000001f,
68
- TYPE_NULL: 0x00000000,
69
- TYPE_REFERENCE: 0x00000001,
70
- TYPE_STRING: 0x00000003,
71
- };
72
-
73
- type BinaryXmlParserOptions = {
74
- debug?: boolean;
75
- };
76
-
77
- export class BinaryXmlParser {
78
- buffer: Buffer;
79
- cursor = 0;
80
- strings: string[] = [];
81
- resources: number[] = [];
82
- document: any = null;
83
- parent: any = null;
84
- stack: any[] = [];
85
- debug: boolean;
86
-
87
- constructor(buffer: Buffer, options: BinaryXmlParserOptions = {}) {
88
- this.buffer = buffer;
89
- this.cursor = 0;
90
- this.strings = [];
91
- this.resources = [];
92
- this.document = null;
93
- this.parent = null;
94
- this.stack = [];
95
- this.debug = options.debug || false;
96
- }
97
-
98
- readU8() {
99
- this.debug && console.group('readU8');
100
- this.debug && console.debug('cursor:', this.cursor);
101
- const val = this.buffer[this.cursor];
102
- this.debug && console.debug('value:', val);
103
- this.cursor += 1;
104
- this.debug && console.groupEnd();
105
- return val;
106
- }
107
-
108
- readU16() {
109
- this.debug && console.group('readU16');
110
- this.debug && console.debug('cursor:', this.cursor);
111
- const val = this.buffer.readUInt16LE(this.cursor);
112
- this.debug && console.debug('value:', val);
113
- this.cursor += 2;
114
- this.debug && console.groupEnd();
115
- return val;
116
- }
117
-
118
- readS32() {
119
- this.debug && console.group('readS32');
120
- this.debug && console.debug('cursor:', this.cursor);
121
- const val = this.buffer.readInt32LE(this.cursor);
122
- this.debug && console.debug('value:', val);
123
- this.cursor += 4;
124
- this.debug && console.groupEnd();
125
- return val;
126
- }
127
-
128
- readU32() {
129
- this.debug && console.group('readU32');
130
- this.debug && console.debug('cursor:', this.cursor);
131
- const val = this.buffer.readUInt32LE(this.cursor);
132
- this.debug && console.debug('value:', val);
133
- this.cursor += 4;
134
- this.debug && console.groupEnd();
135
- return val;
136
- }
137
-
138
- readLength8() {
139
- this.debug && console.group('readLength8');
140
- let len = this.readU8();
141
- if (len & 0x80) {
142
- len = (len & 0x7f) << 8;
143
- len += this.readU8();
144
- }
145
- this.debug && console.debug('length:', len);
146
- this.debug && console.groupEnd();
147
- return len;
148
- }
149
-
150
- readLength16() {
151
- this.debug && console.group('readLength16');
152
- let len = this.readU16();
153
- if (len & 0x8000) {
154
- len = (len & 0x7fff) << 16;
155
- len += this.readU16();
156
- }
157
- this.debug && console.debug('length:', len);
158
- this.debug && console.groupEnd();
159
- return len;
160
- }
161
-
162
- readDimension() {
163
- this.debug && console.group('readDimension');
164
-
165
- const dimension: {
166
- value: number | null;
167
- unit: string | null;
168
- rawUnit: number | null;
169
- } = {
170
- value: null,
171
- unit: null,
172
- rawUnit: null,
173
- };
174
-
175
- const value = this.readU32();
176
- const unit = value & 0xff;
177
-
178
- dimension.value = value >> 8;
179
- dimension.rawUnit = unit;
180
-
181
- switch (unit) {
182
- case TypedValue.COMPLEX_UNIT_MM:
183
- dimension.unit = 'mm';
184
- break;
185
- case TypedValue.COMPLEX_UNIT_PX:
186
- dimension.unit = 'px';
187
- break;
188
- case TypedValue.COMPLEX_UNIT_DIP:
189
- dimension.unit = 'dp';
190
- break;
191
- case TypedValue.COMPLEX_UNIT_SP:
192
- dimension.unit = 'sp';
193
- break;
194
- case TypedValue.COMPLEX_UNIT_PT:
195
- dimension.unit = 'pt';
196
- break;
197
- case TypedValue.COMPLEX_UNIT_IN:
198
- dimension.unit = 'in';
199
- break;
200
- }
201
-
202
- this.debug && console.groupEnd();
203
-
204
- return dimension;
205
- }
206
-
207
- readFraction() {
208
- this.debug && console.group('readFraction');
209
-
210
- const fraction: {
211
- value: number | null;
212
- type: string | null;
213
- rawType: number | null;
214
- } = {
215
- value: null,
216
- type: null,
217
- rawType: null,
218
- };
219
-
220
- const value = this.readU32();
221
- const type = value & 0xf;
222
-
223
- fraction.value = this.convertIntToFloat(value >> 4);
224
- fraction.rawType = type;
225
-
226
- switch (type) {
227
- case TypedValue.COMPLEX_UNIT_FRACTION:
228
- fraction.type = '%';
229
- break;
230
- case TypedValue.COMPLEX_UNIT_FRACTION_PARENT:
231
- fraction.type = '%p';
232
- break;
233
- }
234
-
235
- this.debug && console.groupEnd();
236
-
237
- return fraction;
238
- }
239
-
240
- readHex24() {
241
- this.debug && console.group('readHex24');
242
- const val = (this.readU32() & 0xffffff).toString(16);
243
- this.debug && console.groupEnd();
244
- return val;
245
- }
246
-
247
- readHex32() {
248
- this.debug && console.group('readHex32');
249
- const val = this.readU32().toString(16);
250
- this.debug && console.groupEnd();
251
- return val;
252
- }
253
-
254
- readTypedValue() {
255
- this.debug && console.group('readTypedValue');
256
-
257
- const typedValue: {
258
- value: any;
259
- type: string | null;
260
- rawType: number | null;
261
- } = {
262
- value: null,
263
- type: null,
264
- rawType: null,
265
- };
266
-
267
- const start = this.cursor;
268
-
269
- let size = this.readU16();
270
- /* const zero = */ this.readU8();
271
- const dataType = this.readU8();
272
-
273
- if (size === 0) {
274
- size = 8;
275
- }
276
-
277
- typedValue.rawType = dataType;
278
-
279
- switch (dataType) {
280
- case TypedValue.TYPE_INT_DEC:
281
- typedValue.value = this.readS32();
282
- typedValue.type = 'int_dec';
283
- break;
284
- case TypedValue.TYPE_INT_HEX:
285
- typedValue.value = this.readS32();
286
- typedValue.type = 'int_hex';
287
- break;
288
- case TypedValue.TYPE_STRING: {
289
- const ref = this.readS32();
290
- typedValue.value = ref > 0 ? this.strings[ref] : '';
291
- typedValue.type = 'string';
292
- break;
293
- }
294
- case TypedValue.TYPE_REFERENCE: {
295
- const id = this.readU32();
296
- typedValue.value = `resourceId:0x${id.toString(16)}`;
297
- typedValue.type = 'reference';
298
- break;
299
- }
300
- case TypedValue.TYPE_INT_BOOLEAN:
301
- typedValue.value = this.readS32() !== 0;
302
- typedValue.type = 'boolean';
303
- break;
304
- case TypedValue.TYPE_NULL:
305
- this.readU32();
306
- typedValue.value = null;
307
- typedValue.type = 'null';
308
- break;
309
- case TypedValue.TYPE_INT_COLOR_RGB8:
310
- typedValue.value = this.readHex24();
311
- typedValue.type = 'rgb8';
312
- break;
313
- case TypedValue.TYPE_INT_COLOR_RGB4:
314
- typedValue.value = this.readHex24();
315
- typedValue.type = 'rgb4';
316
- break;
317
- case TypedValue.TYPE_INT_COLOR_ARGB8:
318
- typedValue.value = this.readHex32();
319
- typedValue.type = 'argb8';
320
- break;
321
- case TypedValue.TYPE_INT_COLOR_ARGB4:
322
- typedValue.value = this.readHex32();
323
- typedValue.type = 'argb4';
324
- break;
325
- case TypedValue.TYPE_DIMENSION:
326
- typedValue.value = this.readDimension();
327
- typedValue.type = 'dimension';
328
- break;
329
- case TypedValue.TYPE_FRACTION:
330
- typedValue.value = this.readFraction();
331
- typedValue.type = 'fraction';
332
- break;
333
- default: {
334
- const type = dataType.toString(16);
335
- console.debug(
336
- `Not sure what to do with typed value of type 0x${type}, falling back to reading an uint32.`,
337
- );
338
- typedValue.value = this.readU32();
339
- typedValue.type = 'unknown';
340
- }
341
- }
342
-
343
- const end = start + size;
344
- if (this.cursor !== end) {
345
- const type = dataType.toString(16);
346
- const diff = end - this.cursor;
347
- console.debug(`Cursor is off by ${diff} bytes at ${this.cursor} at supposed end \
348
- of typed value of type 0x${type}. The typed value started at offset ${start} \
349
- and is supposed to end at offset ${end}. Ignoring the rest of the value.`);
350
- this.cursor = end;
351
- }
352
-
353
- this.debug && console.groupEnd();
354
-
355
- return typedValue;
356
- }
357
-
358
- // https://twitter.com/kawasima/status/427730289201139712
359
- convertIntToFloat(int: number) {
360
- const buf = new ArrayBuffer(4);
361
- new Int32Array(buf)[0] = int;
362
- return new Float32Array(buf)[0];
363
- }
364
-
365
- readString(encoding: string) {
366
- this.debug && console.group('readString', encoding);
367
- switch (encoding) {
368
- case 'utf-8': {
369
- const stringLength = this.readLength8();
370
- this.debug && console.debug('stringLength:', stringLength);
371
- const byteLength = this.readLength8();
372
- this.debug && console.debug('byteLength:', byteLength);
373
- const value = this.buffer.toString(
374
- encoding,
375
- this.cursor,
376
- (this.cursor += byteLength),
377
- );
378
- this.debug && console.debug('value:', value);
379
- this.debug && console.groupEnd();
380
- return value;
381
- }
382
- case 'ucs2': {
383
- const stringLength = this.readLength16();
384
- this.debug && console.debug('stringLength:', stringLength);
385
- const byteLength = stringLength * 2;
386
- this.debug && console.debug('byteLength:', byteLength);
387
- const value = this.buffer.toString(
388
- encoding,
389
- this.cursor,
390
- (this.cursor += byteLength),
391
- );
392
- this.debug && console.debug('value:', value);
393
- this.debug && console.groupEnd();
394
- return value;
395
- }
396
- default:
397
- throw new Error(`Unsupported encoding '${encoding}'`);
398
- }
399
- }
400
-
401
- readChunkHeader() {
402
- this.debug && console.group('readChunkHeader');
403
- const header = {
404
- startOffset: this.cursor,
405
- chunkType: this.readU16(),
406
- headerSize: this.readU16(),
407
- chunkSize: this.readU32(),
408
- };
409
- this.debug && console.debug('startOffset:', header.startOffset);
410
- this.debug && console.debug('chunkType:', header.chunkType);
411
- this.debug && console.debug('headerSize:', header.headerSize);
412
- this.debug && console.debug('chunkSize:', header.chunkSize);
413
- this.debug && console.groupEnd();
414
- return header;
415
- }
416
-
417
- readStringPool(header: any) {
418
- this.debug && console.group('readStringPool');
419
-
420
- header.stringCount = this.readU32();
421
- this.debug && console.debug('stringCount:', header.stringCount);
422
- header.styleCount = this.readU32();
423
- this.debug && console.debug('styleCount:', header.styleCount);
424
- header.flags = this.readU32();
425
- this.debug && console.debug('flags:', header.flags);
426
- header.stringsStart = this.readU32();
427
- this.debug && console.debug('stringsStart:', header.stringsStart);
428
- header.stylesStart = this.readU32();
429
- this.debug && console.debug('stylesStart:', header.stylesStart);
430
-
431
- if (header.chunkType !== ChunkType.STRING_POOL) {
432
- throw new Error('Invalid string pool header');
433
- }
434
-
435
- const offsets: number[] = [];
436
- for (let i = 0, l = header.stringCount; i < l; ++i) {
437
- this.debug && console.debug('offset:', i);
438
- offsets.push(this.readU32());
439
- }
440
-
441
- const sorted = (header.flags & StringFlags.SORTED) === StringFlags.SORTED;
442
- this.debug && console.debug('sorted:', sorted);
443
- const encoding =
444
- (header.flags & StringFlags.UTF8) === StringFlags.UTF8 ? 'utf-8' : 'ucs2';
445
- this.debug && console.debug('encoding:', encoding);
446
-
447
- const stringsStart = header.startOffset + header.stringsStart;
448
- this.cursor = stringsStart;
449
- for (let i = 0, l = header.stringCount; i < l; ++i) {
450
- this.debug && console.debug('string:', i);
451
- this.debug && console.debug('offset:', offsets[i]);
452
- this.cursor = stringsStart + offsets[i];
453
- this.strings.push(this.readString(encoding));
454
- }
455
-
456
- this.cursor = header.startOffset + header.chunkSize;
457
-
458
- this.debug && console.groupEnd();
459
-
460
- return null;
461
- }
462
-
463
- readResourceMap(header: any) {
464
- this.debug && console.group('readResourceMap');
465
- const count = Math.floor((header.chunkSize - header.headerSize) / 4);
466
- for (let i = 0; i < count; ++i) {
467
- this.resources.push(this.readU32());
468
- }
469
- this.debug && console.groupEnd();
470
- return null;
471
- }
472
-
473
- readXmlNamespaceStart() {
474
- this.debug && console.group('readXmlNamespaceStart');
475
-
476
- /* const line = */ this.readU32();
477
- /* const commentRef = */ this.readU32();
478
- /* const prefixRef = */ this.readS32();
479
- /* const uriRef = */ this.readS32();
480
-
481
- this.debug && console.groupEnd();
482
-
483
- return null;
484
- }
485
-
486
- readXmlNamespaceEnd() {
487
- this.debug && console.group('readXmlNamespaceEnd');
488
-
489
- /* const line = */ this.readU32();
490
- /* const commentRef = */ this.readU32();
491
- /* const prefixRef = */ this.readS32();
492
- /* const uriRef = */ this.readS32();
493
-
494
- this.debug && console.groupEnd();
495
-
496
- return null;
497
- }
498
-
499
- readXmlElementStart() {
500
- this.debug && console.group('readXmlElementStart');
501
-
502
- const node: any = {
503
- namespaceURI: null,
504
- nodeType: NodeType.ELEMENT_NODE,
505
- nodeName: null,
506
- attributes: [],
507
- childNodes: [],
508
- };
509
-
510
- /* const line = */ this.readU32();
511
- /* const commentRef = */ this.readU32();
512
- const nsRef = this.readS32();
513
- const nameRef = this.readS32();
514
-
515
- if (nsRef > 0) {
516
- node.namespaceURI = this.strings[nsRef];
517
- }
518
-
519
- node.nodeName = this.strings[nameRef];
520
-
521
- /* const attrStart = */ this.readU16();
522
- /* const attrSize = */ this.readU16();
523
- const attrCount = this.readU16();
524
- /* const idIndex = */ this.readU16();
525
- /* const classIndex = */ this.readU16();
526
- /* const styleIndex = */ this.readU16();
527
-
528
- for (let i = 0; i < attrCount; ++i) {
529
- node.attributes.push(this.readXmlAttribute());
530
- }
531
-
532
- if (this.document) {
533
- this.parent.childNodes.push(node);
534
- this.parent = node;
535
- } else {
536
- this.document = this.parent = node;
537
- }
538
-
539
- this.stack.push(node);
540
-
541
- this.debug && console.groupEnd();
542
-
543
- return node;
544
- }
545
-
546
- readXmlAttribute() {
547
- this.debug && console.group('readXmlAttribute');
548
-
549
- const attr: any = {
550
- namespaceURI: null,
551
- nodeType: NodeType.ATTRIBUTE_NODE,
552
- nodeName: null,
553
- name: null,
554
- value: null,
555
- typedValue: null,
556
- };
557
-
558
- const nsRef = this.readS32();
559
- const nameRef = this.readS32();
560
- const valueRef = this.readS32();
561
-
562
- if (nsRef > 0) {
563
- attr.namespaceURI = this.strings[nsRef];
564
- }
565
-
566
- attr.nodeName = attr.name = this.strings[nameRef];
567
-
568
- if (valueRef > 0) {
569
- if (attr.name === 'versionName') {
570
- // strip UTF-16 null padding only; keep spaces and non-ASCII chars
571
- // biome-ignore lint/suspicious/noControlCharactersInRegex: removing NUL padding is the point
572
- this.strings[valueRef] = this.strings[valueRef].replace(/\u0000/g, '');
573
- }
574
- attr.value = this.strings[valueRef];
575
- }
576
-
577
- attr.typedValue = this.readTypedValue();
578
-
579
- this.debug && console.groupEnd();
580
-
581
- return attr;
582
- }
583
-
584
- readXmlElementEnd() {
585
- this.debug && console.group('readXmlCData');
586
-
587
- /* const line = */ this.readU32();
588
- /* const commentRef = */ this.readU32();
589
- /* const nsRef = */ this.readS32();
590
- /* const nameRef = */ this.readS32();
591
-
592
- this.stack.pop();
593
- this.parent = this.stack[this.stack.length - 1];
594
-
595
- this.debug && console.groupEnd();
596
-
597
- return null;
598
- }
599
-
600
- readXmlCData() {
601
- this.debug && console.group('readXmlCData');
602
-
603
- const cdata: any = {
604
- namespaceURI: null,
605
- nodeType: NodeType.CDATA_SECTION_NODE,
606
- nodeName: '#cdata',
607
- data: null,
608
- typedValue: null,
609
- };
610
-
611
- /* const line = */ this.readU32();
612
- /* const commentRef = */ this.readU32();
613
- const dataRef = this.readS32();
614
-
615
- if (dataRef > 0) {
616
- cdata.data = this.strings[dataRef];
617
- }
618
-
619
- cdata.typedValue = this.readTypedValue();
620
-
621
- this.parent.childNodes.push(cdata);
622
-
623
- this.debug && console.groupEnd();
624
-
625
- return cdata;
626
- }
627
-
628
- readNull(header: any) {
629
- this.debug && console.group('readNull');
630
- this.cursor += header.chunkSize - header.headerSize;
631
- this.debug && console.groupEnd();
632
- return null;
633
- }
634
-
635
- parse() {
636
- this.debug && console.group('BinaryXmlParser.parse');
637
-
638
- const xmlHeader = this.readChunkHeader();
639
- if (xmlHeader.chunkType !== ChunkType.XML) {
640
- throw new Error('Invalid XML header');
641
- }
642
-
643
- while (this.cursor < this.buffer.length) {
644
- this.debug && console.group('chunk');
645
- const start = this.cursor;
646
- const header = this.readChunkHeader();
647
- switch (header.chunkType) {
648
- case ChunkType.STRING_POOL:
649
- this.readStringPool(header);
650
- break;
651
- case ChunkType.XML_RESOURCE_MAP:
652
- this.readResourceMap(header);
653
- break;
654
- case ChunkType.XML_START_NAMESPACE:
655
- this.readXmlNamespaceStart();
656
- break;
657
- case ChunkType.XML_END_NAMESPACE:
658
- this.readXmlNamespaceEnd();
659
- break;
660
- case ChunkType.XML_START_ELEMENT:
661
- this.readXmlElementStart();
662
- break;
663
- case ChunkType.XML_END_ELEMENT:
664
- this.readXmlElementEnd();
665
- break;
666
- case ChunkType.XML_CDATA:
667
- this.readXmlCData();
668
- break;
669
- case ChunkType.NULL:
670
- this.readNull(header);
671
- break;
672
- default:
673
- throw new Error(`Unsupported chunk type '${header.chunkType}'`);
674
- }
675
-
676
- const end = start + header.chunkSize;
677
- if (this.cursor !== end) {
678
- const diff = end - this.cursor;
679
- const type = header.chunkType.toString(16);
680
- console.debug(`Cursor is off by ${diff} bytes at ${this.cursor} at supposed \
681
- end of chunk of type 0x${type}. The chunk started at offset ${start} and is \
682
- supposed to end at offset ${end}. Ignoring the rest of the chunk.`);
683
- this.cursor = end;
684
- }
685
-
686
- this.debug && console.groupEnd();
687
- }
688
-
689
- this.debug && console.groupEnd();
690
-
691
- return this.document;
692
- }
693
- }