Skip to content

Commit

Permalink
feat - downloads: always show download link (ReChronoRain#872)
Browse files Browse the repository at this point in the history
* feat - downloads: always show download link

* opt - AlwaysShowDownloadLink: using dexkit

* opt - downloadlink : add field dexkit
  • Loading branch information
frank-782 authored Sep 29, 2024
1 parent 4bea2d1 commit ec264bf
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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.app;

import com.sevtinge.hyperceiler.module.base.BaseModule;
import com.sevtinge.hyperceiler.module.base.HookExpand;
import com.sevtinge.hyperceiler.module.hook.downloads.ui.AlwaysShowDownloadLink;

@HookExpand(pkg = "com.android.providers.downloads.ui", tarAndroid = 33)
public class DownloadsUI extends BaseModule {

@Override
public void handleLoadPackage() {
initHook(new AlwaysShowDownloadLink(), mPrefsMap.getBoolean("downloads_ui_always_show_link"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/*
* 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.downloads.ui;

import static de.robv.android.xposed.XposedHelpers.getObjectField;
import static de.robv.android.xposed.XposedHelpers.setObjectField;

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.*;
import org.luckypray.dexkit.query.matchers.*;
import org.luckypray.dexkit.result.*;

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

public class AlwaysShowDownloadLink extends BaseHook {

@Override
public void init() {

Class<?> class1 = (Class<?>) DexKit.getDexKitBridge("DownloadInfo", new IDexKit() {
@Override
public AnnotatedElement dexkit(DexKitBridge bridge) throws ReflectiveOperationException {
ClassData classData = bridge.findClass(FindClass.create()
.excludePackages("androidx")
.matcher(
ClassMatcher.create()
.usingEqStrings("/s", " | ", "/")
)).singleOrNull();
return classData.getInstance(lpparam.classLoader);
}
});


Method method1 = (Method) DexKit.getDexKitBridge("ShowTaskDetailMatcher", new IDexKit() {
@Override
public AnnotatedElement dexkit(DexKitBridge bridge) throws ReflectiveOperationException {
MethodData methodData = bridge.findMethod(FindMethod.create()
.matcher(MethodMatcher.create()
.declaredClass(ClassMatcher.create().usingStrings("onEventMainThread noScrollListView="))
.usingNumbers(4, 8, 0)
.paramTypes(class1)
.returnType(void.class)
)).singleOrNull();
return methodData.getMethodInstance(lpparam.classLoader);
}
});

Field field1 = (Field) DexKit.getDexKitBridge("DownloadUrl", new IDexKit() {
@Override
public AnnotatedElement dexkit(DexKitBridge bridge) throws ReflectiveOperationException {
FieldData fieldData = bridge.findField(FindField.create()
.matcher(FieldMatcher.create()
.addReadMethod(MethodMatcher.create()
.usingStrings("android.intent.action.PICK", "com.android.fileexplorer"))
.declaredClass(class1)
.type(String.class)
)).singleOrNull();
return fieldData.getFieldInstance(lpparam.classLoader);
}
});

Field field2 = (Field) DexKit.getDexKitBridge("DownloadDesc", new IDexKit() {
@Override
public AnnotatedElement dexkit(DexKitBridge bridge) throws ReflectiveOperationException {
FieldDataList fieldDataList = bridge.findField(FindField.create()
.matcher(FieldMatcher.create()
.addReadMethod(MethodMatcher.create()
.declaredClass(ClassMatcher.create().usingStrings("onEventMainThread noScrollListView="))
.usingNumbers(4, 8, 0)
.paramTypes(class1)
.returnType(void.class))
.type(String.class)
));
// 感觉不太优雅 先这样吧.jpg 暂时没有更好的匹配方式了 反正method里就这两string
for (FieldData field : fieldDataList) {
if (field.getName().equals(field1.getName())) continue;
return field.getFieldInstance(lpparam.classLoader);
}
return null;

}
});

hookMethod(method1, new MethodHook() {
public void before(MethodHookParam param) throws Throwable {
String url = (String) getObjectField(param.args[0], field1.getName());
// @TODO 显示来源应用和路径
logD(TAG, lpparam.packageName, "url:" + url);
setObjectField(param.args[0], field2.getName(), "");
}
});

// findAndHookMethod("h1.h", "R", "i1.a",new MethodHook() {
// @Override
// public void before(MethodHookParam param) throws Throwable {
// logD(TAG, lpparam.packageName, "source: " + getObjectField(param.args[0], "r") + " path: " + getObjectField(param.args[0], "i"));
// setObjectField(param.args[0], "y", "");
// }
// });
}
}
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 @@ -621,6 +621,8 @@
<string name="downloads">下载管理程序</string>
<string name="various_fuck_xlDownload">阻止创建 .xlDownload 文件夹</string>
<string name="various_fuck_xlDownload_desc">防止下载管理程序在内部存储的根目录上生成 .xlDownload 文件夹</string>
<string name="downloads_ui_always_show_link">总是显示完整下载链接</string>
<string name="downloads_ui_always_show_link_desc">同时修复部分下载任务无法复制的问题</string>
<!--系统界面-->
<string name="system_ui">系统界面</string>
<string name="system_ui_lockscreen_title">锁屏</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-zh-rHK/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,8 @@
<string name="downloads">下載管理程序</string>
<string name="various_fuck_xlDownload">阻止創建 .xlDownload 文件夾</string>
<string name="various_fuck_xlDownload_desc">防止下載管理程序喺內部存儲嘅根目錄上生成 .xlDownload 文件夾</string>
<string name="downloads_ui_always_show_link">總是顯示完整下載連結</string>
<string name="downloads_ui_always_show_link_desc">同時修復部分下載任務無法複製的問題</string>
<!--系統界面-->
<string name="system_ui">系統界面</string>
<string name="system_ui_lockscreen_title">鎖屏</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 @@ -607,6 +607,8 @@
<string name="downloads">Downloads</string>
<string name="various_fuck_xlDownload">Block creation of .xlDownload folder</string>
<string name="various_fuck_xlDownload_desc">Prevent Downloads from creating the .xlDownload folder in the root of internal storage</string>
<string name="downloads_ui_always_show_link">Always show full download link</string>
<string name="downloads_ui_always_show_link_desc">Also fix some download tasks cannot be copied</string>
<!--System UI-->
<string name="system_ui">System UI</string>
<string name="system_ui_lockscreen_title">Lock screen</string>
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/xml/downloads.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,10 @@
android:summary="@string/various_fuck_xlDownload_desc"
android:key="prefs_key_various_fuck_xlDownload"
android:defaultValue="false" />
<SwitchPreference
android:title="@string/downloads_ui_always_show_link"
android:summary="@string/downloads_ui_always_show_link_desc"
android:key="prefs_key_downloads_ui_always_show_link"
android:defaultValue="false" />

</PreferenceScreen>

0 comments on commit ec264bf

Please sign in to comment.