mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-06-13 05:37:40 +02:00
feat(YouTube/Hide suggestions shelf): add method to detect navbar index
This commit is contained in:
@ -10,6 +10,7 @@ import app.revanced.patcher.patch.annotation.Patch
|
|||||||
import app.revanced.patches.youtube.general.suggestions.fingerprints.BreakingNewsFingerprint
|
import app.revanced.patches.youtube.general.suggestions.fingerprints.BreakingNewsFingerprint
|
||||||
import app.revanced.patches.youtube.utils.browseid.BrowseIdHookPatch
|
import app.revanced.patches.youtube.utils.browseid.BrowseIdHookPatch
|
||||||
import app.revanced.patches.youtube.utils.litho.LithoFilterPatch
|
import app.revanced.patches.youtube.utils.litho.LithoFilterPatch
|
||||||
|
import app.revanced.patches.youtube.utils.navbarindex.NavBarIndexHookPatch
|
||||||
import app.revanced.patches.youtube.utils.settings.SettingsPatch
|
import app.revanced.patches.youtube.utils.settings.SettingsPatch
|
||||||
import app.revanced.util.integrations.Constants.COMPONENTS_PATH
|
import app.revanced.util.integrations.Constants.COMPONENTS_PATH
|
||||||
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
||||||
@ -20,6 +21,7 @@ import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
BrowseIdHookPatch::class,
|
BrowseIdHookPatch::class,
|
||||||
LithoFilterPatch::class,
|
LithoFilterPatch::class,
|
||||||
|
NavBarIndexHookPatch::class,
|
||||||
SettingsPatch::class
|
SettingsPatch::class
|
||||||
],
|
],
|
||||||
compatiblePackages = [
|
compatiblePackages = [
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
package app.revanced.patches.youtube.utils.fingerprints
|
|
||||||
|
|
||||||
import app.revanced.patcher.fingerprint.MethodFingerprint
|
|
||||||
import com.android.tools.smali.dexlib2.Opcode
|
|
||||||
|
|
||||||
object OnBackPressedFingerprint : MethodFingerprint(
|
|
||||||
opcodes = listOf(Opcode.RETURN_VOID),
|
|
||||||
customFingerprint = { methodDef, _ -> methodDef.definingClass.endsWith("/WatchWhileActivity;") && methodDef.name == "onBackPressed" }
|
|
||||||
)
|
|
@ -5,7 +5,7 @@ import app.revanced.patcher.data.BytecodeContext
|
|||||||
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
|
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
|
||||||
import app.revanced.patcher.patch.BytecodePatch
|
import app.revanced.patcher.patch.BytecodePatch
|
||||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
||||||
import app.revanced.patches.youtube.utils.fingerprints.OnBackPressedFingerprint
|
import app.revanced.patches.youtube.utils.fix.doublebacktoclose.fingerprint.OnBackPressedFingerprint
|
||||||
import app.revanced.patches.youtube.utils.fix.doublebacktoclose.fingerprint.ScrollPositionFingerprint
|
import app.revanced.patches.youtube.utils.fix.doublebacktoclose.fingerprint.ScrollPositionFingerprint
|
||||||
import app.revanced.patches.youtube.utils.fix.doublebacktoclose.fingerprint.ScrollTopFingerprint
|
import app.revanced.patches.youtube.utils.fix.doublebacktoclose.fingerprint.ScrollTopFingerprint
|
||||||
import app.revanced.patches.youtube.utils.fix.doublebacktoclose.fingerprint.ScrollTopParentFingerprint
|
import app.revanced.patches.youtube.utils.fix.doublebacktoclose.fingerprint.ScrollTopParentFingerprint
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
package app.revanced.patches.youtube.utils.fix.doublebacktoclose.fingerprint
|
||||||
|
|
||||||
|
import app.revanced.patcher.extensions.or
|
||||||
|
import app.revanced.patcher.fingerprint.MethodFingerprint
|
||||||
|
import com.android.tools.smali.dexlib2.AccessFlags
|
||||||
|
import com.android.tools.smali.dexlib2.Opcode
|
||||||
|
|
||||||
|
object OnBackPressedFingerprint : MethodFingerprint(
|
||||||
|
returnType = "V",
|
||||||
|
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
|
||||||
|
opcodes = listOf(Opcode.RETURN_VOID),
|
||||||
|
customFingerprint = { methodDef, _ ->
|
||||||
|
methodDef.definingClass.endsWith("WatchWhileActivity;")
|
||||||
|
&& methodDef.name == "onBackPressed"
|
||||||
|
}
|
||||||
|
)
|
@ -1,139 +1,69 @@
|
|||||||
package app.revanced.patches.youtube.utils.navbarindex
|
package app.revanced.patches.youtube.utils.navbarindex
|
||||||
|
|
||||||
import app.revanced.extensions.exception
|
import app.revanced.extensions.exception
|
||||||
import app.revanced.extensions.findMutableMethodOf
|
|
||||||
import app.revanced.patcher.data.BytecodeContext
|
import app.revanced.patcher.data.BytecodeContext
|
||||||
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
|
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
|
||||||
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
|
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
|
||||||
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
|
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
|
||||||
import app.revanced.patcher.fingerprint.MethodFingerprint
|
import app.revanced.patcher.fingerprint.MethodFingerprint
|
||||||
import app.revanced.patcher.patch.BytecodePatch
|
import app.revanced.patcher.patch.BytecodePatch
|
||||||
import app.revanced.patcher.patch.PatchException
|
|
||||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
|
||||||
import app.revanced.patches.youtube.utils.fingerprints.OnBackPressedFingerprint
|
|
||||||
import app.revanced.patches.youtube.utils.navbarindex.fingerprints.DefaultTabsBarFingerprint
|
|
||||||
import app.revanced.patches.youtube.utils.navbarindex.fingerprints.MobileTopBarButtonOnClickFingerprint
|
import app.revanced.patches.youtube.utils.navbarindex.fingerprints.MobileTopBarButtonOnClickFingerprint
|
||||||
import app.revanced.patches.youtube.utils.navbarindex.fingerprints.OnResumeFragmentsFingerprints
|
import app.revanced.patches.youtube.utils.navbarindex.fingerprints.PivotBarIndexFingerprint
|
||||||
import app.revanced.patches.youtube.utils.navbarindex.fingerprints.SettingsActivityOnBackPressedFingerprint
|
import app.revanced.patches.youtube.utils.navbarindex.fingerprints.SettingsActivityOnBackPressedFingerprint
|
||||||
import app.revanced.util.integrations.Constants.UTILS_PATH
|
import app.revanced.util.integrations.Constants.UTILS_PATH
|
||||||
import com.android.tools.smali.dexlib2.Opcode
|
|
||||||
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
|
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
|
||||||
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
|
|
||||||
import com.android.tools.smali.dexlib2.iface.reference.Reference
|
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
object NavBarIndexHookPatch : BytecodePatch(
|
object NavBarIndexHookPatch : BytecodePatch(
|
||||||
setOf(
|
setOf(
|
||||||
DefaultTabsBarFingerprint,
|
|
||||||
MobileTopBarButtonOnClickFingerprint,
|
MobileTopBarButtonOnClickFingerprint,
|
||||||
OnBackPressedFingerprint,
|
PivotBarIndexFingerprint,
|
||||||
OnResumeFragmentsFingerprints,
|
|
||||||
SettingsActivityOnBackPressedFingerprint
|
SettingsActivityOnBackPressedFingerprint
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
override fun execute(context: BytecodeContext) {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Change NavBar Index value according to selected Tab
|
|
||||||
*/
|
|
||||||
DefaultTabsBarFingerprint.result?.let {
|
|
||||||
it.mutableMethod.apply {
|
|
||||||
val targetIndex = it.scanResult.patternScanResult!!.startIndex
|
|
||||||
val setTabIndexReference =
|
|
||||||
getInstruction<ReferenceInstruction>(targetIndex).reference
|
|
||||||
|
|
||||||
val (onClickMethod, insertIndex) = getOnClickMethod(context, setTabIndexReference)
|
|
||||||
|
|
||||||
onClickMethod.apply {
|
|
||||||
val indexRegister =
|
|
||||||
getInstruction<FiveRegisterInstruction>(insertIndex).registerD
|
|
||||||
|
|
||||||
addInstruction(
|
|
||||||
insertIndex,
|
|
||||||
"invoke-static {v$indexRegister}, $INTEGRATIONS_CLASS_DESCRIPTOR->setCurrentNavBarIndex(I)V"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} ?: throw DefaultTabsBarFingerprint.exception
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 MobileTopBarButtonOnClickFingerprint.exception
|
|
||||||
}
|
|
||||||
|
|
||||||
private const val INTEGRATIONS_CLASS_DESCRIPTOR =
|
private const val INTEGRATIONS_CLASS_DESCRIPTOR =
|
||||||
"$UTILS_PATH/NavBarIndexPatch;"
|
"$UTILS_PATH/NavBarIndexPatch;"
|
||||||
|
|
||||||
private fun getOnClickMethod(
|
override fun execute(context: BytecodeContext) {
|
||||||
context: BytecodeContext,
|
|
||||||
targetReference: Reference
|
|
||||||
): Pair<MutableMethod, Int> {
|
|
||||||
context.classes.forEach { classDef ->
|
|
||||||
classDef.methods.forEach { method ->
|
|
||||||
if (method.name == "onClick") {
|
|
||||||
method.implementation?.instructions?.forEachIndexed { index, instruction ->
|
|
||||||
if (instruction.opcode != Opcode.INVOKE_VIRTUAL)
|
|
||||||
return@forEachIndexed
|
|
||||||
if ((instruction as ReferenceInstruction).reference != targetReference)
|
|
||||||
return@forEachIndexed
|
|
||||||
|
|
||||||
val targetMethod = context.proxy(classDef)
|
/**
|
||||||
.mutableClass
|
* Change NavBar Index value according to selected Tab.
|
||||||
.findMutableMethodOf(method)
|
*/
|
||||||
|
PivotBarIndexFingerprint.result?.let {
|
||||||
return Pair(targetMethod, index)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw PatchException("OnClickMethod not found!")
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 {
|
it.mutableMethod.apply {
|
||||||
|
val insertIndex = it.scanResult.patternScanResult!!.startIndex + 1
|
||||||
|
val booleanRegister = getInstruction<FiveRegisterInstruction>(insertIndex).registerD
|
||||||
|
val freeRegister = implementation!!.registerCount - parameters.size - 2
|
||||||
|
|
||||||
addInstruction(
|
addInstruction(
|
||||||
insertIndex,
|
insertIndex,
|
||||||
"invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR->setLastNavBarIndex()V"
|
"invoke-static {v$freeRegister, v$booleanRegister}, $INTEGRATIONS_CLASS_DESCRIPTOR->setNavBarIndex(IZ)V"
|
||||||
|
)
|
||||||
|
addInstruction(
|
||||||
|
0,
|
||||||
|
"move/16 v$freeRegister, p1"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} ?: throw exception
|
} ?: throw PivotBarIndexFingerprint.exception
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Since it is used only after opening the library tab, set index to 4.
|
||||||
|
*/
|
||||||
|
arrayOf(
|
||||||
|
MobileTopBarButtonOnClickFingerprint,
|
||||||
|
SettingsActivityOnBackPressedFingerprint
|
||||||
|
).forEach { fingerprint ->
|
||||||
|
fingerprint.injectIndex()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun MethodFingerprint.injectIndex(index: Int) {
|
private fun MethodFingerprint.injectIndex() {
|
||||||
result?.let {
|
result?.let {
|
||||||
it.mutableMethod.apply {
|
it.mutableMethod.apply {
|
||||||
addInstructions(
|
addInstructions(
|
||||||
0, """
|
0, """
|
||||||
const/4 v0, 0x$index
|
const/4 v0, 0x4
|
||||||
invoke-static {v0}, $INTEGRATIONS_CLASS_DESCRIPTOR->setCurrentNavBarIndex(I)V
|
invoke-static {v0}, $INTEGRATIONS_CLASS_DESCRIPTOR->setNavBarIndex(I)V
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
package app.revanced.patches.youtube.utils.navbarindex.fingerprints
|
|
||||||
|
|
||||||
import app.revanced.patcher.fingerprint.MethodFingerprint
|
|
||||||
|
|
||||||
object OnResumeFragmentsFingerprints : MethodFingerprint(
|
|
||||||
customFingerprint = { methodDef, _ ->
|
|
||||||
methodDef.definingClass.endsWith("WatchWhileActivity;")
|
|
||||||
&& methodDef.name == "onResumeFragments"
|
|
||||||
}
|
|
||||||
)
|
|
@ -5,13 +5,14 @@ import app.revanced.patcher.fingerprint.MethodFingerprint
|
|||||||
import com.android.tools.smali.dexlib2.AccessFlags
|
import com.android.tools.smali.dexlib2.AccessFlags
|
||||||
import com.android.tools.smali.dexlib2.Opcode
|
import com.android.tools.smali.dexlib2.Opcode
|
||||||
|
|
||||||
object DefaultTabsBarFingerprint : MethodFingerprint(
|
object PivotBarIndexFingerprint : MethodFingerprint(
|
||||||
returnType = "V",
|
returnType = "V",
|
||||||
accessFlags = AccessFlags.PROTECTED or AccessFlags.FINAL,
|
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
|
||||||
parameters = listOf("Landroid/view/View;"),
|
parameters = listOf("I", "Z"),
|
||||||
opcodes = listOf(
|
opcodes = listOf(
|
||||||
|
Opcode.IGET_OBJECT,
|
||||||
Opcode.INVOKE_VIRTUAL,
|
Opcode.INVOKE_VIRTUAL,
|
||||||
Opcode.IGET
|
Opcode.INVOKE_VIRTUAL
|
||||||
),
|
),
|
||||||
customFingerprint = { methodDef, _ -> methodDef.definingClass.endsWith("/DefaultTabsBar;") }
|
customFingerprint = { methodDef, _ -> methodDef.definingClass.endsWith("/PivotBar;") }
|
||||||
)
|
)
|
@ -589,6 +589,16 @@ Known issue: Official headers in search results are hidden."</string>
|
|||||||
|
|
||||||
Known issue: Autoplay does not work."</string>
|
Known issue: Autoplay does not work."</string>
|
||||||
<string name="revanced_hide_suggested_video_overlay_title">Hide suggested video overlay</string>
|
<string name="revanced_hide_suggested_video_overlay_title">Hide suggested video overlay</string>
|
||||||
|
<string name="revanced_hide_suggestions_shelf_method_summary_off">"Identifies the suggestions shelf through the browse id.
|
||||||
|
|
||||||
|
Known issues:
|
||||||
|
• When Browseid is not identified, suggestions shelf may not be hidden."</string>
|
||||||
|
<string name="revanced_hide_suggestions_shelf_method_summary_on">"Identifies the suggestions shelf through the current tab.
|
||||||
|
|
||||||
|
Known issues:
|
||||||
|
• More drawer shelves may be hidden.
|
||||||
|
• Playlist shelves may be hidden."</string>
|
||||||
|
<string name="revanced_hide_suggestions_shelf_method_title">Select method to hide shelves</string>
|
||||||
<string name="revanced_hide_suggestions_shelf_summary">"Hides following shelves:
|
<string name="revanced_hide_suggestions_shelf_summary">"Hides following shelves:
|
||||||
• Breaking news
|
• Breaking news
|
||||||
• Continue watching
|
• Continue watching
|
||||||
|
@ -247,7 +247,8 @@
|
|||||||
<Preference android:title=" " android:selectable="false" android:summary="@string/revanced_experimental_flag" />SETTINGS: GENERAL_EXPERIMENTAL_FLAGS -->
|
<Preference android:title=" " android:selectable="false" android:summary="@string/revanced_experimental_flag" />SETTINGS: GENERAL_EXPERIMENTAL_FLAGS -->
|
||||||
|
|
||||||
<!-- SETTINGS: HIDE_SUGGESTIONS_SHELF
|
<!-- SETTINGS: HIDE_SUGGESTIONS_SHELF
|
||||||
<SwitchPreference android:title="@string/revanced_hide_suggestions_shelf_title" android:key="revanced_hide_suggestions_shelf" android:defaultValue="false" android:summary="@string/revanced_hide_suggestions_shelf_summary" />SETTINGS: HIDE_SUGGESTIONS_SHELF -->
|
<SwitchPreference android:title="@string/revanced_hide_suggestions_shelf_title" android:key="revanced_hide_suggestions_shelf" android:defaultValue="false" android:summary="@string/revanced_hide_suggestions_shelf_summary" />
|
||||||
|
<SwitchPreference android:title="@string/revanced_hide_suggestions_shelf_method_title" android:key="revanced_hide_suggestions_shelf_method" android:defaultValue="false" android:summaryOn="@string/revanced_hide_suggestions_shelf_method_summary_on" android:summaryOff="@string/revanced_hide_suggestions_shelf_method_summary_off" android:dependency="revanced_hide_suggestions_shelf" />SETTINGS: HIDE_SUGGESTIONS_SHELF -->
|
||||||
|
|
||||||
<!-- SETTINGS: HIDE_LAYOUT_COMPONENTS
|
<!-- SETTINGS: HIDE_LAYOUT_COMPONENTS
|
||||||
<SwitchPreference android:title="@string/revanced_hide_video_with_low_view_title" android:key="revanced_hide_video_with_low_view" android:defaultValue="false" android:summary="@string/revanced_hide_video_with_low_view_summary" />SETTINGS: HIDE_LAYOUT_COMPONENTS -->
|
<SwitchPreference android:title="@string/revanced_hide_video_with_low_view_title" android:key="revanced_hide_video_with_low_view" android:defaultValue="false" android:summary="@string/revanced_hide_video_with_low_view_summary" />SETTINGS: HIDE_LAYOUT_COMPONENTS -->
|
||||||
|
Reference in New Issue
Block a user