viber_messages.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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_messages'
  11. module.exports.description = 'List Viber messages'
  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. viberMessagesReport(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.ZDISPLAYFULLNAME,
  26. 'Text': el => el.ZTEXT,
  27. 'State': el => el.ZSTATE
  28. }
  29. })
  30. resolve(result)
  31. })
  32. .catch(reject)
  33. }
  34. const viberMessagesReport = (backup) => {
  35. return new Promise((resolve, reject) => {
  36. var vibermessagesdb = backup.getDatabase(database)
  37. try {
  38. const query = `
  39. SELECT * FROM ZVIBERMESSAGE
  40. INNER JOIN ZCONVERSATION
  41. ON ZCONVERSATION.Z_PK = ZVIBERMESSAGE.ZCONVERSATION
  42. INNER JOIN ZMEMBER
  43. ON ZCONVERSATION.ZINTERLOCUTOR = ZMEMBER.Z_PK
  44. ORDER BY ZVIBERMESSAGE.Z_PK DESC;
  45. `
  46. vibermessagesdb.all(query, async function (err, rows) {
  47. if (err) reject(err)
  48. resolve(rows)
  49. })
  50. } catch (e) {
  51. reject(e)
  52. }
  53. })
  54. }