BaseHook.java 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. package com.example.modifiermodule;
  2. import android.annotation.SuppressLint;
  3. import android.app.Application;
  4. import android.content.ContentResolver;
  5. import android.content.Context;
  6. import android.database.Cursor;
  7. import android.net.Uri;
  8. import android.text.TextUtils;
  9. import android.util.Base64;
  10. import android.util.Log;
  11. import org.apache.commons.io.FileUtils;
  12. import org.json.JSONObject;
  13. import java.io.File;
  14. import java.lang.reflect.Method;
  15. import java.nio.charset.StandardCharsets;
  16. import de.robv.android.xposed.XposedBridge;
  17. import de.robv.android.xposed.XposedHelpers;
  18. public class BaseHook {
  19. // static final String PROP_MCC = "persist.spoof.mcc";
  20. // static final String PROP_MNC = "persist.spoof.mnc";
  21. // static final String PROP_ICCID = "persist.spoof.iccid";
  22. // static final String PROP_IMSI = "persist.spoof.imsi";
  23. // static final String PROP_IMEI = "persist.spoof.imei";
  24. // static final String PROP_NUMBER = "persist.spoof.number";
  25. // static final String PROP_COUNTRY = "persist.spoof.country";
  26. // static final String PROP_CARRIER_ID = "persist.spoof.carrier.id";
  27. // static final String PROP_CARRIER_NAME = "persist.spoof.carrier.name";
  28. // static final String PROP_UPI_POLICY = "persist.spoof.upi.policy";
  29. static final String PROP_MCC = "mcc";
  30. static final String PROP_MNC = "mnc";
  31. static final String PROP_ICCID = "iccid";
  32. static final String PROP_IMSI = "imsi";
  33. static final String PROP_IMEI = "imei";
  34. static final String PROP_NUMBER = "number";
  35. static final String PROP_COUNTRY = "country";
  36. static final String PROP_CARRIER_ID = "carrierId";
  37. static final String PROP_CARRIER_NAME = "carrierName";
  38. static final String PROP_UPI_POLICY = "upi_policy";
  39. static final String PROP_MAC = "mac";
  40. static final String PROP_BSSID = "bssid";
  41. static final String PROP_SERIAL = "serialNo";
  42. static final String PROP_ANDROID_ID = "androidId";
  43. static final String TAG = "Modifier";
  44. public BaseHook(ClassLoader classLoader) {
  45. this.classLoader = classLoader;
  46. }
  47. static void log(String message) {
  48. Log.i(TAG, message);
  49. XposedBridge.log(TAG + ": " + message);
  50. }
  51. private ClassLoader classLoader;
  52. // @SuppressLint("PrivateApi")
  53. // public String getProperty(String key, String defaultValue) {
  54. // String value = defaultValue;
  55. // try {
  56. // Class<?> c = Class.forName("android.os.SystemProperties");
  57. // Method get = c.getMethod("get", String.class, String.class);
  58. // value = (String) (get.invoke(c, key, defaultValue));
  59. // if (TextUtils.isEmpty(value)) {
  60. // value = defaultValue;
  61. // }
  62. // } catch (Exception e) {
  63. // e.printStackTrace();
  64. // }
  65. // return value;
  66. // }
  67. //
  68. // public int getIntProperty(String key, int defaultValue) {
  69. // int value = defaultValue;
  70. // try {
  71. // String prop = getProperty(key, String.valueOf(defaultValue));
  72. // if (TextUtils.isEmpty(prop)) {
  73. // return defaultValue;
  74. // }
  75. // value = Integer.parseInt(prop);
  76. // } catch (NumberFormatException e) {
  77. // e.printStackTrace();
  78. // }
  79. // return value;
  80. // }
  81. @SuppressLint("PrivateApi")
  82. public String getProperty(String key, String defaultValue) {
  83. log("getProperty: " + key);
  84. String value = defaultValue;
  85. try {
  86. Context context = getContext();
  87. String packageName = context.getPackageName();
  88. File configFile;
  89. if (packageName.equals("android")) {
  90. configFile = new File("/data/system/config.json");
  91. } else if (packageName.equals("com.android.phone")) {
  92. configFile = new File(context.getExternalFilesDir("config"), "config.json");
  93. } else {
  94. return defaultValue;
  95. }
  96. if (configFile.exists()) {
  97. String json = FileUtils.readFileToString(configFile, StandardCharsets.UTF_8);
  98. if (!TextUtils.isEmpty(json)) {
  99. JSONObject jsonObject = new JSONObject(json);
  100. if (jsonObject.has(key)) {
  101. value = jsonObject.getString(key);
  102. }
  103. }
  104. }
  105. } catch (Exception e) {
  106. log("getProperty: " + e.getMessage());
  107. e.printStackTrace();
  108. }
  109. return value;
  110. }
  111. public int getIntProperty(String key, int defaultValue) {
  112. int value = defaultValue;
  113. try {
  114. String prop = getProperty(key, String.valueOf(defaultValue));
  115. if (TextUtils.isEmpty(prop)) {
  116. return defaultValue;
  117. }
  118. value = Integer.parseInt(prop);
  119. } catch (NumberFormatException e) {
  120. e.printStackTrace();
  121. }
  122. return value;
  123. }
  124. public Context getContext() {
  125. Class<?> ActivityThread = XposedHelpers.findClass("android.app.ActivityThread", classLoader);
  126. Object currentActivityThread = XposedHelpers.callStaticMethod(ActivityThread, "currentActivityThread");
  127. Application application = (Application) XposedHelpers.callMethod(currentActivityThread, "getApplication");
  128. return application.getApplicationContext();
  129. }
  130. }