feat(YouTube): add Remove viewer discretion dialog patch

This commit is contained in:
inotia00
2023-12-30 23:06:30 +09:00
parent 0ab7695eaa
commit 68fdbbb912
6 changed files with 172 additions and 0 deletions

View File

@ -0,0 +1,22 @@
package app.revanced.patches.shared.fingerprints.dialog
import app.revanced.patcher.fingerprint.MethodFingerprint
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
internal object CreateDialogFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PROTECTED.value,
parameters = listOf("L", "L", "Ljava/lang/String;"),
opcodes = listOf(
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT_OBJECT,
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT_OBJECT,
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT_OBJECT,
Opcode.IPUT_OBJECT,
Opcode.IGET_OBJECT,
Opcode.INVOKE_VIRTUAL // dialog.show()
)
)

View File

@ -0,0 +1,53 @@
package app.revanced.patches.shared.patch.dialog
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patches.shared.fingerprints.dialog.CreateDialogFingerprint
import app.revanced.util.exception
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
abstract class AbstractRemoveViewerDiscretionDialogPatch(
private val classDescriptor: String,
private val additionalFingerprints: Set<MethodFingerprint> = emptySet()
) : BytecodePatch(
buildSet {
add(CreateDialogFingerprint)
additionalFingerprints.let(::addAll)
}
) {
private fun MutableMethod.invoke() {
val showDialogIndex = implementation!!.instructions.indexOfFirst { instruction ->
((instruction as? ReferenceInstruction)?.reference as? MethodReference)?.name == "show"
}
val dialogRegister = getInstruction<FiveRegisterInstruction>(showDialogIndex).registerC
addInstruction(
showDialogIndex + 1,
"invoke-static { v$dialogRegister }, $classDescriptor->confirmDialog(Landroid/app/AlertDialog;)V",
)
}
override fun execute(context: BytecodeContext) {
CreateDialogFingerprint.result?.mutableMethod?.invoke()
?: throw CreateDialogFingerprint.exception
if (additionalFingerprints.isNotEmpty()) {
additionalFingerprints.forEach { fingerprint ->
fingerprint.result?.let {
val targetMethod = context.toMethodWalker(it.method)
.nextMethod(it.scanResult.patternScanResult!!.endIndex - 1, true)
.getMethod() as MutableMethod
targetMethod.invoke()
} ?: throw fingerprint.exception
}
}
}
}

View File

@ -0,0 +1,64 @@
package app.revanced.patches.youtube.general.dialog
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.patch.annotation.CompatiblePackage
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.shared.patch.dialog.AbstractRemoveViewerDiscretionDialogPatch
import app.revanced.patches.youtube.general.dialog.fingerprints.AgeRestrictionFingerprint
import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL
import app.revanced.patches.youtube.utils.settings.SettingsPatch
@Patch(
name = "Remove viewer discretion dialog",
description = "Removes the dialog that appears when you try to watch a video that has been age-restricted " +
"by accepting it automatically. This does not bypass the age restriction.",
dependencies = [SettingsPatch::class],
compatiblePackages = [
CompatiblePackage(
"com.google.android.youtube",
[
"18.25.40",
"18.27.36",
"18.29.38",
"18.30.37",
"18.31.40",
"18.32.39",
"18.33.40",
"18.34.38",
"18.35.36",
"18.36.39",
"18.37.36",
"18.38.44",
"18.39.41",
"18.40.34",
"18.41.39",
"18.42.41",
"18.43.45",
"18.44.41",
"18.45.43"
]
)
]
)
@Suppress("unused")
object RemoveViewerDiscretionDialogPatch : AbstractRemoveViewerDiscretionDialogPatch(
GENERAL,
setOf(AgeRestrictionFingerprint)
) {
override fun execute(context: BytecodeContext) {
super.execute(context)
/**
* Add settings
*/
SettingsPatch.addPreference(
arrayOf(
"PREFERENCE: GENERAL_SETTINGS",
"SETTINGS: REMOVE_VIEWER_DISCRETION_DIALOG"
)
)
SettingsPatch.updatePatchStatus("Remove viewer discretion dialog")
}
}

View File

@ -0,0 +1,26 @@
package app.revanced.patches.youtube.general.dialog.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
object AgeRestrictionFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("L", "Ljava/util/Map;"),
opcodes = listOf(
Opcode.INVOKE_VIRTUAL,
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT_OBJECT,
Opcode.INVOKE_VIRTUAL,
Opcode.INVOKE_VIRTUAL,
Opcode.RETURN_VOID
),
strings = listOf(
"com.google.android.libraries.youtube.rendering.elements.sender_view",
"com.google.android.libraries.youtube.innertube.endpoint.tag",
"com.google.android.libraries.youtube.innertube.bundle",
"com.google.android.libraries.youtube.logging.interaction_logger"
)
)