spoof_phone2.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. class Log {
  2. static TAG = '[Phone]'
  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(JSON.stringify(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. setImmediate(() => {
  34. Java.perform(function () {
  35. function checkPackage(name) {
  36. // return (
  37. // name.startsWith('com.google.android.gsf') ||
  38. // name.startsWith('com.google.android.gms') ||
  39. // name.startsWith('com.google.android.apps') ||
  40. // name.startsWith('com.example')
  41. // )
  42. return true
  43. }
  44. const SystemProperties = Java.use('android.os.SystemProperties')
  45. const PhoneInterfaceManager = Java.use('com.android.phone.PhoneInterfaceManager')
  46. PhoneInterfaceManager.getLine1NumberForDisplay.overload(
  47. 'int',
  48. 'java.lang.String',
  49. 'java.lang.String'
  50. ).implementation = function (subId, callingPackage, callingFeatureId) {
  51. const res = this.getLine1NumberForDisplay(subId, callingPackage, callingFeatureId)
  52. if (!checkPackage(callingPackage)) {
  53. return res
  54. }
  55. Log.i(
  56. `spoof PhoneInterfaceManager.getLine1NumberForDisplay(${subId}, ${callingPackage}, ${callingFeatureId}): ${res} -> ${SystemProperties.get('persist.spoof.number')}`
  57. )
  58. return SystemProperties.get('persist.spoof.number')
  59. }
  60. PhoneInterfaceManager.getNetworkCountryIsoForPhone.overload('int').implementation = function (phoneId) {
  61. const res = this.getNetworkCountryIsoForPhone(phoneId)
  62. Log.i(`spoof PhoneInterfaceManager.getNetworkCountryIsoForPhone(${phoneId}): ${res} -> ${SystemProperties.get('persist.spoof.country')}`)
  63. return SystemProperties.get('persist.spoof.country')
  64. }
  65. PhoneInterfaceManager.getImeiForSlot.overload('int', 'java.lang.String', 'java.lang.String').implementation =
  66. function (slotId, callingPackage, callingFeatureId) {
  67. const res = this.getImeiForSlot(slotId, callingPackage, callingFeatureId)
  68. if (!checkPackage(callingPackage)) {
  69. return res
  70. }
  71. Log.i(
  72. `spoof PhoneInterfaceManager.getImeiForSlot(${slotId}, ${callingPackage}, ${callingFeatureId}): ${res} -> ${SystemProperties.get('persist.spoof.imei')}`
  73. )
  74. return SystemProperties.get('persist.spoof.imei')
  75. }
  76. SystemProperties.get.overload('java.lang.String').implementation = function (key) {
  77. if ('gsm.sim.operator.iso-country' === key) {
  78. Log.i(`spoof SystemProperties.get(${key}): ${SystemProperties.get('persist.spoof.country')}`)
  79. return SystemProperties.get('persist.spoof.country')
  80. }
  81. if ('gsm.sim.operator.numeric' === key) {
  82. Log.i(`spoof SystemProperties.get(${key}): ${SystemProperties.get('persist.spoof.mcc') + SystemProperties.get('persist.spoof.mnc')}`)
  83. return SystemProperties.get('persist.spoof.mcc') + SystemProperties.get('persist.spoof.mnc')
  84. }
  85. if ('gsm.operator.numeric' === key) {
  86. Log.i(`spoof SystemProperties.get(${key}): ${SystemProperties.get('persist.spoof.mcc') + SystemProperties.get('persist.spoof.mnc')}`)
  87. return SystemProperties.get('persist.spoof.mcc') + SystemProperties.get('persist.spoof.mnc')
  88. }
  89. return this.get(key)
  90. }
  91. const SubscriptionController = Java.use('com.android.internal.telephony.SubscriptionController')
  92. SubscriptionController.getSimStateForSlotIndex.overload('int').implementation = function (slotIndex) {
  93. const res = this.getSimStateForSlotIndex(slotIndex)
  94. Log.i(`spoof SubscriptionController.getSimStateForSlotIndex(${slotIndex}): ${res} -> 5`)
  95. return 5
  96. }
  97. SubscriptionController.getPhoneNumberFromFirstAvailableSource.overload(
  98. 'int',
  99. 'java.lang.String',
  100. 'java.lang.String'
  101. ).implementation = function (subId, callingPackage, callingFeatureId) {
  102. const res = this.getPhoneNumberFromFirstAvailableSource(subId, callingPackage, callingFeatureId)
  103. if (!checkPackage(callingPackage)) {
  104. return res
  105. }
  106. Log.i(
  107. `spoof SubscriptionController.getPhoneNumberFromFirstAvailableSource(${subId}, ${callingPackage}, ${callingFeatureId}): ${res} -> ${SystemProperties.get('persist.spoof.number')}`
  108. )
  109. return SystemProperties.get('persist.spoof.number')
  110. }
  111. const SubscriptionInfo = Java.use('android.telephony.SubscriptionInfo')
  112. SubscriptionController.getActiveSubscriptionInfoList.overload('java.lang.String').implementation = function (
  113. callingPackage
  114. ) {
  115. const res = this.getActiveSubscriptionInfoList(callingPackage)
  116. if (!checkPackage(callingPackage)) {
  117. return res
  118. }
  119. Log.i(`spoof SubscriptionController.getActiveSubscriptionInfoList(${callingPackage})`)
  120. for (let i = 0; i < res.size(); i++) {
  121. const info = Java.cast(res.get(i), SubscriptionInfo)
  122. info.mMcc.value = SystemProperties.get('persist.spoof.mcc')
  123. info.mMnc.value = SystemProperties.get('persist.spoof.mnc')
  124. info.mCountryIso.value = SystemProperties.get('persist.spoof.country')
  125. info.mIccId.value = SystemProperties.get('persist.spoof.iccid')
  126. }
  127. SystemProperties.set('gsm.sim.operator.iso-country', SystemProperties.get('persist.spoof.country'))
  128. SystemProperties.set('gsm.sim.operator.numeric', SystemProperties.get('persist.spoof.mcc') + SystemProperties.get('persist.spoof.mnc'))
  129. SystemProperties.set('gsm.operator.numeric', SystemProperties.get('persist.spoof.mcc') + SystemProperties.get('persist.spoof.mnc'))
  130. return res
  131. }
  132. SubscriptionController.getActiveSubscriptionInfoList.overload(
  133. 'java.lang.String',
  134. 'java.lang.String'
  135. ).implementation = function (callingPackage, callingFeatureId) {
  136. const res = this.getActiveSubscriptionInfoList(callingPackage, callingFeatureId)
  137. if (!checkPackage(callingPackage)) {
  138. return res
  139. }
  140. Log.i(`spoof SubscriptionController.getActiveSubscriptionInfoList(${callingPackage}, ${callingFeatureId})`)
  141. for (let i = 0; i < res.size(); i++) {
  142. const info = Java.cast(res.get(i), SubscriptionInfo)
  143. info.mMcc.value = SystemProperties.get('persist.spoof.mcc')
  144. info.mMnc.value = SystemProperties.get('persist.spoof.mnc')
  145. info.mCountryIso.value = SystemProperties.get('persist.spoof.country')
  146. info.mIccId.value = SystemProperties.get('persist.spoof.iccid')
  147. }
  148. SystemProperties.set('gsm.sim.operator.iso-country', SystemProperties.get('persist.spoof.country'))
  149. SystemProperties.set('gsm.sim.operator.numeric', SystemProperties.get('persist.spoof.mcc') + SystemProperties.get('persist.spoof.mnc'))
  150. SystemProperties.set('gsm.operator.numeric', SystemProperties.get('persist.spoof.mcc') + SystemProperties.get('persist.spoof.mnc'))
  151. return res
  152. }
  153. SubscriptionController.getActiveSubscriptionInfoList.overload('java.lang.String').implementation = function (
  154. callingPackage
  155. ) {
  156. const res = this.getActiveSubscriptionInfoList(callingPackage)
  157. if (!checkPackage(callingPackage)) {
  158. return res
  159. }
  160. Log.i(`spoof SubscriptionController.getActiveSubscriptionInfoList(${callingPackage})`)
  161. for (let i = 0; i < res.size(); i++) {
  162. const info = Java.cast(res.get(i), SubscriptionInfo)
  163. info.mMcc.value = SystemProperties.get('persist.spoof.mcc')
  164. info.mMnc.value = SystemProperties.get('persist.spoof.mnc')
  165. info.mCountryIso.value = SystemProperties.get('persist.spoof.country')
  166. info.mIccId.value = SystemProperties.get('persist.spoof.iccid')
  167. }
  168. SystemProperties.set('gsm.sim.operator.iso-country', SystemProperties.get('persist.spoof.country'))
  169. SystemProperties.set('gsm.sim.operator.numeric', SystemProperties.get('persist.spoof.mcc') + SystemProperties.get('persist.spoof.mnc'))
  170. SystemProperties.set('gsm.operator.numeric', SystemProperties.get('persist.spoof.mcc') + SystemProperties.get('persist.spoof.mnc'))
  171. return res
  172. }
  173. const PhoneSubInfoController = Java.use('com.android.internal.telephony.PhoneSubInfoController')
  174. PhoneSubInfoController.getIccSerialNumberForSubscriber.overload(
  175. 'int',
  176. 'java.lang.String',
  177. 'java.lang.String'
  178. ).implementation = function (subId, callingPackage, callingFeatureId) {
  179. const res = this.getIccSerialNumberForSubscriber(subId, callingPackage, callingFeatureId)
  180. if (!checkPackage(callingPackage)) {
  181. return res
  182. }
  183. Log.i(
  184. `spoof PhoneInterfaceManager.getIccSerialNumberForSubscriber(${subId}, ${callingPackage}, ${callingFeatureId}): ${res} -> ${SystemProperties.get('persist.spoof.iccid')}`
  185. )
  186. return SystemProperties.get('persist.spoof.iccid')
  187. }
  188. PhoneSubInfoController.getSubscriberIdForSubscriber.overload(
  189. 'int',
  190. 'java.lang.String',
  191. 'java.lang.String'
  192. ).implementation = function (subId, callingPackage, callingFeatureId) {
  193. const res = this.getSubscriberIdForSubscriber(subId, callingPackage, callingFeatureId)
  194. if (!checkPackage(callingPackage)) {
  195. return res
  196. }
  197. Log.i(
  198. `spoof PhoneInterfaceManager.getSubscriberIdForSubscriber(${subId}, ${callingPackage}, ${callingFeatureId}): ${res} -> ${SystemProperties.get('persist.spoof.imsi')}`
  199. )
  200. return SystemProperties.get('persist.spoof.imsi')
  201. }
  202. })
  203. })