feat:修改kpm config的路径

This commit is contained in:
jiqiu2021
2025-10-25 20:16:44 +08:00
parent 7e23ed7281
commit 6a79189290
3 changed files with 64 additions and 22 deletions

View File

@@ -19,12 +19,13 @@ public class ConfigManager {
public static final String CONFIG_FILE = MODULE_PATH + "/config.json";
public static final String SO_STORAGE_DIR = MODULE_PATH + "/so_files";
public static final String KPM_MODULE_PATH = MODULE_PATH + "/injectHide.kpm";
public static final String KPM_HIDE_CONFIG = MODULE_PATH + "/kpm_hide_config.txt";
public static final String KPM_HIDE_CONFIG = "/data/local/tmp/kpm_hide_config.txt";
private static final String KPM_MODULE_NAME = "hideInject";
private final Context context;
private final Gson gson;
private ModuleConfig config;
private final Object kpmLock = new Object(); // 用于同步 KPM 操作
static {
// Configure Shell to use root
@@ -725,24 +726,59 @@ public class ConfigManager {
* 重新加载 KPM 模块
*/
public boolean reloadKpmModule() {
Log.i(TAG, "Reloading KPM module...");
// 使用锁防止并发重载
synchronized (kpmLock) {
Log.i(TAG, "Reloading KPM module...");
// Unload first
if (isKpmModuleLoaded()) {
if (!unloadKpmModule()) {
Log.e(TAG, "Failed to unload module before reload");
return false;
}
// Give kernel time to cleanup
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
// Unload first
if (isKpmModuleLoaded()) {
if (!unloadKpmModule()) {
Log.e(TAG, "Failed to unload module before reload");
return false;
}
// Load again
return loadKpmModule();
// Give kernel more time to cleanup (1 second for safety)
// 等待时间足够让内核完全清理资源
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
Log.w(TAG, "Sleep interrupted during module reload", e);
Thread.currentThread().interrupt();
return false;
}
// Verify unload was successful
int retries = 5;
for (int i = 0; i < retries; i++) {
if (!isKpmModuleLoaded()) {
break;
}
Log.w(TAG, "Module still loaded, waiting... (" + (i+1) + "/" + retries + ")");
try {
Thread.sleep(200);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return false;
}
}
if (isKpmModuleLoaded()) {
Log.e(TAG, "Module still loaded after unload attempts, aborting reload");
return false;
}
}
// Load again
boolean success = loadKpmModule();
if (success) {
Log.i(TAG, "Module reloaded successfully");
} else {
Log.e(TAG, "Failed to load module after unload");
}
return success;
} // synchronized
}
/**
@@ -770,14 +806,17 @@ public class ConfigManager {
// Ensure module directory exists
Shell.cmd("mkdir -p \"" + MODULE_PATH + "\"").exec();
// Copy to module directory with root
// Ensure /data/local/tmp exists and is writable
Shell.cmd("mkdir -p /data/local/tmp && chmod 777 /data/local/tmp").exec();
// Copy to /data/local/tmp with root
Shell.Result copyResult = Shell.cmd("cp \"" + tempFile + "\" \"" + KPM_HIDE_CONFIG + "\"").exec();
if (!copyResult.isSuccess()) {
Log.e(TAG, "Failed to copy KPM config: " + String.join("\n", copyResult.getErr()));
return false;
}
Shell.cmd("chmod 644 \"" + KPM_HIDE_CONFIG + "\"").exec();
Shell.cmd("chmod 666 \"" + KPM_HIDE_CONFIG + "\"").exec();
// Clean up temp file
new File(tempFile).delete();

View File

@@ -106,7 +106,7 @@
android:id="@+id/tvConfigPath"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="配置文件: /data/adb/modules/zygisk-myinjector/kpm_hide_config.txt"
android:text="配置文件: /data/local/tmp/kpm_hide_config.txt"
android:textSize="10sp"
android:textColor="@android:color/darker_gray"
android:fontFamily="monospace" />

View File

@@ -98,7 +98,7 @@ log "ConfigApp 安装脚本执行完成"
# KPM 模块路径
KPM_MODULE="$MODDIR/injectHide.kpm"
KPM_CONFIG="$MODDIR/kpm_hide_config.txt"
KPM_CONFIG="/data/local/tmp/kpm_hide_config.txt"
log "开始加载 KPM 内核模块"
@@ -111,8 +111,11 @@ else
# 创建初始配置文件(如果不存在)
if [ ! -f "$KPM_CONFIG" ]; then
log "创建初始 KPM 配置文件"
# 确保 /data/local/tmp 目录存在且权限正确
mkdir -p /data/local/tmp
chmod 777 /data/local/tmp
echo "libmyinjector.so" > "$KPM_CONFIG"
chmod 644 "$KPM_CONFIG"
chmod 666 "$KPM_CONFIG"
fi
# 等待一段时间确保系统稳定