calls.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. const fileHash = require('../../util/backup_filehash')
  2. const log = require('../../util/log')
  3. const apple_timestamp = require('../../util/apple_timestamp')
  4. const CALLS_DB = '2b2b0084a1bc3a5ac8c27afdf14afb42c61a19ca'
  5. const CALLS2_DB = fileHash('Library/CallHistoryDB/CallHistory.storedata')
  6. module.exports = {
  7. version: 4,
  8. name: 'phone.calls',
  9. description: `List all call records contained in the backup.`,
  10. requiresBackup: true,
  11. // Run on a v3 lib / backup object.
  12. run (lib, { backup }) {
  13. return getCallsList(backup)
  14. },
  15. // Manifest fields.
  16. output: {
  17. id: el => el.Z_PK,
  18. date: el => el.XFORMATTEDDATESTRING,
  19. answered: el => !!el.ZANSWERED,
  20. originated: el => !!el.ZORIGINATED,
  21. callType: el => {
  22. if (el.ZCALLTYPE === 1) {
  23. return 'Cellular'
  24. } else if (el.ZCALLTYPE === 16) {
  25. return 'FacetimeAudio'
  26. } else if (el.ZCALLTYPE === 8) {
  27. return 'FacetimeVideo'
  28. }
  29. return 'Unknown'
  30. },
  31. duration: el => el.ZDURATION + '',
  32. location: el => {
  33. // console.log(el.ZLOCATION)
  34. if (el.ZLOCATION === '<<RecentsNumberLocationNotFound>>') {
  35. return null
  36. }
  37. return el.ZLOCATION + ''
  38. },
  39. country: el => el.ZISO_COUNTRY_CODE + '',
  40. service: el => el.ZSERVICE_PROVIDER || null,
  41. address: el => (el.ZADDRESS || '').toString()
  42. }
  43. }
  44. function getCallsList (backup) {
  45. return new Promise(async (resolve, reject) => {
  46. try {
  47. var ios7log = await getCallsListiOS7(backup)
  48. } catch (e) {
  49. log.verbose('tried ios7 calls', e)
  50. }
  51. try {
  52. var newerIOS = await getCallsListLater(backup)
  53. } catch (e) {
  54. log.verbose('tried ios7+ calls', e)
  55. }
  56. // Check if they both are not found.
  57. if (ios7log == null && newerIOS == null) {
  58. return reject(new Error('no call logs found'))
  59. }
  60. // Resolve call logs.
  61. resolve([...(ios7log || []), ...(newerIOS || [])])
  62. })
  63. }
  64. // Try older databases.
  65. function getCallsListiOS7 (backup) {
  66. return new Promise((resolve, reject) => {
  67. // Attempt to open database.
  68. backup.openDatabase(CALLS_DB)
  69. .then(db => {
  70. db.all(`
  71. SELECT
  72. ROWID as Z_PK,
  73. datetime(date, 'unixepoch') AS XFORMATTEDDATESTRING,
  74. answered as ZANSWERED,
  75. duration as ZDURATION,
  76. address as ZADDRESS,
  77. country_code as ZISO_COUNTRY_CODE,
  78. country_code as ZISO_COUNTRY_CODE,
  79. *
  80. FROM call
  81. ORDER BY date ASC`,
  82. function (err, rows) {
  83. if (err) reject(err)
  84. resolve(rows)
  85. })
  86. })
  87. .catch(reject)
  88. })
  89. }
  90. // iOS 7+ moves to a new database.
  91. // Try that.
  92. function getCallsListLater (backup) {
  93. return new Promise((resolve, reject) => {
  94. backup.openDatabase(CALLS2_DB)
  95. .then(db => {
  96. db.all(`SELECT *, ${apple_timestamp.parse('ZDATE')} AS XFORMATTEDDATESTRING from ZCALLRECORD ORDER BY ZDATE ASC`, async function (err, rows) {
  97. if (err) reject(err)
  98. resolve(rows)
  99. })
  100. })
  101. .catch(reject)
  102. })
  103. }