Skip to content

Commit

Permalink
[优化] 日志调用 #5
Browse files Browse the repository at this point in the history
  • Loading branch information
lingqiqi5211 authored Oct 28, 2023
2 parents 4be5355 + 51d6840 commit 16724e7
Show file tree
Hide file tree
Showing 96 changed files with 443 additions and 397 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//file:noinspection DependencyNotationArgument
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter

Expand Down Expand Up @@ -133,6 +134,7 @@ dependencies {

implementation 'org.luckypray:dexkit:2.0.0-rc7'
// implementation 'org.luckypray:DexKit:1.1.8'
//noinspection GradleDependency
implementation 'io.github.biezhi:TinyPinyin:2.0.3.RELEASE'
implementation 'com.github.kyuubiran:EzXHelper:2.0.7'
implementation "com.google.accompanist:accompanist-systemuicontroller:0.32.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package com.sevtinge.hyperceiler.module.base;

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

import com.sevtinge.hyperceiler.BuildConfig;
import com.sevtinge.hyperceiler.XposedInit;
import com.sevtinge.hyperceiler.utils.PrefsMap;
import com.sevtinge.hyperceiler.utils.ResourcesHook;
import com.sevtinge.hyperceiler.utils.log.XposedLogUtils;

Expand All @@ -16,15 +12,11 @@
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam;

public abstract class BaseHook {
public abstract class BaseHook extends XposedLogUtils {
public String TAG = getClass().getSimpleName();
private static final boolean isDebugVersion = BuildConfig.BUILD_TYPE.contains("debug");
private static final boolean isNotReleaseVersion = !BuildConfig.BUILD_TYPE.contains("release");
private final boolean detailLog = !mPrefsMap.getBoolean("settings_disable_detailed_log");

public LoadPackageParam lpparam;
public static final ResourcesHook mResHook = XposedInit.mResHook;
public static final PrefsMap<String, Object> mPrefsMap = XposedInit.mPrefsMap;

public static final String ACTION_PREFIX = "com.sevtinge.hyperceiler.module.action.";

Expand All @@ -35,10 +27,10 @@ public void onCreate(LoadPackageParam lpparam) {
setLoadPackageParam(lpparam);
init();
if (detailLog && isNotReleaseVersion) {
XposedLogUtils.logI(TAG, lpparam.packageName, "Hook Success.");
logI(TAG, lpparam.packageName, "Hook Success.");
}
} catch (Throwable t) {
XposedLogUtils.logE(TAG, lpparam.packageName, "Hook Failed", t);
logE(TAG, lpparam.packageName, "Hook Failed", t);
}
}

Expand All @@ -58,7 +50,7 @@ public Class<?> findClassIfExists(String className) {
try {
return findClass(className);
} catch (XposedHelpers.ClassNotFoundError e) {
LogD("findClassIfExists", "find " + className + " is Null", e);
logE("findClassIfExists", "find " + className + " is Null: " + e);
return null;
}
}
Expand All @@ -67,7 +59,7 @@ public Class<?> findClassIfExists(String newClassName, String oldClassName) {
try {
return findClass(findClassIfExists(newClassName) != null ? newClassName : oldClassName);
} catch (XposedHelpers.ClassNotFoundError e) {
LogD("findClassIfExists", "find " + newClassName + " and " + oldClassName + " is Null", e);
logE("findClassIfExists", "find " + newClassName + " and " + oldClassName + " is Null: " + e);
return null;
}
}
Expand All @@ -76,7 +68,7 @@ public Class<?> findClassIfExists(String className, ClassLoader classLoader) {
try {
return findClass(className, classLoader);
} catch (XposedHelpers.ClassNotFoundError e) {
LogD("findClassIfExists", "find " + className + " is Null", e);
logE("findClassIfExists", "find " + className + " is Null: " + e);
return null;
}
}
Expand All @@ -103,7 +95,7 @@ public void beforeHookedMethod(MethodHookParam param) throws Throwable {
try {
this.before(param);
} catch (Throwable t) {
LogD("BeforeHook", t);
logE("BeforeHook", t);
}
}

Expand All @@ -112,7 +104,7 @@ public void afterHookedMethod(MethodHookParam param) throws Throwable {
try {
this.after(param);
} catch (Throwable t) {
LogD("AfterHook", t);
logE("AfterHook", t);
}
}
}
Expand All @@ -131,7 +123,7 @@ public boolean findAndHookMethodSilently(String className, String methodName, Ob
findAndHookMethod(className, methodName, parameterTypesAndCallback);
return true;
} catch (Throwable t) {
LogD("findAndHookMethodSilently", className + methodName + " is null", t);
logE("findAndHookMethodSilently", className + methodName + " is null: " + t);
return false;
}
}
Expand All @@ -141,7 +133,7 @@ public boolean findAndHookMethodSilently(Class<?> clazz, String methodName, Obje
findAndHookMethod(clazz, methodName, parameterTypesAndCallback);
return true;
} catch (Throwable t) {
LogD("findAndHookMethodSilently", clazz + methodName + " is null", t);
logE("findAndHookMethodSilently", clazz + methodName + " is null: " + t);
return false;
}
}
Expand All @@ -166,15 +158,15 @@ public void hookAllMethods(String className, String methodName, XC_MethodHook ca
}

} catch (Throwable t) {
LogD("HookAllMethods", className + " is " + methodName + " abnormal", t);
logE("HookAllMethods", className + " is " + methodName + " abnormal: " + t);
}
}

