|
1 | 1 | package bin.xposed.Unblock163MusicClient;
|
2 | 2 |
|
| 3 | +import android.content.BroadcastReceiver; |
| 4 | +import android.content.Context; |
| 5 | +import android.content.Intent; |
| 6 | +import android.content.IntentFilter; |
| 7 | + |
| 8 | +import org.apache.http.client.methods.HttpGet; |
| 9 | +import org.apache.http.client.methods.HttpUriRequest; |
| 10 | +import org.apache.http.impl.client.AbstractHttpClient; |
| 11 | +import org.xbill.DNS.TextParseException; |
| 12 | + |
| 13 | +import java.net.URI; |
| 14 | +import java.net.URISyntaxException; |
| 15 | + |
3 | 16 | import de.robv.android.xposed.IXposedHookLoadPackage;
|
4 | 17 | import de.robv.android.xposed.XC_MethodHook;
|
| 18 | +import de.robv.android.xposed.XC_MethodReplacement; |
| 19 | +import de.robv.android.xposed.XSharedPreferences; |
5 | 20 | import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam;
|
6 | 21 |
|
7 | 22 | import static de.robv.android.xposed.XposedHelpers.findAndHookMethod;
|
8 | 23 |
|
9 | 24 | public class Main implements IXposedHookLoadPackage {
|
10 | 25 |
|
11 | 26 | public void handleLoadPackage(final LoadPackageParam lpparam) throws Throwable {
|
| 27 | + if (lpparam.packageName.equals(BuildConfig.APPLICATION_ID)) { |
| 28 | + // make current module activated |
| 29 | + findAndHookMethod("bin.xposed.Unblock163MusicClient.ui.SettingsActivity", lpparam.classLoader, |
| 30 | + "getActivatedModuleVersion", XC_MethodReplacement.returnConstant(BuildConfig.VERSION_CODE)); |
| 31 | + } |
12 | 32 |
|
13 | 33 | if (lpparam.packageName.equals("com.netease.cloudmusic")) {
|
14 |
| - Utility.Init(lpparam.classLoader); |
15 |
| - |
16 |
| - findAndHookMethod("com.netease.cloudmusic.utils.u", lpparam.classLoader, |
17 |
| - "i", new XC_MethodHook() { |
| 34 | + Utility.init(lpparam.classLoader); |
| 35 | + findAndHookMethod("com.netease.cloudmusic.utils.u", lpparam.classLoader, "i", new XC_MethodHook() { //3.1.4 |
18 | 36 | @Override
|
19 | 37 | protected void afterHookedMethod(MethodHookParam param) throws Exception {
|
20 |
| - String full_url = (String) Utility.FIELD_utils_c.get(param.thisObject); |
21 |
| - String url = full_url.replace("http://music.163.com", ""); |
22 |
| - if (url.startsWith("/eapi/batch") |
23 |
| - || url.startsWith("/eapi/cloudsearch/pc") |
24 |
| - || url.startsWith("/eapi/v1/artist") |
25 |
| - || url.startsWith("/eapi/v1/album") |
26 |
| - || url.startsWith("/eapi/v1/play/record") |
27 |
| - || url.startsWith("/eapi/v1/search/get") |
28 |
| - || url.startsWith("/eapi/v3/playlist/detail") |
29 |
| - || url.startsWith("/eapi/v3/song/detail") |
30 |
| - || url.startsWith("/eapi/v3/song/enhance/privilege")) { |
31 |
| - String modified = Utility.ModifyDetailApi((String) param.getResult()); |
32 |
| - param.setResult(modified); |
33 |
| - } else if (url.startsWith("/eapi/song/enhance/player/url")) { |
34 |
| - String modified = Utility.ModifyPlayerApi(url, (String) param.getResult()); |
35 |
| - param.setResult(modified); |
| 38 | + String url = (String) Utility.FIELD_utils_c.get(param.thisObject); |
| 39 | + if (url.startsWith("http://music.163.com/eapi/")) { |
| 40 | + String path = url.replace("http://music.163.com", ""); |
| 41 | + |
| 42 | + if (path.startsWith("/eapi/batch") |
| 43 | + || path.startsWith("/eapi/v1/artist") |
| 44 | + || path.startsWith("/eapi/v1/album") |
| 45 | + || path.startsWith("/eapi/v1/play/record") |
| 46 | + || path.startsWith("/eapi/v1/search/get") |
| 47 | + || path.startsWith("/eapi/v3/playlist/detail") |
| 48 | + || path.startsWith("/eapi/v3/song/detail") |
| 49 | + || path.startsWith("/eapi/v3/song/enhance/privilege")) { |
| 50 | + String modified = Utility.modifyDetailApi((String) param.getResult()); |
| 51 | + param.setResult(modified); |
| 52 | + |
| 53 | + } else if (path.startsWith("/eapi/song/enhance/player/url")) { |
| 54 | + String modified = Utility.modifyPlayerApi(path, (String) param.getResult()); |
| 55 | + param.setResult(modified); |
| 56 | + } |
| 57 | + } |
| 58 | + } |
| 59 | + } |
| 60 | + ); |
| 61 | + |
| 62 | + XSharedPreferences xSharedPreferences = new XSharedPreferences(BuildConfig.APPLICATION_ID); |
| 63 | + Utility.OVERSEA_MODE_ENABLED = xSharedPreferences.getBoolean(Settings.OVERSEA_MODE_KEY, Settings.OVERSEA_MODE_DEFAULT); |
| 64 | + |
| 65 | + if (Utility.OVERSEA_MODE_ENABLED) { |
| 66 | + Utility.setDnsServer(xSharedPreferences.getString(Settings.DNS_SERVER_KEY, Settings.DNS_SERVER_DEFAULT)); |
| 67 | + |
| 68 | + findAndHookMethod("com.netease.cloudmusic.NeteaseMusicApplication", lpparam.classLoader, |
| 69 | + "onCreate", new XC_MethodHook() { |
| 70 | + @Override |
| 71 | + protected void beforeHookedMethod(MethodHookParam param) throws Throwable { |
| 72 | + Context context = (Context) param.thisObject; |
| 73 | + BroadcastReceiver settingChangedReceiver = new BroadcastReceiver() { |
| 74 | + @Override |
| 75 | + public void onReceive(Context context, Intent intent) { |
| 76 | + Utility.setDnsServer(intent.getStringExtra(Settings.DNS_SERVER_KEY)); |
| 77 | + } |
| 78 | + }; |
| 79 | + IntentFilter settingChangedFilter = new IntentFilter(Settings.SETTING_CHANGED); |
| 80 | + context.registerReceiver(settingChangedReceiver, settingChangedFilter); |
| 81 | + } |
| 82 | + }); |
| 83 | + |
| 84 | + findAndHookMethod(AbstractHttpClient.class, "execute", HttpUriRequest.class, new XC_MethodHook() { |
| 85 | + @SuppressWarnings("deprecation") |
| 86 | + @Override |
| 87 | + protected void beforeHookedMethod(XC_MethodHook.MethodHookParam param) throws TextParseException, URISyntaxException { |
| 88 | + if (param.args[0] instanceof HttpGet) { |
| 89 | + HttpGet httpGet = (HttpGet) param.args[0]; |
| 90 | + URI uri = httpGet.getURI(); |
| 91 | + |
| 92 | + // only process self-generate url (override original url) |
| 93 | + if (uri.toString().endsWith(".mp3?")) { |
| 94 | + String host = uri.getHost(); |
| 95 | + String ip = Utility.getIpByHost(host); |
| 96 | + if (ip != null) { |
| 97 | + String path = uri.getPath(); // getPath() returns path without "?" |
| 98 | + httpGet.setURI(new URI("http://" + ip + path)); |
| 99 | + httpGet.setHeader("Host", host); |
| 100 | + param.args[0] = httpGet; |
| 101 | + } |
| 102 | + } |
| 103 | + } |
36 | 104 | }
|
37 | 105 | }
|
38 |
| - }); |
| 106 | + ); |
| 107 | + } |
39 | 108 | }
|
40 | 109 | }
|
41 | 110 | }
|
0 commit comments