frida-js
Version:
Pure-JS bindings to control Frida from node.js & browsers.
35 lines • 1.23 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseDBusValue = parseDBusValue;
exports.parseDBusVariantDict = parseDBusVariantDict;
const Long = require("long");
function parseDBusValue(dbusValue) {
const [type] = dbusValue[0];
const [...rawValue] = dbusValue[1];
if (type.type === 's') {
// It's a raw string, great.
return rawValue[0];
}
else if (type.type === 'a' &&
type.child[0].type === '{' &&
type.child[0].child[0].type === 's' &&
type.child[0].child[1].type === 'v') {
// Variant dict - parse into an object
return parseDBusVariantDict(rawValue[0]);
}
else if (type.type === 'x' || type.type === 't') {
const signed = type.type === 'x';
const [low, high] = rawValue;
return Long.fromBits(low, high ?? 0, signed).toString(); // We map all metadata to string
}
else {
throw new Error(`Unrecognized D-Bus type: ${JSON.stringify(type)}`);
}
}
function parseDBusVariantDict(dbusDict) {
return dbusDict.reduce((dict, [key, value]) => {
dict[key] = parseDBusValue(value);
return dict;
}, {});
}
//# sourceMappingURL=dbus-value.js.map