feat(tiktok): remove compatibility version constraints (#2306)

Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
KAZI MMT 2023-05-30 17:42:17 +06:00 committed by GitHub
parent 28594f3eea
commit a12c4bb161
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 102 additions and 115 deletions

View file

@ -5,8 +5,8 @@ import app.revanced.patcher.annotation.Package
@Compatibility( @Compatibility(
[ [
Package("com.ss.android.ugc.trill", arrayOf("27.8.3")), Package("com.ss.android.ugc.trill"),
Package("com.zhiliaoapp.musically", arrayOf("27.8.3")) Package("com.zhiliaoapp.musically")
] ]
) )
@Target(AnnotationTarget.CLASS) @Target(AnnotationTarget.CLASS)

View file

@ -5,8 +5,8 @@ import app.revanced.patcher.annotation.Package
@Compatibility( @Compatibility(
[ [
Package("com.ss.android.ugc.trill", arrayOf("27.8.3")), Package("com.ss.android.ugc.trill"),
Package("com.zhiliaoapp.musically", arrayOf("27.8.3")) Package("com.zhiliaoapp.musically")
] ]
) )
@Target(AnnotationTarget.CLASS) @Target(AnnotationTarget.CLASS)

View file

@ -5,8 +5,8 @@ import app.revanced.patcher.annotation.Package
@Compatibility( @Compatibility(
[ [
Package("com.ss.android.ugc.trill", arrayOf("27.8.3")), Package("com.ss.android.ugc.trill"),
Package("com.zhiliaoapp.musically", arrayOf("27.8.3")) Package("com.zhiliaoapp.musically")
] ]
) )
@Target(AnnotationTarget.CLASS) @Target(AnnotationTarget.CLASS)

View file

@ -0,0 +1,17 @@
package app.revanced.patches.tiktok.misc.settings.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.Opcode
object AboutPageFingerprint : MethodFingerprint(
opcodes = listOf(
Opcode.CONST, // copyrightPolicyLabel resource id
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT_OBJECT,
Opcode.CONST_STRING
),
customFingerprint = { methodDef, _ ->
methodDef.definingClass == "Lcom/ss/android/ugc/aweme/setting/page/AboutPage;" &&
methodDef.name == "onViewCreated"
}
)

View file

@ -1,37 +0,0 @@
package app.revanced.patches.tiktok.misc.settings.fingerprints
import app.revanced.patcher.fingerprint.method.annotation.FuzzyPatternScanMethod
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.Opcode
@FuzzyPatternScanMethod(4)
object AboutViewFingerprint : MethodFingerprint(
opcodes = listOf(
Opcode.NEW_INSTANCE,
Opcode.INVOKE_DIRECT,
Opcode.INVOKE_DIRECT_RANGE,
Opcode.INVOKE_DIRECT,
Opcode.IPUT_OBJECT,
Opcode.NEW_INSTANCE,
Opcode.NEW_INSTANCE,
Opcode.CONST,
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT_OBJECT,
Opcode.SGET_OBJECT,
Opcode.INVOKE_STATIC,
Opcode.MOVE_RESULT_OBJECT,
Opcode.NEW_INSTANCE,
Opcode.INVOKE_DIRECT,
Opcode.CONST_4,
Opcode.CONST_STRING,
Opcode.INVOKE_DIRECT_RANGE,
Opcode.INVOKE_DIRECT,
Opcode.IPUT_OBJECT,
Opcode.CONST,
Opcode.SGET_OBJECT,
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT,
Opcode.IF_EQZ,
Opcode.CONST
)
)

View file

@ -8,7 +8,6 @@ import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.addInstructions import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.extensions.instruction import app.revanced.patcher.extensions.instruction
import app.revanced.patcher.extensions.replaceInstruction import app.revanced.patcher.extensions.replaceInstruction
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve
import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultError import app.revanced.patcher.patch.PatchResultError
@ -17,14 +16,14 @@ import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patches.tiktok.misc.integrations.patch.IntegrationsPatch import app.revanced.patches.tiktok.misc.integrations.patch.IntegrationsPatch
import app.revanced.patches.tiktok.misc.settings.annotations.SettingsCompatibility import app.revanced.patches.tiktok.misc.settings.annotations.SettingsCompatibility
import app.revanced.patches.tiktok.misc.settings.fingerprints.AboutViewFingerprint import app.revanced.patches.tiktok.misc.settings.fingerprints.AboutPageFingerprint
import app.revanced.patches.tiktok.misc.settings.fingerprints.AdPersonalizationActivityOnCreateFingerprint import app.revanced.patches.tiktok.misc.settings.fingerprints.AdPersonalizationActivityOnCreateFingerprint
import app.revanced.patches.tiktok.misc.settings.fingerprints.SettingsOnViewCreatedFingerprint import app.revanced.patches.tiktok.misc.settings.fingerprints.SettingsOnViewCreatedFingerprint
import org.jf.dexlib2.Opcode import org.jf.dexlib2.Opcode
import org.jf.dexlib2.iface.instruction.FiveRegisterInstruction
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
import org.jf.dexlib2.iface.instruction.ReferenceInstruction import org.jf.dexlib2.iface.instruction.ReferenceInstruction
import org.jf.dexlib2.iface.instruction.formats.Instruction35c import org.jf.dexlib2.iface.instruction.WideLiteralInstruction
import org.jf.dexlib2.iface.reference.StringReference
@Patch @Patch
@DependsOn([IntegrationsPatch::class]) @DependsOn([IntegrationsPatch::class])
@ -34,84 +33,92 @@ import org.jf.dexlib2.iface.reference.StringReference
@Version("0.0.1") @Version("0.0.1")
class SettingsPatch : BytecodePatch( class SettingsPatch : BytecodePatch(
listOf( listOf(
AboutPageFingerprint,
AdPersonalizationActivityOnCreateFingerprint, AdPersonalizationActivityOnCreateFingerprint,
SettingsOnViewCreatedFingerprint, SettingsOnViewCreatedFingerprint,
) )
) { ) {
override fun execute(context: BytecodeContext): PatchResult { override fun execute(context: BytecodeContext): PatchResult {
SettingsOnViewCreatedFingerprint.result?.let { SettingsOnViewCreatedFingerprint.result?.mutableMethod?.apply {
AboutViewFingerprint.resolve(context, it.method, it.classDef) val instructions = implementation!!.instructions
}
// Patch Settings UI to add 'Revanced Settings'. // Find the indices that need to be patched.
val targetIndexes = findOptionsOnClickIndex() val copyrightPolicyLabelId = AboutPageFingerprint.result?.let {
with(SettingsOnViewCreatedFingerprint.result!!.mutableMethod) { val startIndex = it.scanResult.patternScanResult!!.startIndex
for (index in targetIndexes) { it.mutableMethod.instruction<WideLiteralInstruction>(startIndex).wideLiteral
if ( } ?: return AboutPageFingerprint.toErrorResult()
instruction(index).opcode != Opcode.NEW_INSTANCE ||
instruction(index - 4).opcode != Opcode.MOVE_RESULT_OBJECT val copyrightIndex = instructions.indexOfFirst {
) (it as? ReferenceInstruction)?.reference.toString() == "copyright_policy"
return PatchResultError("Hardcode offset changed.") } - 6
patchOptionNameAndOnClickEvent(index, context)
}
} val copyrightPolicyIndex = instructions.indexOfFirst {
// Implement settings screen in `AdPersonalizationActivity` (it as? WideLiteralInstruction)?.wideLiteral == copyrightPolicyLabelId
with(AdPersonalizationActivityOnCreateFingerprint.result!!.mutableMethod) { } + 2
for ((index, instruction) in implementation!!.instructions.withIndex()) {
if (instruction.opcode != Opcode.INVOKE_SUPER) continue // Replace an existing settings entry with ReVanced settings entry.
val thisRegister = (instruction as Instruction35c).registerC arrayOf(
addInstructions( copyrightIndex,
index + 1, copyrightPolicyIndex
).forEach { index ->
val instruction = instruction(index)
if (instruction.opcode != Opcode.MOVE_RESULT_OBJECT)
return PatchResultError("Hardcoded offset changed.")
val settingsEntryStringRegister = (instruction as OneRegisterInstruction).registerA
// Replace the settings entry string with a custom one.
replaceInstruction(
index,
""" """
invoke-static {v$thisRegister}, Lapp/revanced/tiktok/settingsmenu/SettingsMenu;->initializeSettings(Lcom/bytedance/ies/ugc/aweme/commercialize/compliance/personalization/AdPersonalizationActivity;)V const-string v$settingsEntryStringRegister, "ReVanced Settings"
"""
)
// Replace the OnClickListener class with a custom one.
val onClickListener = instruction<ReferenceInstruction>(index + 4).reference.toString()
context.findClass(onClickListener)?.mutableClass?.methods?.first {
it.name == "onClick"
}?.addInstructions(
0,
"""
invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR->startSettingsActivity()V
return-void return-void
""" """
) ) ?: return PatchResultError("Could not find the onClick method.")
break
} }
}
} ?: return SettingsOnViewCreatedFingerprint.toErrorResult()
// Initialize the settings menu once the replaced setting entry is clicked.
AdPersonalizationActivityOnCreateFingerprint.result?.mutableMethod?.apply {
val initializeSettingsIndex = implementation!!.instructions.indexOfFirst {
it.opcode == Opcode.INVOKE_SUPER
} + 1
val thisRegister = instruction<FiveRegisterInstruction>(initializeSettingsIndex - 1).registerC
addInstructions(
initializeSettingsIndex,
"""
invoke-static {v$thisRegister}, $INITIALIZE_SETTINGS_METHOD_DESCRIPTOR
return-void
"""
)
} ?: return AdPersonalizationActivityOnCreateFingerprint.toErrorResult()
return PatchResultSuccess() return PatchResultSuccess()
} }
private fun findOptionsOnClickIndex(): IntArray { private companion object {
val results = IntArray(2) private const val INTEGRATIONS_CLASS_DESCRIPTOR =
SettingsOnViewCreatedFingerprint.result?.apply { "Lapp/revanced/tiktok/settingsmenu/SettingsMenu;"
for ((index, instruction) in mutableMethod.implementation!!.instructions.withIndex()) {
// Old UI settings option to replace to 'Revanced Settings'
if (instruction.opcode == Opcode.CONST_STRING) {
val string = ((instruction as ReferenceInstruction).reference as StringReference).string
if (string == "copyright_policy") {
results[0] = index - 2
break
}
}
}
// New UI settings option to replace to 'Revanced Settings' private const val INITIALIZE_SETTINGS_METHOD_DESCRIPTOR =
results[1] = AboutViewFingerprint.result!!.scanResult.patternScanResult!!.startIndex "$INTEGRATIONS_CLASS_DESCRIPTOR->initializeSettings(" +
} ?: throw SettingsOnViewCreatedFingerprint.toErrorResult() "Lcom/bytedance/ies/ugc/aweme/commercialize/compliance/personalization/AdPersonalizationActivity;" +
return results ")V"
}
private fun patchOptionNameAndOnClickEvent(index: Int, context: BytecodeContext) {
with(SettingsOnViewCreatedFingerprint.result!!.mutableMethod) {
// Patch option name
val overrideRegister = instruction<OneRegisterInstruction>(index - 4).registerA
replaceInstruction(
index - 4,
"""
const-string v$overrideRegister, "Revanced Settings"
"""
)
// Patch option OnClick Event
val type = instruction<ReferenceInstruction>(index).reference.toString()
context.findClass(type)!!.mutableClass.methods.first { type == "onClick" }.addInstructions(
0,
"""
invoke-static {}, Lapp/revanced/tiktok/settingsmenu/SettingsMenu;->startSettingsActivity()V
return-void
"""
)
}
} }
} }

View file

@ -5,8 +5,8 @@ import app.revanced.patcher.annotation.Package
@Compatibility( @Compatibility(
[ [
Package("com.ss.android.ugc.trill", arrayOf("27.8.3")), Package("com.ss.android.ugc.trill"),
Package("com.zhiliaoapp.musically", arrayOf("27.8.3")) Package("com.zhiliaoapp.musically")
] ]
) )
@Target(AnnotationTarget.CLASS) @Target(AnnotationTarget.CLASS)