facebook_profile.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 file = fileHash('Library/Preferences/com.facebook.Messenger.plist', 'AppDomain-com.facebook.Messenger')
  10. module.exports.name = 'facebook_profile'
  11. module.exports.description = 'Show Facebook Messenger user id'
  12. // Specify this reporter requires a backup.
  13. // The second parameter to func() is now a backup instead of the path to one.
  14. module.exports.requiresBackup = true
  15. // Specify this reporter supports the promises API for allowing chaining of reports.
  16. module.exports.usesPromises = true
  17. module.exports.func = function (program, backup, resolve, reject) {
  18. facebookProfileReport(backup)
  19. .then((items) => {
  20. var result = program.formatter.format(items, {
  21. program: program,
  22. columns: {
  23. 'Facebook User ID': el => el.fbid
  24. }
  25. })
  26. resolve(result)
  27. })
  28. .catch(reject)
  29. }
  30. const facebookProfileReport = (backup) => {
  31. return new Promise((resolve, reject) => {
  32. var filename = backup.getFileName(file)
  33. try {
  34. let facebookPlist = bplist.parseBuffer(fs.readFileSync(filename))[0]
  35. let facebookUserIds = Object.keys(facebookPlist['kUserGlobalSettings'])
  36. facebookUserIds = facebookUserIds.map((fbid) => ({
  37. fbid: fbid
  38. }))
  39. resolve(facebookUserIds)
  40. } catch (e) {
  41. reject(e)
  42. }
  43. })
  44. }