Skip to content

Commit 9e0b2d9

Browse files
committed
1、修复无版权音乐无法下载的虫子
2、修复系统自带资源管理器选择路径错误的虫子
1 parent 8c645a8 commit 9e0b2d9

File tree

5 files changed

+161
-45
lines changed

5 files changed

+161
-45
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ android {
88
applicationId "com.raincat.dolby_beta"
99
minSdkVersion 14
1010
targetSdkVersion 23
11-
versionCode 200
12-
versionName "2.0.0"
11+
versionCode 201
12+
versionName "2.0.1"
1313
}
1414
buildTypes {
1515
release {

app/src/main/java/com/raincat/dolby_beta/hook/UnblockMusicHook.java

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -53,46 +53,47 @@ public UnblockMusicHook(Context context, int versionCode, boolean isPlayProcess)
5353
classRealCall = "okhttp3.RealCall";
5454
}
5555

56-
if (isPlayProcess) {
57-
final Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 23338));
58-
hookAllConstructors(findClass(classRealCall, context.getClassLoader()), new XC_MethodHook() {
59-
@Override
60-
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
61-
if (param.args.length == 3) {
62-
Object client = param.args[0];
63-
Object request = param.args[1];
64-
65-
Field urlField = request.getClass().getDeclaredField(fieldHttpUrl);
66-
urlField.setAccessible(true);
67-
Field proxyField = client.getClass().getDeclaredField(fieldProxy);
68-
proxyField.setAccessible(true);
69-
70-
Object urlObj = urlField.get(request);
71-
if (urlObj.toString().contains("song/enhance/player/url") || urlObj.toString().contains("song/enhance/download/url")) {
72-
proxyField.set(client, proxy);
73-
} else {
74-
proxyField.set(client, null);
75-
}
56+
final Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 23338));
57+
hookAllConstructors(findClass(classRealCall, context.getClassLoader()), new XC_MethodHook() {
58+
@Override
59+
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
60+
if (param.args.length == 3) {
61+
Object client = param.args[0];
62+
Object request = param.args[1];
63+
64+
Field urlField = request.getClass().getDeclaredField(fieldHttpUrl);
65+
urlField.setAccessible(true);
66+
Field proxyField = client.getClass().getDeclaredField(fieldProxy);
67+
proxyField.setAccessible(true);
68+
69+
Object urlObj = urlField.get(request);
70+
if (urlObj.toString().contains("song/enhance/player/url") || urlObj.toString().contains("song/enhance/download/url")) {
71+
proxyField.set(client, proxy);
72+
} else {
73+
proxyField.set(client, null);
7674
}
7775
}
78-
});
79-
} else {
80-
findAndHookMethod(classMainActivity, context.getClassLoader(), "onCreate", Bundle.class, new XC_MethodHook() {
81-
@Override
82-
protected void afterHookedMethod(MethodHookParam param) {
83-
initScript(context);
84-
}
85-
});
76+
}
77+
});
8678

87-
findAndHookMethod(classMainActivity, context.getClassLoader(), "onDestroy", new XC_MethodHook() {
88-
@Override
89-
protected void beforeHookedMethod(MethodHookParam param) {
90-
Command stop = new Command(0, STOP_PROXY);
91-
Tools.shell(context, stop);
92-
dataPath = null;
93-
}
94-
});
95-
}
79+
if (isPlayProcess)
80+
return;
81+
82+
findAndHookMethod(classMainActivity, context.getClassLoader(), "onCreate", Bundle.class, new XC_MethodHook() {
83+
@Override
84+
protected void afterHookedMethod(MethodHookParam param) {
85+
initScript(context);
86+
}
87+
});
88+
89+
findAndHookMethod(classMainActivity, context.getClassLoader(), "onDestroy", new XC_MethodHook() {
90+
@Override
91+
protected void beforeHookedMethod(MethodHookParam param) {
92+
Command stop = new Command(0, STOP_PROXY);
93+
Tools.shell(context, stop);
94+
dataPath = null;
95+
}
96+
});
9697
}
9798

