Skip to content

Commit

Permalink
1、增加大量try/catch保证某功能失效时不会影响其他功能
Browse files Browse the repository at this point in the history
2、新增Hook失败推送
3、优化黑胶hook逻辑,不再所有人都显示黑胶
  • Loading branch information
nining377 committed Oct 26, 2021
1 parent 763e5e0 commit e259d6f
Show file tree
Hide file tree
Showing 15 changed files with 300 additions and 165 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 21
targetSdkVersion 29
versionCode 331
versionName "3.3.1"
versionCode 332
versionName "3.3.2"

externalNativeBuild {
cmake {
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/com/raincat/dolby_beta/Hook.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
//网络访问
new EAPIHook(context);
//下载MD5校验
new DownloadMD5Hook();
new DownloadMD5Hook(context);
new CdnHook(context, versionCode);

mainProcessInit = true;
Expand All @@ -131,9 +131,9 @@ public void onReceive(Context c, Intent intent) {
context.sendBroadcast(new Intent(msg_hook_play_process));
} else if (msg_send_notification.equals(intent.getAction())) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
NotificationHelper.getInstance(context).sendUnLockNotification(context, 0x10, "UnblockNeteaseMusic产生致命错误", "UnblockNeteaseMusic产生致命错误", intent.getStringExtra("content"));
else
XposedBridge.log("UnblockNeteaseMusic产生致命错误:" + intent.getStringExtra("content"));
NotificationHelper.getInstance(context).sendUnLockNotification(context, intent.getIntExtra("code", 0x10),
intent.getStringExtra("title"), intent.getStringExtra("title"), intent.getStringExtra("message"));
XposedBridge.log(intent.getStringExtra("title") + ":" + intent.getStringExtra("message"));
}
}
}, intentFilter);
Expand Down
299 changes: 157 additions & 142 deletions app/src/main/java/com/raincat/dolby_beta/helper/ClassHelper.java

Large diffs are not rendered by default.

65 changes: 65 additions & 0 deletions app/src/main/java/com/raincat/dolby_beta/helper/MessageHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.raincat.dolby_beta.helper;

import android.content.Context;
import android.content.Intent;

import com.raincat.dolby_beta.Hook;

/**
* <pre>
* author : RainCat
* e-mail : nining377@gmail.com
* time : 2021/10/25
* desc : 通知帮助类
* version: 1.0
* </pre>
*/

