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
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 31 additions and 38 deletions

View file

@ -9,7 +9,6 @@ import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patcher.patch.implementation.BytecodePatch import app.revanced.patcher.patch.implementation.BytecodePatch
import app.revanced.patcher.patch.implementation.misc.PatchResult import app.revanced.patcher.patch.implementation.misc.PatchResult
import app.revanced.patcher.patch.implementation.misc.PatchResultSuccess import app.revanced.patcher.patch.implementation.misc.PatchResultSuccess
import app.revanced.patcher.util.smali.toInstructions
import app.revanced.patches.music.layout.tastebuilder.annotations.RemoveTasteBuilderCompatibility import app.revanced.patches.music.layout.tastebuilder.annotations.RemoveTasteBuilderCompatibility
import app.revanced.patches.music.layout.tastebuilder.signatures.TasteBuilderConstructorSignature import app.revanced.patches.music.layout.tastebuilder.signatures.TasteBuilderConstructorSignature
import org.jf.dexlib2.iface.instruction.formats.Instruction22c import org.jf.dexlib2.iface.instruction.formats.Instruction22c

View file

@ -9,7 +9,6 @@ import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patcher.patch.implementation.BytecodePatch import app.revanced.patcher.patch.implementation.BytecodePatch
import app.revanced.patcher.patch.implementation.misc.PatchResult import app.revanced.patcher.patch.implementation.misc.PatchResult
import app.revanced.patcher.patch.implementation.misc.PatchResultSuccess import app.revanced.patcher.patch.implementation.misc.PatchResultSuccess
import app.revanced.patcher.util.smali.toInstructions
import app.revanced.patches.music.premium.backgroundplay.annotations.BackgroundPlayCompatibility import app.revanced.patches.music.premium.backgroundplay.annotations.BackgroundPlayCompatibility
import app.revanced.patches.music.premium.backgroundplay.signatures.BackgroundPlaybackDisableSignature import app.revanced.patches.music.premium.backgroundplay.signatures.BackgroundPlaybackDisableSignature
@ -24,12 +23,12 @@ class BackgroundPlayPatch : BytecodePatch(
) )
) { ) {
override fun execute(data: BytecodeData): PatchResult { override fun execute(data: BytecodeData): PatchResult {
BackgroundPlaybackDisableSignature.result!!.method.implementation!!.addInstructions( BackgroundPlaybackDisableSignature.result!!.method.addInstructions(
0, 0,
""" """
const/4 v0, 0x1 const/4 v0, 0x1
return v0 return v0
""".trimIndent().toInstructions() """
) )
return PatchResultSuccess() return PatchResultSuccess()

View file

@ -148,11 +148,11 @@ class GeneralBytecodeAdsPatch : BytecodePatch(
mutableClass!!.findMutableMethodOf(method) mutableClass!!.findMutableMethodOf(method)
// TODO: dynamically get registers // TODO: dynamically get registers
mutableMethod!!.implementation!!.addInstructions( mutableMethod!!.addInstructions(
insertIndex, """ insertIndex, """
const/16 v1, 0x8 const/16 v1, 0x8
invoke-virtual {v0,v1}, Landroid/widget/FrameLayout;->setVisibility(I)V invoke-virtual {v0,v1}, Landroid/widget/FrameLayout;->setVisibility(I)V
""".trimIndent().toInstructions() """
) )
} }

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.MethodSignature
import app.revanced.patcher.signature.implementation.method.annotation.DirectPatternScanMethod import app.revanced.patcher.signature.implementation.method.annotation.DirectPatternScanMethod
import app.revanced.patcher.signature.implementation.method.annotation.MatchingMethod import app.revanced.patcher.signature.implementation.method.annotation.MatchingMethod
import app.revanced.patcher.util.smali.toInstructions
import app.revanced.patches.youtube.ad.video.annotations.VideoAdsCompatibility import app.revanced.patches.youtube.ad.video.annotations.VideoAdsCompatibility
import app.revanced.patches.youtube.ad.video.signatures.ShowVideoAdsConstructorSignature import app.revanced.patches.youtube.ad.video.signatures.ShowVideoAdsConstructorSignature
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch
@ -41,11 +40,11 @@ class VideoAdsPatch : BytecodePatch(
) {}) ?: return PatchResultError("Required parent method could not be found.") ) {}) ?: return PatchResultError("Required parent method could not be found.")
// Override the parameter by calling shouldShowAds and setting the parameter to the result // Override the parameter by calling shouldShowAds and setting the parameter to the result
result.method.implementation!!.addInstructions( result.method.addInstructions(
0, """ 0, """
invoke-static { }, Lfi/vanced/libraries/youtube/whitelisting/Whitelist;->shouldShowAds()Z invoke-static { }, Lfi/vanced/libraries/youtube/whitelisting/Whitelist;->shouldShowAds()Z
move-result v1 move-result v1
""".trimIndent().toInstructions() """
) )
return PatchResultSuccess() return PatchResultSuccess()

