contacts.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Derive filenames based on domain + file path
  2. const fileHash = require('../../../util/backup_filehash')
  3. const database = fileHash('com.viber/database/Contacts.data', 'AppDomainGroup-group.viber.share.container')
  4. module.exports.name = 'viber_contacts'
  5. module.exports.description = 'List Viber contacts'
  6. // Specify this reporter requires a backup.
  7. // The second parameter to func() is now a backup instead of the path to one.
  8. module.exports.requiresBackup = true
  9. // Specify this reporter supports the promises API for allowing chaining of reports.
  10. module.exports.usesPromises = true
  11. module.exports.func = function (program, backup, resolve, reject) {
  12. viberContactsReport(backup)
  13. .then((items) => {
  14. var result = program.formatter.format(items, {
  15. program: program,
  16. columns: {
  17. 'PK': el => el.Z_PK,
  18. 'Name': el => el.ZDISPLAYFULLNAME,
  19. 'Phone': el => el.ZPHONE
  20. }
  21. })
  22. resolve(result)
  23. })
  24. .catch(reject)
  25. }
  26. const viberContactsReport = (backup) => {
  27. return new Promise((resolve, reject) => {
  28. var vibercontactsdb = backup.getDatabase(database)
  29. try {
  30. const query = `
  31. SELECT * FROM ZMEMBER
  32. INNER JOIN ZPHONENUMBER
  33. ON ZPHONENUMBER.ZMEMBER = ZMEMBER.Z_PK
  34. ORDER BY ZMEMBER.Z_PK;
  35. `
  36. vibercontactsdb.all(query, async function (err, rows) {
  37. if (err) reject(err)
  38. resolve(rows)
  39. })
  40. } catch (e) {
  41. reject(e)
  42. }
  43. })
  44. }