viber_calls.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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_calls'
  11. module.exports.description = 'List Viber calls'
  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. viberCallsReport(backup)
  19. .then((items) => {
  20. var result = program.formatter.format(items, {
  21. program: program,
  22. columns: {
  23. 'PK': el => el.Z_PK,
  24. 'Date': el => (new Date((el.ZDATE + 978307200) * 1000).toDateString()) + ' ' + (new Date((el.ZDATE + 978307200) * 1000).toTimeString()),
  25. 'Name': el => el.ZMAINNAME + ' ' + el.ZSUFFIXNAME,
  26. 'Phone': el => el.ZPHONENUMBER,
  27. 'Call Type': el => el.ZCALLTYPE
  28. }
  29. })
  30. resolve(result)
  31. })
  32. .catch(reject)
  33. }
  34. const viberCallsReport = (backup) => {
  35. return new Promise((resolve, reject) => {
  36. var vibercallsdb = backup.getDatabase(database)
  37. try {
  38. const query = `
  39. SELECT * FROM ZRECENTSLINE
  40. INNER JOIN ZABCONTACT
  41. ON ZABCONTACT.Z_PK = ZRECENTSLINE.ZCONTACT
  42. ORDER BY ZABCONTACT.Z_PK;
  43. `
  44. vibercallsdb.all(query, async function (err, rows) {
  45. if (err) reject(err)
  46. resolve(rows)
  47. })
  48. } catch (e) {
  49. reject(e)
  50. }
  51. })
  52. }