diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/splashanimation/SplashAnimationPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/general/splashanimation/SplashAnimationPatch.kt index c6d0b777f..893044afc 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/general/splashanimation/SplashAnimationPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/general/splashanimation/SplashAnimationPatch.kt @@ -4,16 +4,17 @@ import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patches.youtube.general.splashanimation.fingerprints.SplashAnimationFingerprint +import app.revanced.patches.youtube.general.splashanimation.fingerprints.StartUpResourceIdFingerprint +import app.revanced.patches.youtube.general.splashanimation.fingerprints.StartUpResourceIdParentFingerprint import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch -import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.DarkSplashAnimation import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.getTargetIndexWithReferenceReversed -import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.patch.BaseBytecodePatch import app.revanced.util.resultOrThrow +import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction @Suppress("unused") object SplashAnimationPatch : BaseBytecodePatch( @@ -24,22 +25,37 @@ object SplashAnimationPatch : BaseBytecodePatch( SharedResourceIdPatch::class ), compatiblePackages = COMPATIBLE_PACKAGE, - fingerprints = setOf(SplashAnimationFingerprint) + fingerprints = setOf( + SplashAnimationFingerprint, + StartUpResourceIdParentFingerprint + ) ) { override fun execute(context: BytecodeContext) { + StartUpResourceIdFingerprint.resolve(context, StartUpResourceIdParentFingerprint.resultOrThrow().classDef) + + val startUpResourceIdMethod = StartUpResourceIdFingerprint.resultOrThrow().mutableMethod + val startUpResourceIdMethodCall = startUpResourceIdMethod.definingClass + "->" + startUpResourceIdMethod.name + "(I)Z" + SplashAnimationFingerprint.resultOrThrow().let { it.mutableMethod.apply { - val constIndex = getWideLiteralInstructionIndex(DarkSplashAnimation) - val targetIndex = getTargetIndexWithReferenceReversed(constIndex, "(I)Z") + 2 - val targetRegister = getInstruction(targetIndex - 1).registerA + for (index in implementation!!.instructions.size - 1 downTo 0) { + val instruction = getInstruction(index) + if (instruction.opcode != Opcode.INVOKE_STATIC) + continue - addInstructions( - targetIndex, """ - invoke-static {v$targetRegister}, $GENERAL_CLASS_DESCRIPTOR->disableSplashAnimation(Z)Z - move-result v$targetRegister - """ - ) + if ((instruction as ReferenceInstruction).reference.toString() != startUpResourceIdMethodCall) + continue + + val register = getInstruction(index + 1).registerA + + addInstructions( + index + 2, """ + invoke-static {v$register}, $GENERAL_CLASS_DESCRIPTOR->disableSplashAnimation(Z)Z + move-result v$register + """ + ) + } } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/splashanimation/fingerprints/StartUpResourceIdFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/general/splashanimation/fingerprints/StartUpResourceIdFingerprint.kt new file mode 100644 index 000000000..c986eb741 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/general/splashanimation/fingerprints/StartUpResourceIdFingerprint.kt @@ -0,0 +1,16 @@ +package app.revanced.patches.youtube.general.splashanimation.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.MethodFingerprint +import app.revanced.util.containsWideLiteralInstructionIndex +import com.android.tools.smali.dexlib2.AccessFlags + +internal object StartUpResourceIdFingerprint : MethodFingerprint( + returnType = "Z", + accessFlags = AccessFlags.PUBLIC or AccessFlags.STATIC, + parameters = listOf("I"), + customFingerprint = { methodDef, _ -> + methodDef.containsWideLiteralInstructionIndex(3) + && methodDef.containsWideLiteralInstructionIndex(4) + } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/splashanimation/fingerprints/StartUpResourceIdParentFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/general/splashanimation/fingerprints/StartUpResourceIdParentFingerprint.kt new file mode 100644 index 000000000..1ff930575 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/general/splashanimation/fingerprints/StartUpResourceIdParentFingerprint.kt @@ -0,0 +1,12 @@ +package app.revanced.patches.youtube.general.splashanimation.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.MethodFingerprint +import com.android.tools.smali.dexlib2.AccessFlags + +internal object StartUpResourceIdParentFingerprint : MethodFingerprint( + returnType = "Z", + accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL or AccessFlags.DECLARED_SYNCHRONIZED, + parameters = listOf("I", "I"), + strings = listOf("early type", "final type") +) \ No newline at end of file