fix: get create button view register by more reliable means (#59)
This commit is contained in:
parent
7642945108
commit
6ab821e377
|
@ -14,11 +14,15 @@ import app.revanced.patcher.patch.implementation.misc.PatchResultSuccess
|
||||||
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
|
||||||
|
import app.revanced.patches.youtube.misc.mapping.patch.ResourceIdMappingProviderResourcePatch
|
||||||
import org.jf.dexlib2.Opcode
|
import org.jf.dexlib2.Opcode
|
||||||
import org.jf.dexlib2.iface.instruction.formats.Instruction35c
|
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
|
||||||
|
import org.jf.dexlib2.iface.instruction.ReferenceInstruction
|
||||||
|
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction
|
||||||
|
import org.jf.dexlib2.iface.reference.MethodReference
|
||||||
|
|
||||||
@Patch
|
@Patch
|
||||||
@Dependencies(dependencies = [IntegrationsPatch::class])
|
@Dependencies(dependencies = [IntegrationsPatch::class, ResourceIdMappingProviderResourcePatch::class])
|
||||||
@Name("disable-create-button")
|
@Name("disable-create-button")
|
||||||
@Description("Disable the create button.")
|
@Description("Disable the create button.")
|
||||||
@CreateButtonCompatibility
|
@CreateButtonCompatibility
|
||||||
|
@ -33,14 +37,25 @@ class CreateButtonRemoverPatch : BytecodePatch(
|
||||||
|
|
||||||
// Get the required register which holds the view object we need to pass to the method hideCreateButton
|
// Get the required register which holds the view object we need to pass to the method hideCreateButton
|
||||||
val implementation = result.method.implementation!!
|
val implementation = result.method.implementation!!
|
||||||
val instruction = implementation.instructions[result.scanResult.endIndex + 1]
|
|
||||||
if (instruction.opcode != Opcode.INVOKE_STATIC) return PatchResultError("Could not find the correct register")
|
val imageOnlyLayout = ResourceIdMappingProviderResourcePatch.resourceMappings["image_only_tab"]
|
||||||
val register = (instruction as Instruction35c).registerC
|
?: return PatchResultError("Required resource could not be found in the map")
|
||||||
|
|
||||||
|
val imageOnlyLayoutConstIndex =
|
||||||
|
implementation.instructions.indexOfFirst { (it as? WideLiteralInstruction)?.wideLiteral == imageOnlyLayout }
|
||||||
|
|
||||||
|
val (instructionIndex, instruction) = implementation.instructions.drop(imageOnlyLayoutConstIndex).withIndex()
|
||||||
|
.first { (((it.value as? ReferenceInstruction)?.reference) as? MethodReference)?.definingClass?.contains("PivotBar") ?: false }
|
||||||
|
|
||||||
|
if (instruction.opcode != Opcode.INVOKE_VIRTUAL) return PatchResultError("Could not find the correct instruction")
|
||||||
|
|
||||||
|
val moveResultIndex = imageOnlyLayoutConstIndex + instructionIndex + 1
|
||||||
|
val moveResultInstruction = implementation.instructions[moveResultIndex] as OneRegisterInstruction
|
||||||
|
|
||||||
// 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
|
||||||
result.method.addInstruction(
|
result.method.addInstruction(
|
||||||
result.scanResult.endIndex + 1,
|
moveResultIndex + 1,
|
||||||
"invoke-static { v$register }, Lfi/razerman/youtube/XAdRemover;->hideCreateButton(Landroid/view/View;)V"
|
"invoke-static { v${moveResultInstruction.registerA} }, Lfi/razerman/youtube/XAdRemover;->hideCreateButton(Landroid/view/View;)V"
|
||||||
)
|
)
|
||||||
|
|
||||||
return PatchResultSuccess()
|
return PatchResultSuccess()
|
||||||
|
|
Loading…
Reference in a new issue