public void hookAllMethods(Class<?> hookClass, String methodName, XC_MethodHook callback) {
try {
XposedBridge.hookAllMethods(hookClass, methodName, callback).size();
} catch (Throwable t) {
LogD("HookAllMethods", hookClass + " is " + methodName + " abnormal", t);
logE("HookAllMethods", hookClass + " is " + methodName + " abnormal: " + t);
}
}

Expand Down Expand Up @@ -206,15 +198,15 @@ public void hookAllConstructors(String className, MethodHook callback) {
XposedBridge.hookAllConstructors(hookClass, callback).size();
}
} catch (Throwable t) {
LogD("hookAllConstructors", className + " is abnormal", t);
logE("hookAllConstructors", className + " is abnormal: " + t);
}
}

public void hookAllConstructors(Class<?> hookClass, MethodHook callback) {
try {
XposedBridge.hookAllConstructors(hookClass, callback).size();
} catch (Throwable t) {
LogD("hookAllConstructors", hookClass + " is abnormal", t);
logE("hookAllConstructors", hookClass + " is abnormal: " + t);
}
}

Expand All @@ -237,21 +229,21 @@ public void setDeclaredField(XC_MethodHook.MethodHookParam param, String iNeedSt
Object result = setString.get(param.thisObject);
checkLast("getDeclaredField", iNeedString, iNeedTo, result);
} catch (IllegalAccessException e) {
XposedLogUtils.logW("IllegalAccessException to: " + iNeedString + " need to: " + iNeedTo + " code:" + e);
logE("IllegalAccessException to: " + iNeedString + " need to: " + iNeedTo + " code: " + e);
}
} catch (NoSuchFieldException e) {
XposedLogUtils.logW("No such the: " + iNeedString + " code: " + e);
logE("No such the: " + iNeedString + " code: " + e);
}
} else {
XposedLogUtils.logW("Param is null Field: " + iNeedString + " to: " + iNeedTo);
logE("Param is null Field: " + iNeedString + " to: " + iNeedTo);
}
}

