manifest.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. module.exports.func = function (program, base) {
  10. if (!program.backup) {
  11. console.log('use -b or --backup <id> to specify backup.')
  12. process.exit(1)
  13. }
  14. // Grab the backup
  15. var backup = iPhoneBackup.fromID(program.backup, base)
  16. backup.getFileManifest()
  17. .then((items) => {
  18. if (program.dump) {
  19. console.log(JSON.stringify(items, null, 4))
  20. return
  21. }
  22. // Extract items for analysis on-disk.
  23. if (program.extract) {
  24. for (var item of items) {
  25. // Filter by the domain.
  26. // Simple "Contains" Search
  27. if (program.filter === 'all' || (program.filter && item.domain.indexOf(program.filter) > -1)) {
  28. // Do nothing, we'll process later.
  29. } else {
  30. // Skip to the next iteration of the loop.
  31. console.log(chalk.yellow('skipped'), item.relativePath)
  32. continue
  33. }
  34. try {
  35. var sourceFile = backup.getFileName(item.fileID)
  36. var stat = fs.lstatSync(sourceFile)
  37. // Only process files that exist.
  38. if (stat.isFile() && fs.existsSync(sourceFile)) {
  39. console.log(chalk.green('export'), item.relativePath)
  40. // Calculate the output dir.
  41. var outDir = path.join(program.extract, item.domain, item.relativePath)
  42. // Create the directory and copy
  43. fs.ensureDirSync(path.dirname(outDir))
  44. fs.copySync(sourceFile, outDir)
  45. // Save output info to the data item.
  46. item.output_dir = outDir
  47. } else if (stat.isDirectory()) {
  48. // Do nothing..
  49. } else {
  50. console.log(chalk.blue('not found'), item.relativePath)
  51. }
  52. } catch (e) {
  53. console.log(chalk.red('fail'), item.relativePath, e.toString())
  54. }
  55. }
  56. } else {
  57. // Otherwise, output the table of items.
  58. items = items.map(el => [
  59. el.fileID + '',
  60. el.domain + ': ' + el.relativePath
  61. ])
  62. items = [['ID', 'Domain/Path'], ['-'], ...items]
  63. items = normalizeCols(items, 1).map(el => el.join(' | ').replace(/\n/g, '')).join('\n')
  64. if (!program.color) { items = stripAnsi(items) }
  65. console.log(items)
  66. }
  67. })
  68. .catch((e) => {
  69. console.log('[!] Encountered an Error:', e)
  70. })
  71. }