Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
res.on('end', function () {
var body = Buffer.concat(buffers)
switch (res.headers['content-type']) {
case 'application/x-apple-binary-plist':
body = bplistDecode(body)[0]
break
case 'text/x-apple-plist+xml':
body = plist.parse(body.toString())
break
case 'text/parameters':
body = body.toString().trim().split('\n').reduce(function (body, line) {
line = line.split(': ')
// TODO: For now it's only floats, but it might be better to not expect that
body[line[0]] = parseFloat(line[1], 10)
return body
}, {})
break
}
cb(err, res, body)
})
read_pos += 4;
// Is there enough data here?
// If not, jump back to our original position and gtfo
if( recieved.length < msg_length + read_pos ) {
read_pos = old_read_pos;
break;
}
// Extract the main body of the message (where the plist should be)
var body = recieved.slice(read_pos, msg_length + read_pos);
// Extract the plist
var plist;
try {
plist = bplist_parse.parseBuffer(body);
} catch (e) {
console.log(e);
}
// bplist_parse.parseBuffer returns an array
if( plist.length === 1 ) {
plist = plist[0];
}
log();
log('plist ===================================='.green);
log();
log(
util.inspect(plist, false, null)
);
log();
data.push(second);
}
}
});
// console.log(data.join(','));
console.log(data.length);
var buf = new Buffer(data.slice(8));
console.log(buf);
console.log(buf.length);
var plist;
try {
plist = bplist_parse.parseBuffer(buf);
} catch (e) {
console.log(e);
}
console.log(util.inspect(plist, false, null));
if( plist[0].__argument.WIRSocketDataKey ) {
console.log(plist[0].__argument.WIRSocketDataKey.toString());
}
if( plist[0].__argument.WIRMessageDataKey ) {
console.log(plist[0].__argument.WIRMessageDataKey.toString());
}
// Jump forward 4 bytes
this.readPos += 4;
// Is there enough data here?
// If not, jump back to our original position and gtfo
if (this.received.length < msgLength + this.readPos) {
this.readPos = oldReadPos;
break;
}
// Extract the main body of the message (where the plist should be)
body = this.received.slice(this.readPos, msgLength + this.readPos);
// Extract the plist
try {
plist = bplistParse.parseBuffer(body);
} catch (e) {
this.logger.error("Error parsing binary plist");
this.logger.debug(e);
}
// bplistParse.parseBuffer returns an array
if (plist.length === 1) {
plist = plist[0];
}
var plistCopy = plist;
if (typeof plistCopy.WIRMessageDataKey !== "undefined") {
plistCopy.WIRMessageDataKey = plistCopy.WIRMessageDataKey.toString("utf8");
}
if (typeof plistCopy.WIRDestinationKey !== "undefined") {
plistCopy.WIRDestinationKey = plistCopy.WIRDestinationKey.toString("utf8");
function parse(aStringOrBuffer, aFile) {
const firstByte = aStringOrBuffer[0]
let results
try {
if (firstByte === 60 || firstByte === '<') {
results = plist.parse(aStringOrBuffer.toString())
} else if (firstByte === 98) {
;[results] = bplistParser.parseBuffer(aStringOrBuffer)
} else if (aFile != null) {
throw new Error(`Unable to determine format for '${aFile}'`)
} else {
throw new Error('Unable to determine format for plist aStringOrBuffer')
}
} catch (error) {
throw new Error(error)
}
return results
}
exports.readFileSync = function(aFile) {
var results,
contents = fs.readFileSync(aFile),
firstByte = contents[0];
if (contents.length === 0) {
console.error("Unable to read file '%s'", aFile);
return {};
}
try {
if (firstByte === 60) {
results = plist.parse(contents.toString());
}
else if (firstByte === 98) {
results = bplistParser.parseBuffer(contents)[0];
}
else {
console.error("Unable to determine format for '%s'", aFile);
results = {};
}
}
catch(e) {
throw Error("'%s' has errors", aFile);
}
return results;
};
private parseBody(body: Buffer): string {
const [ root ] = bplist.parseBuffer(body);
return plist.build(root);
}
function parse(aStringOrBuffer, aFile) {
const firstByte = aStringOrBuffer[0]
let results
try {
if (firstByte === 60 || firstByte === '<') {
results = plist.parse(aStringOrBuffer.toString())
} else if (firstByte === 98) {
;[results] = bplistParser.parseBuffer(aStringOrBuffer)
} else if (aFile != null) {
throw new Error(`Unable to determine format for '${aFile}'`)
} else {
throw new Error('Unable to determine format for plist aStringOrBuffer')
}
} catch (error) {
throw new Error(error)
}
return results
}
function parseArchive (base64String) {
const buf2 = Buffer.from(base64String, 'base64');
const obj = bplistParser.parseBuffer(buf2);
const parser = new NSArchiveParser();
return parser.parse(obj);
}
module.exports = styleParser;
_parsePlist (buffer) {
let result
const bufferType = buffer[0]
if (bufferType === 60 || bufferType === '<' || bufferType === 239) {
result = parsePlist(buffer.toString())
} else if (bufferType === 98) {
result = parseBplist(buffer)[0]
} else {
throw new Error('Unknow plist buffer type.')
}
return result
}
/**