This commit is contained in:
inotia00
2023-02-15 11:57:57 +09:00
parent ec8bf1c2bb
commit 79a808db5c
213 changed files with 1710 additions and 3027 deletions

View File

@ -0,0 +1,14 @@
package app.revanced.patches.youtube.ads.doublebacktoclose.fingerprint
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.Opcode
object OnBackPressedFingerprint : MethodFingerprint(
opcodes = listOf(
Opcode.RETURN_VOID
),
customFingerprint = { methodDef ->
methodDef.definingClass.endsWith("WatchWhileActivity;")
&& methodDef.name == "onBackPressed"
}
)

View File

@ -0,0 +1,19 @@
package app.revanced.patches.youtube.ads.doublebacktoclose.fingerprint
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.Opcode
object ScrollPositionFingerprint : MethodFingerprint(
returnType = "V",
access = AccessFlags.PROTECTED or AccessFlags.FINAL,
parameters = listOf("L"),
opcodes = listOf(
Opcode.IF_NEZ,
Opcode.INVOKE_DIRECT,
Opcode.RETURN_VOID
),
strings = listOf("scroll_position")
)

View File

@ -0,0 +1,21 @@
package app.revanced.patches.youtube.ads.doublebacktoclose.fingerprint
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.Opcode
object ScrollTopFingerprint : MethodFingerprint(
returnType = "V",
access = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf(),
opcodes = listOf(
Opcode.CHECK_CAST,
Opcode.CONST_4,
Opcode.INVOKE_VIRTUAL,
Opcode.GOTO,
Opcode.IGET_OBJECT,
Opcode.INVOKE_INTERFACE
)
)

View File

@ -0,0 +1,26 @@
package app.revanced.patches.youtube.ads.doublebacktoclose.fingerprint
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.Opcode
object ScrollTopParentFingerprint : MethodFingerprint(
returnType = "V",
access = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
parameters = listOf("L", "L", "L", "L"),
opcodes = listOf(
Opcode.INVOKE_DIRECT,
Opcode.IPUT_OBJECT,
Opcode.IPUT_OBJECT,
Opcode.IPUT_OBJECT,
Opcode.IPUT_OBJECT,
Opcode.CONST_16,
Opcode.INVOKE_VIRTUAL,
Opcode.NEW_INSTANCE
),
customFingerprint = { methodDef ->
methodDef.name == "<init>"
}
)

View File

@ -0,0 +1,94 @@
package app.revanced.patches.youtube.ads.doublebacktoclose.patch
import app.revanced.extensions.toErrorResult
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.data.toMethodWalker
import app.revanced.patcher.extensions.addInstruction
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.youtube.ads.gestures.PredictiveBackGesturePatch
import app.revanced.patches.youtube.ads.doublebacktoclose.fingerprint.*
import app.revanced.util.integrations.Constants.UTILS_PATH
@Name("double-back-to-close")
@DependsOn([PredictiveBackGesturePatch::class])
@YouTubeCompatibility
@Version("0.0.1")
class DoubleBackToClosePatch : BytecodePatch(
listOf(
OnBackPressedFingerprint,
ScrollPositionFingerprint,
ScrollTopParentFingerprint
)
) {
override fun execute(context: BytecodeContext): PatchResult {
/*
Hook onBackPressed method inside WatchWhileActivity
*/
OnBackPressedFingerprint.result?.let {
val insertIndex = it.scanResult.patternScanResult!!.endIndex
with(it.mutableMethod) {
addInstruction(
insertIndex,
"invoke-static {p0}, $INTEGRATIONS_CLASS_DESCRIPTOR" +
"->" +
"closeActivityOnBackPressed(Lcom/google/android/apps/youtube/app/watchwhile/WatchWhileActivity;)V"
)
}
} ?: return OnBackPressedFingerprint.toErrorResult()
/*
Inject the methods which start of ScrollView
*/
ScrollPositionFingerprint.result?.let {
val insertMethod = context.toMethodWalker(it.method)
.nextMethod(it.scanResult.patternScanResult!!.startIndex + 1, true)
.getMethod() as MutableMethod
val insertIndex = insertMethod.implementation!!.instructions.size - 1 - 1
injectScrollView(insertMethod, insertIndex, "onStartScrollView")
} ?: return ScrollPositionFingerprint.toErrorResult()
/*
Inject the methods which stop of ScrollView
*/
ScrollTopParentFingerprint.result?.let { parentResult ->
ScrollTopFingerprint.also { it.resolve(context, parentResult.classDef) }.result?.let {
val insertMethod = it.mutableMethod
val insertIndex = it.scanResult.patternScanResult!!.endIndex
injectScrollView(insertMethod, insertIndex, "onStopScrollView")
} ?: return ScrollTopFingerprint.toErrorResult()
} ?: return ScrollTopParentFingerprint.toErrorResult()
return PatchResultSuccess()
}
private companion object {
const val INTEGRATIONS_CLASS_DESCRIPTOR =
"$UTILS_PATH/DoubleBackToClosePatch;"
fun injectScrollView(
method: MutableMethod,
index: Int,
descriptor: String
) {
method.addInstruction(
index,
"invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR->$descriptor()V"
)
}
}
}

