Skip to content

Commit

Permalink
fix: baidu clipboard limit unlock failed
Browse files Browse the repository at this point in the history
  • Loading branch information
HChenX committed Dec 2, 2024
1 parent 215276b commit 9e06f92
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 139 deletions.
6 changes: 6 additions & 0 deletions app/src/main/java/com/sevtinge/hyperceiler/XposedInit.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.sevtinge.hyperceiler.module.hook.systemframework.network.FlightModeHotSpot;
import com.sevtinge.hyperceiler.module.hook.systemsettings.VolumeSeparateControlForSettings;
import com.sevtinge.hyperceiler.module.skip.SystemFrameworkForCorePatch;
import com.sevtinge.hyperceiler.utils.log.LogManager;

import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.IXposedHookZygoteInit;
Expand All @@ -46,6 +47,11 @@ public void initZygote(StartupParam startupParam) throws Throwable {
EzXHelper.initZygote(startupParam);
EzXHelper.setLogTag(TAG);
EzXHelper.setToastTag(TAG);
HCInit.initBasicData(new HCInit.BasicData()
.setModulePackageName(BuildConfig.APPLICATION_ID)
.setLogLevel(LogManager.getLogLevel())
.setTag("HyperCeiler")
);
HCInit.initStartupParam(startupParam);
loadZygoteHook(startupParam);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@
*/
package com.sevtinge.hyperceiler.module.base;

import com.hchen.hooktool.BaseHC;
import com.hchen.hooktool.HCInit;
import com.sevtinge.hyperceiler.BuildConfig;
import com.sevtinge.hyperceiler.XposedInit;
import com.sevtinge.hyperceiler.module.base.dexkit.DexKit;
import com.sevtinge.hyperceiler.safe.CrashData;
import com.sevtinge.hyperceiler.utils.ContextUtils;
import com.sevtinge.hyperceiler.utils.Helpers;
import com.sevtinge.hyperceiler.utils.api.ProjectApi;
import com.sevtinge.hyperceiler.utils.log.LogManager;
import com.sevtinge.hyperceiler.utils.log.XposedLogUtils;
import com.sevtinge.hyperceiler.utils.prefs.PrefsMap;

Expand All @@ -50,21 +49,15 @@ public void init(LoadPackageParam lpparam) {
XposedLogUtils.logI(TAG, "Entry safe mode: " + lpparam.packageName);
return;
}

HCInit.initBasicData(new HCInit.BasicData()
.setModulePackageName(BuildConfig.APPLICATION_ID)
.setLogLevel(LogManager.getLogLevel())
.setTag("HyperCeiler"));
HCInit.initLoadPackageParam(lpparam);
// 把模块资源加载到目标应用
try {
if (!ProjectApi.mAppModulePkg.equals(lpparam.packageName)) {
ContextUtils.getWaitContext(
context -> {
if (context != null) {
BaseXposedInit.mResHook.loadModuleRes(context);
}
}, "android".equals(lpparam.packageName));
ContextUtils.getWaitContext(context -> {
if (context != null) {
BaseXposedInit.mResHook.loadModuleRes(context);
}
}, "android".equals(lpparam.packageName));
}
} catch (Throwable e) {
XposedLogUtils.logE(TAG, "get context failed!" + e);
Expand Down Expand Up @@ -132,6 +125,7 @@ public void initHook(Object hook, boolean isInit, String versionName, int versio

private void onCreate(Object hook) {
if (hook instanceof BaseHook baseHook) baseHook.onCreate(mLoadPackageParam);
else if (hook instanceof BaseHC baseHC) baseHC.onLoadPackage();
else throw new RuntimeException("Unknown hook!");
}
}
Original file line number Diff line number Diff line change
@@ -1,155 +1,79 @@
/*
* This file is part of HyperCeiler.
* This file is part of HyperCeiler.
* HyperCeiler is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License.
* HyperCeiler is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* Copyright (C) 2023-2024 HyperCeiler Contributions
*/
* Copyright (C) 2023-2024 HyperCeiler Contributions
*/
package com.sevtinge.hyperceiler.module.hook.clipboard;

import com.sevtinge.hyperceiler.module.base.BaseHook;
import com.hchen.hooktool.BaseHC;
import com.sevtinge.hyperceiler.module.base.dexkit.DexKit;
import com.sevtinge.hyperceiler.module.base.dexkit.IDexKit;
import com.sevtinge.hyperceiler.module.base.dexkit.IDexKitList;

import org.luckypray.dexkit.DexKitBridge;
import org.luckypray.dexkit.query.FindClass;
import org.luckypray.dexkit.query.FindMethod;
import org.luckypray.dexkit.query.matchers.ClassMatcher;
import org.luckypray.dexkit.query.matchers.MethodMatcher;
import org.luckypray.dexkit.result.MethodData;
import org.luckypray.dexkit.result.ClassData;
import org.luckypray.dexkit.result.MethodDataList;

import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;

public class BaiduClipboard extends BaseHook {
/**
* @author 焕晨HChen
*/
public class BaiduClipboard extends BaseHC {
@Override
public void init() throws NoSuchMethodException {
Method method1 = null;
Method method2 = null;
List<Method> methods = null;
public void init() {
if ("com.baidu.input".equals(lpparam.packageName)) {

method1 = (Method) DexKit.getDexKitBridge("GetMaxQueryCount", new IDexKit() {
Class<?> ClipboardConfig = (Class<?>) DexKit.getDexKitBridge("NewGetMaxQueryCount", new IDexKit() {
@Override
public AnnotatedElement dexkit(DexKitBridge bridge) throws ReflectiveOperationException {
MethodData methodData = bridge.findMethod(
FindMethod.create()
.matcher(
MethodMatcher.create()
.declaredClass(
ClassMatcher.create()
.usingStrings("begin to checkMaxQueryCount")
)
.returnType(int.class)
.usingStrings("clipboard.config.max_query_count")
)
).singleOrNull();
return methodData.getMethodInstance(lpparam.classLoader);
}
});

method2 = (Method) DexKit.getDexKitBridge("GetMaxCount", new IDexKit() {
@Override
public AnnotatedElement dexkit(DexKitBridge bridge) throws ReflectiveOperationException {
MethodData methodData = bridge.findMethod(
FindMethod.create()
.matcher(
MethodMatcher.create()
.declaredClass(
ClassMatcher.create()
.usingStrings("begin to checkMaxQueryCount")
)
.name("getMaxCount")
)
).singleOrNull();
return methodData.getMethodInstance(lpparam.classLoader);
ClassData classData = bridge.findClass(FindClass.create()
.matcher(ClassMatcher.create()
.usingStrings("begin to checkMaxQueryCount")
)).singleOrNull();
return classData.getInstance(lpparam.classLoader);
}
});

if (ClipboardConfig != null) {
Arrays.stream(ClipboardConfig.getDeclaredMethods()).forEach(method -> {
if (method.getReturnType().equals(Integer.class)) {
hook(method, returnResult(Integer.MAX_VALUE));
}
});
}
} else if ("com.baidu.input_mi".equals(lpparam.packageName)) {

methods = DexKit.getDexKitBridgeList("GetMaxQueryCountList", new IDexKitList() {
DexKit.getDexKitBridgeList("GetMaxQueryCountList", new IDexKitList() {
@Override
public List<AnnotatedElement> dexkit(DexKitBridge bridge) throws ReflectiveOperationException {
MethodDataList methodDataList = bridge.findMethod(
FindMethod.create()
.matcher(
MethodMatcher.create()
.declaredClass(
ClassMatcher.create()
.usingStrings("clipboard.config.max_query_count")
)
.returnType(int.class)
MethodDataList methodDataList = bridge.findMethod(FindMethod.create()
.matcher(MethodMatcher.create()
.declaredClass(ClassMatcher.create()
.usingStrings("clipboard.config.max_query_count")
)
.returnType(int.class))
);
return DexKit.toElementList(methodDataList);
}
}).toMethodList();
}

if (method1 == null && method2 == null) {
if (methods.isEmpty()) {
logE(TAG, "list is empty!");
return;
}
if (methods.size() == 1) {
logW(TAG, "list size only one!");
}
if (methods.size() == 1 || methods.size() == 2) {
for (Method method : methods) {
// logE(TAG, "find method: " + method.getMethodInstance(lpparam.classLoader));
hookMethod(method,
new MethodHook() {
@Override
protected void before(MethodHookParam param) {
param.setResult(Integer.MAX_VALUE);
}
}
);
}
return;
}
logE(TAG, "list size to more!");
return;
}

if (method1 != null) {
hookMethod(method1,
new MethodHook() {
@Override
protected void before(MethodHookParam param) {
param.setResult(Integer.MAX_VALUE);
}
}
);
} else {
logE(TAG, "no find method 1");
}

if (method2 != null) {
hookMethod(method2,
new MethodHook() {
@Override
protected void before(MethodHookParam param) {
param.setResult(Integer.MAX_VALUE);
}
}
);
} else {
logE(TAG, "no find method 2");
}).toMethodList().forEach(method -> hook(method, returnResult(Integer.MAX_VALUE)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import android.content.Context;

import androidx.annotation.IntDef;
import androidx.annotation.Nullable;

import com.sevtinge.hyperceiler.utils.log.AndroidLogUtils;

Expand All @@ -33,9 +34,9 @@
@SuppressLint({"PrivateApi", "SoonBlockedPrivateApi", "DiscouragedPrivateApi"})
public class ContextUtils {
@IntDef(value = {
FLAG_ALL,
FLAG_CURRENT_APP,
FlAG_ONLY_ANDROID
FLAG_ALL,
FLAG_CURRENT_APP,
FlAG_ONLY_ANDROID
})
@Retention(RetentionPolicy.SOURCE)
public @interface Duration {
Expand Down Expand Up @@ -102,15 +103,14 @@ public static void getWaitContext(IContext iContext, boolean isSystem) {
break;
}
}
// context 可能为 null 请注意判断
iContext.hadContext(context);
}
iContext.hadContext(context);
});
ThreadPoolManager.shutdown();
}

public interface IContext {
void hadContext(Context context);
void hadContext(@Nullable Context context);
}

private static Context invokeMethod(int flag) throws Throwable {
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dexkit = "2.0.2"
ezxhelper = "2.2.0"
hiddenapibypass = "4.3"
annotation-processor = "4.4.0"
hooktool = "v.1.0.6"
hooktool = "v.1.0.9"
lyricGetterApi = "6.0.0"

[libraries]
Expand All @@ -37,7 +37,7 @@ rikkax-annotation = { module = "dev.rikka.tools.refine:annotation", version.ref
core = { group = "androidx.core", name = "core", version.ref = "core" }
collection = { group = "androidx.collection", name = "collection", version.ref = "collection" }
fragment = { group = "androidx.fragment", name = "fragment", version.ref = "fragment" }
hooktool = { module = "io.github.hchenx:hooktool", version.ref = "hooktool" }
hooktool = { module = "com.github.HChenX:HookTool", version.ref = "hooktool" }
recyclerview = { group = "androidx.recyclerview", name = "recyclerview", version.ref = "recyclerview" }
lifecycle-common = { group = "androidx.lifecycle", name = "lifecycle-common", version.ref = "lifecycle-common" }

Expand Down

0 comments on commit 9e06f92

Please sign in to comment.