safari_recent_searches.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 file = fileHash('Library/Preferences/com.apple.mobilesafari.plist', 'AppDomain-com.apple.mobilesafari')
  10. module.exports.name = 'safari_recent_searches'
  11. module.exports.description = 'Show Safari recent searches'
  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. // Specify this only works for iOS 10+
  18. // If it is iOS-version specific, you can specify version information here.
  19. // You may provide a comma separated string such as ">=6.0,<11.0" to indicate ranges.
  20. module.exports.supportedVersions = '>=10.0'
  21. module.exports.func = function (program, backup, resolve, reject) {
  22. safariRecentSearches(backup)
  23. .then((items) => {
  24. var result = program.formatter.format(items, {
  25. program: program,
  26. columns: {
  27. 'SearchString': el => el.SearchString,
  28. 'Date': el => el.Date
  29. }
  30. })
  31. resolve(result)
  32. })
  33. .catch(reject)
  34. }
  35. const safariRecentSearches = (backup) => {
  36. return new Promise((resolve, reject) => {
  37. var filename = backup.getFileName(file)
  38. try {
  39. let mobilesafariPlist = bplist.parseBuffer(fs.readFileSync(filename))[0]
  40. resolve(mobilesafariPlist['RecentWebSearches'])
  41. } catch (e) {
  42. reject(e)
  43. }
  44. })
  45. }