generated from ReVanced/revanced-patches-template
-
-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(hide-shorts-button): increase patching compatibility across versions
Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
- Loading branch information
Showing
9 changed files
with
175 additions
and
166 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
src/main/kotlin/app/revanced/patches/youtube/layout/pivotbar/InjectionUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package app.revanced.patches.youtube.layout.pivotbar | ||
|
||
import app.revanced.patcher.extensions.addInstruction | ||
import app.revanced.patcher.extensions.instruction | ||
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod | ||
import org.jf.dexlib2.Opcode.MOVE_RESULT_OBJECT | ||
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction | ||
|
||
internal object InjectionUtils { | ||
const val REGISTER_TEMPLATE_REPLACEMENT: String = "REGISTER_INDEX" | ||
|
||
/** | ||
* Injects an instruction into insertIndex of the hook. | ||
* @param hook The hook to insert. | ||
* @param insertIndex The index to insert the instruction at. | ||
* [MOVE_RESULT_OBJECT] has to be the previous instruction before [insertIndex]. | ||
*/ | ||
fun MutableMethod.injectHook(hook: String, insertIndex: Int) { | ||
val injectTarget = this | ||
|
||
// Register to pass to the hook | ||
val registerIndex = insertIndex - 1 // MOVE_RESULT_OBJECT is always the previous instruction | ||
val register = (injectTarget.instruction(registerIndex) as OneRegisterInstruction).registerA | ||
|
||
injectTarget.addInstruction( | ||
insertIndex, | ||
hook.replace("REGISTER_INDEX", register.toString()), | ||
) | ||
} | ||
} |
14 changes: 7 additions & 7 deletions
14
...n/fingerprints/CreateButtonFingerprint.kt → ...otbar/fingerprints/PivotBarFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../annotations/ShortsButtonCompatibility.kt → .../annotations/ShortsButtonCompatibility.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...nced/patches/youtube/layout/pivotbar/shortsbutton/fingerprints/PivotBarEnumFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package app.revanced.patches.youtube.layout.pivotbar.shortsbutton.fingerprints | ||
|
||
import app.revanced.patcher.annotation.Name | ||
import app.revanced.patcher.annotation.Version | ||
import app.revanced.patcher.fingerprint.method.annotation.MatchingMethod | ||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint | ||
import app.revanced.patches.youtube.layout.pivotbar.shortsbutton.annotations.ShortsButtonCompatibility | ||
import org.jf.dexlib2.Opcode | ||
|
||
@Name("pivot-bar-enum-fingerprint") | ||
@MatchingMethod( | ||
"Lknw", "z" | ||
) | ||
@ShortsButtonCompatibility | ||
@Version("0.0.1") | ||
object PivotBarEnumFingerprint : MethodFingerprint( | ||
opcodes = listOf( | ||
Opcode.IF_NEZ, | ||
Opcode.SGET_OBJECT, | ||
Opcode.INVOKE_VIRTUAL, | ||
Opcode.MOVE_RESULT, | ||
Opcode.IGET, | ||
Opcode.AND_INT_LIT8, // unique instruction anchor | ||
) | ||
) |
22 changes: 22 additions & 0 deletions
22
.../youtube/layout/pivotbar/shortsbutton/fingerprints/PivotBarShortsButtonViewFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package app.revanced.patches.youtube.layout.pivotbar.shortsbutton.fingerprints | ||
|
||
import app.revanced.patcher.annotation.Name | ||
import app.revanced.patcher.annotation.Version | ||
import app.revanced.patcher.fingerprint.method.annotation.MatchingMethod | ||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint | ||
import app.revanced.patches.youtube.layout.pivotbar.shortsbutton.annotations.ShortsButtonCompatibility | ||
import org.jf.dexlib2.Opcode | ||
|
||
@Name("pivot-bar-shorts-button-view-fingerprint") | ||
@MatchingMethod( | ||
"Lknw", "z" | ||
) | ||
@ShortsButtonCompatibility | ||
@Version("0.0.1") | ||
object PivotBarShortsButtonViewFingerprint : MethodFingerprint( | ||
opcodes = listOf( | ||
Opcode.INVOKE_VIRTUAL_RANGE, // unique instruction anchor | ||
Opcode.MOVE_RESULT_OBJECT, | ||
Opcode.GOTO, | ||
) | ||
) |
90 changes: 90 additions & 0 deletions
90
...p/revanced/patches/youtube/layout/pivotbar/shortsbutton/patch/ShortsButtonRemoverPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package app.revanced.patches.youtube.layout.pivotbar.shortsbutton.patch | ||
|
||
import app.revanced.patcher.annotation.Description | ||
import app.revanced.patcher.annotation.Name | ||
import app.revanced.patcher.annotation.Version | ||
import app.revanced.patcher.data.impl.BytecodeData | ||
import app.revanced.patcher.extensions.MethodFingerprintExtensions.name | ||
import app.revanced.patcher.fingerprint.method.utils.MethodFingerprintUtils.resolve | ||
import app.revanced.patcher.patch.PatchResult | ||
import app.revanced.patcher.patch.PatchResultError | ||
import app.revanced.patcher.patch.PatchResultSuccess | ||
import app.revanced.patcher.patch.annotations.DependsOn | ||
import app.revanced.patcher.patch.annotations.Patch | ||
import app.revanced.patcher.patch.impl.BytecodePatch | ||
import app.revanced.patches.youtube.layout.pivotbar.InjectionUtils.REGISTER_TEMPLATE_REPLACEMENT | ||
import app.revanced.patches.youtube.layout.pivotbar.InjectionUtils.injectHook | ||
import app.revanced.patches.youtube.layout.pivotbar.fingerprints.PivotBarFingerprint | ||
import app.revanced.patches.youtube.layout.pivotbar.shortsbutton.annotations.ShortsButtonCompatibility | ||
import app.revanced.patches.youtube.layout.pivotbar.shortsbutton.fingerprints.PivotBarEnumFingerprint | ||
import app.revanced.patches.youtube.layout.pivotbar.shortsbutton.fingerprints.PivotBarShortsButtonViewFingerprint | ||
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch | ||
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch | ||
import app.revanced.patches.youtube.misc.settings.framework.components.impl.StringResource | ||
import app.revanced.patches.youtube.misc.settings.framework.components.impl.SwitchPreference | ||
|
||
@Patch | ||
@DependsOn([IntegrationsPatch::class, SettingsPatch::class]) | ||
@Name("hide-shorts-button") | ||
@Description("Hides the shorts button on the navigation bar.") | ||
@ShortsButtonCompatibility | ||
@Version("0.0.1") | ||
class ShortsButtonRemoverPatch : BytecodePatch( | ||
listOf(PivotBarFingerprint) | ||
) { | ||
override fun execute(data: BytecodeData): PatchResult { | ||
SettingsPatch.PreferenceScreen.LAYOUT.addPreferences( | ||
SwitchPreference( | ||
"revanced_shorts_button_enabled", | ||
StringResource("revanced_shorts_button_enabled_title", "Show shorts button"), | ||
false, | ||
StringResource("revanced_shorts_button_summary_on", "Shorts button is shown"), | ||
StringResource("revanced_shorts_button_summary_off", "Shorts button is hidden") | ||
) | ||
) | ||
|
||
/* | ||
* Resolve fingerprints | ||
*/ | ||
|
||
val pivotBarResult = PivotBarFingerprint.result ?: return PatchResultError("PivotBarFingerprint failed") | ||
val fingerprintResults = arrayOf(PivotBarEnumFingerprint, PivotBarShortsButtonViewFingerprint) | ||
.onEach { | ||
val resolutionSucceeded = it.resolve( | ||
data, | ||
pivotBarResult.method, | ||
pivotBarResult.classDef | ||
) | ||
|
||
if (!resolutionSucceeded) return PatchResultError("${it.name} failed") | ||
} | ||
.map { it.result!!.patternScanResult!! } | ||
|
||
val enumScanResult = fingerprintResults[0] | ||
val buttonViewResult = fingerprintResults[1] | ||
|
||
val enumHookInsertIndex = enumScanResult.startIndex | ||
val buttonHookInsertIndex = buttonViewResult.endIndex | ||
|
||
/* | ||
* Inject hooks | ||
*/ | ||
|
||
val integrationsClass = "Lapp/revanced/integrations/patches/HideShortsButtonPatch;" | ||
|
||
val enumHook = | ||
"sput-object v$REGISTER_TEMPLATE_REPLACEMENT, $integrationsClass->lastPivotTab:Ljava/lang/Enum;" | ||
val buttonHook = | ||
"invoke-static { v$REGISTER_TEMPLATE_REPLACEMENT }, $integrationsClass->hideShortsButton(Landroid/view/View;)V" | ||
|
||
// Inject bottom to top to not mess up the indices | ||
mapOf( | ||
buttonHook to buttonHookInsertIndex, | ||
enumHook to enumHookInsertIndex | ||
).forEach { (hook, insertIndex) -> | ||
pivotBarResult.mutableMethod.injectHook(hook, insertIndex) | ||
} | ||
|
||
return PatchResultSuccess() | ||
} | ||
} |
36 changes: 0 additions & 36 deletions
36
...ced/patches/youtube/layout/shorts/button/fingerprints/PivotBarButtonTabEnumFingerprint.kt
This file was deleted.
Oops, something went wrong.
33 changes: 0 additions & 33 deletions
33
...anced/patches/youtube/layout/shorts/button/fingerprints/PivotBarButtonsViewFingerprint.kt
This file was deleted.
Oops, something went wrong.
89 changes: 0 additions & 89 deletions
89
...otlin/app/revanced/patches/youtube/layout/shorts/button/patch/ShortsButtonRemoverPatch.kt
This file was deleted.
Oops, something went wrong.