mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-06-12 21:27:43 +02:00
fix(youtube/navbar-index-hook): match to PR branch
This commit is contained in:
@ -0,0 +1,8 @@
|
||||
package app.revanced.patches.youtube.utils.navbarindex.fingerprints
|
||||
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||
|
||||
object MobileTopBarButtonOnClickFingerprint : MethodFingerprint(
|
||||
strings = listOf("MenuButtonRendererKey"),
|
||||
customFingerprint = { methodDef, _ -> methodDef.name == "onClick" }
|
||||
)
|
@ -1,26 +0,0 @@
|
||||
package app.revanced.patches.youtube.utils.navbarindex.fingerprints
|
||||
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||
import com.android.tools.smali.dexlib2.AccessFlags
|
||||
import com.android.tools.smali.dexlib2.Opcode
|
||||
|
||||
object NavBarBuilderFingerprint : MethodFingerprint(
|
||||
returnType = "V",
|
||||
accessFlags = AccessFlags.PUBLIC.value,
|
||||
parameters = listOf("L"),
|
||||
opcodes = listOf(
|
||||
Opcode.INVOKE_VIRTUAL,
|
||||
Opcode.IGET_OBJECT,
|
||||
Opcode.INVOKE_VIRTUAL,
|
||||
Opcode.IGET_OBJECT,
|
||||
Opcode.INVOKE_VIRTUAL,
|
||||
Opcode.IGET_OBJECT,
|
||||
Opcode.INVOKE_VIRTUAL,
|
||||
Opcode.IGET_OBJECT,
|
||||
Opcode.CONST_4,
|
||||
Opcode.INVOKE_STATIC,
|
||||
Opcode.INVOKE_VIRTUAL,
|
||||
Opcode.INVOKE_VIRTUAL,
|
||||
Opcode.NEW_INSTANCE
|
||||
)
|
||||
)
|
@ -0,0 +1,26 @@
|
||||
package app.revanced.patches.youtube.utils.navbarindex.fingerprints
|
||||
|
||||
import app.revanced.patcher.extensions.or
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||
import app.revanced.util.bytecode.isNarrowLiteralExists
|
||||
import com.android.tools.smali.dexlib2.AccessFlags
|
||||
import com.android.tools.smali.dexlib2.Opcode
|
||||
|
||||
object NavButtonOnClickFingerprint : MethodFingerprint(
|
||||
returnType = "V",
|
||||
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
|
||||
parameters = listOf("Landroid/view/View;"),
|
||||
opcodes = listOf(
|
||||
Opcode.RETURN_VOID,
|
||||
Opcode.IGET_OBJECT,
|
||||
Opcode.CHECK_CAST,
|
||||
Opcode.IGET_OBJECT,
|
||||
Opcode.INVOKE_VIRTUAL,
|
||||
Opcode.MOVE_RESULT,
|
||||
Opcode.INVOKE_VIRTUAL, // insert index
|
||||
Opcode.RETURN_VOID
|
||||
),
|
||||
customFingerprint = { methodDef, _ ->
|
||||
methodDef.name == "onClick" && methodDef.isNarrowLiteralExists(16843611)
|
||||
}
|
||||
)
|
@ -0,0 +1,10 @@
|
||||
package app.revanced.patches.youtube.utils.navbarindex.fingerprints
|
||||
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||
|
||||
object OnResumeFragmentsFingerprints : MethodFingerprint(
|
||||
customFingerprint = { methodDef, _ ->
|
||||
methodDef.definingClass.endsWith("WatchWhileActivity;")
|
||||
&& methodDef.name == "onResumeFragments"
|
||||
}
|
||||
)
|
@ -0,0 +1,14 @@
|
||||
package app.revanced.patches.youtube.utils.navbarindex.fingerprints
|
||||
|
||||
import app.revanced.patcher.extensions.or
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||
import com.android.tools.smali.dexlib2.AccessFlags
|
||||
|
||||
object SettingsActivityOnBackPressedFingerprint : MethodFingerprint(
|
||||
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
|
||||
returnType = "V",
|
||||
customFingerprint = { methodDef, _ ->
|
||||
methodDef.definingClass.endsWith("/SettingsActivity;")
|
||||
&& methodDef.name == "onBackPressed"
|
||||
}
|
||||
)
|
@ -1,19 +0,0 @@
|
||||
package app.revanced.patches.youtube.utils.navbarindex.fingerprints
|
||||
|
||||
import app.revanced.patcher.extensions.or
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||
import com.android.tools.smali.dexlib2.AccessFlags
|
||||
import com.android.tools.smali.dexlib2.Opcode
|
||||
|
||||
object TopBarButtonFingerprint : MethodFingerprint(
|
||||
returnType = "V",
|
||||
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
|
||||
parameters = listOf("L"),
|
||||
opcodes = listOf(
|
||||
Opcode.CONST_HIGH16,
|
||||
Opcode.AND_INT_2ADDR,
|
||||
Opcode.IF_EQZ
|
||||
),
|
||||
strings = listOf("parent_csn", "parent_ve_type"),
|
||||
customFingerprint = { methodDef, _ -> methodDef.name == "onClick" }
|
||||
)
|
@ -7,70 +7,94 @@ import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||
import app.revanced.patcher.patch.BytecodePatch
|
||||
import app.revanced.patcher.patch.PatchException
|
||||
import app.revanced.patches.youtube.utils.fingerprints.OnBackPressedFingerprint
|
||||
import app.revanced.patches.youtube.utils.navbarindex.fingerprints.NavBarBuilderFingerprint
|
||||
import app.revanced.patches.youtube.utils.navbarindex.fingerprints.TopBarButtonFingerprint
|
||||
import app.revanced.patches.youtube.utils.navbarindex.fingerprints.MobileTopBarButtonOnClickFingerprint
|
||||
import app.revanced.patches.youtube.utils.navbarindex.fingerprints.NavButtonOnClickFingerprint
|
||||
import app.revanced.patches.youtube.utils.navbarindex.fingerprints.OnResumeFragmentsFingerprints
|
||||
import app.revanced.patches.youtube.utils.navbarindex.fingerprints.SettingsActivityOnBackPressedFingerprint
|
||||
import app.revanced.util.integrations.Constants.UTILS_PATH
|
||||
import com.android.tools.smali.dexlib2.Opcode
|
||||
import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction35c
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction35c
|
||||
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
|
||||
|
||||
class NavBarIndexHookPatch : BytecodePatch(
|
||||
listOf(
|
||||
NavBarBuilderFingerprint,
|
||||
MobileTopBarButtonOnClickFingerprint,
|
||||
NavButtonOnClickFingerprint,
|
||||
OnBackPressedFingerprint,
|
||||
TopBarButtonFingerprint
|
||||
OnResumeFragmentsFingerprints,
|
||||
SettingsActivityOnBackPressedFingerprint
|
||||
)
|
||||
) {
|
||||
override fun execute(context: BytecodeContext) {
|
||||
|
||||
OnBackPressedFingerprint.result?.let {
|
||||
/**
|
||||
* Change NavBar Index value according to selected Tab
|
||||
*/
|
||||
NavButtonOnClickFingerprint.result?.let {
|
||||
it.mutableMethod.apply {
|
||||
val insertIndex = it.scanResult.patternScanResult!!.endIndex - 1
|
||||
val targetString =
|
||||
getInstruction<BuilderInstruction35c>(insertIndex - 2).reference.toString()
|
||||
if (!targetString.endsWith("Ljava/util/ArrayList;->indexOf(Ljava/lang/Object;)I"))
|
||||
throw PatchException("Reference not found: $targetString")
|
||||
val indexRegister =
|
||||
getInstruction<OneRegisterInstruction>(insertIndex - 1).registerA
|
||||
|
||||
addInstruction(
|
||||
0,
|
||||
"invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR->setLastNavBarIndex()V"
|
||||
insertIndex,
|
||||
"invoke-static {v$indexRegister}, $INTEGRATIONS_CLASS_DESCRIPTOR->setCurrentNavBarIndex(I)V"
|
||||
)
|
||||
}
|
||||
} ?: throw OnBackPressedFingerprint.exception
|
||||
} ?: throw NavButtonOnClickFingerprint.exception
|
||||
|
||||
TopBarButtonFingerprint.injectIndex(0)
|
||||
/**
|
||||
* Set NavBar index to last index on back press
|
||||
*/
|
||||
mapOf(
|
||||
OnBackPressedFingerprint to 0,
|
||||
OnResumeFragmentsFingerprints to 1,
|
||||
SettingsActivityOnBackPressedFingerprint to 0
|
||||
).forEach { (fingerprint, index) ->
|
||||
fingerprint.setLastNavBarIndexHook(index)
|
||||
}
|
||||
|
||||
NavBarBuilderFingerprint.result?.let {
|
||||
val endIndex = it.scanResult.patternScanResult!!.endIndex
|
||||
val onClickListener =
|
||||
it.mutableMethod.getInstruction<ReferenceInstruction>(endIndex).reference.toString()
|
||||
|
||||
val targetMethod =
|
||||
context.findClass(onClickListener)?.mutableClass?.methods?.first { method -> method.name == "onClick" }
|
||||
|
||||
targetMethod?.apply {
|
||||
for ((index, instruction) in implementation!!.instructions.withIndex()) {
|
||||
if (instruction.opcode != Opcode.INVOKE_VIRTUAL) continue
|
||||
|
||||
val invokeInstruction = instruction as Instruction35c
|
||||
if ((invokeInstruction.reference as MethodReference).name != "indexOf") continue
|
||||
|
||||
val targetIndex = index + 2
|
||||
if (getInstruction(targetIndex).opcode != Opcode.INVOKE_VIRTUAL) continue
|
||||
|
||||
val targetRegister = getInstruction<OneRegisterInstruction>(index + 1).registerA
|
||||
|
||||
addInstruction(
|
||||
targetIndex,
|
||||
"invoke-static {v$targetRegister}, $INTEGRATIONS_CLASS_DESCRIPTOR->setCurrentNavBarIndex(I)V"
|
||||
)
|
||||
break
|
||||
}
|
||||
/**
|
||||
* Set Navbar index to zero on clicking MobileTopBarButton
|
||||
* May be you want to switch to Incognito mode while in Library Tab
|
||||
*/
|
||||
MobileTopBarButtonOnClickFingerprint.result?.let {
|
||||
it.mutableMethod.apply {
|
||||
addInstructions(
|
||||
0, """
|
||||
const/4 v0, 0x0
|
||||
invoke-static {v0}, $INTEGRATIONS_CLASS_DESCRIPTOR->setCurrentNavBarIndex(I)V
|
||||
"""
|
||||
)
|
||||
}
|
||||
} ?: throw NavBarBuilderFingerprint.exception
|
||||
} ?: throw MobileTopBarButtonOnClickFingerprint.exception
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val INTEGRATIONS_CLASS_DESCRIPTOR =
|
||||
"$UTILS_PATH/NavBarIndexPatch;"
|
||||
|
||||
/**
|
||||
* Hook setLastNavBarIndex method
|
||||
*
|
||||
* @param insertIndex target index at which we want to inject the method call
|
||||
*/
|
||||
private fun MethodFingerprint.setLastNavBarIndexHook(insertIndex: Int) {
|
||||
result?.let {
|
||||
it.mutableMethod.apply {
|
||||
addInstruction(
|
||||
insertIndex,
|
||||
"invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR->setLastNavBarIndex()V"
|
||||
)
|
||||
}
|
||||
} ?: throw exception
|
||||
}
|
||||
|
||||
fun MethodFingerprint.injectIndex(index: Int) {
|
||||
result?.let {
|
||||
it.mutableMethod.apply {
|
||||
|
Reference in New Issue
Block a user