Skip to content

Commit

Permalink
Merge branch 'new-obfuscation'
Browse files Browse the repository at this point in the history
  • Loading branch information
shatyuka committed Oct 4, 2023
2 parents c91c1ea + bd23e83 commit c9e3af2
Show file tree
Hide file tree
Showing 12 changed files with 279 additions and 109 deletions.
58 changes: 57 additions & 1 deletion app/src/main/java/com/shatyuka/zhiliao/Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

Expand Down Expand Up @@ -68,7 +70,11 @@ static boolean init(ClassLoader classLoader) {
public static void init_class(ClassLoader classLoader) throws Exception {
MorphAdHelper = classLoader.loadClass("com.zhihu.android.morph.ad.utils.MorphAdHelper");
AnswerPagerFragment = classLoader.loadClass("com.zhihu.android.answer.module.pager.AnswerPagerFragment");
IZhihuWebView = classLoader.loadClass("com.zhihu.android.app.search.ui.widget.SearchResultLayout").getDeclaredField("c").getType();
try {
IZhihuWebView = classLoader.loadClass("com.zhihu.android.app.mercury.api.IZhihuWebView");
} catch (ClassNotFoundException ignore) {
IZhihuWebView = classLoader.loadClass("com.zhihu.android.app.search.ui.widget.SearchResultLayout").getDeclaredField("c").getType();
}
WebViewClientWrapper = findClass(classLoader, "com.zhihu.android.app.mercury.web.", 0, 2,
(Class<?> clazz) -> clazz.getSuperclass() == WebViewClient.class);
if (WebViewClientWrapper == null)
Expand Down Expand Up @@ -168,10 +174,21 @@ public static Class<?> findClass(ClassLoader classLoader, String beginWith, int
}
} catch (Exception ignored) {
}
if (i > 26) {
String classNameNew = beginWith + index2StrNew(i);
try {
Class<?> clazz = classLoader.loadClass(classNameNew);
if (check.check(clazz)) {
return clazz;
}
} catch (Exception ignored) {
}
}
}
return null;
}

