telephony.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. class Log {
  2. static TAG = '[telephony]'
  3. static Debug = true
  4. static format(...msg) {
  5. let m = []
  6. for (let i = 0; i < msg.length; i++) {
  7. if (typeof msg[i] === 'object') {
  8. m.push(msg[i] + '')
  9. } else {
  10. m.push(msg[i])
  11. }
  12. }
  13. m = m.join(' ')
  14. return m
  15. }
  16. static i(...msg) {
  17. if (!this.Debug) return
  18. console.log(`\x1b[30m${this.TAG} ${this.format(...msg)}\x1b[0m`)
  19. }
  20. static w(...msg) {
  21. console.log(`\x1b[33m${this.TAG} ${this.format(...msg)}\x1b[0m`)
  22. }
  23. static e(...msg) {
  24. console.log(`\x1b[31m${this.TAG} ${this.format(...msg)}\x1b[0m`)
  25. }
  26. static s(...msg) {
  27. console.log(`\x1b[32m${this.TAG} ${this.format(...msg)}\x1b[0m`)
  28. }
  29. }
  30. function trace(tag) {
  31. Log.e((tag || '') + Java.use('android.util.Log').getStackTraceString(Java.use('java.lang.Throwable').$new()))
  32. }
  33. function randomMac() {
  34. var mac = '00:16:3e'
  35. for (var i = 0; i < 3; i++) {
  36. mac += ':' + ('00' + Math.floor(Math.random() * 256).toString(16)).slice(-2)
  37. }
  38. return mac
  39. }
  40. function buff2json(buf) {
  41. console.log(`buffer length: ${buf.byteLength}`)
  42. try {
  43. var decoded = String.fromCharCode(...new Uint8Array(buf))
  44. console.log(`decoded: ${decoded}`)
  45. return JSON.parse(decoded.trim())
  46. } catch (e) {
  47. console.error(e)
  48. return null
  49. }
  50. }
  51. class Interaction {
  52. failure(err) {
  53. console.error(err.message)
  54. Java.use('android.util.Log').d('frida-system_server', err.message)
  55. }
  56. accepted(connection) {
  57. console.warn('accepted')
  58. connection.input.read(2000).then((data) => {
  59. Java.use('android.util.Log').d('frida-system_server', data + '')
  60. try {
  61. const json = buff2json(data)
  62. console.log('received', json)
  63. this.messageFn && this.messageFn(json)
  64. } catch (e) {}
  65. connection.close()
  66. })
  67. }
  68. accept_loop(listener) {
  69. var next_iter = this.accept_loop.bind(this, listener)
  70. listener
  71. .accept()
  72. .then(this.accepted.bind(this))
  73. .catch(this.failure.bind(this))
  74. .finally(function () {
  75. setImmediate(next_iter)
  76. })
  77. }
  78. listened(listener) {
  79. console.warn('listened')
  80. this.accept_loop(listener)
  81. }
  82. start(port, messageFn) {
  83. this.messageFn = messageFn
  84. console.warn('starting on port', port)
  85. Socket.listen({ family: 'ipv4', host: '0.0.0.0', port: port })
  86. .then(this.listened.bind(this))
  87. .catch(this.failure.bind(this))
  88. }
  89. }
  90. function getContext() {
  91. try {
  92. var ActivityThread = Java.use('android.app.ActivityThread')
  93. var application = ActivityThread.currentApplication()
  94. return application.getApplicationContext()
  95. } catch (e) {
  96. console.log(e)
  97. return null
  98. }
  99. }
  100. setImmediate(() => {
  101. Java.perform(function () {
  102. const context = getContext()
  103. const cr = context.getContentResolver()
  104. const Uri = Java.use('android.net.Uri')
  105. cr.delete(Uri.parse('content://sms/'), null, null)
  106. cr.delete(Uri.parse('content://mms/'), null, null)
  107. })
  108. })