feat: tiktok-feed-filter , tiktok-settings and tiktok-force-login patch (#501)

This commit is contained in:
d4rkk3y 2022-09-22 04:00:03 +07:00 committed by GitHub
parent 2a8abee41d
commit 10e028626f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 428 additions and 0 deletions

View File

@ -0,0 +1,14 @@
package app.revanced.patches.tiktok.feedfilter.annotations
import app.revanced.patcher.annotation.Compatibility
import app.revanced.patcher.annotation.Package
@Compatibility(
[
Package("com.ss.android.ugc.trill"),
Package("com.zhiliaoapp.musically")
]
)
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
internal annotation class FeedFilterCompatibility

View File

@ -0,0 +1,23 @@
package app.revanced.patches.tiktok.feedfilter.fingerprints
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.annotation.MatchingMethod
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.tiktok.feedfilter.annotations.FeedFilterCompatibility
import org.jf.dexlib2.AccessFlags
@Name("feed-api-service-fingerprint")
@MatchingMethod(
"Lcom/ss/android/ugc/aweme/feed/FeedApiService;",
"LIZ",
)
@FeedFilterCompatibility
@Version("0.0.1")
object FeedApiServiceLIZFingerprint : MethodFingerprint(
access = AccessFlags.PUBLIC or AccessFlags.STATIC or AccessFlags.FINAL or AccessFlags.SYNTHETIC,
customFingerprint = { methodDef ->
methodDef.definingClass.endsWith("/FeedApiService;") && methodDef.name == "LIZ"
}
)

View File

@ -0,0 +1,51 @@
package app.revanced.patches.tiktok.feedfilter.patch
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.impl.BytecodeData
import app.revanced.patcher.extensions.addInstruction
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patcher.patch.impl.BytecodePatch
import app.revanced.patches.tiktok.feedfilter.annotations.FeedFilterCompatibility
import app.revanced.patches.tiktok.feedfilter.fingerprints.FeedApiServiceLIZFingerprint
import app.revanced.patches.tiktok.misc.integrations.patch.TikTokIntegrationsPatch
import app.revanced.patches.tiktok.misc.settings.fingerprints.SettingsStatusLoadFingerprint
import app.revanced.patches.tiktok.misc.settings.patch.TikTokSettingsPatch
import org.jf.dexlib2.Opcode
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
@Patch
@DependsOn([TikTokIntegrationsPatch::class, TikTokSettingsPatch::class])
@Name("tiktok-feed-filter")
@Description("Filters tiktok videos: removing ads, removing livestreams.")
@FeedFilterCompatibility
@Version("0.0.1")
class TiktokFeedFilter : BytecodePatch(
listOf(
FeedApiServiceLIZFingerprint,
SettingsStatusLoadFingerprint
)
) {
override fun execute(data: BytecodeData): PatchResult {
val method = FeedApiServiceLIZFingerprint.result!!.mutableMethod
for ((index, instruction) in method.implementation!!.instructions.withIndex()) {
if (instruction.opcode != Opcode.RETURN_OBJECT) continue
val feedItemsRegister = (instruction as OneRegisterInstruction).registerA
method.addInstruction(
index,
"invoke-static {v$feedItemsRegister}, Lapp/revanced/tiktok/feedfilter/FeedItemsFilter;->filter(Lcom/ss/android/ugc/aweme/feed/model/FeedItemList;)V"
)
break
}
val method2 = SettingsStatusLoadFingerprint.result!!.mutableMethod
method2.addInstruction(
0,
"invoke-static {}, Lapp/revanced/tiktok/settingsmenu/SettingsStatus;->enableFeedFilter()V"
)
return PatchResultSuccess()
}
}

View File

@ -0,0 +1,14 @@
package app.revanced.patches.tiktok.misc.forcelogin.annotations
import app.revanced.patcher.annotation.Compatibility
import app.revanced.patcher.annotation.Package
@Compatibility(
[
Package("com.ss.android.ugc.trill"),
Package("com.zhiliaoapp.musically")
]
)
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
internal annotation class DisableForceLoginCompatibility

View File

@ -0,0 +1,18 @@
package app.revanced.patches.tiktok.misc.forcelogin.fingerprints
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.fingerprint.method.annotation.MatchingMethod
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.tiktok.misc.forcelogin.annotations.DisableForceLoginCompatibility
@Name("mandatory-login-service-fingerprint")
@MatchingMethod("/MandatoryLoginService;", "enableForcedLogin")
@DisableForceLoginCompatibility
@Version("0.0.1")
object MandatoryLoginServiceFingerprint : MethodFingerprint(
customFingerprint = { methodDef ->
methodDef.definingClass.endsWith("/MandatoryLoginService;") &&
methodDef.name == "enableForcedLogin"
}
)

View File

@ -0,0 +1,18 @@
package app.revanced.patches.tiktok.misc.forcelogin.fingerprints
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.fingerprint.method.annotation.MatchingMethod
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.tiktok.misc.forcelogin.annotations.DisableForceLoginCompatibility
@Name("mandatory-login-service-fingerprint2")
@MatchingMethod("/MandatoryLoginService;", "shouldShowForcedLogin")
@DisableForceLoginCompatibility
@Version("0.0.1")
object MandatoryLoginServiceFingerprint2 : MethodFingerprint(
customFingerprint = { methodDef ->
methodDef.definingClass.endsWith("/MandatoryLoginService;") &&
methodDef.name == "shouldShowForcedLogin"
}
)

View File

@ -0,0 +1,43 @@
package app.revanced.patches.tiktok.misc.forcelogin.patch
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.impl.BytecodeData
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patcher.patch.impl.BytecodePatch
import app.revanced.patches.tiktok.misc.forcelogin.annotations.DisableForceLoginCompatibility
import app.revanced.patches.tiktok.misc.forcelogin.fingerprints.MandatoryLoginServiceFingerprint
import app.revanced.patches.tiktok.misc.forcelogin.fingerprints.MandatoryLoginServiceFingerprint2
@Patch
@Name("tiktok-force-login")
@Description("Do not force login.")
@DisableForceLoginCompatibility
@Version("0.0.1")
class DisableForceLoginPatch : BytecodePatch(
listOf(
MandatoryLoginServiceFingerprint,
MandatoryLoginServiceFingerprint2
)
) {
override fun execute(data: BytecodeData): PatchResult {
listOf(
MandatoryLoginServiceFingerprint,
MandatoryLoginServiceFingerprint2
).forEach { fingerprint ->
val method = fingerprint.result!!.mutableMethod
method.addInstructions(
0,
"""
const/4 v0, 0x0
return v0
"""
)
}
return PatchResultSuccess()
}
}

View File

@ -0,0 +1,14 @@
package app.revanced.patches.tiktok.misc.integrations.annotations
import app.revanced.patcher.annotation.Compatibility
import app.revanced.patcher.annotation.Package
@Compatibility(
[
Package("com.ss.android.ugc.trill"),
Package("com.zhiliaoapp.musically")
]
)
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
internal annotation class TikTokIntegrationsCompatibility

View File

@ -0,0 +1,20 @@
package app.revanced.patches.tiktok.misc.integrations.fingerprints
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.fingerprint.method.annotation.MatchingMethod
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.tiktok.misc.integrations.annotations.TikTokIntegrationsCompatibility
@Name("init-fingerprint")
@MatchingMethod(
"Lcom/ss/android/ugc/aweme/app/host/AwemeHostApplication;", "onCreate"
)
@TikTokIntegrationsCompatibility
@Version("0.0.1")
object InitFingerprint : MethodFingerprint(
customFingerprint = { methodDef ->
methodDef.definingClass.endsWith("/AwemeHostApplication;") &&
methodDef.name == "onCreate"
}
)

View File

@ -0,0 +1,38 @@
package app.revanced.patches.tiktok.misc.integrations.patch
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.impl.BytecodeData
import app.revanced.patcher.extensions.addInstruction
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultError
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.impl.BytecodePatch
import app.revanced.patches.tiktok.misc.integrations.annotations.TikTokIntegrationsCompatibility
import app.revanced.patches.tiktok.misc.integrations.fingerprints.InitFingerprint
@Name("tiktok-integrations")
@Description("Applies mandatory patches to implement the ReVanced integrations into the application.")
@TikTokIntegrationsCompatibility
@Version("0.0.1")
class TikTokIntegrationsPatch : BytecodePatch(
listOf(
InitFingerprint
)
) {
override fun execute(data: BytecodeData): PatchResult {
if (data.findClass("Lapp/revanced/tiktok/utils/ReVancedUtils") == null)
return PatchResultError("Integrations have not been merged yet. This patch can not succeed without the integrations.")
val result = InitFingerprint.result!!
val method = result.mutableMethod
val implementation = method.implementation!!
val count = implementation.registerCount - 1
method.addInstruction(
0, "sput-object v$count, Lapp/revanced/tiktok/utils/ReVancedUtils;->context:Landroid/content/Context;"
)
return PatchResultSuccess()
}
}

View File

@ -0,0 +1,14 @@
package app.revanced.patches.tiktok.misc.settings.annotations
import app.revanced.patcher.annotation.Compatibility
import app.revanced.patcher.annotation.Package
@Compatibility(
[
Package("com.ss.android.ugc.trill"),
Package("com.zhiliaoapp.musically")
]
)
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
internal annotation class TikTokSettingsCompatibility

View File

@ -0,0 +1,21 @@
package app.revanced.patches.tiktok.misc.settings.fingerprints
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.fingerprint.method.annotation.MatchingMethod
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.tiktok.misc.settings.annotations.TikTokSettingsCompatibility
@Name("ad-personalization-activity-fingerprint")
@MatchingMethod(
"Lcom/bytedance/ies/ugc/aweme/commercialize/compliance/personalization/AdPersonalizationActivity;",
"onCreate"
)
@TikTokSettingsCompatibility
@Version("0.0.1")
object AdPersonalizationActivityFingerprint : MethodFingerprint(
customFingerprint = { methodDef ->
methodDef.definingClass.endsWith("/AdPersonalizationActivity;") &&
methodDef.name == "onCreate"
}
)

View File

@ -0,0 +1,21 @@
package app.revanced.patches.tiktok.misc.settings.fingerprints
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.fingerprint.method.annotation.MatchingMethod
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.tiktok.misc.settings.annotations.TikTokSettingsCompatibility
@Name("copyright-settings-string-fingerprint")
@MatchingMethod(
"Lcom/ss/android/ugc/aweme/setting/ui/SettingNewVersionFragment;",
"onViewCreated"
)
@TikTokSettingsCompatibility
@Version("0.0.1")
object CopyRightSettingsStringFingerprint : MethodFingerprint(
customFingerprint = { methodDef ->
methodDef.definingClass.endsWith("/SettingNewVersionFragment;") &&
methodDef.name == "onViewCreated"
}
)

View File

@ -0,0 +1,21 @@
package app.revanced.patches.tiktok.misc.settings.fingerprints
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.fingerprint.method.annotation.MatchingMethod
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.tiktok.misc.settings.annotations.TikTokSettingsCompatibility
@Name("settings-status-load-fingerprint")
@MatchingMethod(
"Lapp/revanced/tiktok/settingsmenu/SettingsStatus;",
"load"
)
@TikTokSettingsCompatibility
@Version("0.0.1")
object SettingsStatusLoadFingerprint : MethodFingerprint(
customFingerprint = { methodDef ->
methodDef.definingClass.endsWith("Lapp/revanced/tiktok/settingsmenu/SettingsStatus;") &&
methodDef.name == "load"
}
)

View File

@ -0,0 +1,98 @@
package app.revanced.patches.tiktok.misc.settings.patch
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.impl.BytecodeData
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.extensions.replaceInstruction
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultError
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patcher.patch.impl.BytecodePatch
import app.revanced.patches.tiktok.misc.integrations.patch.TikTokIntegrationsPatch
import app.revanced.patches.tiktok.misc.settings.annotations.TikTokSettingsCompatibility
import app.revanced.patches.tiktok.misc.settings.fingerprints.AdPersonalizationActivityFingerprint
import app.revanced.patches.tiktok.misc.settings.fingerprints.CopyRightSettingsStringFingerprint
import org.jf.dexlib2.Opcode
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
import org.jf.dexlib2.iface.instruction.ReferenceInstruction
import org.jf.dexlib2.iface.instruction.formats.Instruction35c
import org.jf.dexlib2.iface.reference.MethodReference
import org.jf.dexlib2.iface.reference.StringReference
@Patch
@DependsOn([TikTokIntegrationsPatch::class])
@Name("tiktok-settings")
@Description("Add settings menu to TikTok.")
@TikTokSettingsCompatibility
@Version("0.0.1")
class TikTokSettingsPatch : BytecodePatch(
listOf(
AdPersonalizationActivityFingerprint,
CopyRightSettingsStringFingerprint
)
) {
override fun execute(data: BytecodeData): PatchResult {
//Replace string `Copyright Policy` to 'Revanced Settings` in TikTok settings.
val method1 = CopyRightSettingsStringFingerprint.result!!.mutableMethod
val implementation1 = method1.implementation!!
for ((index, instruction) in implementation1.instructions.withIndex()) {
if (instruction.opcode != Opcode.CONST_STRING) continue
val string = ((instruction as ReferenceInstruction).reference as StringReference).string
if (string != "copyright_policy") continue
var targetIndex = index
while (targetIndex >= 0) {
targetIndex--
val invokeInstruction = implementation1.instructions[targetIndex]
if (invokeInstruction.opcode != Opcode.INVOKE_VIRTUAL) continue
val methodName = ((invokeInstruction as Instruction35c).reference as MethodReference).name
if (methodName != "getString") continue
val resultInstruction = implementation1.instructions[targetIndex + 1]
if (resultInstruction.opcode != Opcode.MOVE_RESULT_OBJECT) continue
val overrideRegister = (resultInstruction as OneRegisterInstruction).registerA
method1.replaceInstruction(
targetIndex + 1,
"""
const-string v$overrideRegister, "Revanced Settings"
"""
)
break
}
//Change onClick to start settings activity.
val clickInstruction = implementation1.instructions[index - 1]
if (clickInstruction.opcode != Opcode.INVOKE_DIRECT)
return PatchResultError("Can not find click listener.")
val clickClass = ((clickInstruction as ReferenceInstruction).reference as MethodReference).definingClass
val mutableClickClass = data.findClass(clickClass)!!.resolve()
val mutableOnClickMethod = mutableClickClass.methods.first {
it.name == "onClick"
}
mutableOnClickMethod.addInstructions(
0,
"""
invoke-static {}, Lapp/revanced/tiktok/settingsmenu/SettingsMenu;->startSettingsActivity()V
return-void
"""
)
break
}
//Implement revanced settings screen in `AdPersonalizationActivity`
val method2 = AdPersonalizationActivityFingerprint.result!!.mutableMethod
for ((index, instruction) in method2.implementation!!.instructions.withIndex()) {
if (instruction.opcode != Opcode.INVOKE_SUPER) continue
val thisRegister = (instruction as Instruction35c).registerC
method2.addInstructions(
index + 1,
"""
invoke-static {v$thisRegister}, Lapp/revanced/tiktok/settingsmenu/SettingsMenu;->initializeSettings(Lcom/bytedance/ies/ugc/aweme/commercialize/compliance/personalization/AdPersonalizationActivity;)V
return-void
"""
)
break
}
return PatchResultSuccess()
}
}