Skip to content

Commit

Permalink
opt: 优化工具
Browse files Browse the repository at this point in the history
  • Loading branch information
HChenX committed Dec 13, 2024
1 parent f998873 commit d80d704
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

def defVersion = 'v.1.1.0'
int defVersionCode = 2024121200
int defVersionCode = 2024121301

group = 'com.github.HChenX'
version = defVersion
Expand Down
14 changes: 7 additions & 7 deletions app/src/main/java/com/hchen/hooktool/BaseHC.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
*/
public abstract class BaseHC extends CoreTool {
public String TAG = getClass().getSimpleName(); // 快捷获取类的简单名称作为 TAG, 为了效果建议配置相应的混淆规则。
private final ChainTool mChainTool = new ChainTool();
private static final ChainTool mChainTool = new ChainTool();
public static XC_LoadPackage.LoadPackageParam lpparam; // onZygote 状态下为 null。
public static ClassLoader classLoader;

Expand Down Expand Up @@ -110,27 +110,27 @@ public static void chain(Class<?> clazz, ChainTool chain) {
ChainTool.chain(clazz, chain);
}

final public ChainTool.ChainHook method(String name, Object... params) {
public static ChainTool.ChainHook method(String name, Object... params) {
return mChainTool.method(name, params);
}

final public ChainTool.ChainHook methodIfExist(String name, Object... params) {
public static ChainTool.ChainHook methodIfExist(String name, Object... params) {
return mChainTool.methodIfExist(name, params);
}

final public ChainTool.ChainHook anyMethod(String name) {
public static ChainTool.ChainHook anyMethod(String name) {
return mChainTool.anyMethod(name);
}

final public ChainTool.ChainHook constructor(Object... params) {
public static ChainTool.ChainHook constructor(Object... params) {
return mChainTool.constructor(params);
}

final public ChainTool.ChainHook constructorIfExist(Object... params) {
public static ChainTool.ChainHook constructorIfExist(Object... params) {
return mChainTool.constructorIfExist(params);
}

final public ChainTool.ChainHook anyConstructor() {
public static ChainTool.ChainHook anyConstructor() {
return mChainTool.anyConstructor();
}

Expand Down
7 changes: 5 additions & 2 deletions app/src/main/java/com/hchen/hooktool/tool/ChainTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,15 @@ public ChainHook anyConstructor() {

// 各种奇奇怪怪的添加 >.<
private void doFind(Class<?> clazz) {
if (clazz == null) return;
if (clazz == null) {
cacheDataList.clear();
return;
}
if (cacheDataList.isEmpty()) {
logW(getTag(), "cache data list is empty, can't find or hook anything!" + getStackTrace());
cacheDataList.clear();
return;
}

ArrayList<ChainData> members = new ArrayList<>();
for (ChainData cacheData : cacheDataList) {
String UUID = cacheData.mType + "#" + clazz.getName() + "#" + cacheData.mName + "#" + Arrays.toString(cacheData.mParams);
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/hchen/hooktool/tool/PrefsTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,15 @@ private static SharedPreferences currentSp(Context context, String prefsName) {
throw new RuntimeException(HCData.getInitTag() +
"[" + getTag() + "][E]: Context is null, can't create sprefs!" + getStackTrace());
}
if (sPrefs.get(context + prefsName) == null) {
if (sPrefs.get(context.getPackageName() + prefsName) == null) {
SharedPreferences s;
try {
s = context.getSharedPreferences(prefsName, Context.MODE_WORLD_READABLE);
} catch (Throwable ignored) {
s = context.getSharedPreferences(prefsName, Context.MODE_PRIVATE);
AndroidLog.logW(getTag(), "Maybe can't use xSharedPreferences!" + getStackTrace());
}
sPrefs.put(context + prefsName, s);
sPrefs.put(context.getPackageName() + prefsName, s);
return s;
} else {
return sPrefs.get(prefsName);
Expand Down

0 comments on commit d80d704

Please sign in to comment.