Merge remote-tracking branch 'origin/dalvik-patches' into dalvik-patches

This commit is contained in:
oSumAtrIX 2022-04-18 18:01:33 +02:00
commit 50b767314e
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
4 changed files with 201 additions and 12 deletions

View File

@ -0,0 +1,14 @@
package app.revanced.extensions
import app.revanced.patcher.smali.toInstruction
import org.jf.dexlib2.builder.MutableMethodImplementation
internal fun MutableMethodImplementation.injectHideCall(
index: Int,
register: Int
) {
this.addInstruction(
index,
"invoke-static { v$register }, Lfi/razerman/youtube/XAdRemover;->HideView(Landroid/view/View;)V".toInstruction()
)
}

View File

@ -2,9 +2,13 @@ package app.revanced.patches
import app.revanced.patcher.patch.Patch import app.revanced.patcher.patch.Patch
import app.revanced.patches.ad.HomeAdsPatch import app.revanced.patches.ad.HomeAdsPatch
import app.revanced.patches.ad.HomePromoPatch
import app.revanced.patches.ad.VideoAdsPatch import app.revanced.patches.ad.VideoAdsPatch
import app.revanced.patches.interaction.EnableSeekbarTappingPatch import app.revanced.patches.interaction.EnableSeekbarTappingPatch
import app.revanced.patches.layout.* import app.revanced.patches.layout.CreateButtonRemoverPatch
import app.revanced.patches.layout.HideReelsPatch
import app.revanced.patches.layout.MinimizedPlaybackPatch
import app.revanced.patches.layout.OldQualityLayoutPatch
import app.revanced.patches.misc.IntegrationsPatch import app.revanced.patches.misc.IntegrationsPatch
/** /**
@ -20,6 +24,7 @@ object Index {
::IntegrationsPatch, ::IntegrationsPatch,
::HomeAdsPatch, ::HomeAdsPatch,
::VideoAdsPatch, ::VideoAdsPatch,
::HomePromoPatch,
::MinimizedPlaybackPatch, ::MinimizedPlaybackPatch,
::CreateButtonRemoverPatch, ::CreateButtonRemoverPatch,
::HideReelsPatch, ::HideReelsPatch,

View File

@ -1,5 +1,6 @@
package app.revanced.patches.ad package app.revanced.patches.ad
import app.revanced.extensions.injectHideCall
import app.revanced.patcher.PatcherData import app.revanced.patcher.PatcherData
import app.revanced.patcher.extensions.or import app.revanced.patcher.extensions.or
import app.revanced.patcher.patch.Patch import app.revanced.patcher.patch.Patch
@ -10,7 +11,6 @@ import app.revanced.patcher.signature.MethodMetadata
import app.revanced.patcher.signature.MethodSignature import app.revanced.patcher.signature.MethodSignature
import app.revanced.patcher.signature.MethodSignatureMetadata import app.revanced.patcher.signature.MethodSignatureMetadata
import app.revanced.patcher.signature.PatternScanMethod import app.revanced.patcher.signature.PatternScanMethod
import app.revanced.patcher.smali.toInstruction
import org.jf.dexlib2.AccessFlags import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.Opcode import org.jf.dexlib2.Opcode
import org.jf.dexlib2.iface.instruction.formats.Instruction11x import org.jf.dexlib2.iface.instruction.formats.Instruction11x
@ -22,7 +22,7 @@ private val compatiblePackages = listOf("com.google.android.youtube")
class HomeAdsPatch : Patch( class HomeAdsPatch : Patch(
PatchMetadata( PatchMetadata(
"home-ads", "home-ads",
"Home ads patch", "Home Ads Patch",
"Patch to remove ads in YouTube", "Patch to remove ads in YouTube",
compatiblePackages, compatiblePackages,
"0.0.1" "0.0.1"
@ -219,8 +219,7 @@ class HomeAdsPatch : Patch(
Opcode.IPUT_OBJECT, Opcode.IPUT_OBJECT,
Opcode.MOVE_OBJECT_FROM16, Opcode.MOVE_OBJECT_FROM16,
Opcode.CONST, Opcode.CONST,
)
)
), ),
MethodSignature( MethodSignature(
MethodSignatureMetadata( MethodSignatureMetadata(
@ -736,7 +735,7 @@ class HomeAdsPatch : Patch(
), ),
"V", "V",
AccessFlags.PRIVATE or AccessFlags.FINAL, AccessFlags.PRIVATE or AccessFlags.FINAL,
emptyList(), listOf(),
listOf( listOf(
Opcode.INVOKE_VIRTUAL, Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT_OBJECT, Opcode.MOVE_RESULT_OBJECT,
@ -839,7 +838,7 @@ class HomeAdsPatch : Patch(
), ),
"V", "V",
AccessFlags.PRIVATE or AccessFlags.FINAL, AccessFlags.PRIVATE or AccessFlags.FINAL,
emptyList(), listOf(),
listOf( listOf(
Opcode.INVOKE_VIRTUAL, Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT_OBJECT, Opcode.MOVE_RESULT_OBJECT,
@ -1221,12 +1220,9 @@ class HomeAdsPatch : Patch(
if (i < 2) if (i < 2)
(instructions[index - 1] as Instruction11x).registerA (instructions[index - 1] as Instruction11x).registerA
else else
(instructions[index + 1] as Instruction35c).registerC (instructions[index] as Instruction35c).registerC
implementation.addInstruction( implementation.injectHideCall(index, register)
index,
"invoke-static { v$register }, Lfi/razerman/youtube/XAdRemover;->HideView(Landroid/view/View;)V".toInstruction()
)
} }
return PatchResultSuccess() return PatchResultSuccess()

View File

@ -0,0 +1,174 @@
package app.revanced.patches.ad
import app.revanced.extensions.injectHideCall
import app.revanced.patcher.PatcherData
import app.revanced.patcher.extensions.or
import app.revanced.patcher.patch.*
import app.revanced.patcher.proxy.mutableTypes.MutableMethod
import app.revanced.patcher.signature.MethodMetadata
import app.revanced.patcher.signature.MethodSignature
import app.revanced.patcher.signature.MethodSignatureMetadata
import app.revanced.patcher.signature.PatternScanMethod
import app.revanced.patcher.toMethodWalker
import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.Opcode
import org.jf.dexlib2.iface.instruction.formats.Instruction11x
private val compatiblePackages = listOf("com.google.android.youtube")
class HomePromoPatch : Patch(
PatchMetadata(
"home-promo-ads",
"Home Promo Ads Patch",
"Patch to remove promoted ads in YouTube",
compatiblePackages,
"0.0.1"
),
listOf(
MethodSignature(
MethodSignatureMetadata(
"promoted-discovery-app-parent-method",
MethodMetadata(
"Ljjl;",
"lG",
),
PatternScanMethod.Fuzzy(2), // FIXME: Test this threshold and find the best value.
compatiblePackages,
"Found in YouTube version v17.03.38",
"0.0.1"
),
"V",
AccessFlags.PUBLIC or AccessFlags.FINAL or AccessFlags.BRIDGE or AccessFlags.SYNTHETIC,
listOf("L", "L"),
listOf(
Opcode.INVOKE_DIRECT,
Opcode.IGET_BOOLEAN,
Opcode.INVOKE_VIRTUAL,
Opcode.IGET_OBJECT,
Opcode.IGET_OBJECT,
Opcode.IF_NEZ,
Opcode.IGET_OBJECT,
Opcode.IGET_OBJECT,
Opcode.IF_NEZ,
Opcode.SGET_OBJECT,
Opcode.IPUT_OBJECT,
Opcode.IGET_OBJECT,
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT_OBJECT,
Opcode.IGET_OBJECT,
Opcode.IF_NEZ,
Opcode.IGET_OBJECT,
Opcode.IGET_OBJECT,
Opcode.INVOKE_INTERFACE,
Opcode.MOVE_RESULT,
Opcode.NEW_ARRAY,
Opcode.IPUT_OBJECT,
Opcode.CONST_4,
Opcode.INVOKE_INTERFACE,
Opcode.MOVE_RESULT,
Opcode.IF_GE,
Opcode.IGET_OBJECT,
Opcode.INVOKE_INTERFACE,
Opcode.MOVE_RESULT_OBJECT,
Opcode.CHECK_CAST,
Opcode.APUT_OBJECT,
Opcode.ADD_INT_LIT8,
Opcode.GOTO
)
),
MethodSignature(
MethodSignatureMetadata(
"promoted-discovery-action-parent-method",
MethodMetadata(
"Ljjc;",
"lG",
),
PatternScanMethod.Fuzzy(2), // FIXME: Test this threshold and find the best value.
compatiblePackages,
"Found in YouTube version v17.03.38",
"0.0.1"
),
"V",
AccessFlags.PUBLIC or AccessFlags.FINAL or AccessFlags.BRIDGE or AccessFlags.SYNTHETIC,
listOf("L", "L"),
listOf(
Opcode.MOVE_OBJECT_FROM16,
Opcode.MOVE_OBJECT_FROM16,
Opcode.MOVE_OBJECT_FROM16,
Opcode.CHECK_CAST,
Opcode.INVOKE_VIRTUAL_RANGE,
Opcode.INVOKE_VIRTUAL,
Opcode.IGET_OBJECT,
Opcode.INVOKE_VIRTUAL,
Opcode.IGET_OBJECT,
Opcode.IGET_BOOLEAN,
Opcode.CONST_4,
Opcode.XOR_INT_2ADDR,
Opcode.IGET_BOOLEAN,
Opcode.INVOKE_DIRECT,
Opcode.IGET_BOOLEAN,
Opcode.INVOKE_VIRTUAL,
Opcode.IGET_OBJECT,
Opcode.IGET_OBJECT,
Opcode.IF_NEZ,
Opcode.IGET_OBJECT,
Opcode.IGET_OBJECT,
Opcode.IF_NEZ,
Opcode.SGET_OBJECT,
Opcode.IPUT_OBJECT,
Opcode.IGET_OBJECT,
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT_OBJECT,
Opcode.IGET_OBJECT,
Opcode.CONST_4,
Opcode.IF_NEZ,
Opcode.IGET_OBJECT,
Opcode.IGET_OBJECT
)
)
)
) {
override fun execute(patcherData: PatcherData): PatchResult {
for (signature in signatures) {
val result = signature.result!!
val methodMetadata = MethodMetadata(signature.metadata.methodMetadata!!.definingClass, "d")
val requiredMethod = result.findParentMethod(
MethodSignature(
MethodSignatureMetadata(
"promoted-discovery-action-parent-method",
methodMetadata,
PatternScanMethod.Fuzzy(2), // FIXME: Test this threshold and find the best value.
compatiblePackages,
"Found in YouTube version v17.03.38",
"0.0.1"
),
"V",
AccessFlags.PRIVATE or AccessFlags.FINAL,
listOf("Z", "Z"),
null
)
)
?: return PatchResultError("Required parent method ${methodMetadata.name} could not be found in ${methodMetadata.definingClass}")
val toBePatchedInvokeOffset =
requiredMethod.immutableMethod.implementation!!.instructions.indexOfFirst { it.opcode == Opcode.INVOKE_DIRECT }
val toBePatchedMethod = patcherData
.toMethodWalker(requiredMethod.immutableMethod)
.walk(toBePatchedInvokeOffset, true)
.getMethod() as MutableMethod
val implementation = toBePatchedMethod.implementation!!
val invokeVirtualOffset = implementation.instructions.indexOfFirst { it.opcode == Opcode.INVOKE_VIRTUAL }
val moveResultInstruction = implementation.instructions[invokeVirtualOffset + 1]
if (moveResultInstruction.opcode != Opcode.MOVE_RESULT_OBJECT)
return PatchResultError("The toBePatchedInvokeOffset offset was wrong in ${metadata.name}")
val register = (moveResultInstruction as Instruction11x).registerA
implementation.injectHideCall(invokeVirtualOffset + 2, register)
}
return PatchResultSuccess()
}
}