Skip to content

Commit

Permalink
feat: BaseApk: alwaysAPK
Browse files Browse the repository at this point in the history
  • Loading branch information
klxiaoniu committed Sep 17, 2024
1 parent 5e8c98d commit ad6d003
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
24 changes: 21 additions & 3 deletions app/src/main/java/cc/ioctl/dialog/RikkaBaseApkFormatDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import cc.ioctl.util.HostInfo;
import cc.hicore.QApp.QAppUtils;
import cc.ioctl.hook.file.BaseApk;
import cc.ioctl.util.HostInfo;
import io.github.qauxv.BuildConfig;
import io.github.qauxv.R;
import io.github.qauxv.config.ConfigManager;
Expand All @@ -44,12 +45,13 @@

public class RikkaBaseApkFormatDialog {

private static final String DEFAULT_BASE_APK_REGEX = ".*\\.apk";
private static final String DEFAULT_BASE_APK_REGEX = "base(\\([0-9]+\\))?\\.apk";
private static final String DEFAULT_BASE_APK_FORMAT = "%n_%v.APK";

private static final String rq_base_apk_regex = "rq_base_apk_regex";
private static final String rq_base_apk_format = "rq_base_apk_format";
private static final String rq_base_apk_enabled = "rq_base_apk_enabled";
private static final String rq_base_apk_always_APK = "rq_base_apk_always_APK";

@Nullable
private AlertDialog dialog;
Expand All @@ -59,11 +61,16 @@ public class RikkaBaseApkFormatDialog {
private String currentRegex;
private String currentFormat;
private boolean enableBaseApk;
private boolean alwaysAPK;

public static boolean IsEnabled() {
return ConfigManager.getDefaultConfig().getBooleanOrFalse(rq_base_apk_enabled);
}

public static boolean IsAlwaysAPKEnabled() {
return ConfigManager.getDefaultConfig().getBooleanOrFalse(rq_base_apk_always_APK);
}

@Nullable
public static String getCurrentBaseApkRegex() {
ConfigManager cfg = ConfigManager.getDefaultConfig();
Expand Down Expand Up @@ -103,9 +110,16 @@ public void showDialog(@NonNull Context context) {
final TextView regex = vg.findViewById(R.id.editTextBaseApkRegex);
final TextView format = vg.findViewById(R.id.editTextBaseApkFormat);
final CheckBox enable = vg.findViewById(R.id.checkBoxEnableBaseApk);
final CheckBox always = vg.findViewById(R.id.checkBoxAlwaysAPK);
final LinearLayout panel = vg.findViewById(R.id.layoutBaseApkPanel);
enableBaseApk = ConfigManager.getDefaultConfig().getBooleanOrFalse(rq_base_apk_enabled);
enable.setChecked(enableBaseApk);
if (!QAppUtils.isQQnt()) {
always.setVisibility(View.GONE);
} else {
alwaysAPK = ConfigManager.getDefaultConfig().getBooleanOrFalse(rq_base_apk_always_APK);
always.setChecked(alwaysAPK);
}
panel.setVisibility(enableBaseApk ? View.VISIBLE : View.GONE);
currentRegex = ConfigManager.getDefaultConfig().getString(rq_base_apk_regex);
if (currentRegex == null) {
Expand Down Expand Up @@ -159,6 +173,9 @@ public void afterTextChanged(Editable s) {
enableBaseApk = isChecked;
panel.setVisibility(enableBaseApk ? View.VISIBLE : View.GONE);
});
always.setOnCheckedChangeListener((buttonView, isChecked) -> {
alwaysAPK = isChecked;
});
dialog.setView(vg);
dialog.show();
dialog.getButton(AlertDialog.BUTTON_POSITIVE)
Expand All @@ -170,9 +187,10 @@ public void afterTextChanged(Editable s) {
done = true;
} else {
if (currentFormat != null && !currentFormat.isEmpty() &&
currentRegex != null && !currentRegex.isEmpty() &&(
currentRegex != null && !currentRegex.isEmpty() && (
currentFormat.contains("%n") || currentFormat.contains("%p"))) {
cfg.putBoolean(rq_base_apk_enabled, true);
cfg.putBoolean(rq_base_apk_always_APK, alwaysAPK);
cfg.putString(rq_base_apk_regex, currentRegex);
cfg.putString(rq_base_apk_format, currentFormat);
done = true;
Expand Down
18 changes: 14 additions & 4 deletions app/src/main/java/cc/ioctl/hook/file/BaseApk.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
import cc.ioctl.dialog.RikkaBaseApkFormatDialog;
import cc.ioctl.util.HookUtils;
import cc.ioctl.util.HostInfo;
import io.github.qauxv.util.xpcompat.XC_MethodHook;
import io.github.qauxv.util.xpcompat.XposedHelpers;
import io.github.qauxv.base.IUiItemAgent;
import io.github.qauxv.base.annotation.FunctionHookEntry;
import io.github.qauxv.base.annotation.UiItemAgentEntry;
Expand All @@ -46,12 +44,13 @@
import io.github.qauxv.util.dexkit.DexKit;
import io.github.qauxv.util.dexkit.DexKitTarget;
import io.github.qauxv.util.dexkit.TroopSendFile_QQNT;
import io.github.qauxv.util.xpcompat.XC_MethodHook;
import io.github.qauxv.util.xpcompat.XposedHelpers;
import java.io.File;
import java.io.FileNotFoundException;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Objects;
import kotlin.Unit;
import kotlin.jvm.functions.Function3;
import kotlinx.coroutines.flow.MutableStateFlow;
Expand Down Expand Up @@ -117,6 +116,11 @@ public boolean initOnce() throws Exception {
throw new FileNotFoundException("file not found: path='" + localFile + "'");
}
fileName.set(item, getFormattedFileNameByPath(localFile));
} else if (RikkaBaseApkFormatDialog.IsAlwaysAPKEnabled()) {
String fn = (String) fileName.get(item);
if (fn.endsWith(".apk")) {
fileName.set(item, replaceLast(fn, ".apk", ".APK"));
}
}
});
} else if (HostInfo.requireMinQQVersion(QQ_8_6_0)) {
Expand Down Expand Up @@ -199,8 +203,14 @@ private String getFormattedFileNameByPath(String path) {
.replace("%p", applicationInfo.packageName)
.replace("%v", packageArchiveInfo.versionName)
.replace("%c", String.valueOf(packageArchiveInfo.versionCode));
} else
} else {
throw new RuntimeException("format is null");
}
return result;
}

public static String replaceLast(String str, String target, String replacement) {
// 使用正则表达式匹配最后一个目标子字符串,并替换为新字符串
return str.replaceFirst("(?s)(.*)" + target, "$1" + replacement);
}
}
9 changes: 8 additions & 1 deletion app/src/main/res/layout/rikka_base_apk_dialog.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:padding="10dp"
tools:viewBindingIgnore="true">
Expand All @@ -13,12 +13,19 @@
android:layout_height="wrap_content"
android:text="启用重命名 APK" />


<LinearLayout
android:id="@+id/layoutBaseApkPanel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="没命中名称规则时,只修改后缀为.APK"
android:id="@+id/checkBoxAlwaysAPK" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down

0 comments on commit ad6d003

Please sign in to comment.