fix(tiktok/settings): make compatible with newer versions

This commit is contained in:
oSumAtrIX 2022-12-18 02:36:58 +01:00
parent 2ac15460f5
commit c88740dc2b
No known key found for this signature in database
GPG key ID: A9B3094ACDB604B4
3 changed files with 53 additions and 31 deletions

View file

@ -1,12 +0,0 @@
package app.revanced.patches.tiktok.misc.settings.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
object AboutOnClickMethodFingerprint : MethodFingerprint(
strings = listOf(
"//setting/about",
"enter_from",
"settings_page",
"enter_settings_about"
)
)

View file

@ -0,0 +1,39 @@
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.MOVE,
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.NEW_INSTANCE,
Opcode.INVOKE_DIRECT,
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

@ -1,5 +1,6 @@
package app.revanced.patches.tiktok.misc.settings.patch package app.revanced.patches.tiktok.misc.settings.patch
import app.revanced.extensions.toErrorResult
import app.revanced.patcher.annotation.Description import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version import app.revanced.patcher.annotation.Version
@ -7,6 +8,7 @@ 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
@ -15,13 +17,12 @@ 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.AboutOnClickMethodFingerprint import app.revanced.patches.tiktok.misc.settings.fingerprints.AboutViewFingerprint
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.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.Instruction21c
import org.jf.dexlib2.iface.instruction.formats.Instruction35c import org.jf.dexlib2.iface.instruction.formats.Instruction35c
import org.jf.dexlib2.iface.reference.StringReference import org.jf.dexlib2.iface.reference.StringReference
import org.jf.dexlib2.iface.reference.TypeReference import org.jf.dexlib2.iface.reference.TypeReference
@ -29,17 +30,19 @@ import org.jf.dexlib2.iface.reference.TypeReference
@Patch @Patch
@DependsOn([IntegrationsPatch::class]) @DependsOn([IntegrationsPatch::class])
@Name("settings") @Name("settings")
@Description("Adds settings for ReVanced to TikTok.") @Description("Adds ReVanced settings to TikTok.")
@SettingsCompatibility @SettingsCompatibility
@Version("0.0.1") @Version("0.0.1")
class SettingsPatch : BytecodePatch( class SettingsPatch : BytecodePatch(
listOf( listOf(
AdPersonalizationActivityOnCreateFingerprint, AdPersonalizationActivityOnCreateFingerprint,
SettingsOnViewCreatedFingerprint, SettingsOnViewCreatedFingerprint,
AboutOnClickMethodFingerprint
) )
) { ) {
override fun execute(context: BytecodeContext): PatchResult { override fun execute(context: BytecodeContext): PatchResult {
SettingsOnViewCreatedFingerprint.result?.let {
AboutViewFingerprint.resolve(context, it.method, it.classDef)
}
// Patch Settings UI to add 'Revanced Settings'. // Patch Settings UI to add 'Revanced Settings'.
val targetIndexes = findOptionsOnClickIndex() val targetIndexes = findOptionsOnClickIndex()
with(SettingsOnViewCreatedFingerprint.result!!.mutableMethod) { with(SettingsOnViewCreatedFingerprint.result!!.mutableMethod) {
@ -72,29 +75,21 @@ class SettingsPatch : BytecodePatch(
private fun findOptionsOnClickIndex(): IntArray { private fun findOptionsOnClickIndex(): IntArray {
val results = IntArray(2) val results = IntArray(2)
var found = 0 SettingsOnViewCreatedFingerprint.result?.apply {
with(SettingsOnViewCreatedFingerprint.result!!.mutableMethod) { for ((index, instruction) in mutableMethod.implementation!!.instructions.withIndex()) {
for ((index, instruction) in implementation!!.instructions.withIndex()) {
// Old UI settings option to replace to 'Revanced Settings' // Old UI settings option to replace to 'Revanced Settings'
if (instruction.opcode == Opcode.CONST_STRING) { if (instruction.opcode == Opcode.CONST_STRING) {
val string = ((instruction as ReferenceInstruction).reference as StringReference).string val string = ((instruction as ReferenceInstruction).reference as StringReference).string
if (string == "copyright_policy") { if (string == "copyright_policy") {
results[0] = index - 2 results[0] = index - 2
found++ break
} }
} }
// New UI settings option to replace to 'Revanced Settings'
if (instruction.opcode == Opcode.NEW_INSTANCE) {
val onClickClass = ((instruction as Instruction21c).reference as TypeReference).type
if (onClickClass == AboutOnClickMethodFingerprint.result!!.mutableMethod.definingClass) {
results[1] = index
found++
}
}
if (found > 1) break
} }
}
// New UI settings option to replace to 'Revanced Settings'
results[1] = AboutViewFingerprint.result!!.scanResult.patternScanResult!!.startIndex
} ?: throw SettingsOnViewCreatedFingerprint.toErrorResult()
return results return results
} }