Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
Refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
bin456789 committed Feb 16, 2019
1 parent ba6489e commit a9e6fa9
Show file tree
Hide file tree
Showing 21 changed files with 716 additions and 489 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Xposed version of EraserKing's [Unblock163MusicClient](https://github.com/EraserKing/Unblock163MusicClient).

Compatible with app ≈ v5.8.x .
Compatible with app version 4.3 to 5.x


## Thanks
Expand Down
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ android {
}
defaultConfig {
applicationId "bin.xposed.Unblock163MusicClient"
minSdkVersion 16
minSdkVersion 14
// target Android P 之后,在安装过程中会对 APP 文件目录实行严格的 SELinux 限制,即使 makeWorkdReadable,其他 APP 也无法读取插件的任何配置文件
targetSdkVersion 27
versionCode 30
Expand Down Expand Up @@ -51,7 +51,8 @@ dependencies {
compileOnly 'de.robv.android.xposed:api:53:sources'
implementation 'com.annimon:stream:1.2.1'
implementation 'com.gyf.immersionbar:immersionbar:2.3.2'
implementation 'net.dongliu:apk-parser:2.6.5'
implementation 'org.smali:dexlib2:2.2.6'
implementation 'com.google.guava:guava:27.0.1-android'
implementation project(':hotxposed')
}

Expand Down
2 changes: 1 addition & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
boolean isModuleActive();
}

-dontwarn net.dongliu.apk.parser.**
-dontwarn com.google.**
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
import android.view.View;

import com.annimon.stream.Stream;
import com.google.common.collect.Ordering;

import net.dongliu.apk.parser.ApkFile;
import net.dongliu.apk.parser.bean.DexClass;

import org.jf.dexlib2.DexFileFactory;
import org.jf.dexlib2.dexbacked.DexBackedClassDef;
import org.jf.dexlib2.dexbacked.DexBackedDexFile;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
Expand All @@ -29,6 +29,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
Expand All @@ -37,6 +38,8 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import de.robv.android.xposed.XposedHelpers;

Expand All @@ -57,7 +60,7 @@ public static String getVersion() {
return version;
}

