react-native-update-cli 1.30.3 → 1.31.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.
@@ -1,486 +1,351 @@
1
- "use strict";
2
-
3
1
  /**
4
2
  * Code translated from a C# project https://github.com/hylander0/Iteedee.ApkReader/blob/master/Iteedee.ApkReader/ApkResourceFinder.cs
5
3
  *
6
4
  * Decode binary file `resources.arsc` from a .apk file to a JavaScript Object.
7
- */
8
-
5
+ */ "use strict";
9
6
  var ByteBuffer = require("bytebuffer");
10
-
11
7
  var DEBUG = false;
12
-
13
8
  var RES_STRING_POOL_TYPE = 0x0001;
14
9
  var RES_TABLE_TYPE = 0x0002;
15
10
  var RES_TABLE_PACKAGE_TYPE = 0x0200;
16
11
  var RES_TABLE_TYPE_TYPE = 0x0201;
17
12
  var RES_TABLE_TYPE_SPEC_TYPE = 0x0202;
18
-
19
13
  // The 'data' holds a ResTable_ref, a reference to another resource
20
14
  // table entry.
21
15
  var TYPE_REFERENCE = 0x01;
22
16
  // The 'data' holds an index into the containing resource table's
23
17
  // global value string pool.
24
18
  var TYPE_STRING = 0x03;
25
-
26
19
  function ResourceFinder() {
27
- this.valueStringPool = null;
28
- this.typeStringPool = null;
29
- this.keyStringPool = null;
30
-
31
- this.package_id = 0;
32
-
33
- this.responseMap = {};
34
- this.entryMap = {};
20
+ this.valueStringPool = null;
21
+ this.typeStringPool = null;
22
+ this.keyStringPool = null;
23
+ this.package_id = 0;
24
+ this.responseMap = {};
25
+ this.entryMap = {};
35
26
  }
