bluetooth_devices.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. const log = require('../util/log')
  2. const path = require('path')
  3. const sqlite3 = require('sqlite3')
  4. const bplist = require('bplist-parser')
  5. const fs = require('fs')
  6. const plist = require('plist')
  7. // Derive filenames based on domain + file path
  8. const fileHash = require('../util/backup_filehash')
  9. const database_paired = fileHash('Library/Database/com.apple.MobileBluetooth.ledevices.paired.db', 'SysSharedContainerDomain-systemgroup.com.apple.bluetooth')
  10. const database_other = fileHash('Library/Database/com.apple.MobileBluetooth.ledevices.other.db', 'SysSharedContainerDomain-systemgroup.com.apple.bluetooth')
  11. module.exports.name = 'bluetooth_devices'
  12. module.exports.description = 'List known bluetooth devices'
  13. // Specify this reporter requires a backup.
  14. // The second parameter to func() is now a backup instead of the path to one.
  15. module.exports.requiresBackup = true
  16. // Specify this reporter supports the promises API for allowing chaining of reports.
  17. module.exports.usesPromises = true
  18. module.exports.func = function (program, backup, resolve, reject) {
  19. bluetoothReport(backup)
  20. .then((items) => {
  21. var result = program.formatter.format(items, {
  22. program: program,
  23. columns: {
  24. 'Name': el => el.Name ? el.Name : 'N/A',
  25. 'Mac Address': el => {
  26. let address = el.ResolvedAddress ? el.ResolvedAddress : el.Address ? el.Address : 'N/A'
  27. address = address.indexOf(' ') !== -1 ? address.split(' ')[1] : address
  28. return address
  29. },
  30. 'Paired': el => el.Paired ? el.Paired : 'No'
  31. }
  32. })
  33. resolve(result)
  34. })
  35. .catch(reject)
  36. }
  37. const bluetoothReport = (backup) => {
  38. return new Promise((resolve, reject) => {
  39. var paireddb = backup.getDatabase(database_paired)
  40. try {
  41. const query = `
  42. select * from PairedDevices
  43. `
  44. paireddb.all(query, async function (err, rows) {
  45. if (err) reject(err)
  46. rows.forEach(row => row.Paired = 'Yes')
  47. var otherdb = backup.getDatabase(database_other)
  48. try {
  49. const query = `
  50. select * from OtherDevices
  51. `
  52. otherdb.all(query, async function (err, rows_other) {
  53. if (err) reject(err)
  54. rows_other.forEach(row_other => rows.push(row_other))
  55. resolve(rows)
  56. })
  57. } catch (e) {
  58. reject(e)
  59. }
  60. })
  61. } catch (e) {
  62. reject(e)
  63. }
  64. })
  65. }