refactor: Deprecate Instruction.getReference in favor of patcher extensions (#6854)

This commit is contained in:
Dawid Krajcarz 2026-03-20 20:08:54 +01:00 committed by GitHub
parent 8f54a7c5a0
commit bfa94c9463
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
64 changed files with 153 additions and 235 deletions

View file

@ -1,12 +1,11 @@
package app.revanced.patches.all.misc.adb
import app.revanced.patcher.extensions.methodReference
import app.revanced.patcher.extensions.replaceInstruction
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.all.misc.transformation.transformInstructionsPatch
import app.revanced.util.getReference
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction35c
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
import com.android.tools.smali.dexlib2.immutable.reference.ImmutableMethodReference
import com.android.tools.smali.dexlib2.util.MethodUtil
@ -44,7 +43,7 @@ val hideADBStatusPatch = bytecodePatch(
filterMap = filterMap@{ classDef, method, instruction, instructionIndex ->
val reference = instruction
.takeIf { it.opcode == Opcode.INVOKE_STATIC }
?.getReference<MethodReference>()
?.methodReference
?.takeIf { reference ->
getIntMethodReferences.any { MethodUtil.methodSignaturesMatch(it, reference) }
}

View file

@ -1,12 +1,11 @@
package app.revanced.patches.all.misc.build
import app.revanced.patcher.extensions.fieldReference
import app.revanced.patcher.extensions.getInstruction
import app.revanced.patcher.extensions.replaceInstruction
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.all.misc.transformation.transformInstructionsPatch
import app.revanced.util.getReference
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
private const val BUILD_CLASS_DESCRIPTOR = "Landroid/os/Build;"
@ -75,7 +74,7 @@ fun baseSpoofBuildInfoPatch(buildInfoSupplier: () -> BuildInfo) = bytecodePatch
dependsOn(
transformInstructionsPatch(
filterMap = filterMap@{ _, _, instruction, instructionIndex ->
val reference = instruction.getReference<FieldReference>() ?: return@filterMap null
val reference = instruction.fieldReference ?: return@filterMap null
if (reference.definingClass != BUILD_CLASS_DESCRIPTOR) return@filterMap null
return@filterMap replacements[reference.name]?.let { instructionIndex to it }

View file

@ -1,13 +1,12 @@
package app.revanced.patches.all.misc.connectivity.location.hide
import app.revanced.patcher.extensions.methodReference
import app.revanced.patcher.extensions.replaceInstruction
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.all.misc.transformation.IMethodCall
import app.revanced.patches.all.misc.transformation.fromMethodReference
import app.revanced.patches.all.misc.transformation.transformInstructionsPatch
import app.revanced.util.getReference
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
@Suppress("unused")
val hideMockLocationPatch = bytecodePatch(
@ -18,7 +17,7 @@ val hideMockLocationPatch = bytecodePatch(
dependsOn(
transformInstructionsPatch(
filterMap = filter@{ _, _, instruction, instructionIndex ->
val reference = instruction.getReference<MethodReference>() ?: return@filter null
val reference = instruction.methodReference ?: return@filter null
if (fromMethodReference<MethodCall>(reference) == null) return@filter null
instruction to instructionIndex

View file

@ -1,11 +1,10 @@
package app.revanced.patches.all.misc.play
import app.revanced.patcher.extensions.methodReference
import app.revanced.patcher.extensions.replaceInstruction
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.all.misc.transformation.transformInstructionsPatch
import app.revanced.util.getReference
import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction35c
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
import com.android.tools.smali.dexlib2.immutable.reference.ImmutableMethodReference
import com.android.tools.smali.dexlib2.util.MethodUtil
@ -30,7 +29,7 @@ val disablePlayIntegrityPatch = bytecodePatch(
transformInstructionsPatch(
filterMap = filterMap@{ classDef, method, instruction, instructionIndex ->
val reference = instruction
.getReference<MethodReference>()
.methodReference
?.takeIf {
MethodUtil.methodSignaturesMatch(CONTEXT_BIND_SERVICE_METHOD_REFERENCE, it)
}

View file

@ -2,14 +2,12 @@ package app.revanced.patches.all.misc.play
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.extensions.getInstruction
import app.revanced.patcher.extensions.methodReference
import app.revanced.patcher.extensions.removeInstructions
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patcher.patch.intOption
import app.revanced.patcher.patch.option
import app.revanced.util.forEachInstructionAsSequence
import app.revanced.util.getReference
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.reference.MethodReference
import com.android.tools.smali.dexlib2.immutable.reference.ImmutableMethodReference
@ -46,7 +44,7 @@ val spoofPlayAgeSignalsPatch = bytecodePatch(
if (classDef.type.startsWith("Lcom/google/android/play/agesignals/")) return@forEachInstructionAsSequence null
// Keep method calls only.
val reference = instruction.getReference<MethodReference>()
val reference = instruction.methodReference
?: return@forEachInstructionAsSequence null
val match = MethodCall.entries.firstOrNull {

View file

@ -1,11 +1,10 @@
package app.revanced.patches.all.misc.screenshot
import app.revanced.patcher.extensions.methodReference
import app.revanced.patcher.extensions.removeInstruction
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.all.misc.transformation.transformInstructionsPatch
import app.revanced.util.getReference
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
import com.android.tools.smali.dexlib2.immutable.reference.ImmutableMethodReference
import com.android.tools.smali.dexlib2.util.MethodUtil
@ -39,7 +38,7 @@ val preventScreenshotDetectionPatch = bytecodePatch(
filterMap = { _, _, instruction, instructionIndex ->
if (instruction.opcode != Opcode.INVOKE_VIRTUAL) return@transformInstructionsPatch null
val reference = instruction.getReference<MethodReference>() ?: return@transformInstructionsPatch null
val reference = instruction.methodReference ?: return@transformInstructionsPatch null
instructionIndex.takeIf {
MethodUtil.methodSignaturesMatch(reference, registerScreenCaptureCallbackMethodReference) ||

View file

@ -1,15 +1,14 @@
package app.revanced.patches.cricbuzz.ads
import app.revanced.patcher.extensions.addInstruction
import app.revanced.patcher.extensions.fieldReference
import app.revanced.patcher.extensions.getInstruction
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.cricbuzz.misc.extension.sharedExtensionPatch
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.returnEarly
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
private const val EXTENSION_CLASS_DESCRIPTOR =
"Lapp/revanced/extension/cricbuzz/ads/HideAdsPatch;"
@ -27,7 +26,7 @@ val hideAdsPatch = bytecodePatch("Hide ads") {
cb11ConstructorMethod.addInstruction(0, "const/4 p7, 0x0")
getBottomBarMethod.apply {
val getIndex = indexOfFirstInstructionOrThrow {
opcode == Opcode.IGET_OBJECT && getReference<FieldReference>()?.name == "bottomBar"
opcode == Opcode.IGET_OBJECT && fieldReference?.name == "bottomBar"
}
val getRegister = getInstruction<TwoRegisterInstruction>(getIndex).registerA

View file

@ -1,16 +1,15 @@
package app.revanced.patches.crunchyroll.ads
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.extensions.fieldReference
import app.revanced.patcher.extensions.getInstruction
import app.revanced.patcher.extensions.instructions
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstruction
import app.revanced.util.removeFlags
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
@Suppress("unused")
val hideAdsPatch = bytecodePatch("Hide ads") {
@ -22,7 +21,7 @@ val hideAdsPatch = bytecodePatch("Hide ads") {
val stringIndex = videoUrlReadyToStringMethodMatch[-1]
val fieldIndex = it.indexOfFirstInstruction(stringIndex, Opcode.IGET_BOOLEAN)
it.getInstruction<ReferenceInstruction>(fieldIndex).getReference<FieldReference>()!!
it.getInstruction<ReferenceInstruction>(fieldIndex).fieldReference!!
}
// Remove final access flag on field.

View file

@ -2,23 +2,20 @@ package app.revanced.patches.googlenews.misc.extension.hooks
import app.revanced.patcher.definingClass
import app.revanced.patcher.extensions.instructions
import app.revanced.patcher.instructions
import app.revanced.patcher.invoke
import app.revanced.patcher.extensions.methodReference
import app.revanced.patcher.name
import app.revanced.patcher.opcodes
import app.revanced.patches.shared.misc.extension.extensionHook
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
private var getApplicationContextIndex = -1
internal val startActivityInitHook = extensionHook(
getInsertIndex = {
getApplicationContextIndex = indexOfFirstInstructionOrThrow {
getReference<MethodReference>()?.name == "getApplicationContext"
methodReference?.name == "getApplicationContext"
}
getApplicationContextIndex + 2 // Below the move-result-object instruction.

View file

@ -2,23 +2,20 @@ package app.revanced.patches.googlephotos.misc.extension
import app.revanced.patcher.definingClass
import app.revanced.patcher.extensions.instructions
import app.revanced.patcher.instructions
import app.revanced.patcher.invoke
import app.revanced.patcher.extensions.methodReference
import app.revanced.patcher.name
import app.revanced.patcher.opcodes
import app.revanced.patches.shared.misc.extension.extensionHook
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
private var getApplicationContextIndex = -1
internal val homeActivityInitHook = extensionHook(
getInsertIndex = {
getApplicationContextIndex = indexOfFirstInstructionOrThrow {
getReference<MethodReference>()?.name == "getApplicationContext"
methodReference?.name == "getApplicationContext"
}
getApplicationContextIndex + 2 // Below the move-result-object instruction.

View file

@ -2,12 +2,11 @@ package app.revanced.patches.googlephotos.misc.features
import app.revanced.patcher.extensions.instructions
import app.revanced.patcher.extensions.replaceInstruction
import app.revanced.patcher.extensions.stringReference
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patcher.patch.stringsOption
import app.revanced.util.getReference
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.StringReference
@Suppress("unused")
val spoofFeaturesPatch = bytecodePatch(
@ -62,7 +61,7 @@ val spoofFeaturesPatch = bytecodePatch(
initializeFeaturesEnumMethod.apply {
instructions.filter { it.opcode == Opcode.CONST_STRING }.forEach {
val feature = it.getReference<StringReference>()!!.string
val feature = it.stringReference!!.string
val spoofedFeature = when (feature) {
in featuresToEnable -> "android.hardware.wifi"

View file

@ -7,10 +7,6 @@ import app.revanced.patches.googlephotos.misc.extension.extensionPatch
import app.revanced.patches.googlephotos.misc.gms.Constants.PHOTOS_PACKAGE_NAME
import app.revanced.patches.googlephotos.misc.gms.Constants.REVANCED_PHOTOS_PACKAGE_NAME
import app.revanced.patches.shared.misc.gms.gmsCoreSupportPatch
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
@Suppress("unused")

View file

@ -9,10 +9,8 @@ import app.revanced.patcher.immutableClassDef
import app.revanced.patcher.name
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.instagram.misc.extension.sharedExtensionPatch
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
internal const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/instagram/feed/LimitFeedToFollowedProfiles;"
@ -40,7 +38,7 @@ val limitFeedToFollowedProfilesPatch = bytecodePatch(
reference?.type == "Ljava/util/Map;" &&
reference.definingClass == mainFeedRequestClassMethod.classDef.type
}.let { instructionIndex ->
getInstruction(instructionIndex).getReference<FieldReference>()!!.name
getInstruction(instructionIndex).fieldReference!!.name
}
}
@ -49,7 +47,7 @@ val limitFeedToFollowedProfilesPatch = bytecodePatch(
}.apply {
// Finds the instruction where the map is being initialized in the constructor
val getHeaderIndex = indexOfFirstInstructionOrThrow {
getReference<FieldReference>().let {
fieldReference.let {
it?.name == mainFeedRequestHeaderFieldName
}
}

View file

@ -1,5 +1,6 @@
package app.revanced.patches.instagram.hide.navigation
import app.revanced.patcher.extensions.fieldReference
import app.revanced.patcher.extensions.getInstruction
import app.revanced.patcher.firstMethodDeclaratively
import app.revanced.patcher.immutableClassDef
@ -9,12 +10,10 @@ import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.instagram.misc.extension.sharedExtensionPatch
import app.revanced.util.addInstructionsAtControlFlowLabel
import app.revanced.util.findFreeRegister
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
import java.util.logging.Logger
private const val EXTENSION_CLASS_DESCRIPTOR =
@ -82,7 +81,7 @@ val hideNavigationButtonsPatch = bytecodePatch(
opcode == Opcode.IPUT_OBJECT &&
(this as TwoRegisterInstruction).registerA == 2 // p2 register.
}.let {
method.getInstruction(it).getReference<FieldReference>()!!.name
method.getInstruction(it).fieldReference!!.name
}
}

View file

@ -2,6 +2,7 @@ package app.revanced.patches.music.layout.branding
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.extensions.getInstruction
import app.revanced.patcher.extensions.typeReference
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.music.misc.extension.sharedExtensionPatch
import app.revanced.patches.music.misc.gms.Constants.MUSIC_MAIN_ACTIVITY_NAME
@ -12,12 +13,10 @@ import app.revanced.patches.shared.layout.branding.EXTENSION_CLASS_DESCRIPTOR
import app.revanced.patches.shared.layout.branding.baseCustomBrandingPatch
import app.revanced.patches.shared.misc.mapping.ResourceType
import app.revanced.patches.shared.misc.mapping.resourceMappingPatch
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.indexOfFirstLiteralInstructionOrThrow
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.TypeReference
private val disableSplashAnimationPatch = bytecodePatch {
@ -37,7 +36,7 @@ private val disableSplashAnimationPatch = bytecodePatch {
)
val checkCastIndex = indexOfFirstInstructionOrThrow(literalIndex) {
opcode == Opcode.CHECK_CAST &&
getReference<TypeReference>()?.type == "Lcom/airbnb/lottie/LottieAnimationView;"
typeReference?.type == "Lcom/airbnb/lottie/LottieAnimationView;"
}
val register = getInstruction<OneRegisterInstruction>(checkCastIndex).registerA

View file

@ -4,6 +4,7 @@ package app.revanced.patches.music.layout.miniplayercolor
import app.revanced.patcher.accessFlags
import app.revanced.patcher.extensions.getInstruction
import app.revanced.patcher.extensions.methodReference
import app.revanced.patcher.firstMethodDeclaratively
import app.revanced.patcher.parameterTypes
import app.revanced.patcher.patch.bytecodePatch
@ -20,7 +21,6 @@ import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
private const val EXTENSION_CLASS_DESCRIPTOR =
"Lapp/revanced/extension/music/patches/ChangeMiniplayerColorPatch;"
@ -72,7 +72,7 @@ val changeMiniplayerColorPatch = bytecodePatch(
val colorGreyIndex =
miniPlayerConstructorMethodMatch.immutableMethod.indexOfFirstInstructionReversedOrThrow {
getReference<MethodReference>()?.name == "getColor"
methodReference?.name == "getColor"
}
val iPutIndex =
miniPlayerConstructorMethodMatch.immutableMethod.indexOfFirstInstructionOrThrow(

View file

@ -1,15 +1,14 @@
package app.revanced.patches.openinghours.misc.fix.crash
import app.revanced.patcher.extensions.instructions
import app.revanced.patcher.extensions.methodReference
import app.revanced.patcher.extensions.newLabel
import app.revanced.patcher.extensions.replaceInstruction
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.util.getReference
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction21t
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.Instruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
@Suppress("unused")
val fixCrashPatch = bytecodePatch(
@ -78,7 +77,7 @@ val fixCrashPatch = bytecodePatch(
}
private fun isInvokeInstruction(instruction: Instruction, className: String, methodName: String): Boolean {
val methodRef = instruction.getReference<MethodReference>() ?: return false
val methodRef = instruction.methodReference ?: return false
return methodRef.definingClass == className && methodRef.name == methodName
}

View file

@ -3,11 +3,10 @@ package app.revanced.patches.piccomafr.tracking
import app.revanced.patcher.extensions.addInstruction
import app.revanced.patcher.extensions.instructions
import app.revanced.patcher.extensions.replaceInstruction
import app.revanced.patcher.extensions.stringReference
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.util.getReference
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.StringReference
@Suppress("unused")
val disableTrackingPatch = bytecodePatch(
@ -48,7 +47,7 @@ val disableTrackingPatch = bytecodePatch(
firebaseInstallMethod.instructions.filter {
it.opcode == Opcode.CONST_STRING
}.filter {
it.getReference<StringReference>()?.string == "firebaseinstallations.googleapis.com"
it.stringReference?.string == "firebaseinstallations.googleapis.com"
}.forEach { instruction ->
instruction as OneRegisterInstruction

View file

@ -2,14 +2,13 @@ package app.revanced.patches.primevideo.ads
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.extensions.getInstruction
import app.revanced.patcher.extensions.methodReference
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.primevideo.misc.extension.sharedExtensionPatch
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
@Suppress("unused")
val skipAdsPatch = bytecodePatch(
@ -32,7 +31,7 @@ val skipAdsPatch = bytecodePatch(
// move-result-object { playerRegister }
val getPlayerIndex = indexOfFirstInstructionOrThrow {
opcode == Opcode.INVOKE_VIRTUAL &&
getReference<MethodReference>()?.name == "getPrimaryPlayer"
methodReference?.name == "getPrimaryPlayer"
}
val playerRegister = getInstruction<OneRegisterInstruction>(getPlayerIndex + 1).registerA

View file

@ -1,14 +1,13 @@
package app.revanced.patches.primevideo.video.speed
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.extensions.fieldReference
import app.revanced.patcher.extensions.getInstruction
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.primevideo.misc.extension.sharedExtensionPatch
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
private const val EXTENSION_CLASS_DESCRIPTOR =
"Lapp/revanced/extension/primevideo/videoplayer/PlaybackSpeedPatch;"
@ -30,7 +29,7 @@ val playbackSpeedPatch = bytecodePatch(
playbackUserControlsInitializeMethod.apply {
val getIndex = indexOfFirstInstructionOrThrow {
opcode == Opcode.IPUT_OBJECT &&
getReference<FieldReference>()?.name == "mUserControls"
fieldReference?.name == "mUserControls"
}
val getRegister = getInstruction<OneRegisterInstruction>(getIndex).registerA

View file

@ -1,13 +1,12 @@
package app.revanced.patches.protonvpn.splittunneling
import app.revanced.patcher.extensions.getInstruction
import app.revanced.patcher.extensions.methodReference
import app.revanced.patcher.extensions.removeInstruction
import app.revanced.patcher.extensions.replaceInstruction
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
@Suppress("unused")
val unlockSplitTunnelingPatch = bytecodePatch("Unlock split tunneling") {
@ -22,7 +21,7 @@ val unlockSplitTunnelingPatch = bytecodePatch("Unlock split tunneling") {
initializeSplitTunnelingSettingsUIMethod.apply {
val initSettingsIndex = indexOfFirstInstructionOrThrow {
getReference<MethodReference>()?.name == "getSplitTunneling"
methodReference?.name == "getSplitTunneling"
}
removeInstruction(initSettingsIndex - 1)
}

View file

@ -1,17 +1,16 @@
package app.revanced.patches.reddit.ad.general
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.extensions.methodReference
import app.revanced.patcher.extensions.removeInstruction
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.reddit.ad.comments.hideCommentAdsPatch
import app.revanced.patches.reddit.misc.extension.sharedExtensionPatch
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstruction
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction22c
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
@Suppress("unused")
val hideAdsPatch = bytecodePatch("Hide ads") {
@ -57,7 +56,7 @@ val hideAdsPatch = bytecodePatch("Hide ads") {
// By removing the appending instruction no ad posts gets appended to the feed.
val index = newAdPostMethod.indexOfFirstInstruction {
val reference = getReference<MethodReference>() ?: return@indexOfFirstInstruction false
val reference = methodReference ?: return@indexOfFirstInstruction false
reference.name == "add" && reference.definingClass == "Ljava/util/ArrayList;"
}

View file

@ -1,17 +1,16 @@
package app.revanced.patches.reddit.customclients.baconreader.fix.redgifs
import app.revanced.patcher.extensions.getInstruction
import app.revanced.patcher.extensions.methodReference
import app.revanced.patcher.extensions.removeInstructions
import app.revanced.patcher.extensions.replaceInstruction
import app.revanced.patcher.extensions.typeReference
import app.revanced.patches.reddit.customclients.INSTALL_NEW_CLIENT_METHOD
import app.revanced.patches.reddit.customclients.baconreader.misc.extension.sharedExtensionPatch
import app.revanced.patches.reddit.customclients.fixRedgifsApiPatch
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
internal const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/baconreader/FixRedgifsApiPatch;"
@ -34,7 +33,7 @@ val fixRedgifsApi = fixRedgifsApiPatch(
getOkHttpClientMethod.removeInstructions(originalInterceptorInstallIndex, 5)
val index = getOkHttpClientMethod.indexOfFirstInstructionOrThrow {
val reference = getReference<MethodReference>()
val reference = methodReference
reference?.name == "build" && reference.definingClass == $$"Lokhttp3/OkHttpClient$Builder;"
}
val register = getOkHttpClientMethod.getInstruction<FiveRegisterInstruction>(index).registerC

View file

@ -2,13 +2,12 @@ package app.revanced.patches.reddit.customclients.boostforreddit.api
import app.revanced.patcher.extensions.getInstruction
import app.revanced.patcher.extensions.replaceInstruction
import app.revanced.patcher.extensions.stringReference
import app.revanced.patches.reddit.customclients.spoofClientPatch
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.returnEarly
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.StringReference
@Suppress("unused")
val spoofClientPatch = spoofClientPatch(redirectUri = "http://rubenmayayo.com") { clientIdOption ->
@ -30,7 +29,7 @@ val spoofClientPatch = spoofClientPatch(redirectUri = "http://rubenmayayo.com")
val userAgent = "$randomName:app.revanced.$randomName:v1.0.0 (by /u/revanced)"
val userAgentTemplateIndex = buildUserAgentMethod.indexOfFirstInstructionOrThrow {
opcode == Opcode.CONST_STRING && getReference<StringReference>()?.string == "%s:%s:%s (by /u/%s)"
opcode == Opcode.CONST_STRING && stringReference?.string == "%s:%s:%s (by /u/%s)"
}
val register = buildUserAgentMethod.getInstruction<OneRegisterInstruction>(userAgentTemplateIndex).registerA

View file

@ -3,12 +3,11 @@ package app.revanced.patches.reddit.customclients.redditisfun.api
import app.revanced.patcher.CompositeMatch
import app.revanced.patcher.extensions.getInstruction
import app.revanced.patcher.extensions.replaceInstruction
import app.revanced.patcher.extensions.stringReference
import app.revanced.patches.reddit.customclients.spoofClientPatch
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.returnEarly
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.StringReference
@Suppress("unused")
val spoofClientPatch = spoofClientPatch(redirectUri = "redditisfun://auth") { clientIdOption ->
@ -64,7 +63,7 @@ val spoofClientPatch = spoofClientPatch(redirectUri = "redditisfun://auth") { cl
// Replace old.reddit.com with www.reddit.com to fix this.
buildAuthorizationStringMethodMatch.method.apply {
val index = indexOfFirstInstructionOrThrow {
getReference<StringReference>()?.contains("old.reddit.com") == true
stringReference?.contains("old.reddit.com") == true
}
val targetRegister = getInstruction<OneRegisterInstruction>(index).registerA

View file

@ -2,14 +2,13 @@ package app.revanced.patches.reddit.customclients.sync.syncforreddit.fix.redgifs
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.extensions.getInstruction
import app.revanced.patcher.extensions.methodReference
import app.revanced.patcher.extensions.replaceInstruction
import app.revanced.patches.reddit.customclients.INSTALL_NEW_CLIENT_METHOD
import app.revanced.patches.reddit.customclients.fixRedgifsApiPatch
import app.revanced.patches.reddit.customclients.sync.syncforreddit.extension.sharedExtensionPatch
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
internal const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/syncforreddit/FixRedgifsApiPatch;"
@ -27,7 +26,7 @@ val fixRedgifsApi = fixRedgifsApiPatch(
// region Patch Redgifs OkHttp3 client.
val index = createOkHttpClientMethod.indexOfFirstInstructionOrThrow {
val reference = getReference<MethodReference>()
val reference = methodReference
reference?.name == "build" && reference.definingClass == $$"Lokhttp3/OkHttpClient$Builder;"
}
val register = createOkHttpClientMethod.getInstruction<FiveRegisterInstruction>(index).registerC

View file

@ -2,12 +2,11 @@ package app.revanced.patches.samsung.radio.restrictions.device
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.extensions.removeInstructions
import app.revanced.patcher.extensions.stringReference
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.util.findFreeRegister
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.reference.StringReference
private const val EXTENSION_CLASS_DESCRIPTOR =
"Lapp/revanced/extension/samsung/radio/restrictions/device/BypassDeviceChecksPatch;"
@ -25,7 +24,7 @@ val bypassDeviceChecksPatch = bytecodePatch(
// Find the first string that start with "SM-", that's the list of incompatible devices.
val firstStringIndex = checkDeviceMethod.indexOfFirstInstructionOrThrow {
opcode == Opcode.CONST_STRING &&
getReference<StringReference>()?.string?.startsWith("SM-") == true
stringReference?.string?.startsWith("SM-") == true
}
// Find the following filled-new-array (or filled-new-array/range) instruction.

View file

@ -2,7 +2,9 @@ package app.revanced.patches.shared.layout.branding
import app.revanced.com.android.tools.smali.dexlib2.mutable.MutableMethod
import app.revanced.patcher.extensions.addInstruction
import app.revanced.patcher.extensions.fieldReference
import app.revanced.patcher.extensions.getInstruction
import app.revanced.patcher.extensions.typeReference
import app.revanced.patcher.patch.*
import app.revanced.patches.all.misc.packagename.setOrGetFallbackPackageName
import app.revanced.patches.all.misc.resources.addResources
@ -14,8 +16,6 @@ import app.revanced.util.*
import app.revanced.util.Utils.trimIndentMultiline
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
import com.android.tools.smali.dexlib2.iface.reference.TypeReference
import org.w3c.dom.Element
import org.w3c.dom.NodeList
import java.io.File
@ -125,22 +125,22 @@ internal fun baseCustomBrandingPatch(
val getBuilderIndex = if (isYouTubeMusic) {
// YT Music the field is not a plain object type.
indexOfFirstInstructionOrThrow {
getReference<FieldReference>()?.type == $$"Landroid/app/Notification$Builder;"
fieldReference?.type == $$"Landroid/app/Notification$Builder;"
}
} else {
// Find the field name of the notification builder. Field is an Object type.
val builderCastIndex = indexOfFirstInstructionOrThrow {
val reference = getReference<TypeReference>()
val reference = typeReference
opcode == Opcode.CHECK_CAST &&
reference?.type == $$"Landroid/app/Notification$Builder;"
}
indexOfFirstInstructionReversedOrThrow(builderCastIndex) {
getReference<FieldReference>()?.type == "Ljava/lang/Object;"
fieldReference?.type == "Ljava/lang/Object;"
}
}
val builderFieldName = getInstruction<ReferenceInstruction>(getBuilderIndex)
.getReference<FieldReference>()
.fieldReference
findInstructionIndicesReversedOrThrow(
Opcode.RETURN_VOID,

View file

@ -20,7 +20,6 @@ import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
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.TwoRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
import com.android.tools.smali.dexlib2.immutable.ImmutableMethod
import com.android.tools.smali.dexlib2.immutable.ImmutableMethodParameter
@ -123,7 +122,7 @@ internal fun spoofVideoStreamsPatch(
val resultMethodType = createStreamingDataMethodMatch.classDef.type
val videoDetailsIndex = createStreamingDataMethodMatch[-1]
val videoDetailsRegister = getInstruction<TwoRegisterInstruction>(videoDetailsIndex).registerA
val videoDetailsClass = getInstruction(videoDetailsIndex).getReference<FieldReference>()!!.type
val videoDetailsClass = getInstruction(videoDetailsIndex).fieldReference!!.type
addInstruction(
videoDetailsIndex + 1,
@ -135,15 +134,15 @@ internal fun spoofVideoStreamsPatch(
val setStreamingDataIndex = createStreamingDataMethodMatch[0]
val playerProtoClass = getInstruction(setStreamingDataIndex + 1)
.getReference<FieldReference>()!!.definingClass
.fieldReference!!.definingClass
val setStreamingDataField = getInstruction(setStreamingDataIndex).getReference<FieldReference>()
val setStreamingDataField = getInstruction(setStreamingDataIndex).fieldReference
val getStreamingDataField = getInstruction(
indexOfFirstInstructionOrThrow {
opcode == Opcode.IGET_OBJECT && getReference<FieldReference>()?.definingClass == playerProtoClass
opcode == Opcode.IGET_OBJECT && fieldReference?.definingClass == playerProtoClass
},
).getReference<FieldReference>()
).fieldReference
// Use a helper method to avoid the need of picking out multiple free registers from the hooked code.
createStreamingDataMethodMatch.classDef.methods.add(
@ -275,7 +274,7 @@ internal fun spoofVideoStreamsPatch(
val mediaFetchEnumClass = definingClass
val sabrFieldIndex = indexOfFirstInstructionOrThrow(disabledBySABRStreamingUrlString) {
opcode == Opcode.SPUT_OBJECT &&
getReference<FieldReference>()?.type == mediaFetchEnumClass
fieldReference?.type == mediaFetchEnumClass
}
Pair(

View file

@ -1,16 +1,15 @@
package app.revanced.patches.shared.misc.spoof
import app.revanced.patcher.extensions.getInstruction
import app.revanced.patcher.extensions.methodReference
import app.revanced.patcher.extensions.replaceInstruction
import app.revanced.patcher.extensions.stringReference
import app.revanced.patches.all.misc.transformation.IMethodCall
import app.revanced.patches.all.misc.transformation.filterMapInstruction35c
import app.revanced.patches.all.misc.transformation.transformInstructionsPatch
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstruction
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
import com.android.tools.smali.dexlib2.iface.reference.StringReference
private const val USER_AGENT_STRING_BUILDER_APPEND_METHOD_REFERENCE =
"Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;"
@ -37,7 +36,7 @@ fun userAgentClientSpoofPatch(originalPackageName: String) = transformInstructio
// IndexOutOfBoundsException is technically possible here,
// but no such occurrences are present in the app.
val referee = getInstruction(instructionIndex + 2).getReference<MethodReference>()?.toString()
val referee = getInstruction(instructionIndex + 2).methodReference?.toString()
// Only replace string builder usage.
if (referee != USER_AGENT_STRING_BUILDER_APPEND_METHOD_REFERENCE) {
@ -48,7 +47,7 @@ fun userAgentClientSpoofPatch(originalPackageName: String) = transformInstructio
// Changing these package names will result in playback limitations,
// particularly Android VR background audio only playback.
val resourceOrGmsStringInstructionIndex = indexOfFirstInstruction {
val reference = getReference<StringReference>()
val reference = stringReference
opcode == Opcode.CONST_STRING &&
(reference?.string == "android.resource://" || reference?.string == "gcore_")
}

View file

@ -1,12 +1,11 @@
package app.revanced.patches.shared.misc.string
import app.revanced.patcher.extensions.replaceInstruction
import app.revanced.patcher.extensions.stringReference
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.all.misc.transformation.transformInstructionsPatch
import app.revanced.util.getReference
import com.android.tools.smali.dexlib2.ReferenceType
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.StringReference
import kotlin.text.contains
fun replaceStringPatch(
@ -20,7 +19,7 @@ fun replaceStringPatch(
filterMap = filterMap@{ _, _, instruction, instructionIndex ->
if (instruction.opcode.referenceType != ReferenceType.STRING) return@filterMap null
val stringReference = instruction.getReference<StringReference>()!!.string
val stringReference = instruction.stringReference!!.string
if (from !in stringReference) return@filterMap null
Triple(instructionIndex, instruction as OneRegisterInstruction, stringReference)

View file

@ -3,10 +3,8 @@ package app.revanced.patches.soundcloud.offlinesync
import app.revanced.patcher.extensions.*
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.soundcloud.shared.featureConstructorMethod
import app.revanced.util.getReference
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
@Suppress("unused")
val enableOfflineSyncPatch = bytecodePatch("Enable offline sync") {
@ -40,7 +38,7 @@ val enableOfflineSyncPatch = bytecodePatch("Enable offline sync") {
val getEndpointsEnumFieldInstruction = getInstruction<OneRegisterInstruction>(getEndpointsEnumFieldIndex)
val targetRegister = getEndpointsEnumFieldInstruction.registerA
val endpointsType = getEndpointsEnumFieldInstruction.getReference<FieldReference>()!!.type
val endpointsType = getEndpointsEnumFieldInstruction.fieldReference!!.type
replaceInstruction(
getEndpointsEnumFieldIndex,

View file

@ -2,16 +2,15 @@ package app.revanced.patches.spotify.layout.theme
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.extensions.getInstruction
import app.revanced.patcher.extensions.methodReference
import app.revanced.patcher.immutableClassDef
import app.revanced.patcher.patch.booleanOption
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patcher.patch.resourcePatch
import app.revanced.patcher.patch.stringOption
import app.revanced.patches.spotify.misc.extension.sharedExtensionPatch
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
import org.w3c.dom.Element
private const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/spotify/layout/theme/CustomThemePatch;"
@ -39,7 +38,7 @@ private val customThemeBytecodePatch = bytecodePatch {
// including the solid color of it.
parseLottieJsonMethod.apply {
val invokeParseColorIndex = indexOfFirstInstructionOrThrow {
val reference = getReference<MethodReference>()
val reference = methodReference
reference?.definingClass == "Landroid/graphics/Color;" &&
reference.name == "parseColor"
}
@ -60,7 +59,7 @@ private val customThemeBytecodePatch = bytecodePatch {
// Lottie animated color parser.
parseAnimatedColorMethod.apply {
val invokeArgbIndex = indexOfFirstInstructionOrThrow {
val reference = getReference<MethodReference>()
val reference = methodReference
reference?.definingClass == "Landroid/graphics/Color;" &&
reference.name == "argb"
}

View file

@ -1,15 +1,14 @@
package app.revanced.patches.spotify.misc.extension
import app.revanced.patcher.extensions.fieldReference
import app.revanced.patcher.extensions.getInstruction
import app.revanced.patcher.extensions.string
import app.revanced.patcher.instructions
import app.revanced.patcher.invoke
import app.revanced.patches.shared.misc.extension.activityOnCreateExtensionHook
import app.revanced.patches.shared.misc.extension.extensionHook
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstruction
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
internal val mainActivityOnCreateHook = activityOnCreateExtensionHook(
"Lcom/spotify/music/SpotifyMainActivity;"
@ -25,7 +24,7 @@ internal val loadOrbitLibraryHook = extensionHook(
},
getContextRegister = {
contextReferenceIndex = indexOfFirstInstruction {
getReference<FieldReference>()?.type == "Landroid/content/Context;"
fieldReference?.type == "Landroid/content/Context;"
}
val contextRegister =
getInstruction<TwoRegisterInstruction>(contextReferenceIndex).registerA

View file

@ -4,6 +4,7 @@ import app.revanced.com.android.tools.smali.dexlib2.mutable.MutableMethod
import app.revanced.patcher.classDef
import app.revanced.patcher.extensions.addInstruction
import app.revanced.patcher.extensions.getInstruction
import app.revanced.patcher.extensions.methodReference
import app.revanced.patcher.extensions.replaceInstruction
import app.revanced.patcher.firstMethodDeclaratively
import app.revanced.patcher.instructions
@ -12,13 +13,10 @@ import app.revanced.patcher.parameterTypes
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patcher.patch.stringOption
import app.revanced.patcher.returnType
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstruction
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.indexOfFirstInstructionReversedOrThrow
import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction35c
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
import com.android.tools.smali.dexlib2.immutable.reference.ImmutableMethodReference
import java.net.InetAddress
import java.net.URI
@ -70,10 +68,10 @@ val changeLyricsProviderPatch = bytecodePatch(
val patchedHttpClientBuilderMethod = with(httpClientBuilderMethod) {
val invokeBuildUrlIndex = indexOfFirstInstructionOrThrow {
getReference<MethodReference>()?.returnType == "Lokhttp3/HttpUrl;"
methodReference?.returnType == "Lokhttp3/HttpUrl;"
}
val setUrlBuilderHostIndex = indexOfFirstInstructionReversedOrThrow(invokeBuildUrlIndex) {
val reference = getReference<MethodReference>()
val reference = methodReference
reference?.definingClass == "Lokhttp3/HttpUrl${"$"}Builder;" &&
reference.parameterTypes.firstOrNull() == "Ljava/lang/String;"
}
@ -103,7 +101,7 @@ val changeLyricsProviderPatch = bytecodePatch(
getLyricsHttpClientMethod.apply {
val getLyricsHttpClientIndex = indexOfFirstInstructionOrThrow {
getReference<MethodReference>() == httpClientBuilderMethod
methodReference == httpClientBuilderMethod
}
val getLyricsHttpClientInstruction = getInstruction<BuilderInstruction35c>(getLyricsHttpClientIndex)

View file

@ -1,12 +1,7 @@
package app.revanced.patches.spotify.misc.lyrics
import app.revanced.patcher.gettingFirstImmutableMethod
import app.revanced.patcher.gettingFirstImmutableMethodDeclaratively
import app.revanced.patcher.parameterTypes
import app.revanced.patcher.patch.BytecodePatchContext
import app.revanced.patcher.returnType
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
internal val BytecodePatchContext.httpClientBuilderMethod by gettingFirstImmutableMethod("client == null", "scheduler == null")

View file

@ -4,12 +4,12 @@ import app.revanced.com.android.tools.smali.dexlib2.mutable.MutableMethod.Compan
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.extensions.getInstruction
import app.revanced.patcher.extensions.instructions
import app.revanced.patcher.extensions.typeReference
import app.revanced.patcher.immutableClassDef
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patcher.patch.resourcePatch
import app.revanced.util.childElementsSequence
import app.revanced.util.findElementByAttributeValueOrThrow
import app.revanced.util.getReference
import com.android.tools.smali.dexlib2.AccessFlags.*
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.builder.MutableMethodImplementation
@ -18,7 +18,6 @@ import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction21c
import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction31i
import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction35c
import com.android.tools.smali.dexlib2.iface.instruction.NarrowLiteralInstruction
import com.android.tools.smali.dexlib2.iface.reference.TypeReference
import com.android.tools.smali.dexlib2.immutable.ImmutableClassDef
import com.android.tools.smali.dexlib2.immutable.ImmutableField
import com.android.tools.smali.dexlib2.immutable.ImmutableMethod
@ -115,7 +114,7 @@ val addGiveGroupKudosButtonToGroupActivityPatch = bytecodePatch(
val checkCastButtonInstruction =
getInstruction<BuilderInstruction21c>(constLeaveIdInstruction.location.index + 3)
val buttonClassName = checkCastButtonInstruction.getReference<TypeReference>()!!.type
val buttonClassName = checkCastButtonInstruction.typeReference!!.type
addInstructions(
constLeaveIdInstruction.location.index,

View file

@ -4,19 +4,18 @@ import app.revanced.patcher.extensions.ExternalLabel
import app.revanced.patcher.extensions.addInstruction
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.extensions.addInstructionsWithLabels
import app.revanced.patcher.extensions.fieldReference
import app.revanced.patcher.extensions.getInstruction
import app.revanced.patcher.extensions.instructions
import app.revanced.patcher.extensions.typeReference
import app.revanced.patcher.firstImmutableClassDef
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.shared.misc.mapping.ResourceType
import app.revanced.patches.shared.misc.mapping.resourceMappingPatch
import app.revanced.patches.strava.misc.extension.sharedExtensionPatch
import app.revanced.util.getReference
import app.revanced.util.writeRegister
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction22c
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
import com.android.tools.smali.dexlib2.iface.reference.TypeReference
private const val ACTION_CLASS_DESCRIPTOR = "Lcom/strava/bottomsheet/Action;"
private const val MEDIA_CLASS_DESCRIPTOR = "Lcom/strava/photos/data/Media;"
@ -45,7 +44,7 @@ val addMediaDownloadPatch = bytecodePatch(
}
val actionRegistrarRegister = getInstruction<BuilderInstruction22c>(setTrueIndex).registerB
val actionRegister = instructions.first { instruction ->
instruction.getReference<TypeReference>()?.type == ACTION_CLASS_DESCRIPTOR
instruction.typeReference?.type == ACTION_CLASS_DESCRIPTOR
}.writeRegister!!
fun addMenuItem(actionId: String, string: String, color: String, drawable: String) = addInstructions(
@ -74,7 +73,7 @@ val addMediaDownloadPatch = bytecodePatch(
// Move media to last parameter of `Action` constructor.
val getMediaInstruction = instructions.first { instruction ->
instruction.getReference<FieldReference>()?.type == MEDIA_CLASS_DESCRIPTOR
instruction.fieldReference?.type == MEDIA_CLASS_DESCRIPTOR
}
addInstruction(
getMediaInstruction.location.index + 1,

View file

@ -6,11 +6,9 @@ import app.revanced.patches.tiktok.misc.extension.sharedExtensionPatch
import app.revanced.patches.tiktok.misc.settings.settingsPatch
import app.revanced.patches.tiktok.misc.settings.settingsStatusLoadMethod
import app.revanced.util.findInstructionIndicesReversedOrThrow
import app.revanced.util.getReference
import app.revanced.util.returnEarly
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
private const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/tiktok/download/DownloadsPatch;"
@ -50,7 +48,7 @@ val downloadsPatch = bytecodePatch(
// Change the download path patch.
downloadUriMethod.apply {
findInstructionIndicesReversedOrThrow {
getReference<FieldReference>().let {
fieldReference.let {
it?.definingClass == "Landroid/os/Environment;" && it.name.startsWith("DIRECTORY_")
}
}.forEach { fieldIndex ->

View file

@ -4,15 +4,13 @@ import app.revanced.patcher.classDef
import app.revanced.patcher.extensions.addInstruction
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.extensions.getInstruction
import app.revanced.patcher.firstClassDef
import app.revanced.patcher.extensions.methodReference
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.tiktok.shared.getEnterFromMethod
import app.revanced.patches.tiktok.shared.onRenderFirstFrameMethod
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.returnEarly
import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction11x
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
@Suppress("unused")
val playbackSpeedPatch = bytecodePatch(
@ -28,7 +26,7 @@ val playbackSpeedPatch = bytecodePatch(
apply {
getSpeedMethod.apply {
val injectIndex =
indexOfFirstInstructionOrThrow { getReference<MethodReference>()?.returnType == "F" } + 2
indexOfFirstInstructionOrThrow { methodReference?.returnType == "F" } + 2
val register = getInstruction<Instruction11x>(injectIndex - 1).registerA
addInstruction(

View file

@ -2,10 +2,10 @@ package app.revanced.patches.tiktok.misc.share
import app.revanced.patcher.extensions.addInstructionsWithLabels
import app.revanced.patcher.extensions.getInstruction
import app.revanced.patcher.extensions.methodReference
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.tiktok.misc.extension.sharedExtensionPatch
import app.revanced.util.findFreeRegister
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
@ -30,7 +30,7 @@ val sanitizeSharingLinksPatch = bytecodePatch(
apply {
urlShorteningMethod.apply {
val invokeIndex = indexOfFirstInstructionOrThrow {
val reference = getReference<MethodReference>()
val reference = methodReference
reference?.name == "LIZ" && reference.definingClass.startsWith("LX/")
}
@ -43,7 +43,7 @@ val sanitizeSharingLinksPatch = bytecodePatch(
.reference.toString()
val observableFactoryIndex = indexOfFirstInstructionOrThrow {
val ref = getReference<MethodReference>()
val ref = methodReference
ref?.name == "LJ" && ref.definingClass.startsWith("LX/")
}
val observableFactoryRef = getInstruction<ReferenceInstruction>(observableFactoryIndex)

View file

@ -14,10 +14,8 @@ import app.revanced.patches.youtube.misc.playservice.versionCheckPatch
import app.revanced.patches.youtube.misc.settings.PreferenceScreen
import app.revanced.patches.youtube.misc.settings.settingsPatch
import app.revanced.util.findInstructionIndicesReversed
import app.revanced.util.getReference
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
private const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/youtube/patches/SlideToSeekPatch;"
@ -45,7 +43,7 @@ val enableSlideToSeekPatch = bytecodePatch(
val checkIndex = slideToSeekMethodMatch[0]
val checkReference = slideToSeekMethodMatch.method.getInstruction(checkIndex)
.getReference<MethodReference>()!!
.methodReference!!
val extensionMethodDescriptor = "$EXTENSION_CLASS_DESCRIPTOR->isSlideToSeekDisabled(Z)Z"

View file

@ -3,6 +3,7 @@ package app.revanced.patches.youtube.interaction.seekbar
import app.revanced.patcher.extensions.ExternalLabel
import app.revanced.patcher.extensions.addInstructionsWithLabels
import app.revanced.patcher.extensions.getInstruction
import app.revanced.patcher.extensions.methodReference
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.all.misc.resources.addResources
import app.revanced.patches.all.misc.resources.addResourcesPatch
@ -12,8 +13,6 @@ import app.revanced.patches.youtube.misc.settings.PreferenceScreen
import app.revanced.patches.youtube.misc.settings.settingsPatch
import app.revanced.util.findFreeRegister
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.MethodReference
private const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/youtube/patches/TapToSeekPatch;"
@ -35,8 +34,7 @@ val enableTapToSeekPatch = bytecodePatch(
// Find the required methods to tap the seekbar.
val tapToSeekMethods = onTouchEventHandlerMethodMatch.let {
fun getReference(index: Int) = it.method.getInstruction<ReferenceInstruction>(index)
.reference as MethodReference
fun getReference(index: Int) = it.method.getInstruction(index).methodReference!!
listOf(
getReference(it[0]),

View file

@ -26,13 +26,11 @@ import app.revanced.patches.youtube.misc.settings.PreferenceScreen
import app.revanced.patches.youtube.misc.settings.settingsPatch
import app.revanced.util.addInstructionsAtControlFlowLabel
import app.revanced.util.findInstructionIndicesReversedOrThrow
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.insertLiteralOverride
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
import kotlin.collections.plusAssign
private const val EXTENSION_CLASS_DESCRIPTOR =
@ -235,7 +233,7 @@ val navigationBarPatch = bytecodePatch(
// Fix missing left padding when using wide searchbar.
wideSearchbarLayoutMethod.apply {
findInstructionIndicesReversedOrThrow {
val reference = getReference<MethodReference>()
val reference = methodReference
reference?.definingClass == "Landroid/view/LayoutInflater;" && reference.name == "inflate"
}.forEach { inflateIndex ->
val register =

View file

@ -17,12 +17,11 @@ import app.revanced.util.*
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
private const val EXTENSION_CLASS_DESCRIPTOR =
"Lapp/revanced/extension/youtube/patches/HidePlayerOverlayButtonsPatch;"
@Suppress("ObjectPropertyName")
@Suppress("unused")
val hidePlayerOverlayButtonsPatch = bytecodePatch(
name = "Hide player overlay buttons",
description = "Adds options to hide the player Cast, Autoplay, Captions, Previous & Next buttons, and the player " +
@ -121,7 +120,7 @@ val hidePlayerOverlayButtonsPatch = bytecodePatch(
// Add a conditional branch around the code that inflates and adds the auto-repeat button.
val gotoIndex = indexOfFirstInstructionOrThrow(constIndex) {
val parameterTypes = getReference<MethodReference>()?.parameterTypes
val parameterTypes = methodReference?.parameterTypes
opcode == Opcode.INVOKE_VIRTUAL &&
parameterTypes?.size == 2 &&
parameterTypes.first() == "Landroid/view/ViewStub;"

View file

@ -2,6 +2,7 @@ package app.revanced.patches.youtube.layout.hide.fullscreenambientmode
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.extensions.getInstruction
import app.revanced.patcher.extensions.methodReference
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.all.misc.resources.addResources
import app.revanced.patches.all.misc.resources.addResourcesPatch
@ -9,10 +10,8 @@ import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch
import app.revanced.patches.youtube.misc.settings.PreferenceScreen
import app.revanced.patches.youtube.misc.settings.settingsPatch
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionReversedOrThrow
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
private const val EXTENSION_CLASS_DESCRIPTOR =
"Lapp/revanced/extension/youtube/patches/DisableFullscreenAmbientModePatch;"
@ -51,7 +50,7 @@ val disableFullscreenAmbientModePatch = bytecodePatch(
setFullScreenBackgroundColorMethod.apply {
val insertIndex = indexOfFirstInstructionReversedOrThrow {
getReference<MethodReference>()?.name == "setBackgroundColor"
methodReference?.name == "setBackgroundColor"
}
val register = getInstruction<FiveRegisterInstruction>(insertIndex).registerD

View file

@ -21,7 +21,6 @@ import app.revanced.patches.youtube.misc.settings.PreferenceScreen
import app.revanced.patches.youtube.misc.settings.settingsPatch
import app.revanced.util.findFreeRegister
import app.revanced.util.findInstructionIndicesReversedOrThrow
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionReversedOrThrow
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
@ -31,7 +30,6 @@ import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
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.TwoRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
import com.android.tools.smali.dexlib2.immutable.ImmutableMethod
import com.android.tools.smali.dexlib2.immutable.ImmutableMethodParameter
@ -489,7 +487,7 @@ val hideLayoutComponentsPatch = hideLayoutComponentsPatch(
yoodlesImageViewMethod.apply {
findInstructionIndicesReversedOrThrow {
getReference<MethodReference>()?.name == "setImageDrawable"
methodReference?.name == "setImageDrawable"
}.forEach { insertIndex ->
val drawableRegister = getInstruction<FiveRegisterInstruction>(insertIndex).registerD
val imageViewRegister = getInstruction<FiveRegisterInstruction>(insertIndex).registerC
@ -512,7 +510,7 @@ val hideLayoutComponentsPatch = hideLayoutComponentsPatch(
// Find the instruction where the text dimension is retrieved.
val applyDimensionIndex = indexOfFirstInstructionReversedOrThrow {
val reference = getReference<MethodReference>()
val reference = methodReference
opcode == Opcode.INVOKE_STATIC &&
reference?.definingClass == "Landroid/util/TypedValue;" &&
reference.returnType == "F" &&

View file

@ -7,7 +7,9 @@ import app.revanced.com.android.tools.smali.dexlib2.mutable.MutableMethod.Compan
import app.revanced.patcher.classDef
import app.revanced.patcher.extensions.addInstruction
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.extensions.fieldReference
import app.revanced.patcher.extensions.getInstruction
import app.revanced.patcher.extensions.methodReference
import app.revanced.patcher.extensions.replaceInstruction
import app.revanced.patcher.immutableClassDef
import app.revanced.patcher.patch.bytecodePatch
@ -29,8 +31,6 @@ import com.android.tools.smali.dexlib2.iface.ClassDef
import com.android.tools.smali.dexlib2.iface.Method
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
import com.android.tools.smali.dexlib2.immutable.ImmutableMethod
import com.android.tools.smali.dexlib2.immutable.ImmutableMethodParameter
@ -269,7 +269,7 @@ val miniplayerPatch = bytecodePatch(
it.apply {
if (AccessFlags.CONSTRUCTOR.isSet(accessFlags)) {
val iPutIndex = indexOfFirstInstructionOrThrow {
this.opcode == Opcode.IPUT && this.getReference<FieldReference>()?.type == "I"
this.opcode == Opcode.IPUT && this.fieldReference?.type == "I"
}
insertModernMiniplayerTypeOverride(iPutIndex)
@ -394,7 +394,7 @@ val miniplayerPatch = bytecodePatch(
if (is_20_31_or_greater) {
miniplayerSetIconsMethod.apply {
findInstructionIndicesReversedOrThrow {
val reference = getReference<MethodReference>()
val reference = methodReference
opcode == Opcode.INVOKE_INTERFACE &&
reference?.returnType == "Z" && reference.parameterTypes.isEmpty()
}.forEach { index ->

View file

@ -5,6 +5,7 @@ import app.revanced.com.android.tools.smali.dexlib2.mutable.MutableMethod.Compan
import app.revanced.patcher.*
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.extensions.getInstruction
import app.revanced.patcher.extensions.methodReference
import app.revanced.patcher.extensions.replaceInstruction
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.shared.layout.theme.lithoColorHookPatch
@ -18,14 +19,12 @@ import app.revanced.patches.youtube.misc.playservice.is_21_02_or_greater
import app.revanced.patches.youtube.misc.playservice.versionCheckPatch
import app.revanced.patches.youtube.shared.mainActivityOnCreateMethod
import app.revanced.util.findInstructionIndicesReversedOrThrow
import app.revanced.util.getReference
import app.revanced.util.insertLiteralOverride
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.builder.MutableMethodImplementation
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
import com.android.tools.smali.dexlib2.immutable.ImmutableMethod
import com.android.tools.smali.dexlib2.immutable.ImmutableMethodParameter
@ -158,7 +157,7 @@ val seekbarColorPatch = bytecodePatch(
val setAnimationIntMethodName = lottieAnimationViewSetAnimationIntMethod.name
findInstructionIndicesReversedOrThrow {
val reference = getReference<MethodReference>()
val reference = methodReference
reference?.definingClass == LOTTIE_ANIMATION_VIEW_CLASS_TYPE &&
reference.name == setAnimationIntMethodName
}.forEach { index ->

View file

@ -5,6 +5,7 @@ import app.revanced.patcher.classDef
import app.revanced.patcher.extensions.addInstruction
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.extensions.addInstructionsWithLabels
import app.revanced.patcher.extensions.fieldReference
import app.revanced.patcher.extensions.getInstruction
import app.revanced.patcher.extensions.methodReference
import app.revanced.patcher.immutableClassDef
@ -20,22 +21,19 @@ import app.revanced.patches.youtube.misc.settings.PreferenceScreen
import app.revanced.patches.youtube.misc.settings.settingsPatch
import app.revanced.patches.youtube.shared.mainActivityOnCreateMethod
import app.revanced.util.findInstructionIndicesReversedOrThrow
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.builder.MutableMethodImplementation
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.reference.FieldReference
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
import com.android.tools.smali.dexlib2.immutable.ImmutableMethod
import com.android.tools.smali.dexlib2.immutable.ImmutableMethodParameter
private const val EXTENSION_CLASS_DESCRIPTOR =
"Lapp/revanced/extension/youtube/patches/ShortsAutoplayPatch;"
@Suppress("ObjectPropertyName")
@Suppress("unused")
val shortsAutoplayPatch = bytecodePatch(
name = "Shorts autoplay",
description = "Adds options to automatically play the next Short.",
@ -99,7 +97,7 @@ val shortsAutoplayPatch = bytecodePatch(
reelPlaybackRepeatMethod.apply {
// The behavior enums are looked up from an ordinal value to an enum type.
findInstructionIndicesReversedOrThrow {
val reference = getReference<MethodReference>()
val reference = methodReference
reference?.definingClass == reelEnumClass &&
reference.parameterTypes.firstOrNull() == "I" &&
reference.returnType == reelEnumClass
@ -129,12 +127,12 @@ val shortsAutoplayPatch = bytecodePatch(
// Find the first call modified by extension code above.
val extensionReturnResultIndex = indexOfFirstInstructionOrThrow {
opcode == Opcode.INVOKE_STATIC &&
getReference<MethodReference>()?.definingClass == EXTENSION_CLASS_DESCRIPTOR
methodReference?.definingClass == EXTENSION_CLASS_DESCRIPTOR
} + 1
val enumRegister =
getInstruction<OneRegisterInstruction>(extensionReturnResultIndex).registerA
val getReelSequenceControllerIndex = indexOfFirstInstructionOrThrow {
val reference = getReference<FieldReference>()
val reference = fieldReference
opcode == Opcode.IGET_OBJECT &&
reference?.definingClass == definingClass &&
reference.type == reelSequenceControllerMethodReference.definingClass

View file

@ -24,13 +24,11 @@ import app.revanced.patches.youtube.shared.mainActivityOnCreateMethod
import app.revanced.patches.youtube.video.information.playbackStartDescriptorToStringMethodMatch
import app.revanced.util.addInstructionsAtControlFlowLabel
import app.revanced.util.findInstructionIndicesReversedOrThrow
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstruction
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.indexOfFirstInstructionReversedOrThrow
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
private const val EXTENSION_CLASS_DESCRIPTOR =
"Lapp/revanced/extension/youtube/patches/OpenShortsInRegularPlayerPatch;"
@ -149,14 +147,14 @@ val openShortsInRegularPlayerPatch = bytecodePatch(
// Method call for Activity.finish()
val finishIndexFirst = indexOfFirstInstructionOrThrow {
val reference = getReference<MethodReference>()
val reference = methodReference
reference?.name == "finish"
}
// Second Activity.finish() call. Has been present since 19.x but started
// to interfere with back to exit fullscreen around 20.47.
val finishIndexSecond = indexOfFirstInstruction(finishIndexFirst + 1) {
val reference = getReference<MethodReference>()
val reference = methodReference
reference?.name == "finish"
}
val getBooleanFieldIndex = indexOfFirstInstructionReversedOrThrow(finishIndexSecond) {

View file

@ -2,7 +2,9 @@ package app.revanced.patches.youtube.layout.sponsorblock
import app.revanced.patcher.extensions.addInstruction
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.extensions.fieldReference
import app.revanced.patcher.extensions.getInstruction
import app.revanced.patcher.extensions.methodReference
import app.revanced.patcher.immutableClassDef
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patcher.patch.resourcePatch
@ -33,7 +35,6 @@ import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
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.reference.FieldReference
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
private val sponsorBlockResourcePatch = resourcePatch {
dependsOn(
@ -157,7 +158,7 @@ val sponsorBlockPatch = bytecodePatch(
val rectangleIndex = indexOfFirstInstructionReversedOrThrow(
it[0],
) {
getReference<FieldReference>()?.type == "Landroid/graphics/Rect;"
fieldReference?.type == "Landroid/graphics/Rect;"
}
rectangleFieldName =
getInstruction<ReferenceInstruction>(rectangleIndex).reference as FieldReference
@ -182,7 +183,7 @@ val sponsorBlockPatch = bytecodePatch(
// Find the drawCircle call and draw the segment before it.
val drawCircleIndex = indexOfFirstInstructionReversedOrThrow {
getReference<MethodReference>()?.name == "drawCircle"
methodReference?.name == "drawCircle"
}
val drawCircleInstruction = getInstruction<FiveRegisterInstruction>(drawCircleIndex)
val canvasInstanceRegister = drawCircleInstruction.registerC

View file

@ -2,6 +2,7 @@ package app.revanced.patches.youtube.layout.startupshortsreset
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.extensions.getInstruction
import app.revanced.patcher.extensions.methodReference
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.all.misc.resources.addResources
import app.revanced.patches.all.misc.resources.addResourcesPatch
@ -14,11 +15,9 @@ import app.revanced.patches.youtube.misc.settings.PreferenceScreen
import app.revanced.patches.youtube.misc.settings.settingsPatch
import app.revanced.util.addInstructionsAtControlFlowLabel
import app.revanced.util.findFreeRegister
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
private const val EXTENSION_CLASS_DESCRIPTOR =
"Lapp/revanced/extension/youtube/patches/DisableResumingStartupShortsPlayerPatch;"
@ -78,8 +77,8 @@ val disableResumingShortsOnStartupPatch = bytecodePatch(
userWasInShortsLegacyMethod.apply {
val listenableInstructionIndex = indexOfFirstInstructionOrThrow {
opcode == Opcode.INVOKE_INTERFACE &&
getReference<MethodReference>()?.definingClass == "Lcom/google/common/util/concurrent/ListenableFuture;" &&
getReference<MethodReference>()?.name == "isDone"
methodReference?.definingClass == "Lcom/google/common/util/concurrent/ListenableFuture;" &&
methodReference?.name == "isDone"
}
val freeRegister = findFreeRegister(listenableInstructionIndex)

View file

@ -3,13 +3,13 @@ package app.revanced.patches.youtube.layout.toolbar
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.extensions.fieldReference
import app.revanced.patcher.extensions.getInstruction
import app.revanced.patcher.extensions.methodReference
import app.revanced.patcher.extensions.removeInstruction
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.shared.misc.mapping.resourceMappingPatch
import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch
import app.revanced.patches.youtube.shared.getToolBarButtonMethodMatch
import app.revanced.util.findFreeRegister
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstruction
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.indexOfFirstInstructionReversedOrThrow
@ -17,7 +17,6 @@ import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.Method
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.MethodReference
internal const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/youtube/patches/ToolbarPatch;"
@ -33,14 +32,14 @@ val toolbarHookPatch = bytecodePatch {
fun indexOfGetDrawableInstruction(method: Method) =
method.indexOfFirstInstruction {
opcode == Opcode.INVOKE_VIRTUAL &&
getReference<MethodReference>()?.toString() == "Landroid/content/res/Resources;->getDrawable(I)Landroid/graphics/drawable/Drawable;"
methodReference?.toString() == "Landroid/content/res/Resources;->getDrawable(I)Landroid/graphics/drawable/Drawable;"
}
getToolBarButtonMethodMatch().method.apply {
val getDrawableIndex = indexOfGetDrawableInstruction(this)
val enumOrdinalIndex = indexOfFirstInstructionReversedOrThrow(getDrawableIndex) {
opcode == Opcode.INVOKE_INTERFACE &&
getReference<MethodReference>()?.returnType == "I"
methodReference?.returnType == "I"
}
val replaceReference = getInstruction<ReferenceInstruction>(enumOrdinalIndex).reference
val replaceRegister = getInstruction<FiveRegisterInstruction>(enumOrdinalIndex).registerC

View file

@ -2,6 +2,7 @@ package app.revanced.patches.youtube.misc.backgroundplayback
import app.revanced.patcher.extensions.getInstruction
import app.revanced.patcher.extensions.instructions
import app.revanced.patcher.extensions.methodReference
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.all.misc.resources.addResources
import app.revanced.patches.all.misc.resources.addResourcesPatch
@ -20,7 +21,6 @@ import app.revanced.patches.youtube.video.information.videoInformationPatch
import app.revanced.util.*
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
internal var prefBackgroundAndOfflineCategoryId = -1L
private set
@ -86,7 +86,7 @@ val removeBackgroundPlaybackRestrictionsPatch = bytecodePatch(
// Enable background playback option in YouTube settings
backgroundPlaybackSettingsMethod.apply {
val booleanCalls = instructions.withIndex().filter {
it.value.getReference<MethodReference>()?.returnType == "Z"
it.value.methodReference?.returnType == "Z"
}
val settingsBooleanIndex = booleanCalls.elementAt(1).index

View file

@ -9,9 +9,7 @@ import app.revanced.patcher.extensions.getInstruction
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch
import app.revanced.patches.youtube.shared.getEngagementPanelControllerMethodMatch
import app.revanced.util.getReference
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
import kotlin.properties.Delegates
private const val EXTENSION_CLASS_DESCRIPTOR =

View file

@ -1,13 +1,12 @@
package app.revanced.patches.youtube.misc.fix.backtoexitgesture
import app.revanced.patcher.extensions.addInstruction
import app.revanced.patcher.extensions.methodReference
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.youtube.shared.mainActivityOnBackPressedMethod
import app.revanced.util.addInstructionsAtControlFlowLabel
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
private const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/youtube/patches/FixBackToExitGesturePatch;"
@ -26,7 +25,7 @@ internal val fixBackToExitGesturePatch = bytecodePatch(
with(scrollPositionMethodMatch) {
navigate(immutableMethod).to(scrollPositionMethodMatch[0] + 1).stop().apply {
val index = indexOfFirstInstructionOrThrow {
opcode == Opcode.INVOKE_VIRTUAL && getReference<MethodReference>()?.definingClass ==
opcode == Opcode.INVOKE_VIRTUAL && methodReference?.definingClass ==
"Landroid/support/v7/widget/RecyclerView;"
}

View file

@ -2,18 +2,16 @@ package app.revanced.patches.youtube.misc.fix.playbackspeed
import app.revanced.patcher.accessFlags
import app.revanced.patcher.custom
import app.revanced.patcher.gettingFirstImmutableMethodDeclaratively
import app.revanced.patcher.extensions.fieldReference
import app.revanced.patcher.gettingFirstMethodDeclaratively
import app.revanced.patcher.opcodes
import app.revanced.patcher.parameterTypes
import app.revanced.patcher.patch.BytecodePatchContext
import app.revanced.patcher.returnType
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionReversed
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.Method
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
/**
* This method is usually used to set the initial speed (1.0x) when playback starts from the feed.
@ -40,5 +38,5 @@ internal val BytecodePatchContext.playbackSpeedInFeedsMethod by gettingFirstMeth
internal fun indexOfGetPlaybackSpeedInstruction(method: Method) = method.indexOfFirstInstructionReversed {
opcode == Opcode.IGET &&
getReference<FieldReference>()?.type == "F"
fieldReference?.type == "F"
}

View file

@ -5,11 +5,11 @@ import app.revanced.com.android.tools.smali.dexlib2.mutable.MutableMethod.Compan
import app.revanced.patcher.classDef
import app.revanced.patcher.extensions.addInstruction
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.extensions.fieldReference
import app.revanced.patcher.extensions.instructions
import app.revanced.patcher.immutableClassDef
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch
import app.revanced.util.getReference
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.builder.MutableMethodImplementation
@ -40,7 +40,7 @@ val cronetImageURLHookPatch = bytecodePatch(
// The URL is required for the failure callback hook, but the URL field is obfuscated.
// Add a helper get method that returns the URL field.
val urlFieldInstruction = requestMethod.instructions.first {
val reference = it.getReference<FieldReference>()
val reference = it.fieldReference
it.opcode == Opcode.IPUT_OBJECT && reference?.type == "Ljava/lang/String;"
} as ReferenceInstruction

View file

@ -7,6 +7,7 @@ import app.revanced.patcher.extensions.addInstruction
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.extensions.getInstruction
import app.revanced.patcher.extensions.instructions
import app.revanced.patcher.extensions.methodReference
import app.revanced.patcher.extensions.reference
import app.revanced.patcher.immutableClassDef
import app.revanced.patcher.patch.PatchException
@ -20,19 +21,14 @@ import app.revanced.patches.youtube.shared.mainActivityOnBackPressedMethod
import app.revanced.util.ResourceGroup
import app.revanced.util.copyResources
import app.revanced.util.findFreeRegister
import app.revanced.util.getReference
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.builder.MutableMethodImplementation
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.Instruction
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.Instruction31i
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
import com.android.tools.smali.dexlib2.immutable.ImmutableMethod
import com.android.tools.smali.dexlib2.util.MethodUtil
import java.util.logging.Logger
internal const val EXTENSION_CLASS_DESCRIPTOR =
"Lapp/revanced/extension/youtube/shared/NavigationBar;"
@ -84,14 +80,14 @@ val navigationBarHookPatch = bytecodePatch(description = "Hooks the active navig
val navigationEnumClassName = navigationEnumMethod.classDef.type
addHook(NavigationHook.SET_LAST_APP_NAVIGATION_ENUM) {
opcode == Opcode.INVOKE_STATIC &&
getReference<MethodReference>()?.definingClass == navigationEnumClassName
methodReference?.definingClass == navigationEnumClassName
}
// Hook the creation of navigation tab views.
val drawableTabMethod = pivotBarButtonsCreateDrawableViewMethod
addHook(NavigationHook.NAVIGATION_TAB_LOADED) predicate@{
MethodUtil.methodSignaturesMatch(
getReference<MethodReference>() ?: return@predicate false,
methodReference ?: return@predicate false,
drawableTabMethod,
)
}
@ -99,7 +95,7 @@ val navigationBarHookPatch = bytecodePatch(description = "Hooks the active navig
if (is_20_21_or_greater && !is_20_28_or_greater) {
addHook(NavigationHook.NAVIGATION_TAB_LOADED) predicate@{
MethodUtil.methodSignaturesMatch(
getReference<MethodReference>() ?: return@predicate false,
methodReference ?: return@predicate false,
pivotBarButtonsCreateResourceIntViewMethod,
)
}
@ -107,7 +103,7 @@ val navigationBarHookPatch = bytecodePatch(description = "Hooks the active navig
addHook(NavigationHook.NAVIGATION_IMAGE_RESOURCE_TAB_LOADED) predicate@{
MethodUtil.methodSignaturesMatch(
getReference<MethodReference>() ?: return@predicate false,
methodReference ?: return@predicate false,
pivotBarButtonsCreateResourceStyledViewMethod,
)
}

View file

@ -1,6 +1,7 @@
package app.revanced.patches.youtube.video.codecs
import app.revanced.patcher.extensions.addInstructionsWithLabels
import app.revanced.patcher.extensions.methodReference
import app.revanced.patcher.extensions.replaceInstruction
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.all.misc.resources.addResources
@ -10,9 +11,7 @@ import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch
import app.revanced.patches.youtube.misc.settings.PreferenceScreen
import app.revanced.patches.youtube.misc.settings.settingsPatch
import app.revanced.util.getReference
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
private const val EXTENSION_CLASS_DESCRIPTOR =
"Lapp/revanced/extension/youtube/patches/DisableVideoCodecsPatch;"
@ -35,7 +34,7 @@ val disableVideoCodecsPatch = bytecodePatch(
return@filterMap null
}
val reference = instruction.getReference<MethodReference>()
val reference = instruction.methodReference
if (reference?.definingClass == "Landroid/view/Display\$HdrCapabilities;" && reference.name == "getSupportedHdrTypes") {
return@filterMap instruction to instructionIndex
}

View file

@ -23,7 +23,6 @@ import app.revanced.patches.youtube.video.videoid.hookVideoId
import app.revanced.patches.youtube.video.videoid.videoIdPatch
import app.revanced.util.addInstructionsAtControlFlowLabel
import app.revanced.util.addStaticFieldToExtension
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.patcher.patch.PatchException
import com.android.tools.smali.dexlib2.AccessFlags
@ -105,7 +104,7 @@ val videoInformationPatch = bytecodePatch(
// Find the location of the first invoke-direct call
// and extract the register storing the 'this' object reference.
val initThisIndex = playerInitMethod.indexOfFirstInstructionOrThrow {
opcode == Opcode.INVOKE_DIRECT && getReference<MethodReference>()?.name == "<init>"
opcode == Opcode.INVOKE_DIRECT && methodReference?.name == "<init>"
}
playerInitInsertRegister =
playerInitMethod.getInstruction<FiveRegisterInstruction>(initThisIndex).registerC
@ -123,7 +122,7 @@ val videoInformationPatch = bytecodePatch(
mdxInitMethod = classDef.methods.first { MethodUtil.isConstructor(it) }
val initThisIndex = mdxInitMethod.indexOfFirstInstructionOrThrow {
opcode == Opcode.INVOKE_DIRECT && getReference<MethodReference>()?.name == "<init>"
opcode == Opcode.INVOKE_DIRECT && methodReference?.name == "<init>"
}
mdxInitInsertRegister =
mdxInitMethod.getInstruction<FiveRegisterInstruction>(initThisIndex).registerC
@ -201,7 +200,7 @@ val videoInformationPatch = bytecodePatch(
setPlaybackSpeedMethodReference = getInstruction<ReferenceInstruction>(
indexOfFirstInstructionOrThrow(speedSelectionValueInstructionIndex) {
val reference = getReference<MethodReference>()
val reference = methodReference
reference?.parameterTypes?.size == 1 && reference.parameterTypes.first() == "F"
}
).reference as MethodReference
@ -231,7 +230,7 @@ val videoInformationPatch = bytecodePatch(
setPlaybackSpeedClassFieldReference = getInstruction<ReferenceInstruction>(
indexOfFirstInstructionOrThrow(speedSelectionValueInstructionIndex) {
getReference<FieldReference>()?.type?.startsWith("L") == true
fieldReference?.type?.startsWith("L") == true
}
).reference as FieldReference
@ -398,7 +397,6 @@ val videoInformationPatch = bytecodePatch(
// Detect video quality changes and override the current quality.
videoQualitySetterMethod.immutableClassDef.getSetVideoQualityMethod().let {
it
// This instruction refers to the field with the type that contains the setQuality method.
val onItemClickListenerClassReference =
it.getInstruction<ReferenceInstruction>(0).reference

View file

@ -21,9 +21,7 @@ import com.android.tools.smali.dexlib2.iface.Method
import com.android.tools.smali.dexlib2.iface.MethodParameter
import com.android.tools.smali.dexlib2.iface.instruction.*
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
import com.android.tools.smali.dexlib2.iface.reference.Reference
import com.android.tools.smali.dexlib2.iface.reference.StringReference
import com.android.tools.smali.dexlib2.iface.value.*
import com.android.tools.smali.dexlib2.immutable.ImmutableField
import com.android.tools.smali.dexlib2.immutable.ImmutableMethod
@ -40,7 +38,7 @@ import kotlin.collections.remove
*/
private fun Method.findInstructionIndexFromToString(fieldName: String): Int {
val stringIndex = indexOfFirstInstruction {
val reference = getReference<StringReference>()
val reference = stringReference
reference?.string?.contains(fieldName) == true
}
if (stringIndex < 0) {
@ -50,7 +48,7 @@ private fun Method.findInstructionIndexFromToString(fieldName: String): Int {
// Find use of the string with a StringBuilder.
val stringUsageIndex = indexOfFirstInstruction(stringIndex) {
val reference = getReference<MethodReference>()
val reference = methodReference
reference?.definingClass == "Ljava/lang/StringBuilder;" &&
(this as? FiveRegisterInstruction)?.registerD == stringRegister
}
@ -60,7 +58,7 @@ private fun Method.findInstructionIndexFromToString(fieldName: String): Int {
// Find the next usage of StringBuilder, which should be the desired field.
val fieldUsageIndex = indexOfFirstInstruction(stringUsageIndex + 1) {
val reference = getReference<MethodReference>()
val reference = methodReference
reference?.definingClass == "Ljava/lang/StringBuilder;" && reference.name == "append"
}
if (fieldUsageIndex < 0) {
@ -104,7 +102,7 @@ internal fun Method.findMethodFromToString(fieldName: String): MutableMethod {
*/
internal fun Method.findFieldFromToString(fieldName: String): FieldReference {
val methodUsageIndex = findInstructionIndexFromToString(fieldName)
return getInstruction<ReferenceInstruction>(methodUsageIndex).getReference<FieldReference>()!!
return getInstruction<ReferenceInstruction>(methodUsageIndex).fieldReference!!
}
/**
@ -380,6 +378,8 @@ fun BytecodePatchContext.traverseClassHierarchy(targetClass: MutableClassDef, ca
* if the [Instruction] is not a [ReferenceInstruction] or the [Reference] is not of type [T].
* @see ReferenceInstruction
*/
@Deprecated("Instead use `methodReference`, `fieldReference`, `typeReference` or `stringReference`")
@Suppress("unused")
inline fun <reified T : Reference> Instruction.getReference() = (this as? ReferenceInstruction)?.reference as? T
/**

View file

@ -2,6 +2,7 @@ package app.revanced.util
import app.revanced.patcher.extensions.getInstruction
import app.revanced.patcher.extensions.instructions
import app.revanced.patcher.extensions.reference
import app.revanced.util.FreeRegisterProvider.Companion.conditionalBranchOpcodes
import app.revanced.util.FreeRegisterProvider.Companion.logFreeRegisterSearch
import app.revanced.util.FreeRegisterProvider.Companion.returnOpcodes
@ -345,7 +346,7 @@ private fun Method.findFreeRegistersInternal(
// If it appears more than once, it's also read.
if (occurrences <= 1) {
if (logFreeRegisterSearch) println("Found free register at $i: $writeRegister " +
"opcode: " + instruction.opcode + " reference: " + (instruction.getReference()))
"opcode: " + instruction.opcode + " reference: " + (instruction.reference))
freeRegisters.add(writeRegister)
// If the requested number of free registers is found and this is not a branch,
// then no additional searching is needed.