Skip to content

Commit

Permalink
fix: qhmk functions
Browse files Browse the repository at this point in the history
  • Loading branch information
alphime authored and cinit committed Oct 12, 2023
1 parent 813178c commit 1f477bb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 28 deletions.
38 changes: 11 additions & 27 deletions app/src/main/java/com/alphi/qhmk/module/DisableX5.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@
import io.github.qauxv.util.Initiator;
import io.github.qauxv.util.Log;
import io.github.qauxv.util.SyncUtils;
import io.github.qauxv.util.dexkit.DexKit;
import io.github.qauxv.util.dexkit.DexKitTarget;
import io.github.qauxv.util.dexkit.X5_Properties_conf;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.List;
import kotlin.collections.ArraysKt;

@UiItemAgentEntry
Expand All @@ -21,7 +25,7 @@ public class DisableX5 extends CommonSwitchFunctionHook {
public static final DisableX5 INSTANCE = new DisableX5();

private DisableX5() {
super(SyncUtils.PROC_MAIN | SyncUtils.PROC_TOOL);
super(SyncUtils.PROC_MAIN | SyncUtils.PROC_TOOL, new DexKitTarget[]{X5_Properties_conf.INSTANCE});
}

@Override
Expand All @@ -30,49 +34,29 @@ protected boolean initOnce() throws Exception {
Class<?> kQbSdk = Initiator.load("com/tencent/smtt/sdk/QbSdk");
if (kQbSdk != null) {
Method method = kQbSdk.getDeclaredMethod("getIsSysWebViewForcedByOuter");
HookUtils.hookBeforeIfEnabled(this, method, param -> {
param.setResult(true);
});
HookUtils.hookBeforeIfEnabled(this, method, param -> param.setResult(true));
return true;
}
// older
Class<?> tbsClass = Initiator.load("com.tencent.smtt.sdk.WebView");
Class<?> tbsClassConfig = null;
if (tbsClass != null) {
for (Field field : tbsClass.getDeclaredFields()) {
Class<?> type = field.getType();
Package tPackage = type.getPackage();
// 因为 8.9 存在有个类 util.*.* 不然会 hook 错地方
if (tPackage != null && tPackage.getName().equals("com.tencent.smtt.utils")) {
tbsClassConfig = type;
}
}
Class<?> tbsClassConfig = DexKit.requireClassFromCache(X5_Properties_conf.INSTANCE);
List<Method> methods = ArraysKt.filter(tbsClassConfig.getDeclaredMethods(), m -> m.getReturnType() == void.class);
if (methods.isEmpty()) {
throw new RuntimeException("DisableX5: no method found in " + tbsClassConfig);
}
if (tbsClassConfig != null) {
Method method = ArraysKt.single(tbsClassConfig.getDeclaredMethods(), m -> m.getReturnType() == void.class);
for (Method method : methods) {
HookUtils.hookAfterIfEnabled(this, method, param -> {
boolean result = false;
Log.d("hook:" + param.thisObject.getClass());
for (Field field : param.thisObject.getClass().getFields()) {
if (field.getType() == boolean.class) {
try {
field.set(param.thisObject, true);
result = true;
} catch (IllegalAccessException e) {
traceError(e);
}
}
}
if (result) {
Log.d("old:ForceUseSystemWebView success!");
} else {
Log.e("old:ForceUseSystemWebView fail!!!");
}
});
}
if (tbsClassConfig == null && kQbSdk == null) {
throw new IllegalStateException("X5Settings init fail!!! cause by not found class...");
}
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/alphi/qhmk/module/HookUpgrade.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected boolean initOnce() throws Exception {
}
}

return false;
return true;
}

@NonNull
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/io/github/qauxv/util/dexkit/DexKitTarget.kt
Original file line number Diff line number Diff line change
Expand Up @@ -811,3 +811,9 @@ data object NT_SysAndEmojiResInfo : DexKitTarget.UsingStringVector() {
override val declaringClass = ""
override val filter = DexKitFilter.allowAll
}

data object X5_Properties_conf: DexKitTarget.UsingStr() {
override val traitString: Array<String> = arrayOf("setting_forceUseSystemWebview", "result_systemWebviewForceUsed", "debug.conf")
override val declaringClass: String = "com.tencent.smtt.utils.LoadPropertiesUtils"
override val filter = DexKitFilter.allowAll
}

0 comments on commit 1f477bb

Please sign in to comment.