refactor: Migrate to new extension methods for String.toInstruction(...) and String.toInstructions(...) (#45)

This commit is contained in:
Itroublve
2022-06-23 02:22:42 +02:00
committed by GitHub
parent d34c6905cb
commit 314e955a3d
13 changed files with 31 additions and 38 deletions

View File

@ -4,13 +4,13 @@ import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.implementation.BytecodeData
import app.revanced.patcher.extensions.addInstruction
import app.revanced.patcher.patch.annotations.Dependencies
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patcher.patch.implementation.BytecodePatch
import app.revanced.patcher.patch.implementation.misc.PatchResult
import app.revanced.patcher.patch.implementation.misc.PatchResultError
import app.revanced.patcher.patch.implementation.misc.PatchResultSuccess
import app.revanced.patcher.util.smali.toInstruction
import app.revanced.patches.youtube.layout.createbutton.annotations.CreateButtonCompatibility
import app.revanced.patches.youtube.layout.createbutton.signatures.CreateButtonSignature
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch
@ -38,9 +38,9 @@ class CreateButtonRemoverPatch : BytecodePatch(
val register = (instruction as Instruction35c).registerC
// Hide the button view via proxy by passing it to the hideCreateButton method
implementation.addInstruction(
result.method.addInstruction(
result.scanResult.endIndex + 1,
"invoke-static { v$register }, Lfi/razerman/youtube/XAdRemover;->hideCreateButton(Landroid/view/View;)V".toInstruction()
"invoke-static { v$register }, Lfi/razerman/youtube/XAdRemover;->hideCreateButton(Landroid/view/View;)V"
)
return PatchResultSuccess()

View File

@ -3,13 +3,12 @@ package app.revanced.patches.youtube.layout.minimizedplayback.patch
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.implementation.BytecodeData
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.data.implementation.BytecodeData
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patcher.patch.implementation.BytecodePatch
import app.revanced.patcher.patch.implementation.misc.PatchResult
import app.revanced.patcher.patch.implementation.misc.PatchResultSuccess
import app.revanced.patcher.util.smali.toInstructions
import app.revanced.patches.youtube.layout.minimizedplayback.annotations.MinimizedPlaybackCompatibility
import app.revanced.patches.youtube.layout.minimizedplayback.signatures.MinimizedPlaybackManagerSignature
@ -27,11 +26,11 @@ class MinimizedPlaybackPatch : BytecodePatch(
override fun execute(data: BytecodeData): PatchResult {
// Instead of removing all instructions like Vanced,
// we return the method at the beginning instead
MinimizedPlaybackManagerSignature.result!!.method.implementation!!.addInstructions(
MinimizedPlaybackManagerSignature.result!!.method.addInstructions(
0, """
const/4 v0, 0x1
return v0
""".trimIndent().toInstructions()
"""
)
return PatchResultSuccess()
}

View File

@ -15,7 +15,6 @@ import app.revanced.patcher.patch.implementation.misc.PatchResultSuccess
import app.revanced.patcher.signature.implementation.method.MethodSignature
import app.revanced.patcher.signature.implementation.method.annotation.FuzzyPatternScanMethod
import app.revanced.patcher.signature.implementation.method.annotation.MatchingMethod
import app.revanced.patcher.util.smali.toInstructions
import app.revanced.patches.youtube.layout.oldqualitylayout.annotations.OldQualityLayoutCompatibility
import app.revanced.patches.youtube.layout.oldqualitylayout.signatures.OldQualityParentSignature
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch
@ -57,11 +56,11 @@ class OldQualityLayoutPatch : BytecodePatch(
Opcode.IF_NEZ, 0, implementation.instructions[result.scanResult.endIndex].location.labels.first()
)
implementation.addInstruction(5, jmpInstruction)
implementation.addInstructions(
result.method.addInstructions(
0, """
invoke-static { }, Lfi/razerman/youtube/XGlobals;->useOldStyleQualitySettings()Z
move-result v0
""".trimIndent().toInstructions()
"""
)
return PatchResultSuccess()

View File

@ -4,10 +4,10 @@ import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.implementation.BytecodeData
import app.revanced.patcher.extensions.addInstruction
import app.revanced.patcher.patch.implementation.BytecodePatch
import app.revanced.patcher.patch.implementation.misc.PatchResult
import app.revanced.patcher.patch.implementation.misc.PatchResultSuccess
import app.revanced.patcher.util.smali.toInstruction
import app.revanced.patches.youtube.layout.reels.annotations.HideReelsCompatibility
import app.revanced.patches.youtube.layout.reels.signatures.HideReelsSignature
@ -23,13 +23,12 @@ class HideReelsPatch : BytecodePatch(
) {
override fun execute(data: BytecodeData): PatchResult {
val result = HideReelsSignature.result!!
val implementation = result.method.implementation!!
// HideReel will hide the reel view before it is being used,
// so we pass the view to the HideReel method
implementation.addInstruction(
result.method.addInstruction(
result.scanResult.endIndex,
"invoke-static { v2 }, Lfi/razerman/youtube/XAdRemover;->HideReel(Landroid/view/View;)V".toInstruction()
"invoke-static { v2 }, Lfi/razerman/youtube/XAdRemover;->HideReel(Landroid/view/View;)V"
)
return PatchResultSuccess()

View File

@ -4,12 +4,12 @@ import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.implementation.BytecodeData
import app.revanced.patcher.extensions.addInstruction
import app.revanced.patcher.patch.annotations.Dependencies
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patcher.patch.implementation.BytecodePatch
import app.revanced.patcher.patch.implementation.misc.PatchResult
import app.revanced.patcher.patch.implementation.misc.PatchResultSuccess
import app.revanced.patcher.util.smali.toInstruction
import app.revanced.patches.youtube.layout.shorts.button.annotations.ShortsButtonCompatibility
import app.revanced.patches.youtube.layout.shorts.button.signatures.PivotBarButtonTabenumSignature
import app.revanced.patches.youtube.layout.shorts.button.signatures.PivotBarButtonsViewSignature
@ -39,16 +39,16 @@ class ShortsButtonRemoverPatch : BytecodePatch(
val viewRegister = (moveViewInstruction as Instruction11x).registerA
// Save the tab enum in XGlobals to avoid smali/register workarounds
implementation1.addInstruction(
result1.method.addInstruction(
result1.scanResult.endIndex + 1,
"sput-object v$enumRegister, Lfi/razerman/youtube/XGlobals;->lastPivotTab:Ljava/lang/Enum;".toInstruction()
"sput-object v$enumRegister, Lfi/razerman/youtube/XGlobals;->lastPivotTab:Ljava/lang/Enum;"
)
// Hide the button view via proxy by passing it to the hideShortsButton method
// It only hides it if the last tab name is "TAB_SHORTS"
implementation2.addInstruction(
result2.method.addInstruction(
result2.scanResult.endIndex + 2,
"invoke-static { v$viewRegister }, Lfi/razerman/youtube/XAdRemover;->hideShortsButton(Landroid/view/View;)V".toInstruction()
"invoke-static { v$viewRegister }, Lfi/razerman/youtube/XAdRemover;->hideShortsButton(Landroid/view/View;)V"
)
return PatchResultSuccess()