feat(youtube/hide-button-container): now it support versions other than YouTube v18.20.39 https://github.com/ReVanced/revanced-patches/pull/2723

This commit is contained in:
inotia00 2023-08-05 07:27:50 +09:00
parent d8a10fecf5
commit 1fbb5c4bee
10 changed files with 33 additions and 146 deletions

View File

@ -1,17 +0,0 @@
package app.revanced.patches.shared.fingerprints.litho
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
object PbToFbFingerprint : MethodFingerprint(
returnType = "L",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("[B"),
opcodes = listOf(
Opcode.NEW_INSTANCE,
Opcode.INVOKE_DIRECT
),
strings = listOf("PbToFb failed: ")
)

View File

@ -1,16 +0,0 @@
package app.revanced.patches.shared.fingerprints.litho
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
object PbToFbLegacyFingerprint : MethodFingerprint(
returnType = "L",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
opcodes = listOf(
Opcode.NEW_INSTANCE,
Opcode.INVOKE_DIRECT
),
strings = listOf("Failed to convert Element to Flatbuffers: %s")
)

View File

@ -6,37 +6,28 @@ import app.revanced.patcher.data.toMethodWalker
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.extensions.or
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultError
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.util.proxy.mutableTypes.MutableField.Companion.toMutable
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.shared.fingerprints.litho.ByteBufferHookFingerprint
import app.revanced.patches.shared.fingerprints.litho.EmptyComponentBuilderFingerprint
import app.revanced.patches.shared.fingerprints.litho.IdentifierFingerprint
import app.revanced.patches.shared.fingerprints.litho.PbToFbFingerprint
import app.revanced.patches.shared.fingerprints.litho.PbToFbLegacyFingerprint
import app.revanced.util.bytecode.getStringIndex
import com.android.tools.smali.dexlib2.AccessFlags
import app.revanced.util.integrations.Constants.ADS_PATH
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction35c
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.ImmutableField
import kotlin.properties.Delegates
class ComponentParserPatch : BytecodePatch(
listOf(
ByteBufferHookFingerprint,
EmptyComponentBuilderFingerprint,
IdentifierFingerprint,
PbToFbFingerprint,
PbToFbLegacyFingerprint
IdentifierFingerprint
)
) {
override fun execute(context: BytecodeContext): PatchResult {
@ -68,35 +59,6 @@ class ComponentParserPatch : BytecodePatch(
}
} ?: return EmptyComponentBuilderFingerprint.toErrorResult()
val pbToFbResult = PbToFbFingerprint.result
?: PbToFbLegacyFingerprint.result
?: throw PbToFbLegacyFingerprint.toErrorResult()
pbToFbResult.let {
it.mutableMethod.apply {
val byteBufferClassIndex = it.scanResult.patternScanResult!!.startIndex
byteBufferClassLabel =
getInstruction<ReferenceInstruction>(byteBufferClassIndex).reference.toString()
}
}
ByteBufferHookFingerprint.result?.let {
(context
.toMethodWalker(it.method)
.nextMethod(it.scanResult.patternScanResult!!.endIndex, true)
.getMethod() as MutableMethod
).apply {
val methodName =
EmptyComponentBuilderFingerprint.result!!.mutableMethod.definingClass
addInstruction(
0,
"sput-object p2, $methodName->buffer:Ljava/nio/ByteBuffer;"
)
}
} ?: return ByteBufferHookFingerprint.toErrorResult()
IdentifierFingerprint.result?.let {
it.mutableMethod.apply {
insertMethod = this
@ -129,18 +91,6 @@ class ComponentParserPatch : BytecodePatch(
register
insertIndex = stringBuilderIndex + 1
it.mutableClass.staticFields.add(
ImmutableField(
definingClass,
"buffer",
"Ljava/nio/ByteBuffer;",
AccessFlags.PUBLIC or AccessFlags.STATIC,
null,
annotations,
null
).toMutable()
)
}
} ?: return IdentifierFingerprint.toErrorResult()
@ -148,7 +98,6 @@ class ComponentParserPatch : BytecodePatch(
}
internal companion object {
lateinit var byteBufferClassLabel: String
lateinit var emptyComponentLabel: String
lateinit var insertMethod: MutableMethod
@ -167,8 +116,7 @@ class ComponentParserPatch : BytecodePatch(
addInstructionsWithLabels(
insertIndex,
"""
sget-object v$freeRegister, $definingClass->buffer:Ljava/nio/ByteBuffer;
invoke-static {v$stringBuilderRegister, v$identifierRegister, v$objectRegister, v$freeRegister}, $descriptor(Ljava/lang/StringBuilder;Ljava/lang/String;Ljava/lang/Object;Ljava/nio/ByteBuffer;)Z
invoke-static {v$stringBuilderRegister, v$identifierRegister, v$objectRegister}, $descriptor(Ljava/lang/StringBuilder;Ljava/lang/String;Ljava/lang/Object;)Z
move-result v$freeRegister
if-eqz v$freeRegister, :unfiltered
""" + emptyComponentLabel,
@ -192,27 +140,5 @@ class ComponentParserPatch : BytecodePatch(
)
}
}
// only for YouTube v18.20.39
fun legacyHook(
descriptor: String
) {
insertMethod.apply {
addInstructionsWithLabels(
insertIndex,
"""
move-object/from16 v$freeRegister, p3
iget-object v$freeRegister, v$freeRegister, ${parameters[2]}->b:Ljava/lang/Object;
if-eqz v$freeRegister, :unfiltered
check-cast v$freeRegister, $byteBufferClassLabel
iget-object v$freeRegister, v$freeRegister, $byteBufferClassLabel->b:Ljava/nio/ByteBuffer;
invoke-static {v$stringBuilderRegister, v$identifierRegister, v$objectRegister, v$freeRegister}, $descriptor(Ljava/lang/StringBuilder;Ljava/lang/String;Ljava/lang/Object;Ljava/nio/ByteBuffer;)Z
move-result v$freeRegister
if-eqz v$freeRegister, :unfiltered
""" + emptyComponentLabel,
ExternalLabel("unfiltered", getInstruction(insertIndex))
)
}
}
}
}

View File

@ -28,16 +28,6 @@ import app.revanced.util.integrations.Constants.PATCHES_PATH
class ButtonContainerPatch : ResourcePatch {
override fun execute(context: ResourceContext): PatchResult {
if (SettingsPatch.below1820) {
LithoFilterPatch.addFilter("$PATCHES_PATH/ads/ActionButtonsFilter;")
SettingsPatch.addPreference(
arrayOf(
"PREFERENCE: BOTTOM_PLAYER_SETTINGS",
"SETTINGS: EXPERIMENTAL_BUTTON_CONTAINER"
)
)
}
LithoFilterPatch.addFilter("$PATCHES_PATH/ads/ButtonsFilter;")
/**

View File

@ -1,9 +1,9 @@
package app.revanced.patches.shared.fingerprints.litho
package app.revanced.patches.youtube.utils.litho.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import com.android.tools.smali.dexlib2.Opcode
object ByteBufferHookFingerprint : MethodFingerprint(
object GeneralByteBufferFingerprint : MethodFingerprint(
returnType = "L",
opcodes = listOf(
Opcode.ADD_INT_2ADDR,

View File

@ -5,7 +5,7 @@ import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
object ByteBufferFingerprint : MethodFingerprint(
object LowLevelByteBufferFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.STATIC,
parameters = listOf("L", "L"),

View File

@ -3,6 +3,7 @@ package app.revanced.patches.youtube.utils.litho.patch
import app.revanced.extensions.toErrorResult
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.data.toMethodWalker
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.removeInstructions
@ -11,12 +12,13 @@ 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.patch.litho.ComponentParserPatch
import app.revanced.patches.shared.patch.litho.ComponentParserPatch.Companion.generalHook
import app.revanced.patches.shared.patch.litho.ComponentParserPatch.Companion.legacyHook
import app.revanced.patches.youtube.utils.annotations.YouTubeCompatibility
import app.revanced.patches.youtube.utils.litho.fingerprints.ByteBufferFingerprint
import app.revanced.patches.youtube.utils.litho.fingerprints.GeneralByteBufferFingerprint
import app.revanced.patches.youtube.utils.litho.fingerprints.LithoFilterFingerprint
import app.revanced.patches.youtube.utils.litho.fingerprints.LowLevelByteBufferFingerprint
import app.revanced.patches.youtube.utils.playertype.patch.PlayerTypeHookPatch
import app.revanced.patches.youtube.utils.settings.resource.patch.SettingsPatch
import app.revanced.util.integrations.Constants.ADS_PATH
@ -33,22 +35,33 @@ import java.io.Closeable
@Version("0.0.1")
class LithoFilterPatch : BytecodePatch(
listOf(
ByteBufferFingerprint,
LithoFilterFingerprint
GeneralByteBufferFingerprint,
LithoFilterFingerprint,
LowLevelByteBufferFingerprint
)
), Closeable {
override fun execute(context: BytecodeContext): PatchResult {
ByteBufferFingerprint.result?.mutableMethod?.addInstruction(
LowLevelByteBufferFingerprint.result?.mutableMethod?.addInstruction(
0,
"sput-object p0, $ADS_PATH/LowLevelFilter;->byteBuffer:Ljava/nio/ByteBuffer;"
) ?: return ByteBufferFingerprint.toErrorResult()
"invoke-static { p0 }, $ADS_PATH/LowLevelFilter;->setProtoBuffer(Ljava/nio/ByteBuffer;)V"
) ?: return LowLevelByteBufferFingerprint.toErrorResult()
if (SettingsPatch.below1820)
legacyHook("$ADS_PATH/LithoFilterPatch;->filters")
else
generalHook("$ADS_PATH/LithoFilterPatch;->filters")
GeneralByteBufferFingerprint.result?.let {
(context
.toMethodWalker(it.method)
.nextMethod(it.scanResult.patternScanResult!!.endIndex, true)
.getMethod() as MutableMethod
).apply {
addInstruction(
0,
"invoke-static { p2 }, $ADS_PATH/LithoFilterPatch;->setProtoBuffer(Ljava/nio/ByteBuffer;)V"
)
}
} ?: return GeneralByteBufferFingerprint.toErrorResult()
generalHook("$ADS_PATH/LithoFilterPatch;->filters")
LithoFilterFingerprint.result?.mutableMethod?.apply {
removeInstructions(2, 4) // Remove dummy filter.

View File

@ -74,7 +74,6 @@ class SettingsPatch : AbstractSettingsResourcePatch(
val playServicesVersion = node.textContent.toInt()
below1820 = playServicesVersion <= 232100000
upward1828 = playServicesVersion >= 232900000
break
@ -184,7 +183,6 @@ class SettingsPatch : AbstractSettingsResourcePatch(
private val threadPoolExecutor = Executors.newFixedThreadPool(THREAD_COUNT)
internal lateinit var contexts: ResourceContext
internal var below1820: Boolean = false
internal var upward1828: Boolean = false
internal fun addPreference(settingArray: Array<String>) {

View File

@ -163,9 +163,6 @@
<string name="revanced_hide_account_menu_summary">Known issue: May not work in landscape mode or on high dpi devices</string>
<string name="revanced_hide_account_menu_title">Hide account menu</string>
<string name="revanced_hide_account_menu_filter_strings_title">Edit account menu filter</string>
<string name="revanced_hide_action_buttons_summary_off">Action buttons are shown</string>
<string name="revanced_hide_action_buttons_summary_on">Action buttons are hidden</string>
<string name="revanced_hide_action_buttons_title">Hide action buttons</string>
<string name="revanced_hide_album_card_summary_off">Album cards are shown</string>
<string name="revanced_hide_album_card_summary_on">Album cards are hidden</string>
<string name="revanced_hide_album_card_title">Hide album cards</string>

View File

@ -32,22 +32,18 @@
<!-- SETTINGS: BUTTON_CONTAINER
<Preference android:title=" " android:selectable="false" android:summary="@string/revanced_button_container_title" />
<SwitchPreference android:title="@string/revanced_hide_action_buttons_title" android:key="revanced_hide_action_buttons" android:defaultValue="false" android:summaryOn="@string/revanced_hide_action_buttons_summary_on" android:summaryOff="@string/revanced_hide_action_buttons_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_button_create_clip_title" android:key="revanced_hide_button_create_clip" android:defaultValue="false" android:summaryOn="@string/revanced_hide_button_create_clip_summary_on" android:summaryOff="@string/revanced_hide_button_create_clip_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_button_dislike_title" android:key="revanced_hide_button_dislike" android:defaultValue="false" android:summaryOn="@string/revanced_hide_button_dislike_summary_on" android:summaryOff="@string/revanced_hide_button_dislike_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_button_download_title" android:key="revanced_hide_button_download" android:defaultValue="false" android:summaryOn="@string/revanced_hide_button_download_summary_on" android:summaryOff="@string/revanced_hide_button_download_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_button_like_title" android:key="revanced_hide_button_like" android:defaultValue="false" android:summaryOn="@string/revanced_hide_button_like_summary_on" android:summaryOff="@string/revanced_hide_button_like_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_button_playlist_title" android:key="revanced_hide_button_playlist" android:defaultValue="false" android:summaryOn="@string/revanced_hide_button_playlist_summary_on" android:summaryOff="@string/revanced_hide_button_playlist_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_button_rewards_title" android:key="revanced_hide_button_rewards" android:defaultValue="false" android:summaryOn="@string/revanced_hide_button_rewards_summary_on" android:summaryOff="@string/revanced_hide_button_rewards_summary_off" />SETTINGS: BUTTON_CONTAINER -->
<!-- SETTINGS: EXPERIMENTAL_BUTTON_CONTAINER
<Preference android:title=" " android:selectable="false" android:summary="@string/revanced_experimental_flag" />
<SwitchPreference android:title="@string/revanced_hide_button_live_chat_title" android:key="revanced_hide_button_live_chat" android:defaultValue="false" android:summaryOn="@string/revanced_hide_button_live_chat_summary_on" android:summaryOff="@string/revanced_hide_button_live_chat_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_button_playlist_title" android:key="revanced_hide_button_playlist" android:defaultValue="false" android:summaryOn="@string/revanced_hide_button_playlist_summary_on" android:summaryOff="@string/revanced_hide_button_playlist_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_button_remix_title" android:key="revanced_hide_button_remix" android:defaultValue="false" android:summaryOn="@string/revanced_hide_button_remix_summary_on" android:summaryOff="@string/revanced_hide_button_remix_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_button_report_title" android:key="revanced_hide_button_report" android:defaultValue="false" android:summaryOn="@string/revanced_hide_button_report_summary_on" android:summaryOff="@string/revanced_hide_button_report_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_button_rewards_title" android:key="revanced_hide_button_rewards" android:defaultValue="false" android:summaryOn="@string/revanced_hide_button_rewards_summary_on" android:summaryOff="@string/revanced_hide_button_rewards_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_button_share_title" android:key="revanced_hide_button_share" android:defaultValue="false" android:summaryOn="@string/revanced_hide_button_share_summary_on" android:summaryOff="@string/revanced_hide_button_share_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_button_shop_title" android:key="revanced_hide_button_shop" android:defaultValue="false" android:summaryOn="@string/revanced_hide_button_shop_summary_on" android:summaryOff="@string/revanced_hide_button_shop_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_button_thanks_title" android:key="revanced_hide_button_thanks" android:defaultValue="false" android:summaryOn="@string/revanced_hide_button_thanks_summary_on" android:summaryOff="@string/revanced_hide_button_thanks_summary_off" />SETTINGS: EXPERIMENTAL_BUTTON_CONTAINER -->
<SwitchPreference android:title="@string/revanced_hide_button_thanks_title" android:key="revanced_hide_button_thanks" android:defaultValue="false" android:summaryOn="@string/revanced_hide_button_thanks_summary_on" android:summaryOff="@string/revanced_hide_button_thanks_summary_off" />SETTINGS: BUTTON_CONTAINER -->
<!-- SETTINGS: COMMENT_COMPONENTS