// a...z, aa...az, ba...bz
private static String index2Str(int n) {
StringBuilder result = new StringBuilder();
while (n != 0) {
Expand All @@ -186,4 +203,43 @@ private static String index2Str(int n) {
}
return result.toString();
}

// a...z, a0...z0, a1...z1
private static String index2StrNew(int n) {
StringBuilder result = new StringBuilder();
int m = n % 26;
result.insert(0, (char) ('a' + m));
int cnt = n / 26;
if (cnt > 0) {
result.append(cnt - 1);
}
return result.toString();
}

public static Method getMethodByParameterTypes(Class<?> clazz, Class<?>... parameterTypes) {
if (clazz == null) return null;
for (Method method : clazz.getDeclaredMethods()) {
Class<?>[] types = method.getParameterTypes();
if (Arrays.equals(types, parameterTypes)) {
return method;
}
}
return null;
}

public static Method getMethodByParameterTypes(Class<?> clazz, int skip, Class<?>... parameterTypes) {
if (clazz == null) return null;
int count = 0;
for (Method method : clazz.getDeclaredMethods()) {
Class<?>[] types = method.getParameterTypes();
if (Arrays.equals(types, parameterTypes)) {
if (count < skip) {
count++;
continue;
}
return method;
}
}
return null;
}
}
9 changes: 6 additions & 3 deletions app/src/main/java/com/shatyuka/zhiliao/hooks/AnswerAd.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ public String getName() {

@Override
public void init(ClassLoader classLoader) throws Throwable {
Helper.findClass(classLoader, "com.zhihu.android.appview.a$",
Class<?> AppView = classLoader.loadClass("com.zhihu.android.answer.module.content.appview.AnswerAppView").getSuperclass();
if (AppView == null)
throw new ClassNotFoundException("com.zhihu.android.appview.AppView");
Helper.findClass(classLoader, AppView.getName() + "$",
(Class<?> ZhihuWebViewClient) -> {
shouldInterceptRequest = ZhihuWebViewClient.getMethod("a", Helper.IZhihuWebView, WebResourceRequest.class);
return true;
shouldInterceptRequest = Helper.getMethodByParameterTypes(ZhihuWebViewClient, Helper.IZhihuWebView, WebResourceRequest.class);
return shouldInterceptRequest != null;
});
if (shouldInterceptRequest == null)
throw new NoSuchMethodException("com.zhihu.android.appview.AppView$ZhihuWebViewClient.shouldInterceptRequest(IZhihuWebView, WebResourceRequest)");
Expand Down
37 changes: 27 additions & 10 deletions app/src/main/java/com/shatyuka/zhiliao/hooks/Article.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,40 @@ public void init(ClassLoader classLoader) throws Throwable {
ContentMixAdapter = classLoader.loadClass("com.zhihu.android.mix.b.a");
getItemCount = ContentMixAdapter.getMethod("getItemCount");
} catch (Throwable e2) {
ContentMixAdapter = classLoader.loadClass("com.zhihu.android.mix.adapter.a");
getItemCount = ContentMixAdapter.getMethod("getItemCount");
try {
ContentMixAdapter = classLoader.loadClass("com.zhihu.android.mix.adapter.a");
getItemCount = ContentMixAdapter.getMethod("getItemCount");
} catch (Throwable e3) {
ContentMixAdapter = classLoader.loadClass("com.zhihu.android.mix.adapter.ContentMixAdapter");
getItemCount = ContentMixAdapter.getMethod("getItemCount");
}
}
}
ContentMixPagerFragment = classLoader.loadClass("com.zhihu.android.mix.fragment.ContentMixPagerFragment");
ContentMixAdapter_fragment = ContentMixAdapter.getDeclaredField("f");
if (!ContentMixAdapter_fragment.getType().getName().equals("androidx.fragment.app.Fragment")) {
ContentMixAdapter_fragment = ContentMixAdapter.getDeclaredField("g");
if (!ContentMixAdapter_fragment.getType().getName().equals("androidx.fragment.app.Fragment")) {
ContentMixAdapter_fragment = ContentMixAdapter.getDeclaredField("h");
if (!ContentMixAdapter_fragment.getType().getName().equals("androidx.fragment.app.Fragment")) {
throw new NoSuchFieldException("fragment");
String[] fragment_names = new String[]{"f", "g", "h", "B"};
for (String name : fragment_names) {
try {
Field field = ContentMixAdapter.getDeclaredField(name);
if (field.getType().getName().equals("androidx.fragment.app.Fragment")) {
ContentMixAdapter_fragment = field;
break;
}
} catch (NoSuchFieldException ignore) {
}
}
if (ContentMixAdapter_fragment == null) {
throw new NoSuchFieldException("fragment");
}
ContentMixAdapter_fragment.setAccessible(true);
ContentMixPagerFragment_type = ContentMixPagerFragment.getField("c");
try {
ContentMixPagerFragment_type = ContentMixPagerFragment.getField("c");
if (ContentMixPagerFragment_type.getType() != String.class)
throw new NoSuchFieldException("type");
} catch (NoSuchFieldException e) {
ContentMixPagerFragment_type = ContentMixPagerFragment.getField("t");
if (ContentMixPagerFragment_type.getType() != String.class)
throw new NoSuchFieldException("type");
}
}
}

Expand Down
34 changes: 20 additions & 14 deletions app/src/main/java/com/shatyuka/zhiliao/hooks/FeedAd.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,28 @@ protected void beforeHookedMethod(MethodHookParam param) {
}
}
});
XposedHelpers.findAndHookMethod(Helper.MorphAdHelper, "resolve", Context.class, FeedAdvert, boolean.class, Boolean.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) {
if (Helper.prefs.getBoolean("switch_mainswitch", false) && Helper.prefs.getBoolean("switch_feedad", true)) {
param.setResult(false);
try {
XposedHelpers.findAndHookMethod(Helper.MorphAdHelper, "resolve", Context.class, FeedAdvert, boolean.class, Boolean.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) {
if (Helper.prefs.getBoolean("switch_mainswitch", false) && Helper.prefs.getBoolean("switch_feedad", true)) {
param.setResult(false);
}
}
}
});
XposedHelpers.findAndHookMethod(Helper.MorphAdHelper, "resolve", Context.class, ListAd, Boolean.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) {
if (Helper.prefs.getBoolean("switch_mainswitch", false) && Helper.prefs.getBoolean("switch_feedad", true)) {
param.setResult(false);
});
} catch (NoSuchMethodError ignore) {
}
try {
XposedHelpers.findAndHookMethod(Helper.MorphAdHelper, "resolve", Context.class, ListAd, Boolean.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) {
if (Helper.prefs.getBoolean("switch_mainswitch", false) && Helper.prefs.getBoolean("switch_feedad", true)) {
param.setResult(false);
}
}
}
});
});
} catch (NoSuchMethodError ignore) {
}
XposedHelpers.findAndHookMethod(Advert, "isSlidingWindow", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) {
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/shatyuka/zhiliao/hooks/Horizontal.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ public void init(ClassLoader classLoader) throws Throwable {
if (UserAction == null)
throw new ClassNotFoundException("com.zhihu.android.bootstrap.vertical_pager.UserAction");

nextAnswer = VerticalPagerContainer.getMethod("a", UserAction);
lastAnswer = VerticalPagerContainer.getMethod("b", UserAction);
nextAnswer = Helper.getMethodByParameterTypes(VerticalPagerContainer, UserAction);
lastAnswer = Helper.getMethodByParameterTypes(VerticalPagerContainer, 1, UserAction);

UserAction_DRAG_UP = UserAction.getField("DRAG_UP");
UserAction_DRAG_DOWN = UserAction.getField("DRAG_DOWN");
Expand Down Expand Up @@ -196,7 +196,7 @@ protected void beforeHookedMethod(MethodHookParam param) {
});

if (Helper.packageInfo.versionCode > 2614) {
XposedHelpers.findAndHookMethod(ContentMixPagerFragment, "a", MotionEvent.class, new XC_MethodHook() {
XposedBridge.hookMethod(Helper.getMethodByParameterTypes(ContentMixPagerFragment, MotionEvent.class), new XC_MethodHook() {
float old_x = 0;
float old_y = 0;
long time = 0;
Expand Down
8 changes: 6 additions & 2 deletions app/src/main/java/com/shatyuka/zhiliao/hooks/LaunchAd.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ public String getName() {

@Override
public void init(final ClassLoader classLoader) throws Throwable {
AdNetworkManager = classLoader.loadClass("com.zhihu.android.sdk.launchad.b");
Helper.findClass(classLoader, "com.zhihu.android.app.util.", 3, 2,
AdNetworkManager = Helper.findClass(classLoader, "com.zhihu.android.sdk.launchad.",
(Class<?> clazz) -> clazz.getDeclaredField("c").getType().getName().startsWith("okhttp3."));
if (AdNetworkManager == null) {
throw new ClassNotFoundException("com.zhihu.android.sdk.launchad.AdNetworkManager");
}
Helper.findClass(classLoader, "com.zhihu.android.app.util.", 3, 8,
(Class<?> LaunchAdHelper) -> {
isShowLaunchAd = LaunchAdHelper.getMethod("isShowLaunchAd");
return true;
Expand Down
26 changes: 19 additions & 7 deletions app/src/main/java/com/shatyuka/zhiliao/hooks/NavButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class NavButton implements IHook {
static Class<?> BottomNavMenuView;
static Class<?> IMenuItem;

static Method getMenuName;
static Method getItemId;

static Field Tab_tabView;

Expand All @@ -29,10 +29,22 @@ public void init(ClassLoader classLoader) throws Throwable {
try {
IMenuItem = classLoader.loadClass("com.zhihu.android.bottomnav.core.a.b");
} catch (ClassNotFoundException e) {
IMenuItem = classLoader.loadClass("com.zhihu.android.bottomnav.core.b.b");
try {
IMenuItem = classLoader.loadClass("com.zhihu.android.bottomnav.core.b.b");
} catch (ClassNotFoundException e2) {
try {
IMenuItem = classLoader.loadClass("com.zhihu.android.bottomnav.core.t.g");
} catch (ClassNotFoundException e3) {
IMenuItem = classLoader.loadClass("com.zhihu.android.bottomnav.core.w.d");
}
}
}

getMenuName = IMenuItem.getMethod("a");
try {
getItemId = IMenuItem.getMethod("getItemId");
} catch (NoSuchMethodException e) {
getItemId = IMenuItem.getMethod("a");
}

Tab_tabView = classLoader.loadClass("com.google.android.material.tabs.TabLayout$Tab").getField("view");
}
Expand All @@ -43,10 +55,10 @@ public void hook() throws Throwable {
XposedHelpers.findAndHookMethod(BottomNavMenuView, "a", IMenuItem, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
if (("market".equals(getMenuName.invoke(param.args[0])) && Helper.prefs.getBoolean("switch_vipnav", false)) ||
("video".equals(getMenuName.invoke(param.args[0])) && Helper.prefs.getBoolean("switch_videonav", false)) ||
("friend".equals(getMenuName.invoke(param.args[0])) && Helper.prefs.getBoolean("switch_friendnav", false)) ||
("panel".equals(getMenuName.invoke(param.args[0]))&& Helper.prefs.getBoolean("switch_panelnav", false))){
if (("market".equals(getItemId.invoke(param.args[0])) && Helper.prefs.getBoolean("switch_vipnav", false)) ||
("video".equals(getItemId.invoke(param.args[0])) && Helper.prefs.getBoolean("switch_videonav", false)) ||
("friend".equals(getItemId.invoke(param.args[0])) && Helper.prefs.getBoolean("switch_friendnav", false)) ||
("panel".equals(getItemId.invoke(param.args[0]))&& Helper.prefs.getBoolean("switch_panelnav", false))){
((View) Tab_tabView.get(param.getResult())).setVisibility(View.GONE);
}
}
Expand Down
43 changes: 33 additions & 10 deletions app/src/main/java/com/shatyuka/zhiliao/hooks/NavRes.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XC_MethodReplacement;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;

public class NavRes implements IHook {
Expand All @@ -27,30 +28,52 @@ public String getName() {
public void init(ClassLoader classLoader) throws Throwable {
try {
BottomNav = classLoader.loadClass("com.zhihu.android.bottomnav.a");
if (BottomNav.getDeclaredField("a").getType() != boolean.class)
throw new Throwable("");
} catch (Throwable ignored) {
BottomNav = classLoader.loadClass("com.zhihu.android.bottomnav.b");
if (BottomNav.getDeclaredField("a").getType() != boolean.class)
throw new ClassNotFoundException("com.zhihu.android.bottomnav.BottomNav");
} catch (Throwable e) {
try {
BottomNav = classLoader.loadClass("com.zhihu.android.bottomnav.b");
if (BottomNav.getDeclaredField("a").getType() != boolean.class)
throw new ClassNotFoundException("com.zhihu.android.bottomnav.BottomNav");
} catch (Throwable e2) {
BottomNav = classLoader.loadClass("com.zhihu.android.bottomnav.e");
if (BottomNav.getDeclaredField("a").getType() != boolean.class)
throw new ClassNotFoundException("com.zhihu.android.bottomnav.BottomNav");
}
}
try {
BottomNavBgViewExploreA = classLoader.loadClass("com.zhihu.android.bottomnav.core.explore.BottomNavBgViewExploreA");
BottomNavBgViewExploreA_right = BottomNavBgViewExploreA.getDeclaredField("b");
BottomNavBgViewExploreA_right.setAccessible(true);
BottomNavBgViewExploreA_center = BottomNavBgViewExploreA.getDeclaredField("c");
BottomNavBgViewExploreA_center.setAccessible(true);
try {
BottomNavBgViewExploreA_right = BottomNavBgViewExploreA.getDeclaredField("b");
BottomNavBgViewExploreA_right.setAccessible(true);
BottomNavBgViewExploreA_center = BottomNavBgViewExploreA.getDeclaredField("c");
BottomNavBgViewExploreA_center.setAccessible(true);
} catch (NoSuchFieldException e) {
BottomNavBgViewExploreA_right = BottomNavBgViewExploreA.getDeclaredField("l");
BottomNavBgViewExploreA_right.setAccessible(true);
BottomNavBgViewExploreA_center = BottomNavBgViewExploreA.getDeclaredField("m");
BottomNavBgViewExploreA_center.setAccessible(true);
}
} catch (Throwable ignored) {
}
FeedConfigManager = Helper.findClass(classLoader, "com.zhihu.android.", (Class<?> FeedConfigManager) -> FeedConfigManager.getMethod("a").getReturnType().getDeclaredField("a").getType().equals(String.class));
FeedConfigManager = Helper.findClass(classLoader, "com.zhihu.android.", 0, 2,
(Class<?> FeedConfigManager) -> {
Class<?>[] types = FeedConfigManager.getConstructors()[0].getParameterTypes();
return types.length == 6 && types[0] == String.class && types[1] == String.class && types[2] == long.class && types[3] == long.class && types[4] == types[5];
});
}

@Override
public void hook() throws Throwable {
if (Helper.prefs.getBoolean("switch_mainswitch", false) && Helper.prefs.getBoolean("switch_navres", false)) {
XposedHelpers.findAndHookMethod(BottomNav, "b", XC_MethodReplacement.returnConstant(null));
if (FeedConfigManager != null) {
XposedHelpers.findAndHookMethod(FeedConfigManager, "a", XC_MethodReplacement.returnConstant(null));
XposedBridge.hookAllConstructors(FeedConfigManager, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
param.args[3] = 0;
}
});
}
}

Expand Down
Loading

0 comments on commit c9e3af2

Please sign in to comment.