|
|
@@ -2,19 +2,14 @@ package com.example.modifiermodule;
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
import android.app.Application;
|
|
|
-import android.content.ContentResolver;
|
|
|
import android.content.Context;
|
|
|
-import android.database.Cursor;
|
|
|
-import android.net.Uri;
|
|
|
import android.text.TextUtils;
|
|
|
-import android.util.Base64;
|
|
|
import android.util.Log;
|
|
|
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
import java.io.File;
|
|
|
-import java.lang.reflect.Method;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
|
|
import de.robv.android.xposed.XposedBridge;
|
|
|
@@ -51,6 +46,10 @@ public class BaseHook {
|
|
|
|
|
|
static final String TAG = "ModifierModule";
|
|
|
|
|
|
+ private JSONObject config = null;
|
|
|
+ private File configFile = null;
|
|
|
+ private ConfigFileObserver configFileObserver = null;
|
|
|
+
|
|
|
public BaseHook(ClassLoader classLoader) {
|
|
|
this.classLoader = classLoader;
|
|
|
}
|
|
|
@@ -92,34 +91,54 @@ public class BaseHook {
|
|
|
// return value;
|
|
|
// }
|
|
|
|
|
|
- @SuppressLint("PrivateApi")
|
|
|
- public String getProperty(String key, String defaultValue) {
|
|
|
- String value = defaultValue;
|
|
|
+ public void setConfigFile(File configFile) {
|
|
|
+ this.configFile = configFile;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void readAndObserve() {
|
|
|
+ if (configFileObserver != null) {
|
|
|
+ configFileObserver.stopWatching();
|
|
|
+ }
|
|
|
+ if (configFile != null) {
|
|
|
+ readConfig();
|
|
|
+ configFileObserver = new ConfigFileObserver(configFile, () -> readConfig());
|
|
|
+ configFileObserver.startWatching();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void readConfig() {
|
|
|
try {
|
|
|
- Context context = getContext();
|
|
|
- String packageName = context.getPackageName();
|
|
|
- File configFile;
|
|
|
- if (packageName.equals("android")) {
|
|
|
- configFile = new File("/data/system/config.json");
|
|
|
- } else if (packageName.equals("com.android.phone")) {
|
|
|
- configFile = new File(context.getExternalFilesDir("config"), "config.json");
|
|
|
- } else {
|
|
|
- return defaultValue;
|
|
|
+ log("readConfig: " + configFile.getAbsolutePath());
|
|
|
+ if (!configFile.exists()) {
|
|
|
+ new File(configFile.getAbsolutePath()).getParentFile().mkdirs();
|
|
|
+ new File(configFile.getAbsolutePath()).createNewFile();
|
|
|
}
|
|
|
if (configFile.exists()) {
|
|
|
String json = FileUtils.readFileToString(configFile, StandardCharsets.UTF_8);
|
|
|
if (!TextUtils.isEmpty(json)) {
|
|
|
- JSONObject jsonObject = new JSONObject(json);
|
|
|
- if (jsonObject.has(key)) {
|
|
|
- value = jsonObject.getString(key);
|
|
|
- }
|
|
|
+ config = new JSONObject(json);
|
|
|
}
|
|
|
}
|
|
|
+ } catch (Exception e) {
|
|
|
+ log("BaseHook: " + e.getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @SuppressLint("PrivateApi")
|
|
|
+ public String getProperty(String key, String defaultValue) {
|
|
|
+ try {
|
|
|
+ if (config == null) {
|
|
|
+ readAndObserve();
|
|
|
+ }
|
|
|
+ if (config != null && config.has(key)) {
|
|
|
+ return config.optString(key, defaultValue);
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
log("getProperty: " + e.getMessage());
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- return value;
|
|
|
+ return defaultValue;
|
|
|
}
|
|
|
|
|
|
public int getIntProperty(String key, int defaultValue) {
|