Skip to content

Commit

Permalink
feat: theme manager - Allow more downloads without logging in
Browse files Browse the repository at this point in the history
  • Loading branch information
Sevtinge committed Jul 16, 2024
1 parent b87808e commit 94eeff5
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.sevtinge.hyperceiler.module.base.BaseModule;
import com.sevtinge.hyperceiler.module.base.HookExpand;
import com.sevtinge.hyperceiler.module.hook.thememanager.AllowDownloadMore;
import com.sevtinge.hyperceiler.module.hook.thememanager.AllowThirdTheme;
import com.sevtinge.hyperceiler.module.hook.thememanager.DisableThemeAdNew;
import com.sevtinge.hyperceiler.module.hook.thememanager.EnableFoldTheme;
Expand All @@ -33,6 +34,7 @@ public class ThemeManager extends BaseModule {
public void handleLoadPackage() {
initHook(new AllowThirdTheme(), mPrefsMap.getBoolean("system_framework_allow_third_theme"));
initHook(new DisableThemeAdNew(), mPrefsMap.getBoolean("various_theme_disable_ads"));
initHook(new AllowDownloadMore(), mPrefsMap.getBoolean("theme_manager_allow_download_more"));
initHook(new EnablePadTheme(), mPrefsMap.getBoolean("various_theme_enable_pad_theme"));
initHook(new EnableFoldTheme(), mPrefsMap.getBoolean("various_theme_enable_fold_theme"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public AnnotatedElement dexkit(DexKitBridge bridge) throws ReflectiveOperationEx
}
});
long etime = System.currentTimeMillis();
logE(TAG, "代码执行时间(毫秒): " + (etime - stime));
//logE(TAG, "代码执行时间(毫秒): " + (etime - stime));
// logE("find class: " + lpparam.packageName);
// logE(TAG, "method: " + method);
hookMethod(method, new MethodHook() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* 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.hook.thememanager;

import static com.sevtinge.hyperceiler.module.base.tool.OtherTool.getPackageVersionCode;

import android.util.SparseArray;

import com.sevtinge.hyperceiler.module.base.BaseHook;
import com.sevtinge.hyperceiler.module.base.dexkit.DexKit;
import com.sevtinge.hyperceiler.module.base.dexkit.IDexKit;

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

import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;
import java.util.Iterator;

public class AllowDownloadMore extends BaseHook {
@Override
public void init() throws NoSuchMethodException {
Class<?> clazz = (Class<?>) DexKit.getDexKitBridge("DownloadCounter", new IDexKit() {
@Override
public AnnotatedElement dexkit(DexKitBridge bridge) throws ReflectiveOperationException {
ClassData clazzData = bridge.findClass(FindClass.create()
.matcher(ClassMatcher.create()
.usingStrings("anonymous_use_resources")
)).singleOrNull();
return clazzData.getInstance(lpparam.classLoader);
}
});

Method method1 = (Method) DexKit.getDexKitBridge("DownloadList", new IDexKit() {
@Override
public AnnotatedElement dexkit(DexKitBridge bridge) throws ReflectiveOperationException {
MethodData methodData = bridge.findMethod(FindMethod.create()
.matcher(MethodMatcher.create()
.declaredClass(clazz)
.returnType(clazz)
)).singleOrNull();
return methodData.getMethodInstance(lpparam.classLoader);
}
});

Method method2 = (Method) DexKit.getDexKitBridge("DownloadListSize", new IDexKit() {
@Override
public AnnotatedElement dexkit(DexKitBridge bridge) throws ReflectiveOperationException {
MethodData methodData1 = bridge.findMethod(FindMethod.create()
.matcher(MethodMatcher.create()
.declaredClass(clazz)
.returnType(int.class)
.usingNumbers(0)
)).singleOrNull();
MethodDataList methodData2 = bridge.findMethod(FindMethod.create()
.matcher(MethodMatcher.create()
.declaredClass(clazz)
.returnType(int.class)
)
);
methodData2.remove(methodData1);
if (methodData2.size() == 1) {
for (MethodData method : methodData2) {
return method.getMethodInstance(lpparam.classLoader);
}
}
return null;
}
});

hookMethod(method1, new MethodHook() {
@Override
protected void after(MethodHookParam param) throws Throwable {
hookMethod(method2, new MethodHook() {
@Override
protected void after(MethodHookParam param) throws Throwable {
param.setResult(1);
}
});
}
});
}
}
2 changes: 2 additions & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,8 @@
<string name="theme_manager_diable_ads_desc">将 \"猜你喜欢\" 的广告替换为空白卡片,其余位置的广告将完全移除</string>
<string name="theme_manager_enable_pad_theme">启用 Pad 主题</string>
<string name="theme_manager_enable_fold_theme">启用 Fold 主题</string>
<string name="theme_manager_allow_download_more">允许在未登录的情况下下载更多内容</string>
<string name="theme_manager_allow_download_more_desc">允许在未登录的情况下下载超过 10 个内容</string>
<!--万能遥控-->
<string name="remotecontroller">万能遥控</string>
<string name="remotecontroller_disable_ad">禁用推广</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,8 @@
<string name="theme_manager_diable_ads_desc">Replace \"guess what you like\" ads with blank cards, and remove the rest of the ads completely</string>
<string name="theme_manager_enable_pad_theme">Enable Pad theme</string>
<string name="theme_manager_enable_fold_theme">Enable Fold theme</string>
<string name="theme_manager_allow_download_more">Allow more downloads without logging in</string>
<string name="theme_manager_allow_download_more_desc">Allow downloading more than 10 items without logging in</string>
<!--remotecontroller-->
<string name="remotecontroller">Remote Controller</string>
<string name="remotecontroller_disable_ad">Disable Ad</string>
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/xml/theme_manager.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
android:key="prefs_key_various_theme_disable_ads"
android:defaultValue="false" />

<SwitchPreference
android:title="@string/theme_manager_allow_download_more"
android:summary="@string/theme_manager_allow_download_more_desc"
android:key="prefs_key_theme_manager_allow_download_more_ads"
android:defaultValue="false" />

<DropDownPreference
android:key="prefs_key_theme_manager_new_version_code_modify"
android:summary="@string/theme_manager_version_code_modify_desc"
Expand Down

0 comments on commit 94eeff5

Please sign in to comment.