cast work in progress

some terrible code
This commit is contained in:
Canny1913 2022-06-15 22:58:24 +03:00 committed by GitHub
parent b814b96d4c
commit bfc592c0b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 92 additions and 0 deletions

View File

@ -0,0 +1,13 @@
package app.revanced.patches.youtube.layout.castbutton.annotations
import app.revanced.patcher.annotation.Compatibility
import app.revanced.patcher.annotation.Package
@Compatibility(
[Package(
"com.google.android.youtube", arrayOf("17.14.35", "17.17.34", "17.19.36", "17.20.37", "17.22.36")
)]
)
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
internal annotation class CastButtonCompatibility

View File

@ -0,0 +1,50 @@
package app.revanced.patches.youtube.layout.castbutton.patch
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.implementation.BytecodeData
import app.revanced.patcher.extensions.or
import app.revanced.patcher.patch.annotations.Dependencies
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patcher.patch.implementation.BytecodePatch
import app.revanced.patcher.patch.implementation.misc.PatchResult
import app.revanced.patcher.patch.implementation.misc.PatchResultError
import app.revanced.patcher.patch.implementation.misc.PatchResultSuccess
import app.revanced.patcher.signature.implementation.method.MethodSignature
import app.revanced.patcher.signature.implementation.method.annotation.FuzzyPatternScanMethod
import app.revanced.patcher.signature.implementation.method.annotation.MatchingMethod
import app.revanced.patcher.util.smali.toInstruction
import app.revanced.patches.youtube.layout.castbutton.annotations.CastButtonCompatibility
import app.revanced.patches.youtube.layout.castbutton.signatures.CastButtonSignature
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch
import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.Opcode
@Patch
@Dependencies(dependencies = [IntegrationsPatch::class])
@Name("disable-cast-button")
@Description("Patch to remove the cast button.")
@CastButtonCompatibility
@Version("0.0.1")
class CastButtonRemoverPatch : BytecodePatch(
listOf(
CastButtonSignature
)
) {
override fun execute(data: BytecodeData): PatchResult {
val result = signatures.first().result!!
val implementation = result.method.implementation!!
implementation.addInstruction(
0,
"invoke-static {p1}, Lfi/razerman/youtube/XGlobals;->getCastButtonOverrideV2(I)I".toInstruction()
)
implementation.addInstruction(
1,
"move-result p1".toInstruction()
)
return PatchResultSuccess()
}
}

View File

@ -0,0 +1,29 @@
package app.revanced.patches.youtube.layout.castbutton.signatures
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.extensions.or
import app.revanced.patcher.signature.implementation.method.MethodSignature
import app.revanced.patcher.signature.implementation.method.annotation.FuzzyPatternScanMethod
import app.revanced.patcher.signature.implementation.method.annotation.MatchingMethod
import app.revanced.patches.youtube.layout.castbutton.annotations.CastButtonCompatibility
import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.Opcode
@Name("cast-button-signature")
@MatchingMethod(
"Landroidx/mediarouter/app/MediaRouteButton", "setVisibility"
)
@FuzzyPatternScanMethod(2) // FIXME: Test this threshold and find the best value.
@CastButtonCompatibility
@Version("0.0.1")
object CastButtonSignature : MethodSignature(
"V",
AccessFlags.PUBLIC or AccessFlags.FINAL,
listOf("L","L"),
listOf(
Opcode.IPUT,
Opcode.INVOKE_VIRTUAL,
Opcode.RETURN_VOID,
)
)