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