manifest.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. const stripAnsi = require('strip-ansi')
  2. const iPhoneBackup = require('../util/iphone_backup.js').iPhoneBackup
  3. const normalizeCols = require('../util/normalize.js')
  4. const fs = require('fs-extra')
  5. const chalk = require('chalk')
  6. const path = require('path')
  7. module.exports.name = 'manifest'
  8. module.exports.description = 'List all the files contained in the backup (iOS 10+)'
  9. // Specify this reporter requires a backup.
  10. // The second parameter to func() is now a backup instead of the path to one.
  11. module.exports.requiresBackup = true
  12. // Specify this reporter supports the promises API for allowing chaining of reports.
  13. module.exports.usesPromises = true
  14. // Specify this only works for iOS 10+
  15. module.exports.supportedVersions = '>=10.0'
  16. module.exports.func = function (program, backup, resolve, reject) {
  17. backup.getFileManifest()
  18. .then((items) => {
  19. if (program.dump) {
  20. console.log(JSON.stringify(items, null, 4))
  21. return
  22. }
  23. // Extract items for analysis on-disk.
  24. if (program.extract) {
  25. for (var item of items) {
  26. // Filter by the domain.
  27. // Simple "Contains" Search
  28. if (program.filter === 'all' || (program.filter && item.domain.indexOf(program.filter) > -1)) {
  29. // Do nothing, we'll process later.
  30. } else {
  31. // Skip to the next iteration of the loop.
  32. console.log(chalk.yellow('skipped'), item.relativePath)
  33. continue
  34. }
  35. try {
  36. var sourceFile = backup.getFileName(item.fileID)
  37. var stat = fs.lstatSync(sourceFile)
  38. // Only process files that exist.
  39. if (stat.isFile() && fs.existsSync(sourceFile)) {
  40. console.log(chalk.green('export'), item.relativePath)
  41. // Calculate the output dir.
  42. var outDir = path.join(program.extract, item.domain, item.relativePath)
  43. // Create the directory and copy
  44. fs.ensureDirSync(path.dirname(outDir))
  45. fs.copySync(sourceFile, outDir)
  46. // Save output info to the data item.
  47. item.output_dir = outDir
  48. } else if (stat.isDirectory()) {
  49. // Do nothing..
  50. } else {
  51. console.log(chalk.blue('not found'), item.relativePath)
  52. }
  53. } catch (e) {
  54. console.log(chalk.red('fail'), item.relativePath, e.toString())
  55. }
  56. }
  57. resolve(result)
  58. } else {
  59. var result = program.formatter.format(items, {
  60. program: program,
  61. columns: {
  62. 'ID': el => el.fileID,
  63. 'Domain/Path': el => el.domain + ': ' + el.relativePath
  64. }
  65. })
  66. resolve(result)
  67. }
  68. })
  69. .catch((e) => {
  70. console.log('[!] Encountered an Error:', e)
  71. })
  72. }