public class MessageHelper {
public static void sendNotification(Context context, int code) {
if (!SettingHelper.getInstance().getSetting(SettingHelper.warn_key))
return;
Intent intent = new Intent(Hook.msg_send_notification);
intent.putExtra("code", cookieClassNotFoundCode);
switch (code) {
case cookieClassNotFoundCode:
intent.putExtra("title", "错误");
intent.putExtra("message", cookieClassNotFoundMessage);
break;
case transferClassNotFoundCode:
intent.putExtra("title", "错误");
intent.putExtra("message", transferClassNotFoundMessage);
break;
case coreClassNotFoundCode:
intent.putExtra("title", "错误");
intent.putExtra("message", coreClassNotFoundMessage);
break;
case tabClassNotFoundCode:
intent.putExtra("title", "错误");
intent.putExtra("message", tabClassNotFoundMessage);
break;
case sidebarClassNotFoundCode:
intent.putExtra("title", "错误");
intent.putExtra("message", sidebarClassNotFoundMessage);
break;
}
context.sendBroadcast(intent);
}

private final static String normalMessage = "请确保已使用官方版网易云。";

public final static int cookieClassNotFoundCode = 1000;
private final static String cookieClassNotFoundMessage = "找不到Cookie类,这将导致签到、打卡、收藏等功能失效," + normalMessage;

public final static int transferClassNotFoundCode = 1001;
private final static String transferClassNotFoundMessage = "找不到DownloadTransfer类,这将导致下载校验功能失效," + normalMessage;

public final static int coreClassNotFoundCode = 1002;
private final static String coreClassNotFoundMessage = "找不到核心类,这将导致音源代理功能失效," + normalMessage;

public final static int tabClassNotFoundCode = 1003;
private final static String tabClassNotFoundMessage = "找不到Tab类,这将导致Tab精简功能失效," + normalMessage;

public final static int sidebarClassNotFoundCode = 1004;
private final static String sidebarClassNotFoundMessage = "找不到Sidebar类,这将导致侧边栏精简功能失效," + normalMessage;
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ private static void getLogcatInfo(int level, String tag, String text) {
return;
if ((text.contains("mERROR") && text.contains("Error:")) || text.contains("Port ") || text.contains("Please ")) {
Intent intent = new Intent(Hook.msg_send_notification);
intent.putExtra("content", text);
intent.putExtra("message", text);
intent.putExtra("title", "UnblockNeteaseMusic产生致命错误");
neteaseContext.sendBroadcast(intent);
} else if (text.contains("HTTP Server running")) {
ExtraHelper.setExtraDate(ExtraHelper.SCRIPT_STATUS, "1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public class SettingHelper {
public static final String dex_title = "启用DEX缓存";
public static final String dex_sub = "加快模块加载速度,但同版本号的内测版与稳定版互装可能会有兼容性问题";

public static final String warn_key = "β_warn_key";
public static final String warn_title = "开启Hook警告";
public static final String warn_sub = "当模块出现部分类无法Hook时在通知栏上显示,方便定位排查问题";

public static final String black_key = "β_black_key";
public static final String black_title = "本地黑胶";
public static final String black_sub = "去广告、鲸云音效、个性换肤等(自定义启动图等需要访问网易服务器的设置不可用)";
Expand Down Expand Up @@ -126,6 +130,7 @@ public void refreshSetting(Context context) {

settingMap.put(master_key, sharedPreferences.getBoolean(master_key, true));
settingMap.put(dex_key, sharedPreferences.getBoolean(dex_key, true));
settingMap.put(warn_key, sharedPreferences.getBoolean(warn_key, true));
settingMap.put(black_key, sharedPreferences.getBoolean(black_key, true));
settingMap.put(update_key, sharedPreferences.getBoolean(update_key, true));
settingMap.put(sign_key, sharedPreferences.getBoolean(sign_key, true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import de.robv.android.xposed.XposedBridge;

/**
* <pre>
* author : RainCat
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/raincat/dolby_beta/hook/CdnHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class CdnHook {
public CdnHook(Context context, int versionCode) {
if (versionCode < 138)
return;
for (Method m : ClassHelper.HttpInterceptor.getMethodList())
for (Method m : ClassHelper.HttpInterceptor.getMethodList(context))
XposedBridge.hookMethod(m, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.raincat.dolby_beta.hook;


import android.content.Context;

import com.raincat.dolby_beta.helper.ClassHelper;

import java.io.FileInputStream;
Expand All @@ -23,8 +25,8 @@
*/

public class DownloadMD5Hook {
public DownloadMD5Hook() {
hookMethod(ClassHelper.Transfer.getCheckMd5Method(), new XC_MethodHook() {
public DownloadMD5Hook(Context context) {
hookMethod(ClassHelper.DownloadTransfer.getCheckMd5Method(context), new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) {
final Object[] array = (Object[]) param.args[3];
Expand All @@ -34,7 +36,7 @@ protected void beforeHookedMethod(MethodHookParam param) {
}
});

hookMethod(ClassHelper.Transfer.getCheckDownloadStatusMethod(), new XC_MethodHook() {
hookMethod(ClassHelper.DownloadTransfer.getCheckDownloadStatusMethod(context), new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) {
Method[] methods = param.args[0].getClass().getDeclaredMethods();
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/java/com/raincat/dolby_beta/hook/EAPIHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

public class EAPIHook {
public EAPIHook(final Context context) {
XposedBridge.hookMethod(ClassHelper.HttpResponse.getResultMethod(), new XC_MethodHook() {
XposedBridge.hookMethod(ClassHelper.HttpResponse.getResultMethod(context), new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
//代理和黑胶都未开启
Expand All @@ -43,8 +43,8 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
return;
}
ClassHelper.HttpResponse httpResponse = new ClassHelper.HttpResponse(param.thisObject);
Object eapi = httpResponse.getEapi();
Uri uri = ClassHelper.HttpUrl.getUri(eapi);
Object eapi = httpResponse.getEapi(context);
Uri uri = ClassHelper.HttpUrl.getUri(context, eapi);
if (!uri.getPath().contains("/eapi/"))
return;
String path = uri.getPath();
Expand All @@ -55,9 +55,9 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
original = EAPIHelper.modifyPlayer(original.replace("\"data\":", "\"data\":[").replace("},\"code\"", "}],\"code\""));
original = original.replace("[", "").replace("]", "");
} else if (path.contains("v1/playlist/manipulate/tracks")) {
original = EAPIHelper.modifyManipulate(ClassHelper.HttpParams.getParams(eapi), original);
original = EAPIHelper.modifyManipulate(ClassHelper.HttpParams.getParams(context, eapi), original);
} else if (path.contains("song/like")) {
original = EAPIHelper.modifyLike(ClassHelper.HttpParams.getParams(eapi), original);
original = EAPIHelper.modifyLike(ClassHelper.HttpParams.getParams(context, eapi), original);
} else if (path.contains("sound/mobile") || path.contains("page=audio_effect")) {
original = EAPIHelper.modifyEffect(original);
} else if (path.contains("batch")) {
Expand All @@ -82,7 +82,7 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
original = original.replace("\"waitTime\":60,", "\"waitTime\":5,");
CloudDao.getInstance(context).saveSong(Integer.parseInt(jsonObject.getString("id")), original);
} else if (path.contains("cloud/pub/v2")) {
String songid = EAPIHelper.decrypt(ClassHelper.HttpParams.getParams(eapi).get("params")).getString("songid");
String songid = EAPIHelper.decrypt(ClassHelper.HttpParams.getParams(context, eapi).get("params")).getString("songid");
EAPIHelper.uploadCloud(songid);
original = CloudDao.getInstance(context).getSong(Integer.parseInt(songid));
} else if (path.contains("album") || path.contains("artist") || path.contains("play")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public HideSidebarHook(Context context, int versionCode) {
sidebarSettingMap = SettingHelper.getInstance().getSidebarSetting(SidebarEnum.getSidebarEnum());
}

if (versionCode >= 7003010 && ClassHelper.SidebarItem.getClazz() != null) {
XposedBridge.hookAllConstructors(ClassHelper.SidebarItem.getClazz(), new XC_MethodHook() {
if (versionCode >= 7003010 && ClassHelper.SidebarItem.getClazz(context) != null) {
XposedBridge.hookAllConstructors(ClassHelper.SidebarItem.getClazz(context), new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
super.beforeHookedMethod(param);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
}

if (versionCode >= 8000010) {
Class<?> bottomTabViewClass = ClassHelper.BottomTabView.getClazz();
Class<?> bottomTabViewClass = ClassHelper.BottomTabView.getClazz(context);
if (bottomTabViewClass != null) {
findAndHookMethod(bottomTabViewClass, ClassHelper.BottomTabView.getTabInitMethod().getName(), new XC_MethodHook() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import com.raincat.dolby_beta.view.setting.SignView;
import com.raincat.dolby_beta.view.setting.TitleView;
import com.raincat.dolby_beta.view.setting.UpdateView;
import com.raincat.dolby_beta.view.setting.WarnView;

import java.lang.reflect.Field;
import java.util.HashMap;
Expand Down Expand Up @@ -216,6 +217,8 @@ private void showSettingDialog(final Context context) {
MasterView masterView = new MasterView(context);
DexView dexView = new DexView(context);
dexView.setBaseOnView(masterView);
WarnView warnView = new WarnView(context);
warnView.setBaseOnView(masterView);
BlackView blackView = new BlackView(context);
blackView.setBaseOnView(masterView);
UpdateView updateView = new UpdateView(context);
Expand All @@ -234,6 +237,7 @@ private void showSettingDialog(final Context context) {
dialogRoot.addView(new TitleView(context));
dialogRoot.addView(masterView);
dialogRoot.addView(dexView);
dialogRoot.addView(warnView);
dialogRoot.addView(blackView);
dialogRoot.addView(updateView);
dialogRoot.addView(signView);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
new Thread(() -> {
if (ExtraHelper.getExtraDate(ExtraHelper.COOKIE).equals("-1"))
ExtraHelper.setExtraDate(ExtraHelper.COOKIE, ClassHelper.Cookie.getCookie());
ExtraHelper.setExtraDate(ExtraHelper.COOKIE, ClassHelper.Cookie.getCookie(context));
if (ExtraHelper.getExtraDate(ExtraHelper.USER_ID).equals("-1"))
UserHelper.getUserInfo();
}).start();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.raincat.dolby_beta.view.setting;

import android.content.Context;
import android.util.AttributeSet;

import com.raincat.dolby_beta.helper.SettingHelper;
import com.raincat.dolby_beta.view.BaseDialogItem;

/**
* <pre>
* author : RainCat
* e-mail : nining377@gmail.com
* time : 2021/10/26
* desc : 通知栏警告
* version: 1.0
* </pre>
*/

public class WarnView extends BaseDialogItem {
public WarnView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}

public WarnView(Context context, AttributeSet attrs) {
super(context, attrs);
}

public WarnView(Context context) {
super(context);
}

@Override
public void init(Context context, AttributeSet attrs) {
super.init(context, attrs);
title = SettingHelper.warn_title;
sub = SettingHelper.warn_sub;
key = SettingHelper.warn_key;
setData(true, SettingHelper.getInstance().getSetting(key));

setOnClickListener(view -> {
SettingHelper.getInstance().setSetting(key, !checkBox.isChecked());
sendBroadcast(SettingHelper.refresh_setting);
});
}
}

0 comments on commit e259d6f

Please sign in to comment.