refactor: simplify casting instructions

This commit is contained in:
inotia00
2023-05-10 21:31:51 +09:00
parent 0f5350e691
commit 2b70050200
144 changed files with 888 additions and 1272 deletions

View File

@ -56,7 +56,7 @@ class PowerSaveModePatch : BytecodePatch(
if (powerManagerIndex == -1) return PatchResultError("Couldn't find PowerManager reference")
} ?: return PowerSaveModeFingerprint.toErrorResult()
/*
/**
* Add settings
*/
SettingsPatch.addPreference(

View File

@ -26,10 +26,9 @@ class ClientSpoofPatch : BytecodePatch(
override fun execute(context: BytecodeContext): PatchResult {
UserAgentHeaderBuilderFingerprint.result?.let {
val insertIndex = it.scanResult.patternScanResult!!.endIndex
with (it.mutableMethod) {
val packageNameRegister = (instruction(insertIndex) as FiveRegisterInstruction).registerD
it.mutableMethod.apply {
val insertIndex = it.scanResult.patternScanResult!!.endIndex
val packageNameRegister = instruction<FiveRegisterInstruction>(insertIndex).registerD
addInstruction(insertIndex, "const-string v$packageNameRegister, \"$PACKAGE_NAME\"")
}
} ?: return UserAgentHeaderBuilderFingerprint.toErrorResult()

View File

@ -6,6 +6,7 @@ import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.extensions.instruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
@ -15,7 +16,7 @@ import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.youtube.misc.externalbrowser.fingerprints.*
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
import app.revanced.util.integrations.Constants.MISC_PATH
import org.jf.dexlib2.iface.instruction.formats.Instruction21c
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
@Patch
@Name("enable-external-browser")
@ -38,19 +39,19 @@ class ExternalBrowserPatch : BytecodePatch(
ExternalBrowserTertiaryFingerprint
).forEach {
val result = it.result?: return it.toErrorResult()
val endIndex = result.scanResult.patternScanResult!!.endIndex
with (result.mutableMethod) {
val register = (implementation!!.instructions[endIndex] as Instruction21c).registerA
it.result?.mutableMethod?.apply {
val endIndex = result.scanResult.patternScanResult!!.endIndex
val register = instruction<OneRegisterInstruction>(endIndex).registerA
addInstructions(
endIndex + 1, """
invoke-static {v$register}, $MISC_PATH/ExternalBrowserPatch;->enableExternalBrowser(Ljava/lang/String;)Ljava/lang/String;
move-result-object v$register
"""
"""
)
}
}
/*
/**
* Add settings
*/
SettingsPatch.addPreference(

View File

@ -9,7 +9,5 @@ object Vp9PropsFingerprint : MethodFingerprint(
returnType = "L",
access = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf(),
opcodes = listOf(
Opcode.OR_INT_LIT16
)
opcodes = listOf(Opcode.OR_INT_LIT16)
)

View File

@ -64,8 +64,9 @@ class ForceVP9CodecPatch : BytecodePatch(
VideoCapabilitiesParentFingerprint.result?.let { parentResult ->
VideoCapabilitiesFingerprint.also { it.resolve(context, parentResult.classDef) }.result?.let {
with (it.mutableMethod) {
it.mutableMethod.apply {
val insertIndex = it.scanResult.patternScanResult!!.startIndex
addInstructions(
insertIndex, """
invoke-static {p1}, $INTEGRATIONS_CLASS_DESCRIPTOR->overrideMinHeight(I)I
@ -82,7 +83,7 @@ class ForceVP9CodecPatch : BytecodePatch(
} ?: return VideoCapabilitiesFingerprint.toErrorResult()
} ?: return VideoCapabilitiesParentFingerprint.toErrorResult()
/*
/**
* Add settings
*/
SettingsPatch.addPreference(
@ -104,12 +105,12 @@ class ForceVP9CodecPatch : BytecodePatch(
"$INTEGRATIONS_CLASS_DESCRIPTOR->shouldForceVP9(Z)Z"
fun MethodFingerprintResult.injectOverride() {
with (mutableMethod) {
mutableMethod.apply {
val startIndex = scanResult.patternScanResult!!.startIndex
val endIndex = scanResult.patternScanResult!!.endIndex
val startRegister = (instruction(startIndex) as OneRegisterInstruction).registerA
val endRegister = (instruction(endIndex) as OneRegisterInstruction).registerA
val startRegister = instruction<OneRegisterInstruction>(startIndex).registerA
val endRegister = instruction<OneRegisterInstruction>(endIndex).registerA
hookOverride(endIndex + 1, endRegister)
removeInstruction(endIndex)
@ -147,7 +148,7 @@ class ForceVP9CodecPatch : BytecodePatch(
if (indexString != targetString) continue
val register = (instruction as OneRegisterInstruction).registerA
val register = instruction<OneRegisterInstruction>(index).registerA
addInstructions(
index + 1, """

View File

@ -36,7 +36,7 @@ class LayoutSwitchPatch : BytecodePatch(
ClientFormFactorParentFingerprint.result?.let { parentResult ->
ClientFormFactorFingerprint.also { it.resolve(context, parentResult.classDef) }.result?.let {
with (it.mutableMethod) {
it.mutableMethod.apply {
val jumpIndex = it.scanResult.patternScanResult!!.startIndex + 1
addInstructions(
1, """
@ -56,7 +56,7 @@ class LayoutSwitchPatch : BytecodePatch(
"""
) ?: return LayoutSwitchFingerprint.toErrorResult()
/*
/*(
* Add settings
*/
SettingsPatch.addPreference(

View File

@ -0,0 +1,51 @@
package app.revanced.patches.youtube.misc.litho.patch
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.ResourceContext
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.extensions.instruction
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.util.smali.ExternalLabel
import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.youtube.misc.playertype.patch.PlayerTypeHookPatch
import app.revanced.util.integrations.Constants.ADS_PATH
@DependsOn(
[
LithoFilterPatch::class,
PlayerTypeHookPatch::class
]
)
@YouTubeCompatibility
@Version("0.0.1")
class ByteBufferFilterPatch : ResourcePatch {
override fun execute(context: ResourceContext): PatchResult {
return PatchResultSuccess()
}
companion object{
fun inject(descriptor: String){
LithoFilterPatch.lithoMethod.addInstructions(
0, """
move-object/from16 v10, p3
iget-object v10, v10, ${LithoFilterPatch.objectReference}
if-eqz v10, :do_not_block
check-cast v10, ${LithoFilterPatch.bufferReference}
iget-object v10, v10, ${LithoFilterPatch.bufferReference}->b:Ljava/nio/ByteBuffer;
move-object/from16 v3, p2
invoke-static {v3, v10}, $descriptor(Ljava/lang/Object;Ljava/nio/ByteBuffer;)Z
move-result v10
if-eqz v10, :do_not_block
move-object/from16 v15, p1
invoke-static {v15}, ${LithoFilterPatch.builderMethodDescriptor}
move-result-object v0
iget-object v0, v0, ${LithoFilterPatch.emptyComponentFieldDescriptor}
return-object v0
""", listOf(ExternalLabel("do_not_block", LithoFilterPatch.lithoMethod.instruction(0)))
)
}
}
}

View File

@ -18,16 +18,15 @@ import app.revanced.patches.shared.fingerprints.LithoObjectFingerprint
import app.revanced.patches.youtube.ads.doublebacktoclose.patch.DoubleBackToClosePatch
import app.revanced.patches.youtube.ads.swiperefresh.patch.SwipeRefreshPatch
import app.revanced.util.bytecode.BytecodeHelper.updatePatchStatus
import app.revanced.util.bytecode.getNarrowLiteralIndex
import app.revanced.util.bytecode.getStringIndex
import app.revanced.util.integrations.Constants.ADS_PATH
import org.jf.dexlib2.Opcode
import org.jf.dexlib2.builder.instruction.BuilderInstruction21c
import org.jf.dexlib2.builder.instruction.BuilderInstruction35c
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
import org.jf.dexlib2.iface.instruction.ReferenceInstruction
import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction
import org.jf.dexlib2.iface.instruction.formats.Instruction31i
import org.jf.dexlib2.iface.reference.FieldReference
import org.jf.dexlib2.iface.reference.MethodReference
import org.jf.dexlib2.iface.reference.Reference
import kotlin.properties.Delegates
@DependsOn(
@ -47,70 +46,56 @@ class LithoFilterPatch : BytecodePatch(
) {
override fun execute(context: BytecodeContext): PatchResult {
with (LithoBufferFingerprint.result!!) {
val startIndex = this.scanResult.patternScanResult!!.startIndex
bufferReference = (this.mutableMethod.instruction(startIndex) as BuilderInstruction21c).reference.toString()
}
LithoBufferFingerprint.result?.let {
val startIndex = it.scanResult.patternScanResult!!.startIndex
bufferReference = it.mutableMethod.instruction<ReferenceInstruction>(startIndex).reference
} ?: return LithoBufferFingerprint.toErrorResult()
LithoObjectFingerprint.result?.let {
val endIndex = it.scanResult.patternScanResult!!.endIndex
objectRegister = (it.mutableMethod.instruction(endIndex) as BuilderInstruction35c).registerC
objectRegister = it.mutableMethod.instruction<BuilderInstruction35c>(endIndex).registerC
} ?: return LithoObjectFingerprint.toErrorResult()
LithoFingerprint.result?.let { result ->
val endIndex = result.scanResult.patternScanResult!!.endIndex
lithoMethod = result.mutableMethod
with (lithoMethod.implementation!!.instructions) {
val bufferIndex = indexOfFirst {
it.opcode == Opcode.CONST &&
(it as Instruction31i).narrowLiteral == 168777401
}
val bufferRegister = (lithoMethod.instruction(bufferIndex) as Instruction31i).registerA
lithoMethod.apply {
val bufferIndex = getNarrowLiteralIndex(168777401)
val bufferRegister = instruction<OneRegisterInstruction>(bufferIndex).registerA
val targetIndex = getStringIndex("Element missing type extension") + 2
val identifierRegister = instruction<OneRegisterInstruction>(endIndex).registerA
val targetIndex = indexOfFirst {
it.opcode == Opcode.CONST_STRING &&
(it as BuilderInstruction21c).reference.toString() == "Element missing type extension"
} + 2
builderMethodDescriptor = (elementAt(targetIndex) as ReferenceInstruction).reference as MethodReference
emptyComponentFieldDescriptor = (elementAt(targetIndex + 2) as ReferenceInstruction).reference as FieldReference
builderMethodDescriptor = instruction<ReferenceInstruction>(targetIndex).reference
emptyComponentFieldDescriptor = instruction<ReferenceInstruction>(targetIndex + 2).reference
implementation!!.instructions.apply {
filter { instruction ->
val fieldReference = (instruction as? ReferenceInstruction)?.reference as? FieldReference
fieldReference?.let { it.type == "Ljava/lang/StringBuilder;" } == true
}.forEach { instruction ->
val insertIndex = indexOf(instruction)
val stringBuilderRegister = lithoMethod.instruction<TwoRegisterInstruction>(insertIndex).registerA
val identifierRegister = (lithoMethod.instruction(endIndex) as OneRegisterInstruction).registerA
filter { instruction ->
val fieldReference = (instruction as? ReferenceInstruction)?.reference as? FieldReference
fieldReference?.let { it.type == "Ljava/lang/StringBuilder;" } == true
}.forEach { instruction ->
val insertIndex = indexOf(instruction)
val stringBuilderRegister = (lithoMethod.instruction(insertIndex) as TwoRegisterInstruction).registerA
val instructionList =
"""
invoke-static {v$stringBuilderRegister, v$identifierRegister, v$objectRegister, v$bufferRegister}, $ADS_PATH/LithoFilterPatch;->filter(Ljava/lang/StringBuilder;Ljava/lang/String;Ljava/lang/Object;Ljava/nio/ByteBuffer;)Z
move-result v$bufferRegister
if-eqz v$bufferRegister, :not_an_ad
move-object/from16 v$identifierRegister, p1
invoke-static {v$identifierRegister}, $builderMethodDescriptor
move-result-object v0
iget-object v0, v0, $emptyComponentFieldDescriptor
return-object v0
"""
val objectIndex = indexOfFirst {
it.opcode == Opcode.CONST_STRING &&
(it as BuilderInstruction21c).reference.toString() == ""
} - 2
objectReference = (elementAt(objectIndex) as ReferenceInstruction).reference as FieldReference
lithoMethod.addInstructions(
insertIndex + 1,
"""
val objectIndex = lithoMethod.getStringIndex("") - 2
objectReference = lithoMethod.instruction<ReferenceInstruction>(objectIndex).reference
lithoMethod.addInstructions(
insertIndex + 1, """
move-object/from16 v$bufferRegister, p3
iget-object v$bufferRegister, v$bufferRegister, ${objectReference.definingClass}->${objectReference.name}:${objectReference.type}
iget-object v$bufferRegister, v$bufferRegister, $objectReference
if-eqz v$bufferRegister, :not_an_ad
check-cast v$bufferRegister, $bufferReference
iget-object v$bufferRegister, v$bufferRegister, $bufferReference->b:Ljava/nio/ByteBuffer;
""" + instructionList,listOf(ExternalLabel("not_an_ad", lithoMethod.instruction(insertIndex + 1)))
)
invoke-static {v$stringBuilderRegister, v$identifierRegister, v$objectRegister, v$bufferRegister}, $ADS_PATH/LithoFilterPatch;->filters(Ljava/lang/StringBuilder;Ljava/lang/String;Ljava/lang/Object;Ljava/nio/ByteBuffer;)Z
move-result v$bufferRegister
if-eqz v$bufferRegister, :not_an_ad
move-object/from16 v$identifierRegister, p1
invoke-static {v$identifierRegister}, $builderMethodDescriptor
move-result-object v0
iget-object v0, v0, $emptyComponentFieldDescriptor
return-object v0
""", listOf(ExternalLabel("not_an_ad", lithoMethod.instruction(insertIndex + 1)))
)
}
}
}
} ?: return LithoFingerprint.toErrorResult()
@ -123,9 +108,9 @@ class LithoFilterPatch : BytecodePatch(
var objectRegister by Delegates.notNull<Int>()
lateinit var lithoMethod: MutableMethod
lateinit var bufferReference: String
lateinit var builderMethodDescriptor: MethodReference
lateinit var emptyComponentFieldDescriptor: FieldReference
lateinit var objectReference: FieldReference
lateinit var bufferReference: Reference
lateinit var builderMethodDescriptor: Reference
lateinit var emptyComponentFieldDescriptor: Reference
lateinit var objectReference: Reference
}
}

View File

@ -2,18 +2,14 @@ package app.revanced.patches.youtube.misc.minimizedplayback.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.util.bytecode.isNarrowLiteralExists
import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.Opcode
import org.jf.dexlib2.iface.instruction.NarrowLiteralInstruction
object MinimizedPlaybackManagerFingerprint : MethodFingerprint(
returnType = "Z",
access = AccessFlags.PUBLIC or AccessFlags.STATIC,
parameters = listOf("L"),
opcodes = listOf(Opcode.AND_INT_LIT16),
customFingerprint = { methodDef ->
methodDef.implementation!!.instructions.any {
((it as? NarrowLiteralInstruction)?.narrowLiteral == 64657230)
}
}
customFingerprint = { it.isNarrowLiteralExists(64657230) }
)

View File

@ -2,8 +2,8 @@ package app.revanced.patches.youtube.misc.minimizedplayback.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.backgroundCategoryId
import app.revanced.util.bytecode.isWideLiteralExists
import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.Opcode
@ -19,10 +19,5 @@ object MinimizedPlaybackSettingsFingerprint : MethodFingerprint(
Opcode.IF_NEZ,
Opcode.GOTO
),
customFingerprint = { methodDef ->
methodDef.implementation?.instructions?.any { instruction ->
instruction.opcode.ordinal == Opcode.CONST.ordinal &&
(instruction as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.backgroundCategoryLabelId
} == true
}
customFingerprint = { it.isWideLiteralExists(backgroundCategoryId) }
)

View File

@ -1,16 +0,0 @@
package app.revanced.patches.youtube.misc.minimizedplayback.fingerprints
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 PipControllerFingerprint : MethodFingerprint(
returnType = "L",
access = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("L"),
opcodes = listOf(
Opcode.IGET_BOOLEAN
),
customFingerprint = { it.definingClass == "Lcom/google/android/apps/youtube/app/common/ui/pip/DefaultPipController;" }
)

View File

@ -5,6 +5,7 @@ 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.instruction
import app.revanced.patcher.extensions.replaceInstruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
@ -12,8 +13,7 @@ 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.youtube.misc.openlinksdirectly.fingerprints.OpenLinksDirectlyFingerprintPrimary
import app.revanced.patches.youtube.misc.openlinksdirectly.fingerprints.OpenLinksDirectlyFingerprintSecondary
import app.revanced.patches.youtube.misc.openlinksdirectly.fingerprints.*
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
import app.revanced.util.integrations.Constants.MISC_PATH
import org.jf.dexlib2.iface.instruction.formats.Instruction35c
@ -38,8 +38,8 @@ class OpenLinksDirectlyPatch : BytecodePatch(
).forEach {
val result = it.result?: return it.toErrorResult()
val insertIndex = result.scanResult.patternScanResult!!.startIndex
with (result.mutableMethod) {
val register = (implementation!!.instructions[insertIndex] as Instruction35c).registerC
result.mutableMethod.apply {
val register = instruction<Instruction35c>(insertIndex).registerC
replaceInstruction(
insertIndex,
"invoke-static {v$register}, $MISC_PATH/OpenLinksDirectlyPatch;->enableBypassRedirect(Ljava/lang/String;)Landroid/net/Uri;"
@ -47,7 +47,7 @@ class OpenLinksDirectlyPatch : BytecodePatch(
}
}
/*
/**
* Add settings
*/
SettingsPatch.addPreference(

View File

@ -9,8 +9,6 @@ object SpeedClassFingerprint : MethodFingerprint(
returnType = "L",
access = AccessFlags.PUBLIC or AccessFlags.STATIC,
parameters = listOf("L"),
opcodes = listOf(
Opcode.RETURN_OBJECT
),
opcodes = listOf(Opcode.RETURN_OBJECT),
strings = listOf("PLAYBACK_RATE_MENU_BOTTOM_SHEET_FRAGMENT")
)

View File

@ -22,15 +22,10 @@ import app.revanced.patches.youtube.misc.overridespeed.resource.patch.OverrideSp
import app.revanced.util.integrations.Constants.INTEGRATIONS_PATH
import app.revanced.util.integrations.Constants.VIDEO_PATH
import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.dexbacked.reference.DexBackedMethodReference
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
import org.jf.dexlib2.iface.instruction.ReferenceInstruction
import org.jf.dexlib2.iface.reference.FieldReference
import org.jf.dexlib2.immutable.ImmutableField
import org.jf.dexlib2.immutable.ImmutableMethod
import org.jf.dexlib2.immutable.ImmutableMethodImplementation
import org.jf.dexlib2.immutable.ImmutableMethodParameter
import org.jf.dexlib2.immutable.*
@Name("override-speed-hook")
@DependsOn([OverrideSpeedHookResourcePatch::class])
@ -49,21 +44,15 @@ class OverrideSpeedHookPatch : BytecodePatch(
val parentClassDef = parentResult.classDef
VideoSpeedChangedFingerprint.also { it.resolve(context, parentClassDef) }.result?.let {
videoSpeedChangedResult = it
it.mutableMethod.apply {
videoSpeedChangedResult = it
val startIndex = it.scanResult.patternScanResult!!.startIndex
val endIndex = it.scanResult.patternScanResult!!.endIndex
val startIndex = it.scanResult.patternScanResult!!.startIndex
val endIndex = it.scanResult.patternScanResult!!.endIndex
with (it.method.implementation!!.instructions) {
val firstReference =
(elementAt(startIndex) as ReferenceInstruction).reference as FieldReference
val secondReference =
(elementAt(endIndex - 1) as ReferenceInstruction).reference as FieldReference
val thirdReference =
(elementAt(endIndex) as ReferenceInstruction).reference as DexBackedMethodReference
val reference1 = instruction<ReferenceInstruction>(startIndex).reference
val reference2 = instruction<ReferenceInstruction>(endIndex - 1).reference
val reference3 = instruction<ReferenceInstruction>(endIndex).reference
val fieldReference = reference2 as FieldReference
val parentMutableClass = parentResult.mutableClass
@ -78,30 +67,30 @@ class OverrideSpeedHookPatch : BytecodePatch(
null,
ImmutableMethodImplementation(
4, """
const/4 v0, 0x0
cmpg-float v0, v3, v0
if-lez v0, :cond_0
iget-object v0, v2, ${parentClassDef.type}->${firstReference.name}:${firstReference.type}
check-cast v0, ${secondReference.definingClass}
iget-object v1, v0, ${secondReference.definingClass}->${secondReference.name}:${secondReference.type}
invoke-virtual {v1, v3}, $thirdReference
:cond_0
return-void
""".toInstructions(), null, null
const/4 v0, 0x0
cmpg-float v0, v3, v0
if-lez v0, :cond_0
iget-object v0, v2, $reference1
check-cast v0, ${fieldReference.definingClass}
iget-object v1, v0, $reference2
invoke-virtual {v1, v3}, $reference3
:cond_0
return-void
""".toInstructions(), null, null
)
).toMutable()
)
}
with(context
.toMethodWalker(it.method)
.nextMethod(endIndex, true)
.getMethod() as MutableMethod
) {
addInstruction(
this.implementation!!.instructions.size - 1,
"sput p1, $INTEGRATIONS_VIDEO_HELPER_CLASS_DESCRIPTOR->currentSpeed:F"
)
with(context
.toMethodWalker(this)
.nextMethod(endIndex, true)
.getMethod() as MutableMethod
) {
addInstruction(
this.implementation!!.instructions.size - 1,
"sput p1, $INTEGRATIONS_VIDEO_HELPER_CLASS_DESCRIPTOR->currentSpeed:F"
)
}
}
} ?: return VideoSpeedChangedFingerprint.toErrorResult()
@ -109,9 +98,9 @@ class OverrideSpeedHookPatch : BytecodePatch(
SpeedClassFingerprint.result?.let {
with (it.mutableMethod) {
it.mutableMethod.apply {
val index = it.scanResult.patternScanResult!!.endIndex
val register = (implementation!!.instructions[index] as OneRegisterInstruction).registerA
val register = instruction<OneRegisterInstruction>(index).registerA
SPEED_CLASS = this.returnType
replaceInstruction(
index,
@ -126,7 +115,7 @@ class OverrideSpeedHookPatch : BytecodePatch(
} ?: return SpeedClassFingerprint.toErrorResult()
VideoSpeedPatchFingerprint.result?.let {
with (it.mutableMethod) {
it.mutableMethod.apply {
it.mutableClass.staticFields.add(
ImmutableField(
definingClass,

View File

@ -15,7 +15,7 @@ import app.revanced.util.resources.ResourceUtils.copyXmlNode
class OverrideSpeedHookResourcePatch : ResourcePatch {
override fun execute(context: ResourceContext): PatchResult {
/*
/**
* Copy arrays
*/
context.copyXmlNode("youtube/speed/host", "values/arrays.xml", "resources")

View File

@ -1,16 +1,11 @@
package app.revanced.patches.youtube.misc.playerbutton.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.liveChatButtonId
import app.revanced.util.bytecode.isWideLiteralExists
import org.jf.dexlib2.Opcode
object LiveChatFingerprint : MethodFingerprint(
opcodes = listOf(Opcode.NEW_INSTANCE),
customFingerprint = { methodDef ->
methodDef.implementation?.instructions?.any {
it.opcode.ordinal == Opcode.CONST.ordinal &&
(it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.liveChatButtonId
} == true
}
customFingerprint = { it.isWideLiteralExists(liveChatButtonId) }
)

View File

@ -24,9 +24,7 @@ import org.jf.dexlib2.builder.instruction.BuilderInstruction35c
@YouTubeCompatibility
@Version("0.0.1")
class PlayerButtonPatch : BytecodePatch(
listOf(
LiveChatFingerprint
)
listOf(LiveChatFingerprint)
) {
override fun execute(context: BytecodeContext): PatchResult {

View File

@ -1,8 +1,8 @@
package app.revanced.patches.youtube.misc.playercontrols.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.bottomUiContainerResourceId
import app.revanced.util.bytecode.isWideLiteralExists
import org.jf.dexlib2.Opcode
object BottomControlsInflateFingerprint : MethodFingerprint(
@ -11,10 +11,5 @@ object BottomControlsInflateFingerprint : MethodFingerprint(
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT_OBJECT
),
customFingerprint = { methodDef ->
methodDef.implementation?.instructions?.any {
it.opcode.ordinal == Opcode.CONST.ordinal &&
(it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.bottomUiContainerResourceId
} == true
}
customFingerprint = { it.isWideLiteralExists(bottomUiContainerResourceId) }
)

View File

@ -1,8 +1,8 @@
package app.revanced.patches.youtube.misc.playercontrols.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.controlsLayoutStubResourceId
import app.revanced.util.bytecode.isWideLiteralExists
import org.jf.dexlib2.Opcode
object ControlsLayoutInflateFingerprint : MethodFingerprint(
@ -13,10 +13,5 @@ object ControlsLayoutInflateFingerprint : MethodFingerprint(
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT_OBJECT
),
customFingerprint = { methodDef ->
methodDef.implementation?.instructions?.any {
it.opcode.ordinal == Opcode.CONST.ordinal &&
(it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.controlsLayoutStubResourceId
} == true
}
customFingerprint = { it.isWideLiteralExists(controlsLayoutStubResourceId) }
)

View File

@ -5,7 +5,5 @@ import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
object PlayerControlsVisibilityFingerprint : MethodFingerprint(
returnType = "V",
parameters = listOf("Z", "Z"),
customFingerprint = {
it.definingClass.endsWith("YouTubeControlsOverlay;")
}
customFingerprint = { it.definingClass.endsWith("YouTubeControlsOverlay;") }
)

View File

@ -18,9 +18,7 @@ import app.revanced.util.integrations.Constants.UTILS_PATH
@YouTubeCompatibility
@Version("0.0.1")
class PlayerOverlaysHookPatch : BytecodePatch(
listOf(
PlayerOverlaysOnFinishInflateFingerprint
)
listOf(PlayerOverlaysOnFinishInflateFingerprint)
) {
override fun execute(context: BytecodeContext): PatchResult {
// hook YouTubePlayerOverlaysLayout.onFinishInflate()

View File

@ -4,8 +4,6 @@ import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.Opcode
object BadResponseFingerprint : MethodFingerprint(
opcodes = listOf(
Opcode.CONST_16
),
opcodes = listOf(Opcode.CONST_16),
strings = listOf("Response code: ")
)

View File

@ -4,7 +4,5 @@ import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
object SubtitleWindowFingerprint : MethodFingerprint(
parameters = listOf("I", "I", "I", "Z", "Z"),
customFingerprint = { it.definingClass == "Lcom/google/android/libraries/youtube/player/subtitles/model/SubtitleWindowSettings;"
&& it.name == "<init>"
}
customFingerprint = { it.definingClass.endsWith("SubtitleWindowSettings;") && it.name == "<init>" }
)

View File

@ -44,11 +44,11 @@ class ProtobufSpoofPatch : BytecodePatch(
// hook parameter
ProtobufParameterBuilderFingerprint.result?.let {
with (context
(context
.toMethodWalker(it.method)
.nextMethod(it.scanResult.patternScanResult!!.startIndex, true)
.getMethod() as MutableMethod
) {
).apply {
val protobufParam = 3
addInstructions(
@ -85,7 +85,7 @@ class ProtobufSpoofPatch : BytecodePatch(
// Hook video id, required for subtitle fix.
MainstreamVideoIdPatch.injectCall("$MISC_PATH/ProtobufSpoofPatch;->setCurrentVideoId(Ljava/lang/String;)V")
/*
/**
* Add settings
*/
SettingsPatch.addPreference(

View File

@ -42,7 +42,7 @@ class QUICProtocolPatch : BytecodePatch(
)?: return it.toErrorResult()
}
/*
/**
* Add settings
*/
SettingsPatch.addPreference(

View File

@ -18,46 +18,48 @@ import app.revanced.util.enum.ResourceType.*
@Version("0.0.1")
class SharedResourceIdPatch : ResourcePatch {
internal companion object {
var accessibilityProgressTimeLabelId: Long = -1
var accountSwitcherAccessibilityLabelId: Long = -1
var adAttributionLabelId: Long = -1
var accessibilityProgressTimeId: Long = -1
var accessibilityVideoTimeId: Long = -1
var accountSwitcherAccessibilityId: Long = -1
var adAttributionId: Long = -1
var appearanceStringId: Long = -1
var backgroundCategoryLabelId: Long = -1
var barContainerHeightLabelId: Long = -1
var autoNavPreviewId: Long = -1
var backgroundCategoryId: Long = -1
var barContainerHeightId: Long = -1
var bottomUiContainerResourceId: Long = -1
var channelListSubMenuLabelId: Long = -1
var channelListSubMenuId: Long = -1
var chapterRepeatOnResourceId: Long = -1
var compactLinkLabelId: Long = -1
var compactLinkId: Long = -1
var controlsLayoutStubResourceId: Long = -1
var dislikeButtonLabelId: Long = -1
var dislikeButtonId: Long = -1
var donationCompanionResourceId: Long = -1
var easySeekEduContainerId: Long = -1
var expandButtonId: Long = -1
var fabLabelId: Long = -1
var filterBarHeightLabelId: Long = -1
var floatyBarTopMarginLabelId: Long = -1
var fabId: Long = -1
var filterBarHeightId: Long = -1
var floatyBarTopMarginId: Long = -1
var horizontalCardListId: Long = -1
var imageOnlyTabId: Long = -1
var inlineTimeBarColorizedBarPlayedColorDarkId: Long = -1
var inlineTimeBarPlayedNotHighlightedColorId: Long = -1
var layoutCircle: Long = -1
var layoutIcon: Long = -1
var layoutVideo: Long = -1
var likeButtonLabelId: Long = -1
var layoutCircleId: Long = -1
var layoutIconId: Long = -1
var layoutVideoId: Long = -1
var likeButtonId: Long = -1
var liveChatButtonId: Long = -1
var reelPlayerBadgeLabelId: Long = -1
var reelPlayerBadge2LabelId: Long = -1
var reelPlayerFooterLabelId: Long = -1
var reelPlayerInfoPanelLabelId: Long = -1
var reelPlayerPausedLabelId: Long = -1
var reelRemixLabelId: Long = -1
var relatedChipCloudMarginLabelId: Long = -1
var rightCommentLabelId: Long = -1
var searchSuggestionEntryLabelId: Long = -1
var scrubbingLabelId: Long = -1
var slimMetadataToggleButtonLabelId: Long = -1
var tooltipLabelId: Long = -1
var videoQualityFragmentLabelId: Long = -1
var reelPlayerBadgeId: Long = -1
var reelPlayerBadge2Id: Long = -1
var reelPlayerFooterId: Long = -1
var reelPlayerInfoPanelId: Long = -1
var reelPlayerPausedId: Long = -1
var reelRemixId: Long = -1
var relatedChipCloudMarginId: Long = -1
var rightCommentId: Long = -1
var searchSuggestionEntryId: Long = -1
var scrubbingId: Long = -1
var slimMetadataToggleButtonId: Long = -1
var toolTipId: Long = -1
var videoQualityFragmentId: Long = -1
}
override fun execute(context: ResourceContext): PatchResult {
@ -66,46 +68,48 @@ class SharedResourceIdPatch : ResourcePatch {
.resourceMappings
.single { it.type == type.value && it.name == name }.id
accessibilityProgressTimeLabelId = find(STRING, "accessibility_player_progress_time")
accountSwitcherAccessibilityLabelId = find(STRING, "account_switcher_accessibility_label")
adAttributionLabelId = find(ID, "ad_attribution")
accessibilityProgressTimeId = find(STRING, "accessibility_player_progress_time")
accessibilityVideoTimeId = find(STRING, "accessibility_video_time")
accountSwitcherAccessibilityId = find(STRING, "account_switcher_accessibility_label")
adAttributionId = find(ID, "ad_attribution")
appearanceStringId = find(STRING, "app_theme_appearance_dark")
backgroundCategoryLabelId = find(STRING, "pref_background_and_offline_category")
barContainerHeightLabelId = find(DIMEN, "bar_container_height")
autoNavPreviewId = find(ID, "autonav_preview_stub")
backgroundCategoryId = find(STRING, "pref_background_and_offline_category")
barContainerHeightId = find(DIMEN, "bar_container_height")
bottomUiContainerResourceId = find(ID, "bottom_ui_container_stub")
channelListSubMenuLabelId = find(LAYOUT, "channel_list_sub_menu")
channelListSubMenuId = find(LAYOUT, "channel_list_sub_menu")
chapterRepeatOnResourceId = find(STRING, "chapter_repeat_on")
compactLinkLabelId = find(LAYOUT, "compact_link")
compactLinkId = find(LAYOUT, "compact_link")
controlsLayoutStubResourceId = find(ID, "controls_layout_stub")
dislikeButtonLabelId = find(ID, "dislike_button")
dislikeButtonId = find(ID, "dislike_button")
donationCompanionResourceId = find(LAYOUT, "donation_companion")
easySeekEduContainerId = find(ID, "easy_seek_edu_container")
expandButtonId = find(LAYOUT, "expand_button_down")
fabLabelId = find(ID, "fab")
filterBarHeightLabelId = find(DIMEN, "filter_bar_height")
floatyBarTopMarginLabelId = find(DIMEN, "floaty_bar_button_top_margin")
fabId = find(ID, "fab")
filterBarHeightId = find(DIMEN, "filter_bar_height")
floatyBarTopMarginId = find(DIMEN, "floaty_bar_button_top_margin")
horizontalCardListId = find(LAYOUT, "horizontal_card_list")
imageOnlyTabId = find(LAYOUT, "image_only_tab")
inlineTimeBarColorizedBarPlayedColorDarkId = find(COLOR, "inline_time_bar_colorized_bar_played_color_dark")
inlineTimeBarPlayedNotHighlightedColorId = find(COLOR, "inline_time_bar_played_not_highlighted_color")
layoutCircle = find(LAYOUT, "endscreen_element_layout_circle")
layoutIcon = find(LAYOUT, "endscreen_element_layout_icon")
layoutVideo = find(LAYOUT, "endscreen_element_layout_video")
likeButtonLabelId = find(ID, "like_button")
layoutCircleId = find(LAYOUT, "endscreen_element_layout_circle")
layoutIconId = find(LAYOUT, "endscreen_element_layout_icon")
layoutVideoId = find(LAYOUT, "endscreen_element_layout_video")
likeButtonId = find(ID, "like_button")
liveChatButtonId = find(ID, "live_chat_overlay_button")
reelPlayerBadgeLabelId = find(ID, "reel_player_badge")
reelPlayerBadge2LabelId = find(ID, "reel_player_badge2")
reelPlayerFooterLabelId = find(LAYOUT, "reel_player_dyn_footer_vert_stories3")
reelPlayerInfoPanelLabelId = find(ID, "reel_player_info_panel")
reelPlayerPausedLabelId = find(ID, "reel_player_paused_state_buttons")
reelRemixLabelId = find(ID, "reel_dyn_remix")
relatedChipCloudMarginLabelId = find(LAYOUT, "related_chip_cloud_reduced_margins")
rightCommentLabelId = find(DRAWABLE, "ic_right_comment_32c")
searchSuggestionEntryLabelId = find(LAYOUT, "search_suggestion_entry")
scrubbingLabelId = find(DIMEN, "vertical_touch_offset_to_enter_fine_scrubbing")
slimMetadataToggleButtonLabelId = find(COLOR, "slim_metadata_toggle_button")
tooltipLabelId = find(LAYOUT, "tooltip_content_view")
videoQualityFragmentLabelId = find(LAYOUT, "video_quality_bottom_sheet_list_fragment_title")
reelPlayerBadgeId = find(ID, "reel_player_badge")
reelPlayerBadge2Id = find(ID, "reel_player_badge2")
reelPlayerFooterId = find(LAYOUT, "reel_player_dyn_footer_vert_stories3")
reelPlayerInfoPanelId = find(ID, "reel_player_info_panel")
reelPlayerPausedId = find(ID, "reel_player_paused_state_buttons")
reelRemixId = find(ID, "reel_dyn_remix")
relatedChipCloudMarginId = find(LAYOUT, "related_chip_cloud_reduced_margins")
rightCommentId = find(DRAWABLE, "ic_right_comment_32c")
searchSuggestionEntryId = find(LAYOUT, "search_suggestion_entry")
scrubbingId = find(DIMEN, "vertical_touch_offset_to_enter_fine_scrubbing")
slimMetadataToggleButtonId = find(COLOR, "slim_metadata_toggle_button")
toolTipId = find(LAYOUT, "tooltip_content_view")
videoQualityFragmentId = find(LAYOUT, "video_quality_bottom_sheet_list_fragment_title")
return PatchResultSuccess()
}

View File

@ -72,16 +72,15 @@ class ReturnYouTubeDislikePatch : BytecodePatch(
with (it.mutableMethod) {
val conversionContextIndex = it.scanResult.patternScanResult!!.startIndex
conversionContextFieldReference =
(instruction(conversionContextIndex) as ReferenceInstruction).reference
instruction<ReferenceInstruction>(conversionContextIndex).reference
}
} ?: return TextComponentContextFingerprint.toErrorResult()
TextComponentTmpFingerprint.also { it.resolve(context, parentResult.classDef) }.result?.let {
with (it.mutableMethod) {
it.mutableMethod.apply {
val startIndex = it.scanResult.patternScanResult!!.startIndex
tmpRegister =
(instruction(startIndex) as FiveRegisterInstruction).registerE
instruction<FiveRegisterInstruction>(startIndex).registerE
}
} ?: return TextComponentTmpFingerprint.toErrorResult()
@ -90,10 +89,10 @@ class ReturnYouTubeDislikePatch : BytecodePatch(
with (it.mutableMethod) {
val atomicReferenceStartIndex = it.scanResult.patternScanResult!!.startIndex
val insertIndex = it.scanResult.patternScanResult!!.endIndex
val moveCharSequenceInstruction = instruction(insertIndex) as TwoRegisterInstruction
val moveCharSequenceInstruction = instruction<TwoRegisterInstruction>(insertIndex)
val atomicReferenceRegister =
(instruction(atomicReferenceStartIndex) as FiveRegisterInstruction).registerC
instruction<FiveRegisterInstruction>(atomicReferenceStartIndex).registerC
val charSequenceRegister =
moveCharSequenceInstruction.registerB
@ -114,7 +113,7 @@ class ReturnYouTubeDislikePatch : BytecodePatch(
MainstreamVideoIdPatch.injectCall("$INTEGRATIONS_RYD_CLASS_DESCRIPTOR->newVideoLoaded(Ljava/lang/String;)V")
/*
/**
* Add ReVanced Settings
*/
SettingsPatch.addReVancedPreference("ryd_settings")

View File

@ -2,19 +2,13 @@ package app.revanced.patches.youtube.misc.returnyoutubedislike.oldlayout.fingerp
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.dislikeButtonId
import app.revanced.util.bytecode.isWideLiteralExists
import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.Opcode
object ButtonTagFingerprint : MethodFingerprint(
returnType = "V",
access = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("L"),
customFingerprint = { methodDef ->
methodDef.implementation?.instructions?.any {
it.opcode.ordinal == Opcode.CONST.ordinal &&
(it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.dislikeButtonLabelId
} == true
}
customFingerprint = { it.isWideLiteralExists(dislikeButtonId) }
)

View File

@ -1,16 +1,10 @@
package app.revanced.patches.youtube.misc.returnyoutubedislike.oldlayout.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction
import org.jf.dexlib2.Opcode
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.slimMetadataToggleButtonId
import app.revanced.util.bytecode.isWideLiteralExists
object SlimMetadataButtonParentFingerprint : MethodFingerprint(
returnType = "I",
customFingerprint = { methodDef ->
methodDef.implementation?.instructions?.any {
it.opcode.ordinal == Opcode.CONST.ordinal &&
(it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.slimMetadataToggleButtonLabelId
} == true
}
customFingerprint = { it.isWideLiteralExists(slimMetadataToggleButtonId) }
)

View File

@ -13,13 +13,15 @@ import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.dislikeButtonId
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.likeButtonId
import app.revanced.patches.youtube.misc.returnyoutubedislike.oldlayout.fingerprints.*
import app.revanced.util.bytecode.getWideLiteralIndex
import app.revanced.util.integrations.Constants.UTILS_PATH
import org.jf.dexlib2.iface.instruction.FiveRegisterInstruction
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
import org.jf.dexlib2.iface.instruction.ReferenceInstruction
import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction
import org.jf.dexlib2.iface.reference.Reference
@Name("return-youtube-dislike-old-layout")
@ -37,17 +39,17 @@ class ReturnYouTubeDislikeOldLayoutPatch : BytecodePatch(
SlimMetadataButtonParentFingerprint.result?.let { parentResult ->
SlimMetadataButtonViewFingerprint.also { it.resolve(context, parentResult.classDef) }.result?.let {
with (it.mutableMethod) {
it.mutableMethod.apply {
val startIndex = it.scanResult.patternScanResult!!.startIndex
slimMetadataButtonViewFieldReference =
(instruction(startIndex) as ReferenceInstruction).reference
instruction<ReferenceInstruction>(startIndex).reference
}
} ?: return SlimMetadataButtonViewFingerprint.toErrorResult()
SlimMetadataButtonTextFingerprint.also { it.resolve(context, parentResult.classDef) }.result?.let {
with (it.mutableMethod) {
it.mutableMethod.apply {
val insertIndex = it.scanResult.patternScanResult!!.startIndex
val setTextInstruction = instruction(insertIndex) as FiveRegisterInstruction
val setTextInstruction = instruction<FiveRegisterInstruction>(insertIndex)
val tempRegister =
setTextInstruction.registerC + 1
@ -70,23 +72,19 @@ class ReturnYouTubeDislikeOldLayoutPatch : BytecodePatch(
ButtonTagFingerprint.result?.let { parentResult ->
ButtonTagOnClickFingerprint.also { it.resolve(context, parentResult.classDef) }.result?.let {
with (it.mutableMethod) {
it.mutableMethod.apply {
val startIndex = it.scanResult.patternScanResult!!.startIndex
getActiveBooleanFieldReference =
(instruction(startIndex) as ReferenceInstruction).reference
instruction<ReferenceInstruction>(startIndex).reference
}
} ?: return ButtonTagOnClickFingerprint.toErrorResult()
with (parentResult.mutableMethod.implementation!!.instructions) {
val dislikeButtonIndex = this.indexOfFirst {
(it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.dislikeButtonLabelId
}
parentResult.mutableMethod.apply {
val dislikeButtonIndex = getWideLiteralIndex(dislikeButtonId)
val dislikeButtonRegister = instruction<OneRegisterInstruction>(dislikeButtonIndex).registerA
val dislikeButtonInstruction = instruction<TwoRegisterInstruction>(dislikeButtonIndex - 1)
val dislikeButtonRegister = (elementAt(dislikeButtonIndex) as OneRegisterInstruction).registerA
val dislikeButtonInstruction = elementAt(dislikeButtonIndex - 1) as TwoRegisterInstruction
parentResult.mutableMethod.addInstructions(
addInstructions(
dislikeButtonIndex, """
invoke-virtual {v${dislikeButtonInstruction.registerB}}, $getActiveBooleanFieldReference
move-result v$dislikeButtonRegister
@ -94,15 +92,11 @@ class ReturnYouTubeDislikeOldLayoutPatch : BytecodePatch(
"""
)
val likeButtonIndex = this.indexOfFirst {
(it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.likeButtonLabelId
}
val likeButtonIndex = getWideLiteralIndex(likeButtonId)
val likeButtonRegister = instruction<OneRegisterInstruction>(likeButtonIndex).registerA
val likeButtonInstruction = instruction<TwoRegisterInstruction>(likeButtonIndex - 1)
val likeButtonRegister = (elementAt(likeButtonIndex) as OneRegisterInstruction).registerA
val likeButtonInstruction = elementAt(likeButtonIndex - 1) as TwoRegisterInstruction
parentResult.mutableMethod.addInstructions(
addInstructions(
likeButtonIndex, """
invoke-virtual {v${likeButtonInstruction.registerB}}, $getActiveBooleanFieldReference
move-result v$likeButtonRegister

View File

@ -6,6 +6,7 @@ import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.data.toMethodWalker
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.extensions.instruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
@ -19,28 +20,24 @@ import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
@YouTubeCompatibility
@Version("0.0.1")
class ReturnYouTubeDislikeShortsPatch : BytecodePatch(
listOf(
ShortsTextComponentParentFingerprint
)
listOf(ShortsTextComponentParentFingerprint)
) {
override fun execute(context: BytecodeContext): PatchResult {
ShortsTextComponentParentFingerprint.result?.let {
with (context
(context
.toMethodWalker(it.method)
.nextMethod(it.scanResult.patternScanResult!!.endIndex, true)
.getMethod() as MutableMethod
) {
val insertInstructions = this.implementation!!.instructions
val insertIndex = insertInstructions.size - 1
val insertRegister = (insertInstructions.elementAt(insertIndex) as OneRegisterInstruction).registerA
).apply {
val insertIndex = implementation!!.instructions.size - 1
val insertRegister = instruction<OneRegisterInstruction>(insertIndex).registerA
this.insertShorts(insertIndex, insertRegister)
}
with (it.mutableMethod) {
val insertInstructions = this.implementation!!.instructions
it.mutableMethod.apply {
val insertIndex = it.scanResult.patternScanResult!!.startIndex + 2
val insertRegister = (insertInstructions.elementAt(insertIndex - 1) as OneRegisterInstruction).registerA
val insertRegister = instruction<OneRegisterInstruction>(insertIndex - 1).registerA
this.insertShorts(insertIndex, insertRegister)
}

View File

@ -1,17 +1,12 @@
package app.revanced.patches.youtube.misc.settings.bytecode.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.appearanceStringId
import app.revanced.util.bytecode.isWideLiteralExists
import org.jf.dexlib2.Opcode
object ThemeSetterSystemFingerprint : MethodFingerprint(
returnType = "L",
opcodes = listOf(Opcode.RETURN_OBJECT),
customFingerprint = { methodDef ->
methodDef.implementation?.instructions?.any {
it.opcode.ordinal == Opcode.CONST.ordinal &&
(it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.appearanceStringId
} == true
}
customFingerprint = { it.isWideLiteralExists(appearanceStringId) }
)

View File

@ -34,7 +34,7 @@ class SettingsBytecodePatch : BytecodePatch(
override fun execute(context: BytecodeContext): PatchResult {
// apply the current theme of the settings page
ThemeSetterSystemFingerprint.result?.let {
with(it.mutableMethod) {
it.mutableMethod.apply {
val targetIndex = it.scanResult.patternScanResult!!.startIndex
replaceInstruction(
targetIndex,

View File

@ -3,8 +3,5 @@ package app.revanced.patches.youtube.misc.sponsorblock.bytecode.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
object PlayerControllerFingerprint : MethodFingerprint(
customFingerprint = {
it.definingClass == "Lapp/revanced/integrations/sponsorblock/SegmentPlaybackController;"
&& it.name == "setSponsorBarRect"
}
customFingerprint = { it.definingClass.endsWith("SegmentPlaybackController;") && it.name == "setSponsorBarRect" }
)

View File

@ -5,6 +5,7 @@ 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.extensions.replaceInstruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
@ -55,7 +56,7 @@ class SponsorBlockBytecodePatch : BytecodePatch(
/**
* Hook the video time methods
*/
with(MainstreamVideoIdPatch) {
MainstreamVideoIdPatch.apply {
videoTimeHook(
INTEGRATIONS_PLAYER_CONTROLLER_CLASS_DESCRIPTOR,
"setVideoTime"
@ -89,7 +90,7 @@ class SponsorBlockBytecodePatch : BytecodePatch(
for ((index, instruction) in insertInstructions.withIndex()) {
if (instruction.opcode != Opcode.INVOKE_STATIC) continue
val invokeInstruction = instruction as Instruction35c
val invokeInstruction = insertMethod.instruction<Instruction35c>(index)
if ((invokeInstruction.reference as MethodReference).name != "round") continue
val insertIndex = index + 2
@ -132,9 +133,9 @@ class SponsorBlockBytecodePatch : BytecodePatch(
val drawSegmentInstructionInsertIndex = index - 1
val (canvasInstance, centerY) = (insertInstructions[drawSegmentInstructionInsertIndex] as FiveRegisterInstruction).let {
it.registerC to it.registerE
}
val (canvasInstance, centerY) =
insertMethod.instruction<FiveRegisterInstruction>(drawSegmentInstructionInsertIndex).let { it.registerC to it.registerE }
insertMethod.addInstruction(
drawSegmentInstructionInsertIndex,
"invoke-static {v$canvasInstance, v$centerY}, $INTEGRATIONS_PLAYER_CONTROLLER_CLASS_DESCRIPTOR->drawSponsorTimeBars(Landroid/graphics/Canvas;F)V"
@ -166,7 +167,7 @@ class SponsorBlockBytecodePatch : BytecodePatch(
for ((index, instruction) in instructions.withIndex()) {
if (instruction.opcode != Opcode.CONST_STRING) continue
val register = (instruction as OneRegisterInstruction).registerA
val register = it.instruction<OneRegisterInstruction>(index).registerA
it.replaceInstruction(
index,
"const-string v$register, \"${MainstreamVideoIdPatch.reactReference}\""

View File

@ -32,8 +32,8 @@ import app.revanced.util.resources.ResourceUtils.copyXmlNode
class SponsorBlockResourcePatch : ResourcePatch {
override fun execute(context: ResourceContext): PatchResult {
/*
merge SponsorBlock drawables to main drawables
/**
* merge SponsorBlock drawables to main drawables
*/
arrayOf(
@ -57,8 +57,8 @@ class SponsorBlockResourcePatch : ResourcePatch {
context.copyResources("youtube/sponsorblock", resourceGroup)
}
/*
merge xml nodes from the host to their real xml files
/**
* merge xml nodes from the host to their real xml files
*/
// collect all host resources
@ -94,13 +94,11 @@ class SponsorBlockResourcePatch : ResourcePatch {
}
}
/*
/**
* Add ReVanced Settings
*/
SettingsPatch.addReVancedPreference("sponsorblock_settings")
SettingsPatch.updatePatchStatus("sponsorblock")
return PatchResultSuccess()
}
}

View File

@ -5,6 +5,7 @@ import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprintResult
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
@ -16,13 +17,12 @@ import app.revanced.patches.youtube.misc.timebar.fingerprints.*
@YouTubeCompatibility
@Version("0.0.1")
class HookTimeBarPatch : BytecodePatch(
listOf(
EmptyColorFingerprint
)
listOf(EmptyColorFingerprint)
) {
override fun execute(context: BytecodeContext): PatchResult {
EmptyColorFingerprint.result?.let { parentResult ->
emptyColorResult = parentResult
emptyColorMethod = parentResult.mutableMethod
OnDrawFingerprint.also { it.resolve(context, parentResult.classDef) }.result?.mutableMethod?.let {
setTimeBarMethod = it
@ -34,6 +34,7 @@ class HookTimeBarPatch : BytecodePatch(
}
internal companion object {
lateinit var emptyColorResult: MethodFingerprintResult
lateinit var emptyColorMethod: MutableMethod
lateinit var setTimeBarMethod: MutableMethod
}

View File

@ -20,16 +20,14 @@ import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
@YouTubeCompatibility
@Version("0.0.1")
class LegacyVideoIdPatch : BytecodePatch(
listOf(
LegacyVideoIdFingerprint
)
listOf(LegacyVideoIdFingerprint)
) {
override fun execute(context: BytecodeContext): PatchResult {
LegacyVideoIdFingerprint.result?.let {
insertIndex = it.scanResult.patternScanResult!!.endIndex
with (it.mutableMethod) {
it.mutableMethod.apply {
insertMethod = this
videoIdRegister = (implementation!!.instructions[insertIndex + 1] as OneRegisterInstruction).registerA
}

View File

@ -139,7 +139,6 @@ class MainstreamVideoIdPatch : BytecodePatch(
}
}
MainstreamVideoIdFingerprint.result?.let {
insertIndex = it.scanResult.patternScanResult!!.endIndex