viber_contacts.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 = fileHash('com.viber/database/Contacts.data', 'AppDomainGroup-group.viber.share.container')
  10. module.exports.name = 'viber_contacts'
  11. module.exports.description = 'List Viber contacts'
  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. viberContactsReport(backup)
  19. .then((items) => {
  20. var result = program.formatter.format(items, {
  21. program: program,
  22. columns: {
  23. 'PK': el => el.Z_PK,
  24. 'Name': el => el.ZDISPLAYFULLNAME,
  25. 'Phone': el => el.ZPHONE
  26. }
  27. })
  28. resolve(result)
  29. })
  30. .catch(reject)
  31. }
  32. const viberContactsReport = (backup) => {
  33. return new Promise((resolve, reject) => {
  34. var vibercontactsdb = backup.getDatabase(database)
  35. try {
  36. const query = `
  37. SELECT * FROM ZMEMBER
  38. INNER JOIN ZPHONENUMBER
  39. ON ZPHONENUMBER.ZMEMBER = ZMEMBER.Z_PK
  40. ORDER BY ZMEMBER.Z_PK;
  41. `
  42. vibercontactsdb.all(query, async function (err, rows) {
  43. if (err) reject(err)
  44. resolve(rows)
  45. })
  46. } catch (e) {
  47. reject(e)
  48. }
  49. })
  50. }