Skip to content

Commit

Permalink
优化: 调整Dexkit
Browse files Browse the repository at this point in the history
  • Loading branch information
HChenX committed Apr 28, 2024
1 parent 6b593f2 commit 9104019
Show file tree
Hide file tree
Showing 78 changed files with 487 additions and 392 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.github.kyuubiran.ezxhelper.EzXHelper;
import com.sevtinge.hyperceiler.XposedInit;
import com.sevtinge.hyperceiler.module.base.dexkit.DexKit;
import com.sevtinge.hyperceiler.module.base.dexkit.InitDexKit;
import com.sevtinge.hyperceiler.safe.CrashData;
import com.sevtinge.hyperceiler.utils.ContextUtils;
import com.sevtinge.hyperceiler.utils.Helpers;
Expand Down Expand Up @@ -60,6 +59,7 @@ public void init(LoadPackageParam lpparam) {
// BaseXposedInit.mResHook.putHandler(handler);
// } catch (Throwable e) {
// }
// EzXHelper.initAppContext(context, false);
BaseXposedInit.mResHook.loadModuleRes(context);
// mResHook.loadModuleRes(context);
}
Expand All @@ -69,17 +69,12 @@ public void init(LoadPackageParam lpparam) {
XposedLogUtils.logE(TAG, "get context failed!" + e);
}
mLoadPackageParam = lpparam;
InitDexKit kit = new InitDexKit(lpparam, TAG);
DexKit.INSTANCE.setInitDexKit(kit);
DexKit dexKit = new DexKit(lpparam, TAG);
initZygote();
handleLoadPackage();
if (kit.isInit) {
try {
kit.closeHostDir();
// XposedLogUtils.logE(TAG, "close dexkit s: " + lpparam.packageName);
} catch (Exception e) {
XposedLogUtils.logE(TAG, "close dexkit failed!" + e);
}
if (dexKit.isInit) {
dexKit.close();
// XposedLogUtils.logE(TAG, "close dexkit s: " + lpparam.packageName);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,13 @@ private boolean invoke(LoadPackageParam lpparam, Class<?> clzz) {
return true;
} catch (IllegalAccessException |
InvocationTargetException e) {
logE(TAG, "The method failed to be called! " + e);
return false;
Throwable cause = e.getCause();
if (cause != null) {
throw new RuntimeException(TAG + ": The method failed to be called due to: \n" + cause +
" \ncause: " + cause.getCause());
} else {
throw new RuntimeException(TAG + ": The method failed to be called! \n" + e);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* 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.
* 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/>.
* Copyright (C) 2023-2024 HyperCeiler Contributions
*/
package com.sevtinge.hyperceiler.module.base.dexkit;

import org.jetbrains.annotations.NotNull;
import org.luckypray.dexkit.DexKitBridge;

import de.robv.android.xposed.callbacks.XC_LoadPackage;

public class DexKit {
public boolean isInit = false;
private final String TAG;
private String hostDir = null;
private XC_LoadPackage.LoadPackageParam loadPackageParam;
private static DexKit dexKit = null;
private static DexKitBridge privateDexKitBridge = null;

public DexKit(XC_LoadPackage.LoadPackageParam param, String tag) {
loadPackageParam = param;
TAG = tag;
dexKit = this;
}

private void init() {
if (privateDexKitBridge == null) {
if (hostDir == null) {
if (loadPackageParam == null) {
throw new RuntimeException(TAG != null ? TAG : "InitDexKit" + ": lpparam is null");
}
hostDir = loadPackageParam.appInfo.sourceDir;
}
System.loadLibrary("dexkit");
privateDexKitBridge = DexKitBridge.create(hostDir);
}
isInit = true;
}

@NotNull
public static DexKitBridge getDexKitBridge() {
if (privateDexKitBridge == null) {
if (dexKit == null) {
throw new RuntimeException("InitDexKit is null!!");
} else {
// new DexKitCache(dexKit.loadPackageParam).create();
dexKit.init();
}
}
return privateDexKitBridge;
}

/**
* 请勿手动调用。
*/
public void close() {
if (privateDexKitBridge != null) {
privateDexKitBridge.close();
privateDexKitBridge = null;
}
loadPackageParam = null;
dexKit = null;
hostDir = null;
isInit = false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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.
* 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/>.
* Copyright (C) 2023-2024 HyperCeiler Contributions
*/
package com.sevtinge.hyperceiler.module.base.dexkit;

import com.sevtinge.hyperceiler.callback.ITAG;
import com.sevtinge.hyperceiler.utils.FileUtils;
import com.sevtinge.hyperceiler.utils.log.XposedLogUtils;

import de.robv.android.xposed.callbacks.XC_LoadPackage;

public class DexKitCache {
private final XC_LoadPackage.LoadPackageParam param;
private final String data;
private final String dexPath;
private final String dexFile;

public DexKitCache(XC_LoadPackage.LoadPackageParam param) {
this.param = param;
data = param.appInfo.dataDir;
dexPath = data + "/dexkit";
dexFile = dexPath + "/cache";
XposedLogUtils.logE(ITAG.TAG, "data: " + data + " dex: " + dexPath);
}

public DexKitCache create() {
FileUtils.mkdirs(dexPath);
FileUtils.touch(dexFile);
FileUtils.setPermission(dexFile);
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,13 @@
*/
package com.sevtinge.hyperceiler.module.base.dexkit

import org.luckypray.dexkit.*
import org.luckypray.dexkit.query.enums.*
import org.luckypray.dexkit.query.matchers.*

/**
* DexKit 工具
*/
object DexKit {
var initDexKit: InitDexKit? = null

val dexKitBridge: DexKitBridge by lazy {
initDexKit!!.init()
}

object DexKitTool {
/**
* DexKit 封装查找方式
*/
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
public class DisableWatermark extends BaseHook {
@Override
public void init() throws NoSuchMethodException {
MethodData methodData = DexKit.INSTANCE.getDexKitBridge().findMethod(FindMethod.create()
MethodData methodData = DexKit.getDexKitBridge().findMethod(FindMethod.create()
.matcher(MethodMatcher.create()
.usingStrings("userId", "add watermark")
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ package com.sevtinge.hyperceiler.module.hook.browser

import com.github.kyuubiran.ezxhelper.EzXHelper.safeClassLoader
import com.sevtinge.hyperceiler.module.base.*
import com.sevtinge.hyperceiler.module.base.dexkit.DexKit.addUsingStringsEquals
import com.sevtinge.hyperceiler.module.base.dexkit.DexKit.dexKitBridge
import com.sevtinge.hyperceiler.module.base.dexkit.*
import com.sevtinge.hyperceiler.module.base.dexkit.DexKitTool.addUsingStringsEquals
import com.sevtinge.hyperceiler.module.base.tool.OtherTool.*
import de.robv.android.xposed.*

object DebugMode : BaseHook() {
private var found = false

override fun init() {
dexKitBridge.findMethod {
DexKit.getDexKitBridge().findMethod {
matcher {
addUsingStringsEquals("environment_flag")
returnType = "java.lang.String"
Expand All @@ -43,7 +43,7 @@ object DebugMode : BaseHook() {
)
}

dexKitBridge.findMethod {
DexKit.getDexKitBridge().findMethod {
matcher {
addUsingStringsEquals("pref_key_debug_mode_new")
returnType = "boolean"
Expand All @@ -61,7 +61,7 @@ object DebugMode : BaseHook() {
}

if (!found) {
dexKitBridge.findMethod {
DexKit.getDexKitBridge().findMethod {
matcher {
addUsingStringsEquals("pref_key_debug_mode")
returnType = "boolean"
Expand All @@ -80,7 +80,7 @@ object DebugMode : BaseHook() {
}

if (!found) {
dexKitBridge.findMethod {
DexKit.getDexKitBridge().findMethod {
matcher {
addUsingStringsEquals("pref_key_debug_mode_" + getPackageVersionCode(lpparam))
returnType = "boolean"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
public class EnableDebugEnvironment extends BaseHook {
@Override
public void init() throws NoSuchMethodException {
MethodData methodData = DexKit.INSTANCE.getDexKitBridge().findMethod(FindMethod.create()
MethodData methodData = DexKit.getDexKitBridge().findMethod(FindMethod.create()
.matcher(MethodMatcher.create()
.usingStrings("pref_key_debug_mode_" + getPackageVersionCode(lpparam))
.name("getDebugMode")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public class UnlockSubscription extends BaseHook {
@Override
public void init() throws NoSuchMethodException {
MethodData methodData1 = DexKit.INSTANCE.getDexKitBridge().findMethod(FindMethod.create()
MethodData methodData1 = DexKit.getDexKitBridge().findMethod(FindMethod.create()
.matcher(MethodMatcher.create()
.declaredClass(ClassMatcher.create()
.usingStrings("Cal:D:CalendarApplicationDelegate"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
public class CustomWatermark extends BaseHook {
@Override
public void init() throws NoSuchMethodException {
MethodDataList methodDataList = DexKit.INSTANCE.getDexKitBridge().findMethod(FindMethod.create()
MethodDataList methodDataList = DexKit.getDexKitBridge().findMethod(FindMethod.create()
.matcher(MethodMatcher.create()
.returnType(SparseArray.class)
.paramCount(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
public class EnableLabOptions extends BaseHook {
@Override
public void init() throws NoSuchMethodException {
MethodData methodData = DexKit.INSTANCE.getDexKitBridge().findMethod(FindMethod.create()
MethodData methodData = DexKit.getDexKitBridge().findMethod(FindMethod.create()
.matcher(MethodMatcher.create()
.usingStrings("getBoolean", "SystemProperties", "Exception while getting system property: ")
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void init() throws NoSuchMethodException {
MethodData methodData1 = null;
MethodDataList methodDataList = new MethodDataList();
if ("com.baidu.input".equals(lpparam.packageName)) {
methodData = DexKit.INSTANCE.getDexKitBridge().findMethod(
methodData = DexKit.getDexKitBridge().findMethod(
FindMethod.create()
.matcher(
MethodMatcher.create()
Expand All @@ -29,7 +29,7 @@ public void init() throws NoSuchMethodException {
)
).singleOrNull();

methodData1 = DexKit.INSTANCE.getDexKitBridge().findMethod(
methodData1 = DexKit.getDexKitBridge().findMethod(
FindMethod.create()
.matcher(
MethodMatcher.create()
Expand All @@ -41,7 +41,7 @@ public void init() throws NoSuchMethodException {
)
).singleOrNull();
} else if ("com.baidu.input_mi".equals(lpparam.packageName)) {
methodDataList = DexKit.INSTANCE.getDexKitBridge().findMethod(
methodDataList = DexKit.getDexKitBridge().findMethod(
FindMethod.create()
.matcher(
MethodMatcher.create()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class SoGouClipboard extends BaseHook {
@Override
public void init() {
// DexKit.INSTANCE.initDexKit(lpparam);
MethodData methodData = DexKit.INSTANCE.getDexKitBridge().findMethod(
MethodData methodData = DexKit.getDexKitBridge().findMethod(
FindMethod.create()
.matcher(MethodMatcher.create()
.declaredClass(ClassMatcher.create()
Expand Down
Loading

0 comments on commit 9104019

Please sign in to comment.