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