Skip to content
This repository has been archived by the owner on Sep 15, 2024. It is now read-only.

Commit

Permalink
refactor: remove apktool
Browse files Browse the repository at this point in the history
  • Loading branch information
mkx173 committed Apr 19, 2024
1 parent e9970c8 commit 1e9971d
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 87 deletions.
Binary file removed app/apktool_2.7.0.jar
Binary file not shown.
4 changes: 1 addition & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ android {
if (versionName.contains('beta')) {
versionNameSuffix = '.' + commitCountSinceLatestTag
}
buildConfigField "String", "TARGET_VERSION", "\"12.59.0.3\""
buildConfigField "String", "TARGET_VERSION", "\"12.59.1.0\""
buildConfigField "String", "MIN_VERSION", "\"12.53.1.0\""

testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
Expand Down Expand Up @@ -83,8 +83,6 @@ dependencies {

implementation 'io.reactivex.rxjava3:rxjava:3.1.8'
implementation 'org.luckypray:dexkit:2.0.1'
// https://stackoverflow.com/questions/61195038/excluding-dependency-from-implementation-files
implementation files('apktool_2.7.0.jar')
implementation 'com.squareup.okhttp3:okhttp:4.12.0'
implementation 'dev.rikka.ndk.thirdparty:cxx:1.2.0'
}
9 changes: 7 additions & 2 deletions app/src/main/java/gm/tieba/tabswitch/hooker/TSPreference.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@
import gm.tieba.tabswitch.hooker.TSPreferenceHelper.SwitchButtonHolder;
import gm.tieba.tabswitch.hooker.deobfuscation.DeobfuscationHelper;
import gm.tieba.tabswitch.hooker.deobfuscation.Matcher;
import gm.tieba.tabswitch.hooker.deobfuscation.StringResMatcher;
import gm.tieba.tabswitch.hooker.deobfuscation.MatcherProperties;
import gm.tieba.tabswitch.hooker.deobfuscation.SmaliMatcher;
import gm.tieba.tabswitch.hooker.extra.TraceChecker;
import gm.tieba.tabswitch.util.ClassMatcherUtils;
import gm.tieba.tabswitch.util.DisplayUtils;
import gm.tieba.tabswitch.widget.NavigationBar;
import gm.tieba.tabswitch.widget.TbToast;
Expand All @@ -57,7 +59,10 @@ public String key() {

@Override
public List<? extends Matcher> matchers() {
return List.of(new StringResMatcher("隐私设置"));
return List.of(new SmaliMatcher(
"Lcom/baidu/tbadk/data/MetaData;->getBazhuGradeData()Lcom/baidu/tbadk/coreExtra/data/BazhuGradeData;",
MatcherProperties.create().useClassMatcher(ClassMatcherUtils.usingString("mo/q/wise-bawu-core/privacy-policy"))
));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,11 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.zip.ZipFile;

import brut.androlib.AndrolibException;
import brut.androlib.res.data.value.ResStringValue;
import brut.androlib.res.decoder.ARSCDecoder;
import gm.tieba.tabswitch.XposedContext;
import gm.tieba.tabswitch.dao.AcRules;
import gm.tieba.tabswitch.dao.Preferences;
Expand All @@ -48,51 +44,9 @@ private <T> void forEachProgressed(final PublishSubject<Float> progress,
}
}

public void decodeArsc(final PublishSubject<Float> progress, final Context context)
throws IOException, AndrolibException {
packageResource = context.getPackageResourcePath();
progress.onNext(0F);
final var strToResMatcher = new HashMap<String, ResMatcher>();
final var resIdentifierToResMatcher = new HashMap<String, ResIdentifierMatcher>();
for (final var matcher : matchers) {
if (matcher instanceof ResMatcher) {
if (matcher instanceof final ResIdentifierMatcher resIdentifierMatcher) {
resIdentifierToResMatcher.put(resIdentifierMatcher.toResIdentifier(), resIdentifierMatcher);
} else {
strToResMatcher.put(((StringResMatcher) matcher).toResIdentifier(), (ResMatcher) matcher);
}
}
}

final var zipFile = new ZipFile(packageResource);
final var ze = zipFile.getEntry("resources.arsc");
try (final var in = zipFile.getInputStream(ze)) {
final var pkg = ARSCDecoder.decode(in, true, true).getOnePackage();
forEachProgressed(progress, pkg.listResSpecs(), resResSpec -> {
final var identifierMatcher = resIdentifierToResMatcher.get(String.format("%s.%s", resResSpec.getType().getName(), resResSpec.getName()));
if (identifierMatcher != null) {
identifierMatcher.setId(resResSpec.getId().id);
} else if (resResSpec.hasDefaultResource()) {
try {
final var resValue = resResSpec.getDefaultResource().getValue();
if (resValue instanceof final ResStringValue resStringValue) {
final var str = resStringValue.encodeAsResXmlValue();
final var matcher = strToResMatcher.get(str);
if (matcher != null) {
matcher.setId(resResSpec.getId().id);
}
}
} catch (final AndrolibException e) {
// should not happen
}
}
});
}
zipFile.close();
}

public void dexkit(final PublishSubject<Float> progress) {
public void dexkit(final PublishSubject<Float> progress, final Context context) {
load("dexkit");
packageResource = context.getPackageResourcePath();
final var bridge = DexKitBridge.create(packageResource);
Objects.requireNonNull(bridge);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,8 @@ public void afterHookedMethod(final MethodHookParam param) throws Throwable {

new Thread(() -> {
try {
setMessage("(1/2) 解析安装包资源");
viewModel.deobfuscateStep1(mActivity, mMatchers);

setMessage("(2/2) 搜索资源,字符串和方法调用");
viewModel.deobfuscateStep2();
setMessage("搜索资源,字符串和方法调用");
viewModel.deobfuscate(mActivity, mMatchers);

XposedBridge.log("Deobfuscation complete, current version: "
+ DeobfuscationHelper.getTbVersion(mActivity));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.io.IOException;
import java.util.List;

import brut.androlib.AndrolibException;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.subjects.PublishSubject;

Expand All @@ -14,13 +13,9 @@ public class DeobfuscationViewModel {
public final Observable<Float> progress = _progress;
private final Deobfuscation deobfuscation = new Deobfuscation();

public void deobfuscateStep1(final Context context, final List<Matcher> matchers) throws IOException, AndrolibException {
public void deobfuscate(final Context context, final List<Matcher> matchers) throws IOException {
deobfuscation.setMatchers(matchers);
deobfuscation.decodeArsc(_progress, context);
}

public void deobfuscateStep2() throws IOException {
deobfuscation.dexkit(_progress);
deobfuscation.dexkit(_progress, context);
deobfuscation.saveDexSignatureHashCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,6 @@ class ReturnTypeMatcher<T> @JvmOverloads constructor(val returnType: Class<T>, p
override fun toString(): String = super.toString() + returnType.simpleName
}

open class ResMatcher @JvmOverloads constructor(var id: Long = 0, properties: MatcherProperties? = null) : Matcher(properties) {
open fun toResIdentifier(): String {
throw UnsupportedOperationException()
}
}

class StringResMatcher @JvmOverloads constructor(val str: String, properties: MatcherProperties? = null) : ResMatcher(properties = properties) {
override fun toString(): String = super.toString() + str
override fun toResIdentifier(): String = str
}

class ResIdentifierMatcher @JvmOverloads constructor(val name: String, val defType: String, properties: MatcherProperties? = null) : ResMatcher(properties = properties) {
override fun toString(): String = super.toString() + String.format("%s.%s", defType, name)
override fun toResIdentifier(): String = String.format("%s.%s", defType, name)
class ResMatcher @JvmOverloads constructor(val id: Long, val name: String, properties: MatcherProperties? = null) : Matcher(properties) {
override fun toString(): String = super.toString() + name
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import gm.tieba.tabswitch.hooker.deobfuscation.MatcherProperties;
import gm.tieba.tabswitch.hooker.deobfuscation.MethodNameMatcher;
import gm.tieba.tabswitch.hooker.deobfuscation.Matcher;
import gm.tieba.tabswitch.hooker.deobfuscation.ResIdentifierMatcher;
import gm.tieba.tabswitch.hooker.deobfuscation.ResMatcher;
import gm.tieba.tabswitch.util.ClassMatcherUtils;
import gm.tieba.tabswitch.util.ReflectUtils;

Expand All @@ -36,7 +36,7 @@ public String key() {
@Override
public List<? extends Matcher> matchers() {
return List.of(
new ResIdentifierMatcher("tbds400", "dimen", MatcherProperties.create().useClassMatcher(ClassMatcherUtils.usingString("enter_forum_login_tip"))),
new ResMatcher(ReflectUtils.getR("dimen", "tbds400"), "dimen.tbds400", MatcherProperties.create().useClassMatcher(ClassMatcherUtils.usingString("enter_forum_login_tip"))),
new MethodNameMatcher("onSuccess", MatcherProperties.create().useClassMatcher(ClassMatcherUtils.usingString("enter_forum_login_tip")))
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import gm.tieba.tabswitch.hooker.IHooker;
import gm.tieba.tabswitch.hooker.Obfuscated;
import gm.tieba.tabswitch.hooker.deobfuscation.Matcher;
import gm.tieba.tabswitch.hooker.deobfuscation.StringResMatcher;
import gm.tieba.tabswitch.hooker.deobfuscation.ResMatcher;
import gm.tieba.tabswitch.util.ReflectUtils;

public class ForbidGesture extends XposedContext implements IHooker, Obfuscated {
Expand All @@ -33,16 +33,14 @@ public String key() {

@Override
public List<? extends Matcher> matchers() {
return List.of(new StringResMatcher("特大号字体"));
return List.of(new ResMatcher(ReflectUtils.getR("drawable", "icon_word_t_size"), "icon_word_t_size"));
}

@Override
public void hook() throws Throwable {
// 帖子字号
AcRules.findRule(matchers(), (matcher, clazz, method) -> {
XposedHelpers.findAndHookMethod(clazz, sClassLoader, "c", XC_MethodReplacement.returnConstant(null));
XposedHelpers.findAndHookMethod(clazz, sClassLoader, "d", XC_MethodReplacement.returnConstant(null));
}
AcRules.findRule(matchers(), (matcher, clazz, method) ->
XposedHelpers.findAndHookMethod(clazz, sClassLoader, method, XC_MethodReplacement.returnConstant(null))
);
// 视频帖字号
XposedHelpers.findAndHookMethod("com.baidu.tieba.pb.videopb.fragment.DetailInfoAndReplyFragment", sClassLoader,
Expand Down

0 comments on commit 1e9971d

Please sign in to comment.