messenger.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. const log = require('../../../util/log')
  2. // Derive filenames based on domain + file path
  3. const fileHash = require('../../../util/backup_filehash')
  4. const domain = 'AppDomainGroup-group.com.facebook.Messenger'
  5. module.exports = {
  6. version: 4,
  7. name: 'facebook_messenger_friends',
  8. description: `Show Facebook Messenger friends`,
  9. requiresBackup: true,
  10. // Run on a v3 lib / backup object.
  11. run (lib, { backup }) {
  12. return facebookMessengerFriendsReport(backup)
  13. },
  14. // Fields for apps report
  15. output: {
  16. 'Facebook Friend Username': el => el.field_value
  17. }
  18. }
  19. const facebookMessengerFriendsReport = (backup, file) => {
  20. return new Promise((resolve, reject) => {
  21. backup.getManifest()
  22. .then((items) => {
  23. let filename = 'fbomnistore.db'
  24. let fileitem = items.find((file) => {
  25. if (file && file.relativePath) { return ~file.relativePath.indexOf(filename) }
  26. return false
  27. })
  28. if (fileitem) {
  29. let filepath = fileitem.relativePath
  30. let file = fileHash(filepath, domain)
  31. backup.openDatabase(file).then(database => {
  32. database.get(`
  33. SELECT name
  34. FROM sqlite_master
  35. WHERE type='table'
  36. AND name LIKE 'collection_index#messenger_contacts_ios%'
  37. LIMIT 1
  38. `,
  39. (err, tableName) => {
  40. if (err) return reject(err)
  41. tableName = tableName.name
  42. log.verbose('Table', tableName)
  43. database.all(`
  44. SELECT field_value
  45. FROM '${tableName}'
  46. WHERE field_name='username'
  47. `, (err, rows) => {
  48. if (err) return reject(err)
  49. resolve(rows)
  50. })
  51. })
  52. }).catch(reject)
  53. } else reject("Cannot find fbomnistore.db") // Return an empty array to the formatter, since no fbomnistore.db file can be found in the manifest
  54. })
  55. })
  56. }