9899
private void initScript(final Context c) {

app/src/main/java/com/raincat/dolby_beta/ui/MainActivity.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.raincat.dolby_beta.dialog.SidebarCutDialog;
2626
import com.raincat.dolby_beta.dialog.SignSongDialog;
2727
import com.raincat.dolby_beta.utils.CloudMusicPackage;
28+
import com.raincat.dolby_beta.utils.FileUnits;
2829
import com.raincat.dolby_beta.utils.Tools;
2930

3031
import java.io.File;
@@ -145,7 +146,6 @@ private void addListener() {
145146
Preference script = findPreference(getString(R.string.script_key));
146147
script.setOnPreferenceClickListener(preference -> {
147148
Intent intent = new Intent(Intent.ACTION_GET_CONTENT)
148-
.putExtra(Intent.EXTRA_MIME_TYPES, "application/zip")
149149
.setType("*/*")
150150
.addCategory(Intent.CATEGORY_OPENABLE);
151151
startActivityForResult(intent, SCRIPT);
@@ -282,15 +282,15 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
282282
if (requestCode == NODE) {
283283
Uri uri = data.getData();
284284
if (uri != null && uri.getPath() != null && uri.getPath().toLowerCase().endsWith("node")) {
285-
share.edit().putString("node", uri.getPath()).apply();
286-
findPreference(getString(R.string.node_key)).setSummary(uri.getPath());
285+
share.edit().putString("node", FileUnits.getPath(context, uri)).apply();
286+
findPreference(getString(R.string.node_key)).setSummary(FileUnits.getPath(context, uri));
287287
} else
288288
Toast.makeText(context, "你选择的不是node文件!", Toast.LENGTH_SHORT).show();
289289
} else if (requestCode == SCRIPT) {
290290
Uri uri = data.getData();
291291
if (uri != null && uri.getPath() != null && uri.getPath().toLowerCase().endsWith("zip")) {
292-
share.edit().putString("script", uri.getPath()).apply();
293-
findPreference(getString(R.string.script_key)).setSummary(uri.getPath());
292+
share.edit().putString("script", FileUnits.getPath(context, uri)).apply();
293+
findPreference(getString(R.string.script_key)).setSummary(FileUnits.getPath(context, uri));
294294
} else
295295
Toast.makeText(context, "你选择的不是ZIP文件!", Toast.LENGTH_SHORT).show();
296296
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
package com.raincat.dolby_beta.utils;
2+
3+
import android.content.ContentUris;
4+
import android.content.Context;
5+
import android.database.Cursor;
6+
import android.net.Uri;
7+
import android.os.Build;
8+
import android.os.Environment;
9+
import android.provider.DocumentsContract;
10+
import android.provider.MediaStore;
11+
12+
/**
13+
* <pre>
14+
* author : RainCat
15+
* org : Shenzhen JingYu Network Technology Co., Ltd.
16+
* e-mail : nining377@gmail.com
17+
* time : 2021/03/13
18+
* desc : 说明
19+
* version: 1.0
20+
* </pre>
21+
*/
22+
23+
public class FileUnits {
24+
public static String getPath(final Context context, final Uri uri) {
25+
// DocumentProvider
26+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && DocumentsContract.isDocumentUri(context, uri)) {
27+
// ExternalStorageProvider
28+
if (isExternalStorageDocument(uri)) {
29+
final String docId = DocumentsContract.getDocumentId(uri);
30+
final String[] split = docId.split(":");
31+
final String type = split[0];
32+
33+
if ("primary".equalsIgnoreCase(type)) {
34+
return Environment.getExternalStorageDirectory() + "/" + split[1];
35+
}
36+
}
37+
// DownloadsProvider
38+
else if (isDownloadsDocument(uri)) {
39+
final String id = DocumentsContract.getDocumentId(uri);
40+
final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
41+
return getDataColumn(context, contentUri, null, null);
42+
}
43+
// MediaProvider
44+
else if (isMediaDocument(uri)) {
45+
final String docId = DocumentsContract.getDocumentId(uri);
46+
final String[] split = docId.split(":");
47+
final String type = split[0];
48+
49+
Uri contentUri = null;
50+
if ("image".equals(type)) {
51+
contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
52+
} else if ("video".equals(type)) {
53+
contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
54+
} else if ("audio".equals(type)) {
55+
contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
56+
}
57+
58+
final String selection = "_id=?";
59+
final String[] selectionArgs = new String[]{split[1]};
60+
61+
return getDataColumn(context, contentUri, selection, selectionArgs);
62+
}
63+
}
64+
// MediaStore (and general)
65+
else if ("content".equalsIgnoreCase(uri.getScheme())) {
66+
return getDataColumn(context, uri, null, null);
67+
}
68+
// File
69+
else if ("file".equalsIgnoreCase(uri.getScheme())) {
70+
return uri.getPath();
71+
}
72+
return null;
73+
}
74+
75+
/**
76+
* Get the value of the data column for this Uri. This is useful for
77+
* MediaStore Uris, and other file-based ContentProviders.
78+
*
79+
* @param context The context.
80+
* @param uri The Uri to query.
81+
* @param selection (Optional) Filter used in the query.
82+
* @param selectionArgs (Optional) Selection arguments used in the query.
83+
* @return The value of the _data column, which is typically a file path.
84+
*/
85+
public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
86+
Cursor cursor = null;
87+
final String column = "_data";
88+
final String[] projection = {column};
89+
90+
try {
91+
cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);
92+
if (cursor != null && cursor.moveToFirst()) {
93+
final int column_index = cursor.getColumnIndexOrThrow(column);
94+
return cursor.getString(column_index);
95+
}
96+
} finally {
97+
if (cursor != null)
98+
cursor.close();
99+
}
100+
return null;
101+
}
102+
103+
104+
public static boolean isExternalStorageDocument(Uri uri) {
105+
return "com.android.externalstorage.documents".equals(uri.getAuthority());
106+
}
107+
108+
public static boolean isDownloadsDocument(Uri uri) {
109+
return "com.android.providers.downloads.documents".equals(uri.getAuthority());
110+
}
111+
112+
public static boolean isMediaDocument(Uri uri) {
113+
return "com.android.providers.media.documents".equals(uri.getAuthority());
114+
}
115+
}

0 commit comments

Comments
 (0)