Skip to content

Commit

Permalink
1、修复7.X、8.X版本运存消耗过大导致Node意外退出导致代理失效的虫子(强烈建议不是追求最新功能的童鞋使用6.X及以下版本,总觉得一…
Browse files Browse the repository at this point in the history
…直在更新一些没用的功能还很消耗运存)

2、增加白名单模式,取消打勾后所有URL都走代理
3、增加同步锁,降低数据库频繁开关造成的错误
  • Loading branch information
nining377 committed Mar 20, 2021
1 parent 6511897 commit e6a63cd
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;

import com.raincat.dolby_beta.db.ExtraDao;
import com.raincat.dolby_beta.hook.AdAndUpdateHook;
import com.raincat.dolby_beta.hook.AutoSignInHook;
import com.raincat.dolby_beta.hook.BlackHook;
Expand Down Expand Up @@ -74,8 +75,10 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
if (processName.equals(CloudMusicPackage.PACKAGE_NAME)) {
CloudMusicPackage.init(neteaseContext);
//UnblockMusic代理
if (Setting.isProxyEnabled())
if (Setting.isProxyEnabled()) {
ExtraDao.getInstance(neteaseContext).saveExtra("ScriptRunning", "0");
new UnblockMusicHook(neteaseContext, CloudMusicPackage.versionCode, false);
}
//黑胶
if (Setting.isBlackEnabled()) {
Tools.deleteDirectory(CloudMusicPackage.CACHE_PATH);
Expand Down
48 changes: 29 additions & 19 deletions app/src/main/java/com/raincat/dolby_beta/hook/UnblockMusicHook.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.raincat.dolby_beta.hook;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;

Expand All @@ -20,14 +21,12 @@
import de.robv.android.xposed.XC_MethodHook;

import static de.robv.android.xposed.XposedBridge.hookAllConstructors;
import static de.robv.android.xposed.XposedBridge.log;
import static de.robv.android.xposed.XposedHelpers.findAndHookMethod;
import static de.robv.android.xposed.XposedHelpers.findClass;

/**
* <pre>
* author : RainCat
* org : Shenzhen JingYu Network Technology Co., Ltd.
* e-mail : [email protected]
* time : 2021/03/10
* desc : 音乐代理hook
Expand All @@ -41,6 +40,8 @@ public class UnblockMusicHook {

private static String dataPath;
private static SSLSocketFactory socketFactory;
private static Object objectProxy;
private static Object objectSSLSocketFactory;

private final String classMainActivity = "com.netease.cloudmusic.activity.MainActivity";
private String classRealCall;
Expand All @@ -49,7 +50,6 @@ public class UnblockMusicHook {
private String fieldSSLSocketFactory;

private final List<String> whiteUrlList = Arrays.asList(
// Should be enough for most cases
"song/enhance/player/url", "song/enhance/download/url");

public UnblockMusicHook(Context context, int versionCode, boolean isPlayProcess) {
Expand Down Expand Up @@ -79,8 +79,6 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
urlField.setAccessible(true);
Field proxyField = client.getClass().getDeclaredField(fieldProxy);
proxyField.setAccessible(true);
Field sslSocketFactoryField = client.getClass().getDeclaredField(fieldSSLSocketFactory);
sslSocketFactoryField.setAccessible(true);

Object urlObj = urlField.get(request);

Expand All @@ -90,17 +88,27 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
if (ExtraDao.getInstance(context).getExtra("ScriptRunning").equals("1"))
proxyField.set(client, proxy);
else
Tools.showToastOnLooper(context, "node未成功运行,请到模块内选择正确的脚本与Node路径若已使用存储重定向等APP请保证网易云音乐也可访问到脚本路径!");
return;
Tools.showToastOnLooper(context, "node未成功运行,请到模块内选择正确的脚本与Node路径若已使用存储重定向等APP请保证网易云音乐也可访问到脚本路径!");
break;
}
}
} else {
if (ExtraDao.getInstance(context).getExtra("ScriptRunning").equals("0"))
return;
if (socketFactory == null)
socketFactory = Tools.getSLLContext(dataPath + File.separator + "ca.crt").getSocketFactory();
proxyField.set(client, proxy);
sslSocketFactoryField.set(client, socketFactory);
Field sslSocketFactoryField = client.getClass().getDeclaredField(fieldSSLSocketFactory);
sslSocketFactoryField.setAccessible(true);
if (objectProxy == null)
objectProxy = proxyField.get(client);
if (objectSSLSocketFactory == null)
objectSSLSocketFactory = sslSocketFactoryField.get(client);

if (ExtraDao.getInstance(context).getExtra("ScriptRunning").equals("0")) {
proxyField.set(client, objectProxy);
sslSocketFactoryField.set(client, objectSSLSocketFactory);
} else {
if (socketFactory == null)
socketFactory = Tools.getSLLContext(dataPath + File.separator + "ca.crt").getSocketFactory();
proxyField.set(client, proxy);
sslSocketFactoryField.set(client, socketFactory);
}
}
}
}
Expand All @@ -112,14 +120,14 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
findAndHookMethod(classMainActivity, context.getClassLoader(), "onCreate", Bundle.class, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) {
ExtraDao.getInstance(context).saveExtra("ScriptRunning", "0");
initScript(context);
final Context neteaseContext = (Context) param.thisObject;
initScript(neteaseContext);
}
});

findAndHookMethod(classMainActivity, context.getClassLoader(), "onDestroy", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) {
protected void afterHookedMethod(MethodHookParam param) {
Command stop = new Command(0, STOP_PROXY);
Tools.shell(context, stop);
}
Expand Down Expand Up @@ -165,16 +173,18 @@ private void startScrip(final Context c) {
@Override
public void commandOutput(int id, String line) {
if (line.contains("Error")) {
ExtraDao.getInstance(context).saveExtra("ScriptRunning", "0");
Tools.showToastOnLooper(c, "运行失败,错误为:" + line);
} else if (line.contains("HTTP Server running")) {
ExtraDao.getInstance(context).saveExtra("ScriptRunning", "1");
Tools.showToastOnLooper(c, "UnblockNeteaseMusic运行成功");
} else if (line.contains("Killed")) {
ExtraDao.getInstance(context).saveExtra("ScriptRunning", "0");
Tools.showToastOnLooper(c, "Node被Killed,可能手机运存已耗尽,正在尝试重启……");
startScrip(c);
if (!((Activity) c).isFinishing()) {
Tools.showToastOnLooper(c, "Node被Killed,可能手机运存已耗尽,正在尝试重启……");
startScrip(c);
}
}
log("日志:" + line);
}
};
Tools.shell(c, start);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
/**
* <pre>
* author : RainCat
* org : Shenzhen JingYu Network Technology Co., Ltd.
* e-mail : [email protected]
* time : 2021/03/13
* desc : 说明
Expand Down

0 comments on commit e6a63cd

Please sign in to comment.