Skip to content

Commit

Permalink
1、修复不知名原因的下载失败bug
Browse files Browse the repository at this point in the history
  • Loading branch information
nining377 committed Feb 18, 2021
1 parent b8d04d4 commit 5a61e40
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "com.raincat.dolby_beta"
minSdkVersion 14
targetSdkVersion 23
versionCode 109
versionName "1.0.9"
versionCode 110
versionName "1.1.0"
}
buildTypes {
release {
Expand Down
19 changes: 19 additions & 0 deletions app/src/main/java/com/raincat/dolby_beta/hook/DownloadMD5Hook.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

import java.io.FileInputStream;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.security.MessageDigest;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedHelpers;

import static de.robv.android.xposed.XposedBridge.hookMethod;

Expand All @@ -26,10 +28,27 @@ public DownloadMD5Hook() {
protected void beforeHookedMethod(MethodHookParam param) {
final Object[] array = (Object[]) param.args[3];
String path = param.args[0].toString();
if (((String) array[5]).length() == 32) {
return;
}
array[5] = fileToMD5(path);
param.args[3] = array;
}
});

hookMethod(CloudMusicPackage.Transfer.getCheckDownloadStatusMethod(), new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) {
Method[] methods = param.args[0].getClass().getDeclaredMethods();
for (Method m : methods) {
if (m.getReturnType() == long.class) {
long length = (long) XposedHelpers.callMethod(param.args[0], m.getName());
param.setResult(length);
break;
}
}
}
});
}

private String fileToMD5(String filePath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ static List<String> getFilteredClasses(Pattern pattern, Comparator<String> compa

public static class Transfer {
private static Method checkMd5Method;
private static Method checkDownloadStatusMethod;

//下载完后的MD5检查
public static Method getCheckMd5Method() {
if (checkMd5Method == null) {
Pattern pattern = Pattern.compile("^com\\.netease\\.cloudmusic\\.module\\.transfer\\.download\\.[a-z]$");
Expand All @@ -172,6 +174,30 @@ public static Method getCheckMd5Method() {
}
return checkMd5Method;
}

//下载之前下载状态检查
public static Method getCheckDownloadStatusMethod() {
if (checkDownloadStatusMethod == null) {
Pattern pattern = Pattern.compile("^com\\.netease\\.cloudmusic\\.module\\.transfer\\.download\\.[a-z]$");
List<String> list = ClassHelper.getFilteredClasses(pattern, Collections.reverseOrder());

try {
checkDownloadStatusMethod = Stream.of(list)
.map(c -> findClass(c, getClassLoader()).getDeclaredMethods())
.flatMap(Stream::of)
.filter(m -> m.getReturnType() == long.class)
.filter(m -> m.getParameterTypes().length == 5)
.filter(m -> m.getParameterTypes()[1] == int.class)
.filter(m -> m.getParameterTypes()[3] == File.class)
.filter(m -> m.getParameterTypes()[4] == long.class)
.findFirst()
.get();
} catch (NoSuchElementException e) {
throw new RuntimeException("can't find checkDownloadStatusMethod");
}
}
return checkDownloadStatusMethod;
}
}

public static class NeteaseMusicApplication {
Expand Down

0 comments on commit 5a61e40

Please sign in to comment.