View File

@ -17,7 +17,7 @@ import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.shared.patch.mapping.ResourceMappingPatch
import app.revanced.patches.youtube.ads.general.bytecode.fingerprints.ComponentContextParserFingerprint
import app.revanced.patches.youtube.ads.general.bytecode.fingerprints.EmptyComponentBuilderFingerprint
import app.revanced.util.bytecode.BytecodeHelper
import app.revanced.util.bytecode.BytecodeHelper.updatePatchStatus
import app.revanced.util.integrations.Constants.ADS_PATH
import org.jf.dexlib2.Opcode
import org.jf.dexlib2.builder.instruction.BuilderInstruction21s
@ -79,7 +79,7 @@ class GeneralAdsBytecodePatch : BytecodePatch(
}
} ?: return ComponentContextParserFingerprint.toErrorResult()
BytecodeHelper.patchStatus(context, "GeneralAds")
context.updatePatchStatus("GeneralAds")
return PatchResultSuccess()
}

View File

@ -14,9 +14,8 @@ import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.youtube.ads.general.bytecode.patch.GeneralAdsBytecodePatch
import app.revanced.patches.youtube.ads.general.bytecode.patch.GeneralAdsSecondaryBytecodePatch
import app.revanced.patches.youtube.misc.litho.filter.patch.LithoFilterPatch
import app.revanced.patches.youtube.misc.litho.patch.LithoFilterPatch
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
import app.revanced.util.resources.ResourceHelper
import org.w3c.dom.Element
@Patch
@ -88,33 +87,22 @@ class GeneralAdsPatch : ResourcePatch {
/*
add settings
*/
ResourceHelper.addSettings(
context,
"PREFERENCE_CATEGORY: REVANCED_SETTINGS",
"PREFERENCE: ADS_SETTINGS",
"SETTINGS: HIDE_GENERAL_ADS"
SettingsPatch.addPreference(
arrayOf(
"PREFERENCE: ADS_SETTINGS",
"SETTINGS: HIDE_GENERAL_ADS",
"PREFERENCE: LAYOUT_SETTINGS",
"PREFERENCE_HEADER: GENERAL",
"SETTINGS: HIDE_GENERAL_LAYOUT_ADS",
"PREFERENCE: LAYOUT_SETTINGS",
"PREFERENCE_HEADER: PLAYER",
"SETTINGS: HIDE_VIEW_PRODUCT"
)
)
ResourceHelper.addSettings2(
context,
"PREFERENCE_CATEGORY: REVANCED_SETTINGS",
"PREFERENCE: LAYOUT_SETTINGS",
"PREFERENCE_HEADER: GENERAL",
"SETTINGS: HIDE_GENERAL_LAYOUT_ADS"
)
ResourceHelper.addSettings2(
context,
"PREFERENCE_CATEGORY: REVANCED_SETTINGS",
"PREFERENCE: LAYOUT_SETTINGS",
"PREFERENCE_HEADER: PLAYER",
"SETTINGS: HIDE_VIEW_PRODUCT"
)
ResourceHelper.patchSuccess(
context,
"hide-general-ads"
)
SettingsPatch.updatePatchStatus("hide-general-ads")
return PatchResultSuccess()
}

View File

@ -0,0 +1,35 @@
package app.revanced.patches.youtube.ads.gestures
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.ResourceContext
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.ResourcePatch
@Name("predictive-back-gesture")
@Description("Enables the predictive back gesture introduced on Android 13.")
@Version("0.0.1")
class PredictiveBackGesturePatch : ResourcePatch {
override fun execute(context: ResourceContext): PatchResult {
context.xmlEditor["AndroidManifest.xml"].use { editor ->
val document = editor.file
with(document.getElementsByTagName("application").item(0)) {
if (attributes.getNamedItem(FLAG) != null) return@with
document.createAttribute(FLAG)
.apply { value = "false" }
.let(attributes::setNamedItem)
}
}
return PatchResultSuccess()
}
private companion object {
const val FLAG = "android:enableOnBackInvokedCallback"
}
}

View File

@ -0,0 +1,19 @@
package app.revanced.patches.youtube.ads.swiperefresh.fingerprint
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.Opcode
object SwipeRefreshLayoutFingerprint : MethodFingerprint(
returnType = "Z",
access = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf(),
opcodes = listOf(
Opcode.RETURN,
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT,
Opcode.RETURN
),
customFingerprint = { it.definingClass == "Landroidx/swiperefreshlayout/widget/SwipeRefreshLayout;" }
)

View File

@ -0,0 +1,42 @@
package app.revanced.patches.youtube.ads.swiperefresh.patch
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.addInstruction
import app.revanced.patcher.extensions.instruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patches.youtube.ads.swiperefresh.fingerprint.SwipeRefreshLayoutFingerprint
import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.extensions.toErrorResult
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
@Name("enable-swipe-refresh")
@Description("Enable swipe refresh.")
@YouTubeCompatibility
@Version("0.0.1")
class SwipeRefreshPatch : BytecodePatch(
listOf(
SwipeRefreshLayoutFingerprint
)
) {
override fun execute(context: BytecodeContext): PatchResult {
SwipeRefreshLayoutFingerprint.result?.let {
with (it.mutableMethod) {
val insertIndex = it.scanResult.patternScanResult!!.endIndex
val register = (instruction(insertIndex) as OneRegisterInstruction).registerA
addInstruction(
insertIndex,
"const/4 v$register, 0x0"
)
}
} ?: return SwipeRefreshLayoutFingerprint.toErrorResult()
return PatchResultSuccess()
}
}

View File

@ -1,5 +1,6 @@
package app.revanced.patches.youtube.ads.video.bytecode.patch
package app.revanced.patches.youtube.ads.video.patch
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext
@ -7,26 +8,44 @@ import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.shared.patch.videoads.GeneralVideoAdsPatch
import app.revanced.util.bytecode.BytecodeHelper
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
import app.revanced.util.bytecode.BytecodeHelper.updatePatchStatus
import app.revanced.util.integrations.Constants.ADS_PATH
@Patch
@Name("hide-video-ads")
@Description("Removes ads in the video player.")
@DependsOn(
[
GeneralVideoAdsPatch::class
GeneralVideoAdsPatch::class,
SettingsPatch::class
]
)
@Name("hide-video-ads-bytecode-patch")
@YouTubeCompatibility
@Version("0.0.1")
class VideoAdsBytecodePatch : BytecodePatch() {
class VideoAdsPatch : BytecodePatch() {
override fun execute(context: BytecodeContext): PatchResult {
GeneralVideoAdsPatch.injectLegacyAds(INTEGRATIONS_CLASS_DESCRIPTOR)
GeneralVideoAdsPatch.injectMainstreamAds(INTEGRATIONS_CLASS_DESCRIPTOR)
BytecodeHelper.patchStatus(context, "VideoAds")
context.updatePatchStatus("VideoAds")
/*
add settings
*/
SettingsPatch.addPreference(
arrayOf(
"PREFERENCE: ADS_SETTINGS",
"SETTINGS: HIDE_VIDEO_ADS"
)
)
SettingsPatch.updatePatchStatus("hide-video-ads")
return PatchResultSuccess()
}

View File

@ -1,48 +0,0 @@
package app.revanced.patches.youtube.ads.video.resource.patch
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.ResourceContext
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.ResourcePatch
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.youtube.ads.video.bytecode.patch.VideoAdsBytecodePatch
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
import app.revanced.util.resources.ResourceHelper
@Patch
@Name("hide-video-ads")
@Description("Removes ads in the video player.")
@DependsOn(
[
VideoAdsBytecodePatch::class,
SettingsPatch::class
]
)
@YouTubeCompatibility
@Version("0.0.1")
class VideoAdsPatch : ResourcePatch {
override fun execute(context: ResourceContext): PatchResult {
/*
add settings
*/
ResourceHelper.addSettings(
context,
"PREFERENCE_CATEGORY: REVANCED_SETTINGS",
"PREFERENCE: ADS_SETTINGS",
"SETTINGS: HIDE_VIDEO_ADS"
)
ResourceHelper.patchSuccess(
context,
"hide-video-ads"
)
return PatchResultSuccess()
}
}