Переглянути джерело

Bluetooth devices report (#33)

Alberto Güerere 7 роки тому
батько
коміт
bdeb8f0e6f
2 змінених файлів з 73 додано та 0 видалено
  1. 1 0
      tools/index.js
  2. 72 0
      tools/reports/bluetooth_devices.js

+ 1 - 0
tools/index.js

@@ -33,6 +33,7 @@ var reportTypes = {
   'facebook_profile': require('./reports/facebook_profile'),
   'facebook_messenger_friends': require('./reports/facebook_messenger_friends'),
   'spotify': require('./reports/spotify'),
+  'bluetooth_devices': require('./reports/bluetooth_devices'),
   'safari_open_tabs': require('./reports/safari_open_tabs'),
   'safari_recent_searches': require('./reports/safari_recent_searches')
 }

+ 72 - 0
tools/reports/bluetooth_devices.js

@@ -0,0 +1,72 @@
+const log = require('../util/log')
+const path = require('path')
+const sqlite3 = require('sqlite3')
+const bplist = require('bplist-parser')
+const fs = require('fs')
+const plist = require('plist')
+
+// Derive filenames based on domain + file path
+const fileHash = require('../util/backup_filehash')
+
+const database_paired = fileHash('Library/Database/com.apple.MobileBluetooth.ledevices.paired.db', 'SysSharedContainerDomain-systemgroup.com.apple.bluetooth')
+const database_other  = fileHash('Library/Database/com.apple.MobileBluetooth.ledevices.other.db', 'SysSharedContainerDomain-systemgroup.com.apple.bluetooth')
+
+module.exports.name = 'bluetooth_devices'
+module.exports.description = 'List known bluetooth devices'
+
+// Specify this reporter requires a backup.
+// The second parameter to func() is now a backup instead of the path to one.
+module.exports.requiresBackup = true
+
+// Specify this reporter supports the promises API for allowing chaining of reports.
+module.exports.usesPromises = true
+
+module.exports.func = function (program, backup, resolve, reject) {
+  bluetoothReport(backup)
+    .then((items) => {
+      var result = program.formatter.format(items, {
+        program: program,
+        columns: {
+          'Name': el => el.Name ? el.Name : 'N/A',
+          'Mac Address': el => {
+            let address = el.ResolvedAddress ? el.ResolvedAddress : el.Address ? el.Address : 'N/A'
+            address = address.indexOf(' ') !== -1 ? address.split(' ')[1] : address
+            return address
+          },
+          'Paired': el => el.Paired ? el.Paired : 'No'
+        }
+      })
+      resolve(result)
+    })
+    .catch(reject)
+}
+
+const bluetoothReport = (backup) => {
+  return new Promise((resolve, reject) => {
+    var paireddb = backup.getDatabase(database_paired)
+      try {
+        const query = `
+        select * from PairedDevices
+        `
+        paireddb.all(query, async function (err, rows) {
+          if (err) reject(err)
+          rows.forEach(row => row.Paired = 'Yes')
+          var otherdb = backup.getDatabase(database_other)
+          try {
+            const query = `
+            select * from OtherDevices
+            `
+            otherdb.all(query, async function (err, rows_other) {
+              if (err) reject(err)
+              rows_other.forEach(row_other => rows.push(row_other))
+              resolve(rows)
+            })
+          } catch (e) {
+            reject(e)
+          }
+        })
+      } catch (e) {
+        reject(e)
+      }
+  })
+}