public void checkLast(String setObject, Object fieldName, Object value, Object last) {
if (value.equals(last)) {
XposedLogUtils.logI(setObject + " Success! set " + fieldName + " to " + value);
logI(setObject + " Success! set " + fieldName + " to " + value);
} else {
XposedLogUtils.logW(setObject + " Failed! set " + fieldName + " to " + value + " hope: " + value + " but: " + last);
logE(setObject + " Failed! set " + fieldName + " to " + value + " hope: " + value + " but: " + last);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.sevtinge.hyperceiler.utils.DexKit.closeDexKit
import com.sevtinge.hyperceiler.utils.DexKit.dexKitBridge
import com.sevtinge.hyperceiler.utils.DexKit.initDexKit
import com.sevtinge.hyperceiler.utils.Helpers.getPackageVersionCode
import com.sevtinge.hyperceiler.utils.log.XposedLogUtils

import de.robv.android.xposed.XC_MethodReplacement
import de.robv.android.xposed.XposedBridge

Expand Down Expand Up @@ -69,7 +69,7 @@ object DebugMode : BaseHook() {
}.forEach {
val debugMode = it.getMethodInstance(lpparam.classLoader)
if (debugMode.toString().contains("getDebugMode")) {
XposedLogUtils.logI(TAG, this.lpparam.packageName, "DebugMode method is $debugMode")
logI(TAG, this.lpparam.packageName, "DebugMode method is $debugMode")
found = true
XposedBridge.hookMethod(
debugMode,
Expand All @@ -87,7 +87,7 @@ object DebugMode : BaseHook() {
}.forEach {
val debugMode1 = it.getMethodInstance(safeClassLoader)
if (debugMode1.toString().contains("getDebugMode")) {
XposedLogUtils.logI(TAG, this.lpparam.packageName, "DebugMode1 method is $debugMode1")
logI(TAG, this.lpparam.packageName, "DebugMode1 method is $debugMode1")
found = true
XposedBridge.hookMethod(
debugMode1,
Expand All @@ -106,7 +106,7 @@ object DebugMode : BaseHook() {
}.forEach {
val debugMode2 = it.getMethodInstance(lpparam.classLoader)
if (debugMode2.toString().contains("getDebugMode")) {
XposedLogUtils.logI(TAG, this.lpparam.packageName, "DebugMode2 method is $debugMode2")
logI(TAG, this.lpparam.packageName, "DebugMode2 method is $debugMode2")
found = true
XposedBridge.hookMethod(
debugMode2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.sevtinge.hyperceiler.module.hook.camera

import com.sevtinge.hyperceiler.module.base.BaseHook
import com.sevtinge.hyperceiler.utils.hookBeforeMethod
import com.sevtinge.hyperceiler.utils.log.XposedLogUtils


object EnableLabOptions : BaseHook() {
override fun init() {
Expand All @@ -13,7 +13,7 @@ object EnableLabOptions : BaseHook() {
if (it.args[0] == "camera.lab.options") it.result = true
}
} catch (e: Exception) {
XposedLogUtils.logE(TAG, this.lpparam.packageName, e)
logE(TAG, this.lpparam.packageName, e)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.sevtinge.hyperceiler.module.hook.camera;

import com.sevtinge.hyperceiler.module.base.BaseHook;
import com.sevtinge.hyperceiler.utils.log.XposedLogUtils;


public class UnlockCvlens extends BaseHook {
@Override
Expand Down Expand Up @@ -32,7 +32,7 @@ protected void before(MethodHookParam param) {
}
});
} catch (Exception e) {
XposedLogUtils.logE(TAG, this.lpparam.packageName, "try to hook CvLensVersion failed" + e);
logE(TAG, this.lpparam.packageName, "try to hook CvLensVersion failed" + e);
throw new RuntimeException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import static com.sevtinge.hyperceiler.utils.Helpers.getPackageVersionCode;

import com.sevtinge.hyperceiler.module.base.BaseHook;
import com.sevtinge.hyperceiler.utils.log.XposedLogUtils;


public class EnableHourGlass extends BaseHook {
@Override
Expand All @@ -15,8 +15,8 @@ protected void before(MethodHookParam param) {
if (appVersionCode <= 130206400) {
param.setResult(true);
} else {
XposedLogUtils.logI(TAG, EnableHourGlass.this.lpparam.packageName, "Your clock versionCode is " + appVersionCode);
XposedLogUtils.logI(TAG, EnableHourGlass.this.lpparam.packageName, "Please revert to a supported version yourself");
logI(TAG, EnableHourGlass.this.lpparam.packageName, "Your clock versionCode is " + appVersionCode);
logI(TAG, EnableHourGlass.this.lpparam.packageName, "Please revert to a supported version yourself");
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import android.net.Uri;

import com.sevtinge.hyperceiler.module.base.BaseHook;
import com.sevtinge.hyperceiler.utils.log.XposedLogUtils;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XC_MethodReplacement;
Expand All @@ -24,7 +23,7 @@ public void init() {
XposedHelpers.findAndHookMethod(clazz, "getIntentWithBrowser", String.class, new XC_MethodReplacement() {
@Override
protected Object replaceHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable {
XposedLogUtils.logI(TAG, UseThirdPartyBrowser.this.lpparam.packageName, "hooked url " + param.args[0].toString());
logI(TAG, UseThirdPartyBrowser.this.lpparam.packageName, "hooked url " + param.args[0].toString());
Uri uri = Uri.parse(param.args[0].toString());
Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
Expand All @@ -36,15 +35,15 @@ protected Object replaceHookedMethod(XC_MethodHook.MethodHookParam param) throws
XposedHelpers.findAndHookMethod(clazz, "openGlobalSearch", Context.class, String.class, String.class, new XC_MethodReplacement() {
@Override
protected Object replaceHookedMethod(MethodHookParam param) throws Throwable {
XposedLogUtils.logI(TAG, UseThirdPartyBrowser.this.lpparam.packageName, "hooked all-search on, word is " + param.args[1].toString() + ", from " + param.args[2].toString());
logI(TAG, UseThirdPartyBrowser.this.lpparam.packageName, "hooked all-search on, word is " + param.args[1].toString() + ", from " + param.args[2].toString());
try {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_WEB_SEARCH);
intent.putExtra(SearchManager.QUERY, param.args[1].toString());
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
((Context) param.args[0]).startActivity(intent);
} catch (Exception e) {
XposedLogUtils.logE(TAG, UseThirdPartyBrowser.this.lpparam.packageName, e);
logE(TAG, UseThirdPartyBrowser.this.lpparam.packageName, e);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.os.Environment;

import com.sevtinge.hyperceiler.module.base.BaseHook;
import com.sevtinge.hyperceiler.utils.log.XposedLogUtils;

import java.io.File;
import java.io.FileNotFoundException;
Expand All @@ -18,13 +17,13 @@ public class FuckXlDownload extends BaseHook {
@Override
public void init() {
if (!TARGET_PACKAGE.equals(lpparam.packageName)) return;
XposedLogUtils.logI(TAG, this.lpparam.packageName, "Target path = " + TARGET_PATH);
logI(TAG, this.lpparam.packageName, "Target path = " + TARGET_PATH);
XposedHelpers.findAndHookMethod(File.class, "mkdirs", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) {
final boolean isXlDownload = ((File) param.thisObject).getAbsoluteFile().equals(TARGET_PATH);
if (isXlDownload) {
XposedLogUtils.logI(TAG, FuckXlDownload.this.lpparam.packageName, "blocked");
logI(TAG, FuckXlDownload.this.lpparam.packageName, "blocked");
param.setThrowable(new FileNotFoundException("blocked"));
}
}
Expand Down
Loading

0 comments on commit 16724e7

Please sign in to comment.