View file

@ -11,7 +11,6 @@ import app.revanced.patcher.patch.implementation.BytecodePatch
import app.revanced.patcher.patch.implementation.misc.PatchResult import app.revanced.patcher.patch.implementation.misc.PatchResult
import app.revanced.patcher.patch.implementation.misc.PatchResultError import app.revanced.patcher.patch.implementation.misc.PatchResultError
import app.revanced.patcher.patch.implementation.misc.PatchResultSuccess import app.revanced.patcher.patch.implementation.misc.PatchResultSuccess
import app.revanced.patcher.util.smali.toInstructions
import app.revanced.patches.youtube.interaction.seekbar.annotation.SeekbarTappingCompatibility import app.revanced.patches.youtube.interaction.seekbar.annotation.SeekbarTappingCompatibility
import app.revanced.patches.youtube.interaction.seekbar.signatures.SeekbarTappingParentSignature import app.revanced.patches.youtube.interaction.seekbar.signatures.SeekbarTappingParentSignature
import app.revanced.patches.youtube.interaction.seekbar.signatures.SeekbarTappingSignature import app.revanced.patches.youtube.interaction.seekbar.signatures.SeekbarTappingSignature
@ -73,11 +72,11 @@ class EnableSeekbarTappingPatch : BytecodePatch(
val register = (instruction as Instruction35c).registerC val register = (instruction as Instruction35c).registerC
// the instructions are written in reverse order. // the instructions are written in reverse order.
implementation.addInstructions( result.method.addInstructions(
result.scanResult.endIndex + 1, """ result.scanResult.endIndex + 1, """
invoke-virtual { v$register, v2 }, ${oMethod.definingClass}->${oMethod.name}(I)V invoke-virtual { v$register, v2 }, ${oMethod.definingClass}->${oMethod.name}(I)V
invoke-virtual { v$register, v2 }, ${pMethod.definingClass}->${pMethod.name}(I)V invoke-virtual { v$register, v2 }, ${pMethod.definingClass}->${pMethod.name}(I)V
""".trimIndent().toInstructions() """
) )
// if tap-seeking is disabled, do not invoke the two methods above by jumping to the else label // if tap-seeking is disabled, do not invoke the two methods above by jumping to the else label
@ -85,11 +84,11 @@ class EnableSeekbarTappingPatch : BytecodePatch(
implementation.addInstruction( implementation.addInstruction(
result.scanResult.endIndex + 1, BuilderInstruction21t(Opcode.IF_EQZ, 0, elseLabel) result.scanResult.endIndex + 1, BuilderInstruction21t(Opcode.IF_EQZ, 0, elseLabel)
) )
implementation.addInstructions( result.method.addInstructions(
result.scanResult.endIndex + 1, """ result.scanResult.endIndex + 1, """
invoke-static { }, Lfi/razerman/youtube/preferences/BooleanPreferences;->isTapSeekingEnabled()Z invoke-static { }, Lfi/razerman/youtube/preferences/BooleanPreferences;->isTapSeekingEnabled()Z
move-result v0 move-result v0
""".trimIndent().toInstructions() """
) )
return PatchResultSuccess() return PatchResultSuccess()
} }