36
-
37
27
  /**
38
28
  * Same to C# BinaryReader.readBytes
39
29
  *
40
30
  * @param bb ByteBuffer
41
31
  * @param len length
42
32
  * @returns {Buffer}
43
- */
44
- ResourceFinder.readBytes = function (bb, len) {
45
- var uint8Array = new Uint8Array(len);
46
- for (var i = 0; i < len; i++) {
47
- uint8Array[i] = bb.readUint8();
48
- }
49
-
50
- return ByteBuffer.wrap(uint8Array, "binary", true);
33
+ */ ResourceFinder.readBytes = function(bb, len) {
34
+ var uint8Array = new Uint8Array(len);
35
+ for(var i = 0; i < len; i++){
36
+ uint8Array[i] = bb.readUint8();
37
+ }
38
+ return ByteBuffer.wrap(uint8Array, "binary", true);
51
39
  };
52
-
53
40
  //
54
41
  /**
55
42
  *
56
43
  * @param {ByteBuffer} bb
57
44
  * @return {Map<String, Set<String>>}
58
- */
59
- ResourceFinder.prototype.processResourceTable = function (resourceBuffer) {
60
- const bb = ByteBuffer.wrap(resourceBuffer, "binary", true);
61
-
62
- // Resource table structure
63
- var type = bb.readShort(),
64
- headerSize = bb.readShort(),
65
- size = bb.readInt(),
66
- packageCount = bb.readInt(),
67
- buffer,
68
- bb2;
69
- if (type != RES_TABLE_TYPE) {
70
- throw new Error("No RES_TABLE_TYPE found!");
71
- }
72
- if (size != bb.limit) {
73
- throw new Error("The buffer size not matches to the resource table size.");
74
- }
75
- bb.offset = headerSize;
76
-
77
- var realStringPoolCount = 0,
78
- realPackageCount = 0;
79
-
80
- while (true) {
81
- var pos, t, hs, s;
82
- try {
83
- pos = bb.offset;
84
- t = bb.readShort();
85
- hs = bb.readShort();
86
- s = bb.readInt();
87
- } catch (e) {
88
- break;
45
+ */ ResourceFinder.prototype.processResourceTable = function(resourceBuffer) {
46
+ const bb = ByteBuffer.wrap(resourceBuffer, "binary", true);
47
+ // Resource table structure
48
+ var type = bb.readShort(), headerSize = bb.readShort(), size = bb.readInt(), packageCount = bb.readInt(), buffer, bb2;
49
+ if (type != RES_TABLE_TYPE) {
50
+ throw new Error("No RES_TABLE_TYPE found!");
89
51
  }
90
- if (t == RES_STRING_POOL_TYPE) {
91
- // Process the string pool
92
- if (realStringPoolCount == 0) {
93
- // Only the first string pool is processed.
94
- if (DEBUG) {
95
- console.log("Processing the string pool ...");
52
+ if (size != bb.limit) {
53
+ throw new Error("The buffer size not matches to the resource table size.");
54
+ }
55
+ bb.offset = headerSize;
56
+ var realStringPoolCount = 0, realPackageCount = 0;
57
+ while(true){
58
+ var pos, t, hs, s;
59
+ try {
60
+ pos = bb.offset;
61
+ t = bb.readShort();
62
+ hs = bb.readShort();
63
+ s = bb.readInt();
64
+ } catch (e) {
65
+ break;
96
66
  }
97
-
98
- buffer = new ByteBuffer(s);
99
- bb.offset = pos;
100
- bb.prependTo(buffer);
101
-
102
- bb2 = ByteBuffer.wrap(buffer, "binary", true);
103
-
104
- bb2.LE();
105
- this.valueStringPool = this.processStringPool(bb2);
106
- }
107
- realStringPoolCount++;
108
- } else if (t == RES_TABLE_PACKAGE_TYPE) {
109
- // Process the package
110
- if (DEBUG) {
111
- console.log("Processing the package " + realPackageCount + " ...");
112
- }
113
-
114
- buffer = new ByteBuffer(s);
115
- bb.offset = pos;
116
- bb.prependTo(buffer);
117
-
118
- bb2 = ByteBuffer.wrap(buffer, "binary", true);
119
- bb2.LE();
120
- this.processPackage(bb2);
121
-
122
- realPackageCount++;
123
- } else {
124
- throw new Error("Unsupported type");
67
+ if (t == RES_STRING_POOL_TYPE) {
68
+ // Process the string pool
69
+ if (realStringPoolCount == 0) {
70
+ // Only the first string pool is processed.
71
+ if (DEBUG) {
72
+ console.log("Processing the string pool ...");
73
+ }
74
+ buffer = new ByteBuffer(s);
75
+ bb.offset = pos;
76
+ bb.prependTo(buffer);
77
+ bb2 = ByteBuffer.wrap(buffer, "binary", true);
78
+ bb2.LE();
79
+ this.valueStringPool = this.processStringPool(bb2);
80
+ }
81
+ realStringPoolCount++;
82
+ } else if (t == RES_TABLE_PACKAGE_TYPE) {
83
+ // Process the package
84
+ if (DEBUG) {
85
+ console.log("Processing the package " + realPackageCount + " ...");
86
+ }
87
+ buffer = new ByteBuffer(s);
88
+ bb.offset = pos;
89
+ bb.prependTo(buffer);
90
+ bb2 = ByteBuffer.wrap(buffer, "binary", true);
91
+ bb2.LE();
92
+ this.processPackage(bb2);
93
+ realPackageCount++;
94
+ } else {
95
+ throw new Error("Unsupported type");
96
+ }
97
+ bb.offset = pos + s;
98
+ if (!bb.remaining()) break;
99
+ }
100
+ if (realStringPoolCount != 1) {
101
+ throw new Error("More than 1 string pool found!");
125
102
  }
126
- bb.offset = pos + s;
127
- if (!bb.remaining()) break;
128
- }
129
-
130
- if (realStringPoolCount != 1) {
131
- throw new Error("More than 1 string pool found!");
132
- }
133
- if (realPackageCount != packageCount) {
134
- throw new Error("Real package count not equals the declared count.");
135
- }
136
-
137
- return this.responseMap;
103
+ if (realPackageCount != packageCount) {
104
+ throw new Error("Real package count not equals the declared count.");
105
+ }
106
+ return this.responseMap;
138
107
  };
139
-
140
108
  /**
141
109
  *
142
110
  * @param {ByteBuffer} bb
143
- */
144
- ResourceFinder.prototype.processPackage = function (bb) {
145
- // Package structure
146
- var type = bb.readShort(),
147
- headerSize = bb.readShort(),
148
- size = bb.readInt(),
149
- id = bb.readInt();
150
-
151
- this.package_id = id;
152
-
153
- for (var i = 0; i < 256; ++i) {
154
- bb.readUint8();
155
- }
156
-
157
- var typeStrings = bb.readInt(),
158
- lastPublicType = bb.readInt(),
159
- keyStrings = bb.readInt(),
160
- lastPublicKey = bb.readInt();
161
-
162
- if (typeStrings != headerSize) {
163
- throw new Error("TypeStrings must immediately following the package structure header.");
164
- }
165
-
166
- if (DEBUG) {
167
- console.log("Type strings:");
168
- }
169
-
170
- var lastPosition = bb.offset;
171
- bb.offset = typeStrings;
172
- var bbTypeStrings = ResourceFinder.readBytes(bb, bb.limit - bb.offset);
173
- bb.offset = lastPosition;
174
- this.typeStringPool = this.processStringPool(bbTypeStrings);
175
-
176
- // Key strings
177
- if (DEBUG) {
178
- console.log("Key strings:");
179
- }
180
-
181
- bb.offset = keyStrings;
182
- var key_type = bb.readShort(),
183
- key_headerSize = bb.readShort(),
184
- key_size = bb.readInt();
185
-
186
- lastPosition = bb.offset;
187
- bb.offset = keyStrings;
188
- var bbKeyStrings = ResourceFinder.readBytes(bb, bb.limit - bb.offset);
189
- bb.offset = lastPosition;
190
- this.keyStringPool = this.processStringPool(bbKeyStrings);
191
-
192
- // Iterate through all chunks
193
- var typeSpecCount = 0;
194
- var typeCount = 0;
195
-
196
- bb.offset = keyStrings + key_size;
197
-
198
- var bb2;
199
-
200
- while (true) {
201
- var pos = bb.offset;
202
- try {
203
- var t = bb.readShort();
204
- var hs = bb.readShort();
205
- var s = bb.readInt();
206
- } catch (e) {
207
- break;
111
+ */ ResourceFinder.prototype.processPackage = function(bb) {
112
+ // Package structure
113
+ var type = bb.readShort(), headerSize = bb.readShort(), size = bb.readInt(), id = bb.readInt();
114
+ this.package_id = id;
115
+ for(var i = 0; i < 256; ++i){
116
+ bb.readUint8();
117
+ }
118
+ var typeStrings = bb.readInt(), lastPublicType = bb.readInt(), keyStrings = bb.readInt(), lastPublicKey = bb.readInt();
119
+ if (typeStrings != headerSize) {
120
+ throw new Error("TypeStrings must immediately following the package structure header.");
208
121
  }
209
-
210
- if (t == RES_TABLE_TYPE_SPEC_TYPE) {
211
- bb.offset = pos;
212
- bb2 = ResourceFinder.readBytes(bb, s);
213
- this.processTypeSpec(bb2);
214
-
215
- typeSpecCount++;
216
- } else if (t == RES_TABLE_TYPE_TYPE) {
217
- bb.offset = pos;
218
- bb2 = ResourceFinder.readBytes(bb, s);
219
- this.processType(bb2);
220
-
221
- typeCount++;
122
+ if (DEBUG) {
123
+ console.log("Type strings:");
222
124
  }
223
-
224
- if (s == 0) {
225
- break;
125
+ var lastPosition = bb.offset;
126
+ bb.offset = typeStrings;
127
+ var bbTypeStrings = ResourceFinder.readBytes(bb, bb.limit - bb.offset);
128
+ bb.offset = lastPosition;
129
+ this.typeStringPool = this.processStringPool(bbTypeStrings);
130
+ // Key strings
131
+ if (DEBUG) {
132
+ console.log("Key strings:");
226
133
  }
227
-
228
- bb.offset = pos + s;
229
-
230
- if (!bb.remaining()) {
231
- break;
134
+ bb.offset = keyStrings;
135
+ var key_type = bb.readShort(), key_headerSize = bb.readShort(), key_size = bb.readInt();
136
+ lastPosition = bb.offset;
137
+ bb.offset = keyStrings;
138
+ var bbKeyStrings = ResourceFinder.readBytes(bb, bb.limit - bb.offset);
139
+ bb.offset = lastPosition;
140
+ this.keyStringPool = this.processStringPool(bbKeyStrings);
141
+ // Iterate through all chunks
142
+ var typeSpecCount = 0;
143
+ var typeCount = 0;
144
+ bb.offset = keyStrings + key_size;
145
+ var bb2;
146
+ while(true){
147
+ var pos = bb.offset;
148
+ try {
149
+ var t = bb.readShort();
150
+ var hs = bb.readShort();
151
+ var s = bb.readInt();
152
+ } catch (e) {
153
+ break;
154
+ }
155
+ if (t == RES_TABLE_TYPE_SPEC_TYPE) {
156
+ bb.offset = pos;
157
+ bb2 = ResourceFinder.readBytes(bb, s);
158
+ this.processTypeSpec(bb2);
159
+ typeSpecCount++;
160
+ } else if (t == RES_TABLE_TYPE_TYPE) {
161
+ bb.offset = pos;
162
+ bb2 = ResourceFinder.readBytes(bb, s);
163
+ this.processType(bb2);
164
+ typeCount++;
165
+ }
166
+ if (s == 0) {
167
+ break;
168
+ }
169
+ bb.offset = pos + s;
170
+ if (!bb.remaining()) {
171
+ break;
172
+ }
232
173
  }
233
- }
234
174
  };
235
-
236
175
  /**
237
176
  *
238
177
  * @param {ByteBuffer} bb
239
- */
240
- ResourceFinder.prototype.processType = function (bb) {
241
- var type = bb.readShort(),
242
- headerSize = bb.readShort(),
243
- size = bb.readInt(),
244
- id = bb.readByte(),
245
- res0 = bb.readByte(),
246
- res1 = bb.readShort(),
247
- entryCount = bb.readInt(),
248
- entriesStart = bb.readInt();
249
-
250
- var refKeys = {};
251
-
252
- var config_size = bb.readInt();
253
-
254
- // Skip the config data
255
- bb.offset = headerSize;
256
-
257
- if (headerSize + entryCount * 4 != entriesStart) {
258
- throw new Error("HeaderSize, entryCount and entriesStart are not valid.");
259
- }
260
-
261
- // Start to get entry indices
262
- var entryIndices = new Array(entryCount);
263
- for (var i = 0; i < entryCount; ++i) {
264
- entryIndices[i] = bb.readInt();
265
- }
266
-
267
- // Get entries
268
- for (var i = 0; i < entryCount; ++i) {
269
- if (entryIndices[i] == -1) continue;
270
-
271
- var resource_id = this.package_id << 24 | id << 16 | i;
272
-
273
- var pos = bb.offset,
274
- entry_size,
275
- entry_flag,
276
- entry_key,
277
- value_size,
278
- value_res0,
279
- value_dataType,
280
- value_data;
281
- try {
282
- entry_size = bb.readShort();
283
- entry_flag = bb.readShort();
284
- entry_key = bb.readInt();
285
- } catch (e) {
286
- break;
178
+ */ ResourceFinder.prototype.processType = function(bb) {
179
+ var type = bb.readShort(), headerSize = bb.readShort(), size = bb.readInt(), id = bb.readByte(), res0 = bb.readByte(), res1 = bb.readShort(), entryCount = bb.readInt(), entriesStart = bb.readInt();
180
+ var refKeys = {};
181
+ var config_size = bb.readInt();
182
+ // Skip the config data
183
+ bb.offset = headerSize;
184
+ if (headerSize + entryCount * 4 != entriesStart) {
185
+ throw new Error("HeaderSize, entryCount and entriesStart are not valid.");
287
186
  }
288
-
289
- // Get the value (simple) or map (complex)
290
-
291
- var FLAG_COMPLEX = 0x0001;
292
- if ((entry_flag & FLAG_COMPLEX) == 0) {
293
- // Simple case
294
- value_size = bb.readShort();
295
- value_res0 = bb.readByte();
296
- value_dataType = bb.readByte();
297
- value_data = bb.readInt();
298
-
299
- var idStr = Number(resource_id).toString(16);
300
- var keyStr = this.keyStringPool[entry_key];
301
-
302
- var data = null;
303
-
304
- if (DEBUG) {
305
- console.log("Entry 0x" + idStr + ", key: " + keyStr + ", simple value type: ");
306
- }
307
-
308
- var key = parseInt(idStr, 16);
309
-
310
- var entryArr = this.entryMap[key];
311
- if (entryArr == null) {
312
- entryArr = [];
313
- }
314
- entryArr.push(keyStr);
315
-
316
- this.entryMap[key] = entryArr;
317
-
318
- if (value_dataType == TYPE_STRING) {
319
- data = this.valueStringPool[value_data];
320
-
321
- if (DEBUG) {
322
- console.log(", data: " + this.valueStringPool[value_data] + "");
187
+ // Start to get entry indices
188
+ var entryIndices = new Array(entryCount);
189
+ for(var i = 0; i < entryCount; ++i){
190
+ entryIndices[i] = bb.readInt();
191
+ }
192
+ // Get entries
193
+ for(var i = 0; i < entryCount; ++i){
194
+ if (entryIndices[i] == -1) continue;
195
+ var resource_id = this.package_id << 24 | id << 16 | i;
196
+ var pos = bb.offset, entry_size, entry_flag, entry_key, value_size, value_res0, value_dataType, value_data;
197
+ try {
198
+ entry_size = bb.readShort();
199
+ entry_flag = bb.readShort();
200
+ entry_key = bb.readInt();
201
+ } catch (e) {
202
+ break;
323
203
  }
324
- } else if (value_dataType == TYPE_REFERENCE) {
325
- var hexIndex = Number(value_data).toString(16);
326
-
327
- refKeys[idStr] = value_data;
328
- } else {
329
- data = "" + value_data;
330
- if (DEBUG) {
331
- console.log(", data: " + value_data + "");
204
+ // Get the value (simple) or map (complex)
205
+ var FLAG_COMPLEX = 0x0001;
206
+ if ((entry_flag & FLAG_COMPLEX) == 0) {
207
+ // Simple case
208
+ value_size = bb.readShort();
209
+ value_res0 = bb.readByte();
210
+ value_dataType = bb.readByte();
211
+ value_data = bb.readInt();
212
+ var idStr = Number(resource_id).toString(16);
213
+ var keyStr = this.keyStringPool[entry_key];
214
+ var data = null;
215
+ if (DEBUG) {
216
+ console.log("Entry 0x" + idStr + ", key: " + keyStr + ", simple value type: ");
217
+ }
218
+ var key = parseInt(idStr, 16);
219
+ var entryArr = this.entryMap[key];
220
+ if (entryArr == null) {
221
+ entryArr = [];
222
+ }
223
+ entryArr.push(keyStr);
224
+ this.entryMap[key] = entryArr;
225
+ if (value_dataType == TYPE_STRING) {
226
+ data = this.valueStringPool[value_data];
227
+ if (DEBUG) {
228
+ console.log(", data: " + this.valueStringPool[value_data] + "");
229
+ }
230
+ } else if (value_dataType == TYPE_REFERENCE) {
231
+ var hexIndex = Number(value_data).toString(16);
232
+ refKeys[idStr] = value_data;
233
+ } else {
234
+ data = "" + value_data;
235
+ if (DEBUG) {
236
+ console.log(", data: " + value_data + "");
237
+ }
238
+ }
239
+ this.putIntoMap("@" + idStr, data);
240
+ } else {
241
+ // Complex case
242
+ var entry_parent = bb.readInt();
243
+ var entry_count = bb.readInt();
244
+ for(var j = 0; j < entry_count; ++j){
245
+ var ref_name = bb.readInt();
246
+ value_size = bb.readShort();
247
+ value_res0 = bb.readByte();
248
+ value_dataType = bb.readByte();
249
+ value_data = bb.readInt();
250
+ }
251
+ if (DEBUG) {
252
+ console.log("Entry 0x" + Number(resource_id).toString(16) + ", key: " + this.keyStringPool[entry_key] + ", complex value, not printed.");
253
+ }
332
254
  }
333
- }
334
-
335
- this.putIntoMap("@" + idStr, data);
336
- } else {
337
- // Complex case
338
- var entry_parent = bb.readInt();
339
- var entry_count = bb.readInt();
340
-
341
- for (var j = 0; j < entry_count; ++j) {
342
- var ref_name = bb.readInt();
343
- value_size = bb.readShort();
344
- value_res0 = bb.readByte();
345
- value_dataType = bb.readByte();
346
- value_data = bb.readInt();
347
- }
348
-
349
- if (DEBUG) {
350
- console.log("Entry 0x" + Number(resource_id).toString(16) + ", key: " + this.keyStringPool[entry_key] + ", complex value, not printed.");
351
- }
352
255
  }
353
- }
354
-
355
- for (var refK in refKeys) {
356
- var values = this.responseMap["@" + Number(refKeys[refK]).toString(16).toUpperCase()];
357
- if (values != null && Object.keys(values).length < 1000) {
358
- for (var value in values) {
359
- this.putIntoMap("@" + refK, values[value]);
360
- }
256
+ for(var refK in refKeys){
257
+ var values = this.responseMap["@" + Number(refKeys[refK]).toString(16).toUpperCase()];
258
+ if (values != null && Object.keys(values).length < 1000) {
259
+ for(var value in values){
260
+ this.putIntoMap("@" + refK, values[value]);
261
+ }
262
+ }
361
263
  }
362
- }
363
264
  };
364
-
365
265
  /**
366
266
  *
367
267
  * @param {ByteBuffer} bb
368
268
  * @return {Array}
369
- */
370
- ResourceFinder.prototype.processStringPool = function (bb) {
371
- // String pool structure
372
- //
373
- var type = bb.readShort(),
374
- headerSize = bb.readShort(),
375
- size = bb.readInt(),
376
- stringCount = bb.readInt(),
377
- styleCount = bb.readInt(),
378
- flags = bb.readInt(),
379
- stringsStart = bb.readInt(),
380
- stylesStart = bb.readInt(),
381
- u16len,
382
- buffer;
383
-
384
- var isUTF_8 = (flags & 256) != 0;
385
-
386
- var offsets = new Array(stringCount);
387
- for (var i = 0; i < stringCount; ++i) {
388
- offsets[i] = bb.readInt();
389
- }
390
-
391
- var strings = new Array(stringCount);
392
-
393
- for (var i = 0; i < stringCount; ++i) {
394
- var pos = stringsStart + offsets[i];
395
- bb.offset = pos;
396
-
397
- strings[i] = "";
398
-
399
- if (isUTF_8) {
400
- u16len = bb.readUint8();
401
-
402
- if ((u16len & 0x80) != 0) {
403
- u16len = ((u16len & 0x7f) << 8) + bb.readUint8();
404
- }
405
-
406
- var u8len = bb.readUint8();
407
- if ((u8len & 0x80) != 0) {
408
- u8len = ((u8len & 0x7f) << 8) + bb.readUint8();
409
- }
410
-
411
- if (u8len > 0) {
412
- buffer = ResourceFinder.readBytes(bb, u8len);
413
- try {
414
- strings[i] = ByteBuffer.wrap(buffer, "utf8", true).toString("utf8");
415
- } catch (e) {
416
- if (DEBUG) {
417
- console.error(e);
418
- console.log("Error when turning buffer to utf-8 string.");
419
- }
420
- }
421
- } else {
269
+ */ ResourceFinder.prototype.processStringPool = function(bb) {
270
+ // String pool structure
271
+ //
272
+ var type = bb.readShort(), headerSize = bb.readShort(), size = bb.readInt(), stringCount = bb.readInt(), styleCount = bb.readInt(), flags = bb.readInt(), stringsStart = bb.readInt(), stylesStart = bb.readInt(), u16len, buffer;
273
+ var isUTF_8 = (flags & 256) != 0;
274
+ var offsets = new Array(stringCount);
275
+ for(var i = 0; i < stringCount; ++i){
276
+ offsets[i] = bb.readInt();
277
+ }
278
+ var strings = new Array(stringCount);
279
+ for(var i = 0; i < stringCount; ++i){
280
+ var pos = stringsStart + offsets[i];
281
+ bb.offset = pos;
422
282
  strings[i] = "";
423
- }
424
- } else {
425
- u16len = bb.readUint16();
426
- if ((u16len & 0x8000) != 0) {
427
- // larger than 32768
428
- u16len = ((u16len & 0x7fff) << 16) + bb.readUint16();
429
- }
430
-
431
- if (u16len > 0) {
432
- var len = u16len * 2;
433
- buffer = ResourceFinder.readBytes(bb, len);
434
- try {
435
- strings[i] = ByteBuffer.wrap(buffer, "utf8", true).toString("utf8");
436
- } catch (e) {
437
- if (DEBUG) {
438
- console.error(e);
439
- console.log("Error when turning buffer to utf-8 string.");
440
- }
283
+ if (isUTF_8) {
284
+ u16len = bb.readUint8();
285
+ if ((u16len & 0x80) != 0) {
286
+ u16len = ((u16len & 0x7f) << 8) + bb.readUint8();
287
+ }
288
+ var u8len = bb.readUint8();
289
+ if ((u8len & 0x80) != 0) {
290
+ u8len = ((u8len & 0x7f) << 8) + bb.readUint8();
291
+ }
292
+ if (u8len > 0) {
293
+ buffer = ResourceFinder.readBytes(bb, u8len);
294
+ try {
295
+ strings[i] = ByteBuffer.wrap(buffer, "utf8", true).toString("utf8");
296
+ } catch (e) {
297
+ if (DEBUG) {
298
+ console.error(e);
299
+ console.log("Error when turning buffer to utf-8 string.");
300
+ }
301
+ }
302
+ } else {
303
+ strings[i] = "";
304
+ }
305
+ } else {
306
+ u16len = bb.readUint16();
307
+ if ((u16len & 0x8000) != 0) {
308
+ // larger than 32768
309
+ u16len = ((u16len & 0x7fff) << 16) + bb.readUint16();
310
+ }
311
+ if (u16len > 0) {
312
+ var len = u16len * 2;
313
+ buffer = ResourceFinder.readBytes(bb, len);
314
+ try {
315
+ strings[i] = ByteBuffer.wrap(buffer, "utf8", true).toString("utf8");
316
+ } catch (e) {
317
+ if (DEBUG) {
318
+ console.error(e);
319
+ console.log("Error when turning buffer to utf-8 string.");
320
+ }
321
+ }
322
+ }
323
+ }
324
+ if (DEBUG) {
325
+ console.log("Parsed value: {0}", strings[i]);
441
326
  }
442
- }
443
- }
444
-
445
- if (DEBUG) {
446
- console.log("Parsed value: {0}", strings[i]);
447
327
  }
448
- }
449
-
450
- return strings;
328
+ return strings;
451
329
  };
452
-
453
330
  /**
454
331
  *
455
332
  * @param {ByteBuffer} bb
456
- */
457
- ResourceFinder.prototype.processTypeSpec = function (bb) {
458
- var type = bb.readShort(),
459
- headerSize = bb.readShort(),
460
- size = bb.readInt(),
461
- id = bb.readByte(),
462
- res0 = bb.readByte(),
463
- res1 = bb.readShort(),
464
- entryCount = bb.readInt();
465
-
466
- if (DEBUG) {
467
- console.log("Processing type spec " + this.typeStringPool[id - 1] + "...");
468
- }
469
-
470
- var flags = new Array(entryCount);
471
-
472
- for (var i = 0; i < entryCount; ++i) {
473
- flags[i] = bb.readInt();
474
- }
333
+ */ ResourceFinder.prototype.processTypeSpec = function(bb) {
334
+ var type = bb.readShort(), headerSize = bb.readShort(), size = bb.readInt(), id = bb.readByte(), res0 = bb.readByte(), res1 = bb.readShort(), entryCount = bb.readInt();
335
+ if (DEBUG) {
336
+ console.log("Processing type spec " + this.typeStringPool[id - 1] + "...");
337
+ }
338
+ var flags = new Array(entryCount);
339
+ for(var i = 0; i < entryCount; ++i){
340
+ flags[i] = bb.readInt();
341
+ }
475
342
  };
476
-
477
- ResourceFinder.prototype.putIntoMap = function (resId, value) {
478
- if (this.responseMap[resId.toUpperCase()] == null) {
479
- this.responseMap[resId.toUpperCase()] = [];
480
- }
481
- if (value) {
482
- this.responseMap[resId.toUpperCase()].push(value);
483
- }
343
+ ResourceFinder.prototype.putIntoMap = function(resId, value) {
344
+ if (this.responseMap[resId.toUpperCase()] == null) {
345
+ this.responseMap[resId.toUpperCase()] = [];
346
+ }
347
+ if (value) {
348
+ this.responseMap[resId.toUpperCase()].push(value);
349
+ }
484
350
  };
485
-
486
- module.exports = ResourceFinder;
351
+ module.exports = ResourceFinder;