messages.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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_messages'
  5. module.exports.description = 'List Viber messages'
  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. viberMessagesReport(backup)
  13. .then((items) => {
  14. var result = program.formatter.format(items, {
  15. program: program,
  16. columns: {
  17. 'PK': el => el.Z_PK,
  18. 'Date': el => (new Date((el.ZDATE + 978307200) * 1000).toDateString()) + ' ' + (new Date((el.ZDATE + 978307200) * 1000).toTimeString()),
  19. 'Name': el => el.ZDISPLAYFULLNAME,
  20. 'Text': el => el.ZTEXT,
  21. 'State': el => el.ZSTATE
  22. }
  23. })
  24. resolve(result)
  25. })
  26. .catch(reject)
  27. }
  28. const viberMessagesReport = (backup) => {
  29. return new Promise((resolve, reject) => {
  30. var vibermessagesdb = backup.getDatabase(database)
  31. try {
  32. const query = `
  33. SELECT * FROM ZVIBERMESSAGE
  34. INNER JOIN ZCONVERSATION
  35. ON ZCONVERSATION.Z_PK = ZVIBERMESSAGE.ZCONVERSATION
  36. INNER JOIN ZMEMBER
  37. ON ZCONVERSATION.ZINTERLOCUTOR = ZMEMBER.Z_PK
  38. ORDER BY ZVIBERMESSAGE.Z_PK DESC;
  39. `
  40. vibermessagesdb.all(query, async function (err, rows) {
  41. if (err) reject(err)
  42. resolve(rows)
  43. })
  44. } catch (e) {
  45. reject(e)
  46. }
  47. })
  48. }