View file

@ -4,13 +4,13 @@ import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.implementation.BytecodeData 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.Dependencies
import app.revanced.patcher.patch.annotations.Patch import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patcher.patch.implementation.BytecodePatch import app.revanced.patcher.patch.implementation.BytecodePatch
import app.revanced.patcher.patch.implementation.misc.PatchResult import app.revanced.patcher.patch.implementation.misc.PatchResult
import app.revanced.patcher.patch.implementation.misc.PatchResultError import app.revanced.patcher.patch.implementation.misc.PatchResultError
import app.revanced.patcher.patch.implementation.misc.PatchResultSuccess 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.annotations.CreateButtonCompatibility
import app.revanced.patches.youtube.layout.createbutton.signatures.CreateButtonSignature import app.revanced.patches.youtube.layout.createbutton.signatures.CreateButtonSignature
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch
@ -38,9 +38,9 @@ class CreateButtonRemoverPatch : BytecodePatch(
val register = (instruction as Instruction35c).registerC val register = (instruction as Instruction35c).registerC
// Hide the button view via proxy by passing it to the hideCreateButton method // Hide the button view via proxy by passing it to the hideCreateButton method
implementation.addInstruction( result.method.addInstruction(
result.scanResult.endIndex + 1, 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() 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.Description
import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.implementation.BytecodeData
import app.revanced.patcher.extensions.addInstructions 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.annotations.Patch
import app.revanced.patcher.patch.implementation.BytecodePatch import app.revanced.patcher.patch.implementation.BytecodePatch
import app.revanced.patcher.patch.implementation.misc.PatchResult import app.revanced.patcher.patch.implementation.misc.PatchResult
import app.revanced.patcher.patch.implementation.misc.PatchResultSuccess 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.annotations.MinimizedPlaybackCompatibility
import app.revanced.patches.youtube.layout.minimizedplayback.signatures.MinimizedPlaybackManagerSignature import app.revanced.patches.youtube.layout.minimizedplayback.signatures.MinimizedPlaybackManagerSignature
@ -27,11 +26,11 @@ class MinimizedPlaybackPatch : BytecodePatch(
override fun execute(data: BytecodeData): PatchResult { override fun execute(data: BytecodeData): PatchResult {
// Instead of removing all instructions like Vanced, // Instead of removing all instructions like Vanced,
// we return the method at the beginning instead // we return the method at the beginning instead
MinimizedPlaybackManagerSignature.result!!.method.implementation!!.addInstructions( MinimizedPlaybackManagerSignature.result!!.method.addInstructions(
0, """ 0, """
const/4 v0, 0x1 const/4 v0, 0x1
return v0 return v0
""".trimIndent().toInstructions() """
) )
return PatchResultSuccess() 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.MethodSignature
import app.revanced.patcher.signature.implementation.method.annotation.FuzzyPatternScanMethod import app.revanced.patcher.signature.implementation.method.annotation.FuzzyPatternScanMethod
import app.revanced.patcher.signature.implementation.method.annotation.MatchingMethod 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.annotations.OldQualityLayoutCompatibility
import app.revanced.patches.youtube.layout.oldqualitylayout.signatures.OldQualityParentSignature import app.revanced.patches.youtube.layout.oldqualitylayout.signatures.OldQualityParentSignature
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch 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() Opcode.IF_NEZ, 0, implementation.instructions[result.scanResult.endIndex].location.labels.first()
) )
implementation.addInstruction(5, jmpInstruction) implementation.addInstruction(5, jmpInstruction)
implementation.addInstructions( result.method.addInstructions(
0, """ 0, """
invoke-static { }, Lfi/razerman/youtube/XGlobals;->useOldStyleQualitySettings()Z invoke-static { }, Lfi/razerman/youtube/XGlobals;->useOldStyleQualitySettings()Z
move-result v0 move-result v0
""".trimIndent().toInstructions() """
) )
return PatchResultSuccess() 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.Name
import app.revanced.patcher.annotation.Version import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.implementation.BytecodeData 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.BytecodePatch
import app.revanced.patcher.patch.implementation.misc.PatchResult import app.revanced.patcher.patch.implementation.misc.PatchResult
import app.revanced.patcher.patch.implementation.misc.PatchResultSuccess 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.annotations.HideReelsCompatibility
import app.revanced.patches.youtube.layout.reels.signatures.HideReelsSignature import app.revanced.patches.youtube.layout.reels.signatures.HideReelsSignature
@ -23,13 +23,12 @@ class HideReelsPatch : BytecodePatch(
) { ) {
override fun execute(data: BytecodeData): PatchResult { override fun execute(data: BytecodeData): PatchResult {
val result = HideReelsSignature.result!! val result = HideReelsSignature.result!!
val implementation = result.method.implementation!!
// HideReel will hide the reel view before it is being used, // HideReel will hide the reel view before it is being used,
// so we pass the view to the HideReel method // so we pass the view to the HideReel method
implementation.addInstruction( result.method.addInstruction(
result.scanResult.endIndex, 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() 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.Name
import app.revanced.patcher.annotation.Version import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.implementation.BytecodeData 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.Dependencies
import app.revanced.patcher.patch.annotations.Patch import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patcher.patch.implementation.BytecodePatch import app.revanced.patcher.patch.implementation.BytecodePatch
import app.revanced.patcher.patch.implementation.misc.PatchResult import app.revanced.patcher.patch.implementation.misc.PatchResult
import app.revanced.patcher.patch.implementation.misc.PatchResultSuccess 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.annotations.ShortsButtonCompatibility
import app.revanced.patches.youtube.layout.shorts.button.signatures.PivotBarButtonTabenumSignature import app.revanced.patches.youtube.layout.shorts.button.signatures.PivotBarButtonTabenumSignature
import app.revanced.patches.youtube.layout.shorts.button.signatures.PivotBarButtonsViewSignature import app.revanced.patches.youtube.layout.shorts.button.signatures.PivotBarButtonsViewSignature
@ -39,16 +39,16 @@ class ShortsButtonRemoverPatch : BytecodePatch(
val viewRegister = (moveViewInstruction as Instruction11x).registerA val viewRegister = (moveViewInstruction as Instruction11x).registerA
// Save the tab enum in XGlobals to avoid smali/register workarounds // Save the tab enum in XGlobals to avoid smali/register workarounds
implementation1.addInstruction( result1.method.addInstruction(
result1.scanResult.endIndex + 1, 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 // 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" // It only hides it if the last tab name is "TAB_SHORTS"
implementation2.addInstruction( result2.method.addInstruction(
result2.scanResult.endIndex + 2, 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() return PatchResultSuccess()

View file

@ -36,11 +36,11 @@ class IntegrationsPatch : BytecodePatch(
val implementation = result.method.implementation!! val implementation = result.method.implementation!!
val count = implementation.registerCount - 1 val count = implementation.registerCount - 1
implementation.addInstructions( result.method.addInstructions(
result.scanResult.endIndex + 1, """ result.scanResult.endIndex + 1, """
invoke-static {v$count}, Lpl/jakubweg/StringRef;->setContext(Landroid/content/Context;)V invoke-static {v$count}, Lpl/jakubweg/StringRef;->setContext(Landroid/content/Context;)V
sput-object v$count, Lapp/revanced/integrations/Globals;->context:Landroid/content/Context; sput-object v$count, Lapp/revanced/integrations/Globals;->context:Landroid/content/Context;
""".trimIndent().toInstructions() """
) )
val classDef = result.definingClassProxy.resolve() val classDef = result.definingClassProxy.resolve()

View file

@ -147,8 +147,8 @@ class MicroGBytecodePatch : BytecodePatch(
else -> throw Exception("This case should never happen.") else -> throw Exception("This case should never happen.")
} }
result.method.implementation!!.addInstructions( result.method.addInstructions(
0, stringInstructions.trimIndent().toInstructions() 0, stringInstructions
) )
} }