Skip to content

Commit 7cf6fe1

Browse files
committed
add oversea mode
1 parent 6ca6624 commit 7cf6fe1

File tree

19 files changed

+619
-80
lines changed

19 files changed

+619
-80
lines changed

.gitignore

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
/app/build
2+
/app/src/main/java/bin/xposed/Unblock163MusicClient/note
3+
/gradle.properties
14
*.iml
25
.gradle
36
/local.properties
47
/.idea/workspace.xml
58
/.idea/libraries
69
.DS_Store
710
/build
8-
/captures
9-
/private
11+
/captures

.idea/.name

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
apply plugin: 'com.android.application'
22

3-
Properties props = new Properties()
4-
props.load(new FileInputStream(file("../private/signing.properties")))
5-
63
android {
74
compileSdkVersion 23
85
buildToolsVersion "23.0.2"
6+
useLibrary 'org.apache.http.legacy'
97

108
signingConfigs {
119
config {
1210
try {
13-
keyAlias props['KEY_ALIAS']
14-
keyPassword props['KEY_PASSWORD']
15-
storeFile file(props['STORE_FILE'])
16-
storePassword props['STORE_PASSWORD']
11+
keyAlias KEY_ALIAS
12+
keyPassword KEY_PASSWORD
13+
storeFile file(STORE_FILE)
14+
storePassword STORE_PASSWORD
1715
}
1816
catch (ex) {
19-
throw new InvalidUserDataException(ex.message + " You should define KEY_ALIAS, KEY_PASSWORD, STORE_FILE and STORE_PASSWORD in signing.properties.")
17+
throw new InvalidUserDataException(ex.message + " You should define KEY_ALIAS, KEY_PASSWORD, STORE_FILE and STORE_PASSWORD in gradle.properties.")
2018
}
2119
}
2220
}
@@ -28,6 +26,7 @@ android {
2826
versionCode 1
2927
versionName "0.0.1"
3028
}
29+
3130
buildTypes {
3231
release {
3332
minifyEnabled true
@@ -40,4 +39,5 @@ android {
4039

4140
dependencies {
4241
provided files('libs/XposedBridgeApi-30.jar')
42+
compile 'dnsjava:dnsjava:2.1.7'
4343
}

app/proguard-rules.pro

+7-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,10 @@
1515
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
1616
# public *;
1717
#}
18-
-keep class *
18+
19+
-dontwarn org.xbill.DNS.spi.DNSJavaNameServiceDescriptor
20+
-keep public class bin.xposed.Unblock163MusicClient.Main
21+
-keepclassmembernames class bin.xposed.Unblock163MusicClient.ui.SettingsActivity {
22+
int getActivatedModuleVersion();
23+
}
24+

app/src/main/AndroidManifest.xml

+26-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,32 @@
22
xmlns:tools="http://schemas.android.com/tools"
33
package="bin.xposed.Unblock163MusicClient">
44

5-
<application android:label="@string/app_name">
5+
<uses-permission android:name="android.permission.INTERNET" />
6+
7+
<application
8+
android:label="@string/app_name"
9+
android:theme="@style/AppTheme">
10+
11+
<activity
12+
android:name=".ui.SettingsActivity"
13+
android:label="@string/app_name">
14+
<intent-filter>
15+
<action android:name="android.intent.action.MAIN" />
16+
<category android:name="de.robv.android.xposed.category.MODULE_SETTINGS" />
17+
</intent-filter>
18+
</activity>
19+
20+
<activity-alias
21+
android:name=".ui.SettingsActivity-Alias"
22+
android:enabled="true"
23+
android:label="@string/app_name"
24+
android:targetActivity=".ui.SettingsActivity">
25+
<intent-filter>
26+
<action android:name="android.intent.action.MAIN" />
27+
<category android:name="android.intent.category.LAUNCHER" />
28+
</intent-filter>
29+
</activity-alias>
30+
631
<meta-data
732
android:name="xposedmodule"
833
android:value="true" />
@@ -14,5 +39,4 @@
1439
android:name="xposedminversion"
1540
android:value="30" />
1641
</application>
17-
1842
</manifest>
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,110 @@
11
package bin.xposed.Unblock163MusicClient;
22

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+
316
import de.robv.android.xposed.IXposedHookLoadPackage;
417
import de.robv.android.xposed.XC_MethodHook;
18+
import de.robv.android.xposed.XC_MethodReplacement;
19+
import de.robv.android.xposed.XSharedPreferences;
520
import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam;
621

722
import static de.robv.android.xposed.XposedHelpers.findAndHookMethod;
823

924
public class Main implements IXposedHookLoadPackage {
1025

1126
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+
}
1232

1333
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
1836
@Override
1937
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+
}
36104
}
37105
}
38-
});
106+
);
107+
}
39108
}
40109
}
41110
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package bin.xposed.Unblock163MusicClient;
2+
3+
public final class Settings {
4+
public static final String SETTING_CHANGED = "bin.xposed.Unblock163MusicClient.SETTING_CHANGED";
5+
6+
public static final String OVERSEA_MODE_KEY = "OVERSEA_MODE";
7+
public static final boolean OVERSEA_MODE_DEFAULT = false;
8+
9+
public static final String DNS_SERVER_KEY = "DNS_SERVER";
10+
public static final String DNS_SERVER_DEFAULT = "219.141.140.10"; // beijing telecom dns
11+
12+
public static final String DNS_INSTRUCTION_KEY = "DNS_INSTRUCTION";
13+
14+
public static final String DNS_TEST_KEY = "DNS_TEST";
15+
}

0 commit comments

Comments
 (0)