@expo/plist 0.0.20 → 0.1.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,360 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.parseBuffer = exports.parseFile = exports.UID = exports.maxObjectCount = exports.maxObjectSize = void 0;
7
- // adapted from https://github.com/3breadt/dd-plist
8
- const fs_1 = __importDefault(require("fs"));
9
- const debug = false;
10
- exports.maxObjectSize = 100 * 1000 * 1000; // 100Meg
11
- exports.maxObjectCount = 32768;
12
- // EPOCH = new SimpleDateFormat("yyyy MM dd zzz").parse("2001 01 01 GMT").getTime();
13
- // ...but that's annoying in a static initializer because it can throw exceptions, ick.
14
- // So we just hardcode the correct value.
15
- const EPOCH = 978307200000;
16
- // UID object definition
17
- class UID {
18
- constructor(UID) {
19
- this.UID = UID;
20
- }
21
- }
22
- exports.UID = UID;
23
- async function parseFile(fileNameOrBuffer) {
24
- if (Buffer.isBuffer(fileNameOrBuffer)) {
25
- return exports.parseBuffer(fileNameOrBuffer);
26
- }
27
- const data = await fs_1.default.promises.readFile(fileNameOrBuffer);
28
- return exports.parseBuffer(data);
29
- }
30
- exports.parseFile = parseFile;
31
- ;
32
- const parseBuffer = (buffer) => {
33
- // check header
34
- const header = buffer.slice(0, 'bplist'.length).toString('utf8');
35
- if (header !== 'bplist') {
36
- throw new Error("Invalid binary plist. Expected 'bplist' at offset 0.");
37
- }
38
- // Handle trailer, last 32 bytes of the file
39
- const trailer = buffer.slice(buffer.length - 32, buffer.length);
40
- // 6 null bytes (index 0 to 5)
41
- const offsetSize = trailer.readUInt8(6);
42
- if (debug) {
43
- console.log('offsetSize: ' + offsetSize);
44
- }
45
- const objectRefSize = trailer.readUInt8(7);
46
- if (debug) {
47
- console.log('objectRefSize: ' + objectRefSize);
48
- }
49
- const numObjects = readUInt64BE(trailer, 8);
50
- if (debug) {
51
- console.log('numObjects: ' + numObjects);
52
- }
53
- const topObject = readUInt64BE(trailer, 16);
54
- if (debug) {
55
- console.log('topObject: ' + topObject);
56
- }
57
- const offsetTableOffset = readUInt64BE(trailer, 24);
58
- if (debug) {
59
- console.log('offsetTableOffset: ' + offsetTableOffset);
60
- }
61
- if (numObjects > exports.maxObjectCount) {
62
- throw new Error('maxObjectCount exceeded');
63
- }
64
- // Handle offset table
65
- const offsetTable = [];
66
- for (let i = 0; i < numObjects; i++) {
67
- const offsetBytes = buffer.slice(offsetTableOffset + i * offsetSize, offsetTableOffset + (i + 1) * offsetSize);
68
- offsetTable[i] = readUInt(offsetBytes, 0);
69
- if (debug) {
70
- console.log('Offset for Object #' +
71
- i +
72
- ' is ' +
73
- offsetTable[i] +
74
- ' [' +
75
- offsetTable[i].toString(16) +
76
- ']');
77
- }
78
- }
79
- // Parses an object inside the currently parsed binary property list.
80
- // For the format specification check
81
- // <a href="https://www.opensource.apple.com/source/CF/CF-635/CFBinaryPList.c">
82
- // Apple's binary property list parser implementation</a>.
83
- function parseObject(tableOffset) {
84
- const offset = offsetTable[tableOffset];
85
- const type = buffer[offset];
86
- const objType = (type & 0xf0) >> 4; //First 4 bits
87
- const objInfo = type & 0x0f; //Second 4 bits
88
- switch (objType) {
89
- case 0x0:
90
- return parseSimple();
91
- case 0x1:
92
- return parseInteger();
93
- case 0x8:
94
- return parseUID();
95
- case 0x2:
96
- return parseReal();
97
- case 0x3:
98
- return parseDate();
99
- case 0x4:
100
- return parseData();
101
- case 0x5: // ASCII
102
- return parsePlistString();
103
- case 0x6: // UTF-16
104
- return parsePlistString(true);
105
- case 0xa:
106
- return parseArray();
107
- case 0xd:
108
- return parseDictionary();
109
- default:
110
- throw new Error('Unhandled type 0x' + objType.toString(16));
111
- }
112
- function parseSimple() {
113
- //Simple
114
- switch (objInfo) {
115
- case 0x0: // null
116
- return null;
117
- case 0x8: // false
118
- return false;
119
- case 0x9: // true
120
- return true;
121
- case 0xf: // filler byte
122
- return null;
123
- default:
124
- throw new Error('Unhandled simple type 0x' + objType.toString(16));
125
- }
126
- }
127
- function bufferToHexString(buffer) {
128
- let str = '';
129
- let i;
130
- for (i = 0; i < buffer.length; i++) {
131
- if (buffer[i] != 0x00) {
132
- break;
133
- }
134
- }
135
- for (; i < buffer.length; i++) {
136
- const part = '00' + buffer[i].toString(16);
137
- str += part.substr(part.length - 2);
138
- }
139
- return str;
140
- }
141
- function parseInteger() {
142
- const length = Math.pow(2, objInfo);
143
- if (length < exports.maxObjectSize) {
144
- const data = buffer.slice(offset + 1, offset + 1 + length);
145
- if (length === 16) {
146
- const str = bufferToHexString(data);
147
- return BigInt(str); // bigInt(str, 16);
148
- }
149
- return data.reduce((acc, curr) => {
150
- acc <<= 8;
151
- acc |= curr & 255;
152
- return acc;
153
- });
154
- }
155
- else {
156
- throw new Error('Too little heap space available! Wanted to read ' +
157
- length +
158
- ' bytes, but only ' +
159
- exports.maxObjectSize +
160
- ' are available.');
161
- }
162
- }
163
- function parseUID() {
164
- const length = objInfo + 1;
165
- if (length < exports.maxObjectSize) {
166
- return new UID(readUInt(buffer.slice(offset + 1, offset + 1 + length)));
167
- }
168
- throw new Error('Too little heap space available! Wanted to read ' +
169
- length +
170
- ' bytes, but only ' +
171
- exports.maxObjectSize +
172
- ' are available.');
173
- }
174
- function parseReal() {
175
- const length = Math.pow(2, objInfo);
176
- if (length < exports.maxObjectSize) {
177
- const realBuffer = buffer.slice(offset + 1, offset + 1 + length);
178
- if (length === 4) {
179
- return realBuffer.readFloatBE(0);
180
- }
181
- if (length === 8) {
182
- return realBuffer.readDoubleBE(0);
183
- }
184
- }
185
- else {
186
- throw new Error('Too little heap space available! Wanted to read ' +
187
- length +
188
- ' bytes, but only ' +
189
- exports.maxObjectSize +
190
- ' are available.');
191
- }
192
- return null;
193
- }
194
- function parseDate() {
195
- if (objInfo != 0x3) {
196
- console.error('Unknown date type :' + objInfo + '. Parsing anyway...');
197
- }
198
- const dateBuffer = buffer.slice(offset + 1, offset + 9);
199
- return new Date(EPOCH + 1000 * dateBuffer.readDoubleBE(0));
200
- }
201
- function parseData() {
202
- let dataoffset = 1;
203
- let length = objInfo;
204
- if (objInfo == 0xf) {
205
- const int_type = buffer[offset + 1];
206
- const intType = (int_type & 0xf0) / 0x10;
207
- if (intType != 0x1) {
208
- console.error('0x4: UNEXPECTED LENGTH-INT TYPE! ' + intType);
209
- }
210
- const intInfo = int_type & 0x0f;
211
- const intLength = Math.pow(2, intInfo);
212
- dataoffset = 2 + intLength;
213
- if (intLength < 3) {
214
- length = readUInt(buffer.slice(offset + 2, offset + 2 + intLength));
215
- }
216
- else {
217
- length = readUInt(buffer.slice(offset + 2, offset + 2 + intLength));
218
- }
219
- }
220
- if (length < exports.maxObjectSize) {
221
- return buffer.slice(offset + dataoffset, offset + dataoffset + length);
222
- }
223
- throw new Error('Too little heap space available! Wanted to read ' +
224
- length +
225
- ' bytes, but only ' +
226
- exports.maxObjectSize +
227
- ' are available.');
228
- }
229
- function parsePlistString(isUtf16) {
230
- isUtf16 = isUtf16 || 0;
231
- let enc = 'utf8';
232
- let length = objInfo;
233
- let stroffset = 1;
234
- if (objInfo == 0xf) {
235
- const int_type = buffer[offset + 1];
236
- const intType = (int_type & 0xf0) / 0x10;
237
- if (intType != 0x1) {
238
- console.error('UNEXPECTED LENGTH-INT TYPE! ' + intType);
239
- }
240
- const intInfo = int_type & 0x0f;
241
- const intLength = Math.pow(2, intInfo);
242
- stroffset = 2 + intLength;
243
- if (intLength < 3) {
244
- length = readUInt(buffer.slice(offset + 2, offset + 2 + intLength));
245
- }
246
- else {
247
- length = readUInt(buffer.slice(offset + 2, offset + 2 + intLength));
248
- }
249
- }
250
- // length is String length -> to get byte length multiply by 2, as 1 character takes 2 bytes in UTF-16
251
- length *= isUtf16 + 1;
252
- if (length < exports.maxObjectSize) {
253
- let plistString = Buffer.from(buffer.slice(offset + stroffset, offset + stroffset + length));
254
- if (isUtf16) {
255
- plistString = swapBytes(plistString);
256
- enc = 'ucs2';
257
- }
258
- return plistString.toString(enc);
259
- }
260
- throw new Error('Too little heap space available! Wanted to read ' +
261
- length +
262
- ' bytes, but only ' +
263
- exports.maxObjectSize +
264
- ' are available.');
265
- }
266
- function parseArray() {
267
- let length = objInfo;
268
- let arrayoffset = 1;
269
- if (objInfo == 0xf) {
270
- const int_type = buffer[offset + 1];
271
- const intType = (int_type & 0xf0) / 0x10;
272
- if (intType != 0x1) {
273
- console.error('0xa: UNEXPECTED LENGTH-INT TYPE! ' + intType);
274
- }
275
- const intInfo = int_type & 0x0f;
276
- const intLength = Math.pow(2, intInfo);
277
- arrayoffset = 2 + intLength;
278
- if (intLength < 3) {
279
- length = readUInt(buffer.slice(offset + 2, offset + 2 + intLength));
280
- }
281
- else {
282
- length = readUInt(buffer.slice(offset + 2, offset + 2 + intLength));
283
- }
284
- }
285
- if (length * objectRefSize > exports.maxObjectSize) {
286
- throw new Error('Too little heap space available!');
287
- }
288
- const array = [];
289
- for (let i = 0; i < length; i++) {
290
- const objRef = readUInt(buffer.slice(offset + arrayoffset + i * objectRefSize, offset + arrayoffset + (i + 1) * objectRefSize));
291
- array[i] = parseObject(objRef);
292
- }
293
- return array;
294
- }
295
- function parseDictionary() {
296
- let length = objInfo;
297
- let dictoffset = 1;
298
- if (objInfo == 0xf) {
299
- const int_type = buffer[offset + 1];
300
- const intType = (int_type & 0xf0) / 0x10;
301
- if (intType != 0x1) {
302
- console.error('0xD: UNEXPECTED LENGTH-INT TYPE! ' + intType);
303
- }
304
- const intInfo = int_type & 0x0f;
305
- const intLength = Math.pow(2, intInfo);
306
- dictoffset = 2 + intLength;
307
- if (intLength < 3) {
308
- length = readUInt(buffer.slice(offset + 2, offset + 2 + intLength));
309
- }
310
- else {
311
- length = readUInt(buffer.slice(offset + 2, offset + 2 + intLength));
312
- }
313
- }
314
- if (length * 2 * objectRefSize > exports.maxObjectSize) {
315
- throw new Error('Too little heap space available!');
316
- }
317
- if (debug) {
318
- console.log('Parsing dictionary #' + tableOffset);
319
- }
320
- const dict = {};
321
- for (let i = 0; i < length; i++) {
322
- const keyRef = readUInt(buffer.slice(offset + dictoffset + i * objectRefSize, offset + dictoffset + (i + 1) * objectRefSize));
323
- const valRef = readUInt(buffer.slice(offset + dictoffset + length * objectRefSize + i * objectRefSize, offset + dictoffset + length * objectRefSize + (i + 1) * objectRefSize));
324
- const key = parseObject(keyRef);
325
- const val = parseObject(valRef);
326
- if (debug) {
327
- console.log(' DICT #' + tableOffset + ': Mapped ' + key + ' to ' + val);
328
- }
329
- dict[key] = val;
330
- }
331
- return dict;
332
- }
333
- }
334
- return [parseObject(topObject)];
335
- };
336
- exports.parseBuffer = parseBuffer;
337
- function readUInt(buffer, start = 0) {
338
- start = start || 0;
339
- let l = 0;
340
- for (let i = start; i < buffer.length; i++) {
341
- l <<= 8;
342
- l |= buffer[i] & 0xff;
343
- }
344
- return l;
345
- }
346
- // we're just going to toss the high order bits because javascript doesn't have 64-bit ints
347
- function readUInt64BE(buffer, start) {
348
- const data = buffer.slice(start, start + 8);
349
- return data.readUInt32BE(4, 8);
350
- }
351
- function swapBytes(buffer) {
352
- const len = buffer.length;
353
- for (let i = 0; i < len; i += 2) {
354
- const a = buffer[i];
355
- buffer[i] = buffer[i + 1];
356
- buffer[i + 1] = a;
357
- }
358
- return buffer;
359
- }
360
- //# sourceMappingURL=osxBinary.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"osxBinary.js","sourceRoot":"","sources":["../src/osxBinary.ts"],"names":[],"mappings":";;;;;;AAAA,mDAAmD;AACnD,4CAAoB;AAIpB,MAAM,KAAK,GAAG,KAAK,CAAC;AAEP,QAAA,aAAa,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,SAAS;AAC5C,QAAA,cAAc,GAAG,KAAK,CAAC;AAEpC,oFAAoF;AACpF,uFAAuF;AACvF,yCAAyC;AACzC,MAAM,KAAK,GAAG,YAAY,CA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KACnB;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["// adapted from https://github.com/3breadt/dd-plist\nimport fs from 'fs';\n\nimport { PlistValue } from '.';\n\nconst debug = false;\n\nexport const maxObjectSize = 100 * 1000 * 1000; // 100Meg\nexport const maxObjectCount = 32768;\n\n// EPOCH = new SimpleDateFormat(\"yyyy MM dd zzz\").parse(\"2001 01 01 GMT\").getTime();\n// ...but that's annoying in a static initializer because it can throw exceptions, ick.\n// So we just hardcode the correct value.\nconst EPOCH = 978307200000;\n\n// UID object definition\n\nexport class UID {\n constructor(public UID: number) {}\n}\n\nexport async function parseFile(fileNameOrBuffer: string | Buffer) {\n if (Buffer.isBuffer(fileNameOrBuffer)) {\n return parseBuffer(fileNameOrBuffer);\n }\n\n const data = await fs.promises.readFile(fileNameOrBuffer);\n return parseBuffer(data);\n};\n\nexport const parseBuffer = (buffer: Buffer) => {\n // check header\n const header = buffer.slice(0, 'bplist'.length).toString('utf8');\n if (header !== 'bplist') {\n throw new Error(\"Invalid binary plist. Expected 'bplist' at offset 0.\");\n }\n\n // Handle trailer, last 32 bytes of the file\n const trailer = buffer.slice(buffer.length - 32, buffer.length);\n // 6 null bytes (index 0 to 5)\n const offsetSize = trailer.readUInt8(6);\n if (debug) {\n console.log('offsetSize: ' + offsetSize);\n }\n const objectRefSize = trailer.readUInt8(7);\n if (debug) {\n console.log('objectRefSize: ' + objectRefSize);\n }\n const numObjects = readUInt64BE(trailer, 8);\n if (debug) {\n console.log('numObjects: ' + numObjects);\n }\n const topObject = readUInt64BE(trailer, 16);\n if (debug) {\n console.log('topObject: ' + topObject);\n }\n const offsetTableOffset = readUInt64BE(trailer, 24);\n if (debug) {\n console.log('offsetTableOffset: ' + offsetTableOffset);\n }\n\n if (numObjects > exports.maxObjectCount) {\n throw new Error('maxObjectCount exceeded');\n }\n\n // Handle offset table\n const offsetTable: number[] = [];\n\n for (let i = 0; i < numObjects; i++) {\n const offsetBytes = buffer.slice(\n offsetTableOffset + i * offsetSize,\n offsetTableOffset + (i + 1) * offsetSize\n );\n offsetTable[i] = readUInt(offsetBytes, 0);\n if (debug) {\n console.log(\n 'Offset for Object #' +\n i +\n ' is ' +\n offsetTable[i] +\n ' [' +\n offsetTable[i].toString(16) +\n ']'\n );\n }\n }\n\n // Parses an object inside the currently parsed binary property list.\n // For the format specification check\n // <a href=\"https://www.opensource.apple.com/source/CF/CF-635/CFBinaryPList.c\">\n // Apple's binary property list parser implementation</a>.\n function parseObject(tableOffset: number): PlistValue | null | UID {\n const offset = offsetTable[tableOffset];\n const type = buffer[offset];\n const objType = (type & 0xf0) >> 4; //First 4 bits\n const objInfo = type & 0x0f; //Second 4 bits\n switch (objType) {\n case 0x0:\n return parseSimple();\n case 0x1:\n return parseInteger();\n case 0x8:\n return parseUID();\n case 0x2:\n return parseReal();\n case 0x3:\n return parseDate();\n case 0x4:\n return parseData();\n case 0x5: // ASCII\n return parsePlistString();\n case 0x6: // UTF-16\n return parsePlistString(true);\n case 0xa:\n return parseArray();\n case 0xd:\n return parseDictionary();\n default:\n throw new Error('Unhandled type 0x' + objType.toString(16));\n }\n\n function parseSimple(): boolean | null {\n //Simple\n switch (objInfo) {\n case 0x0: // null\n return null;\n case 0x8: // false\n return false;\n case 0x9: // true\n return true;\n case 0xf: // filler byte\n return null;\n default:\n throw new Error('Unhandled simple type 0x' + objType.toString(16));\n }\n }\n\n function bufferToHexString(buffer: Buffer) {\n let str = '';\n let i;\n for (i = 0; i < buffer.length; i++) {\n if (buffer[i] != 0x00) {\n break;\n }\n }\n for (; i < buffer.length; i++) {\n const part = '00' + buffer[i].toString(16);\n str += part.substr(part.length - 2);\n }\n return str;\n }\n\n function parseInteger(): number | BigInt {\n const length = Math.pow(2, objInfo);\n if (length < exports.maxObjectSize) {\n const data = buffer.slice(offset + 1, offset + 1 + length);\n if (length === 16) {\n const str = bufferToHexString(data);\n return BigInt(str) // bigInt(str, 16);\n }\n return data.reduce((acc, curr) => {\n acc <<= 8;\n acc |= curr & 255;\n return acc;\n });\n } else {\n throw new Error(\n 'Too little heap space available! Wanted to read ' +\n length +\n ' bytes, but only ' +\n exports.maxObjectSize +\n ' are available.'\n );\n }\n }\n\n function parseUID() {\n const length = objInfo + 1;\n if (length < exports.maxObjectSize) {\n return new UID(readUInt(buffer.slice(offset + 1, offset + 1 + length)));\n }\n throw new Error(\n 'Too little heap space available! Wanted to read ' +\n length +\n ' bytes, but only ' +\n exports.maxObjectSize +\n ' are available.'\n );\n }\n\n function parseReal(): number | null {\n const length = Math.pow(2, objInfo);\n if (length < exports.maxObjectSize) {\n const realBuffer = buffer.slice(offset + 1, offset + 1 + length);\n if (length === 4) {\n return realBuffer.readFloatBE(0);\n }\n if (length === 8) {\n return realBuffer.readDoubleBE(0);\n }\n } else {\n throw new Error(\n 'Too little heap space available! Wanted to read ' +\n length +\n ' bytes, but only ' +\n exports.maxObjectSize +\n ' are available.'\n );\n }\n return null;\n }\n\n function parseDate() {\n if (objInfo != 0x3) {\n console.error('Unknown date type :' + objInfo + '. Parsing anyway...');\n }\n const dateBuffer = buffer.slice(offset + 1, offset + 9);\n return new Date(EPOCH + 1000 * dateBuffer.readDoubleBE(0));\n }\n\n function parseData() {\n let dataoffset = 1;\n let length = objInfo;\n if (objInfo == 0xf) {\n const int_type = buffer[offset + 1];\n const intType = (int_type & 0xf0) / 0x10;\n if (intType != 0x1) {\n console.error('0x4: UNEXPECTED LENGTH-INT TYPE! ' + intType);\n }\n const intInfo = int_type & 0x0f;\n const intLength = Math.pow(2, intInfo);\n dataoffset = 2 + intLength;\n if (intLength < 3) {\n length = readUInt(buffer.slice(offset + 2, offset + 2 + intLength));\n } else {\n length = readUInt(buffer.slice(offset + 2, offset + 2 + intLength));\n }\n }\n if (length < exports.maxObjectSize) {\n return buffer.slice(offset + dataoffset, offset + dataoffset + length);\n }\n throw new Error(\n 'Too little heap space available! Wanted to read ' +\n length +\n ' bytes, but only ' +\n exports.maxObjectSize +\n ' are available.'\n );\n }\n\n function parsePlistString(isUtf16?: number): string {\n isUtf16 = isUtf16 || 0;\n let enc = 'utf8';\n let length = objInfo;\n let stroffset = 1;\n if (objInfo == 0xf) {\n const int_type = buffer[offset + 1];\n const intType = (int_type & 0xf0) / 0x10;\n if (intType != 0x1) {\n console.error('UNEXPECTED LENGTH-INT TYPE! ' + intType);\n }\n const intInfo = int_type & 0x0f;\n const intLength = Math.pow(2, intInfo);\n stroffset = 2 + intLength;\n if (intLength < 3) {\n length = readUInt(buffer.slice(offset + 2, offset + 2 + intLength));\n } else {\n length = readUInt(buffer.slice(offset + 2, offset + 2 + intLength));\n }\n }\n // length is String length -> to get byte length multiply by 2, as 1 character takes 2 bytes in UTF-16\n length *= isUtf16 + 1;\n if (length < exports.maxObjectSize) {\n let plistString = Buffer.from(\n buffer.slice(offset + stroffset, offset + stroffset + length)\n );\n if (isUtf16) {\n plistString = swapBytes(plistString);\n enc = 'ucs2';\n }\n return plistString.toString(enc);\n }\n throw new Error(\n 'Too little heap space available! Wanted to read ' +\n length +\n ' bytes, but only ' +\n exports.maxObjectSize +\n ' are available.'\n );\n }\n\n function parseArray() {\n let length = objInfo;\n let arrayoffset = 1;\n if (objInfo == 0xf) {\n const int_type = buffer[offset + 1];\n const intType = (int_type & 0xf0) / 0x10;\n if (intType != 0x1) {\n console.error('0xa: UNEXPECTED LENGTH-INT TYPE! ' + intType);\n }\n const intInfo = int_type & 0x0f;\n const intLength = Math.pow(2, intInfo);\n arrayoffset = 2 + intLength;\n if (intLength < 3) {\n length = readUInt(buffer.slice(offset + 2, offset + 2 + intLength));\n } else {\n length = readUInt(buffer.slice(offset + 2, offset + 2 + intLength));\n }\n }\n if (length * objectRefSize > exports.maxObjectSize) {\n throw new Error('Too little heap space available!');\n }\n const array: (PlistValue | UID | null)[] = [];\n for (let i = 0; i < length; i++) {\n const objRef = readUInt(\n buffer.slice(\n offset + arrayoffset + i * objectRefSize,\n offset + arrayoffset + (i + 1) * objectRefSize\n )\n );\n array[i] = parseObject(objRef);\n }\n return array;\n }\n\n function parseDictionary() {\n let length = objInfo;\n let dictoffset = 1;\n if (objInfo == 0xf) {\n const int_type = buffer[offset + 1];\n const intType = (int_type & 0xf0) / 0x10;\n if (intType != 0x1) {\n console.error('0xD: UNEXPECTED LENGTH-INT TYPE! ' + intType);\n }\n const intInfo = int_type & 0x0f;\n const intLength = Math.pow(2, intInfo);\n dictoffset = 2 + intLength;\n if (intLength < 3) {\n length = readUInt(buffer.slice(offset + 2, offset + 2 + intLength));\n } else {\n length = readUInt(buffer.slice(offset + 2, offset + 2 + intLength));\n }\n }\n if (length * 2 * objectRefSize > exports.maxObjectSize) {\n throw new Error('Too little heap space available!');\n }\n if (debug) {\n console.log('Parsing dictionary #' + tableOffset);\n }\n const dict: Record<string, PlistValue | UID | null> = {};\n for (let i = 0; i < length; i++) {\n const keyRef = readUInt(\n buffer.slice(\n offset + dictoffset + i * objectRefSize,\n offset + dictoffset + (i + 1) * objectRefSize\n )\n );\n const valRef = readUInt(\n buffer.slice(\n offset + dictoffset + length * objectRefSize + i * objectRefSize,\n offset + dictoffset + length * objectRefSize + (i + 1) * objectRefSize\n )\n );\n const key = parseObject(keyRef);\n const val = parseObject(valRef);\n if (debug) {\n console.log(' DICT #' + tableOffset + ': Mapped ' + key + ' to ' + val);\n }\n dict[key] = val;\n }\n return dict;\n }\n }\n\n return [parseObject(topObject)];\n});\n\nfunction readUInt(buffer: Buffer, start: number = 0): number {\n start = start || 0;\n\n let l = 0;\n for (let i = start; i < buffer.length; i++) {\n l <<= 8;\n l |= buffer[i] & 0xff;\n }\n return l;\n}\n\n// we're just going to toss the high order bits because javascript doesn't have 64-bit ints\nfunction readUInt64BE(buffer: Buffer, start: number) {\n const data = buffer.slice(start, start + 8);\n return data.readUInt32BE(4, 8);\n}\n\nfunction swapBytes(buffer: Buffer) {\n const len = buffer.length;\n for (let i = 0; i < len; i += 2) {\n const a = buffer[i];\n buffer[i] = buffer[i + 1];\n buffer[i + 1] = a;\n }\n return buffer;\n}\n"]}