static void init(Context context) throws PackageManager.NameNotFoundException, IllegalAccessException {
static void init(Context context) throws PackageManager.NameNotFoundException {
version = context.getPackageManager().getPackageInfo(PACKAGE_NAME, 0).versionName;
NeteaseMusicApplication.init(context);
Okhttp.init();
Expand Down Expand Up @@ -86,13 +89,21 @@ static List<String> getAllClasses() {
list = new ArrayList<>();

try {
ApkFile apkFile = new ApkFile(getApkPath());
DexClass[] dexClasses = apkFile.getDexClasses();
for (DexClass dexClass : dexClasses) {
String classType = dexClass.getClassType();
classType = classType.substring(1, classType.length() - 1).replace("/", ".");
list.add(classType);
File apkFile = getApkPath();
// 不用 ZipDexContainer 因为会验证zip里面的文件是不是dex,会慢一点
Enumeration zip = new ZipFile(apkFile).entries();
while (zip.hasMoreElements()) {
ZipEntry dexInZip = (ZipEntry) zip.nextElement();
if (dexInZip.getName().endsWith(".dex")) {
DexBackedDexFile dexFile = DexFileFactory.loadDexEntry(apkFile, dexInZip.getName(), true, null);
for (DexBackedClassDef classDef : dexFile.getClasses()) {
String classType = classDef.getType();
classType = classType.substring(1, classType.length() - 1).replace("/", ".");
list.add(classType);
}
}
}

allClassList = new WeakReference<>(list);

} catch (Throwable t) {
Expand Down Expand Up @@ -175,6 +186,30 @@ public String get3rdSourceString() throws JSONException, IOException {
}


}

public static class Program {
private static Class clazz;

private final Object program;

public Program(Object program) {
this.program = program;
}

public static Class getClazz() {
if (clazz == null) {
clazz = findClass("com.netease.cloudmusic.meta.Program", getClassLoader());
}

return clazz;
}

public boolean isLiked() {
return (boolean) callMethod(program, "isLiked");
}


}

public static class NeteaseMusicUtils {
Expand Down Expand Up @@ -247,6 +282,7 @@ public static class HttpEapi {
private static Class clazz;
private static Field uriField;
private static Field dataField;
private static Field dataMapField;

final Object httpBase;

Expand Down Expand Up @@ -292,29 +328,34 @@ public static List<Method> getRawStringMethodList() {
}

public Map<String, String> getRequestData() throws IllegalAccessException {
if (dataField == null) {
if (dataMapField == null) {
Field[] fields = getClazz().getDeclaredFields();

dataField = Stream.of(fields)
.filter(f -> Stream.of(f.getType().getInterfaces()).anyMatch(i -> i == Serializable.class))
.filter(f -> Stream.of(f.getType().getDeclaredFields()).anyMatch(pf -> pf.getType() == LinkedHashMap.class))
.filter(f -> Stream.of(f.getType().getDeclaredFields()).anyMatch(pf -> pf.getType().getName().startsWith("okhttp3")))
.findFirst().get();

dataField.setAccessible(true);

dataMapField = XposedHelpers.findFirstFieldByExactType(dataField.getType(), LinkedHashMap.class);

}

String dataString = dataField.get(this.httpBase).toString();
return Utils.combineRequestData(getUri(), Utils.stringToMap(dataString));
Object data = dataField.get(this.httpBase);
@SuppressWarnings("unchecked")
Map<String, String> dataMap = (Map<String, String>) dataMapField.get(data);
return Utils.combineRequestData(getUri(), dataMap);
}

public String getUri() throws IllegalAccessException {
public Uri getUri() throws IllegalAccessException {
if (uriField == null) {
uriField = XposedHelpers.findFirstFieldByExactType(getClazz(), Uri.class);
uriField.setAccessible(true);

}
return uriField.get(this.httpBase).toString();
return (Uri) uriField.get(this.httpBase);
}

public static class CookieUtil {
Expand Down Expand Up @@ -357,7 +398,7 @@ static Class getClazz() {
}


static String getDefaultCookie() throws UnsupportedEncodingException, InvocationTargetException, IllegalAccessException {
static String getDefaultCookie() throws InvocationTargetException, IllegalAccessException {
if (getSingtonMethod == null) {
getSingtonMethod = XposedHelpers.findMethodsByExactParameters(getClazz(), getClazz())[0];
}
Expand Down Expand Up @@ -421,7 +462,7 @@ public static Method getMaterialDialogWithPositiveBtnMethod() {
try {
materialDialogWithPositiveBtnMethod = findMethodExact(getClazz(),
"materialDialogWithPositiveBtn", Context.class, Object.class, Object.class, View.OnClickListener.class);
} catch (NoSuchElementException e) {
} catch (Throwable t) {
materialDialogWithPositiveBtnMethod = findMethodExact(getClazz(),
"a", Context.class, Object.class, Object.class, View.OnClickListener.class);
}
Expand All @@ -433,6 +474,7 @@ public static Method getMaterialDialogWithPositiveBtnMethod() {
public static class PlayerActivity {
private static Class clazz;
private static Field musicInfoField;
private static Field programField;
private static Method likeButtonOnClickMethod;
private final Object playerActivity;

Expand All @@ -455,7 +497,7 @@ public static Method getLikeButtonOnClickMethod() {
if (playerActivitySuperClass != null) {

Pattern pattern = Pattern.compile(String.format("^%s\\$(\\d+)", playerActivitySuperClass.getName()));
List<String> list = getFilteredClasses(pattern, new Utils.AlphanumComparator());
List<String> list = getFilteredClasses(pattern, Ordering.natural());
int num = Stream.of(list)
.groupBy(s -> {
Matcher m = pattern.matcher(s);
Expand Down Expand Up @@ -492,6 +534,14 @@ public Object getMusicInfo() throws IllegalAccessException {

return musicInfoField.get(playerActivity);
}

public Object getProgram() throws IllegalAccessException {
if (programField == null) {
programField = XposedHelpers.findFirstFieldByExactType(playerActivity.getClass(), Program.getClazz());
}

return programField.get(playerActivity);
}
}

public static class Transfer {
Expand Down
Loading

0 comments on commit a9e6fa9

Please sign in to comment.