bplist-parser
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -86,2 +86,3 @@ 'use strict'; | ||
case 0x1: | ||
case 0x8: // UID (really just an integer) | ||
return parseInteger(); | ||
@@ -98,8 +99,4 @@ case 0x2: | ||
return parsePlistString(true); | ||
case 0x8: | ||
return parseUid(); | ||
case 0xA: | ||
return parseArray(); | ||
case 0xC: | ||
return parseSet(); | ||
case 0xD: | ||
@@ -180,2 +177,4 @@ return parseDictionary(); | ||
function parsePlistString (isUtf16) { | ||
isUtf16 = isUtf16 || 0; | ||
var enc = "utf8"; | ||
var length = objInfo; | ||
@@ -198,24 +197,16 @@ var stroffset = 1; | ||
} | ||
//length is String length -> to get byte length multiply by 2, as 1 character takes 2 bytes in UTF-16 | ||
if (isUtf16) { | ||
console.log('is utf 16'); | ||
length *= 2; | ||
} | ||
// length is String length -> to get byte length multiply by 2, as 1 character takes 2 bytes in UTF-16 | ||
length *= (isUtf16 + 1); | ||
if (length < exports.maxObjectSize) { | ||
return buffer.slice(offset + stroffset, offset + stroffset + length).toString('utf8'); | ||
var plistString = buffer.slice(offset + stroffset, offset + stroffset + length); | ||
if (isUtf16) { | ||
plistString = swapBytes(plistString); | ||
enc = "ucs2"; | ||
} | ||
return plistString.toString(enc); | ||
} else { | ||
throw new Error("To little heap space available! Watned to read " + length + " bytes, but only " + exports.maxObjectSize + " are available."); | ||
throw new Error("To little heap space available! Wanted to read " + length + " bytes, but only " + exports.maxObjectSize + " are available."); | ||
} | ||
} | ||
function parseUid() { | ||
throw new Error("parseUid not implemented"); | ||
// int length = objInfo + 1; | ||
// if (length < exports.maxObjectSize) { | ||
// return new UID(String.valueOf(obj), copyOfRange(bytes, offset + 1, offset + 1 + length)); | ||
// } else { | ||
// throw new Error("To little heap space available! Wanted to read " + length + " bytes, but only " + exports.maxObjectSize + " are available."); | ||
// } | ||
} | ||
function parseArray() { | ||
@@ -250,34 +241,2 @@ var length = objInfo; | ||
function parseSet() { | ||
throw new Error("parseSet not implemented"); | ||
// int length = objInfo; | ||
// int arrayoffset = 1; | ||
// if (objInfo == 0xF) { | ||
// int int_type = bytes[offset + 1]; | ||
// int intType = (int_type & 0xF0) / 0x10; | ||
// if (intType != 0x1) { | ||
// System.err.println("UNEXPECTED LENGTH-INT TYPE! " + intType); | ||
// } | ||
// int intInfo = int_type & 0x0F; | ||
// int intLength = (int) Math.pow(2, intInfo); | ||
// arrayoffset = 2 + intLength; | ||
// if (intLength < 3) { | ||
// length = (int) parseUnsignedInt(copyOfRange(bytes, offset + 2, offset + 2 + intLength)); | ||
// } else { | ||
// length = new BigInteger(copyOfRange(bytes, offset + 2, offset + 2 + intLength)).intValue(); | ||
// } | ||
// }bytes | ||
// if (length * objectRefSize > exports.maxObjectSize) { | ||
// throw new Error("To little heap space available!"); | ||
// } | ||
// NSSet set = new NSSet(); | ||
// for (int i = 0; i < length; i++) { | ||
// int objRef = (int) parseUnsignedInt(copyOfRange(bytes, | ||
// offset + arrayoffset + i * objectRefSize, | ||
// offset + arrayoffset + (i + 1) * objectRefSize)); | ||
// set.addObject(parseObject(objRef)); | ||
// } | ||
// return set; | ||
} | ||
function parseDictionary() { | ||
@@ -341,1 +300,11 @@ var length = objInfo; | ||
} | ||
function swapBytes(buffer) { | ||
var len = buffer.length; | ||
for (var i = 0; i < len; i += 2) { | ||
var a = buffer[i]; | ||
buffer[i] = buffer[i+1]; | ||
buffer[i+1] = a; | ||
} | ||
return buffer; | ||
} |
{ | ||
"name": "bplist-parser", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Binary plist parser.", | ||
@@ -5,0 +5,0 @@ "main": "bplistParser.js", |
@@ -82,3 +82,3 @@ 'use strict'; | ||
'utf16': function (test) { | ||
var file = path.join(__dirname, "utf16.plist"); | ||
var file = path.join(__dirname, "utf16.bplist"); | ||
var startTime = new Date(); | ||
@@ -97,5 +97,26 @@ | ||
test.equal(dict['CFBundleShortVersionString'], '2.6.1'); | ||
test.equal(dict['NSHumanReadableCopyright'], '©2008-2012, sellStuff, Inc.'); | ||
test.done(); | ||
}); | ||
}, | ||
'uid': function (test) { | ||
var file = path.join(__dirname, "uid.bplist"); | ||
var startTime = new Date(); | ||
bplist.parseFile(file, function (err, dicts) { | ||
if (err) { | ||
throw err; | ||
} | ||
var endTime = new Date(); | ||
console.log('Parsed "' + file + '" in ' + (endTime - startTime) + 'ms'); | ||
var dict = dicts[0]; | ||
test.deepEqual(dict['$objects'][1]['NS.keys'], [2, 3, 4]); | ||
test.deepEqual(dict['$objects'][1]['NS.objects'], [5, 6, 7]); | ||
test.equal(dict['$top']['root'], 1); | ||
test.done(); | ||
}); | ||
} | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 2 instances in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
11
0
42927
376
7