mirror of
https://github.com/revanced/revanced-patches
synced 2024-12-01 01:42:54 +01:00
refact: include each signature in its corresponding patch
This commit is contained in:
parent
36a2780ab1
commit
582ce70ce2
@ -1,11 +0,0 @@
|
||||
package app.revanced.patches
|
||||
|
||||
import app.revanced.patcher.signature.MethodMetadata
|
||||
import app.revanced.patcher.signature.PatcherMetadata
|
||||
import app.revanced.patcher.signature.ResolverMethod
|
||||
import app.revanced.patcher.signature.SignatureMetadata
|
||||
|
||||
val SHARED_METADATA = SignatureMetadata(
|
||||
MethodMetadata(null, null, ""),
|
||||
PatcherMetadata(ResolverMethod.Direct())
|
||||
)
|
@ -1,35 +1,99 @@
|
||||
package app.revanced.patches.ad
|
||||
|
||||
import app.revanced.patcher.cache.Cache
|
||||
import app.revanced.patcher.PatcherData
|
||||
import app.revanced.patcher.extensions.AccessFlagExtensions.Companion.or
|
||||
import app.revanced.patcher.extensions.addInstructions
|
||||
import app.revanced.patcher.patch.*
|
||||
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.smali.asInstructions
|
||||
import app.revanced.patches.SHARED_METADATA
|
||||
import org.jf.dexlib2.AccessFlags
|
||||
import org.jf.dexlib2.Opcode
|
||||
|
||||
private val compatiblePackages = arrayOf("com.google.android.youtube")
|
||||
|
||||
class VideoAdsPatch : Patch(
|
||||
PatchMetadata(
|
||||
"video-ads",
|
||||
"TODO",
|
||||
"TODO"
|
||||
metadata = PatchMetadata(
|
||||
shortName = "video-ads",
|
||||
name = "YouTube Video Ads Patch",
|
||||
description = "Patch to remove ads in the YouTube video player",
|
||||
compatiblePackages = compatiblePackages,
|
||||
version = "0.0.1"
|
||||
),
|
||||
signatures = listOf(
|
||||
MethodSignature(
|
||||
methodSignatureMetadata = MethodSignatureMetadata(
|
||||
name = "show-video-ads-constructor",
|
||||
methodMetadata = MethodMetadata(
|
||||
definingClass = "zai",
|
||||
name = "<init>",
|
||||
),
|
||||
patternScanMethod = PatternScanMethod.Fuzzy(2),// FIXME: Test this threshold and find the best value.
|
||||
compatiblePackages = compatiblePackages,
|
||||
description = """Signature for the constructor of some class.
|
||||
This signature is being used to find another method in the parent class
|
||||
and was discovered in the YouTube version v17.03.38""",
|
||||
version = "0.0.1"
|
||||
),
|
||||
returnType = "V",
|
||||
accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
|
||||
methodParameters = listOf("L", "L", "L"),
|
||||
opcodes = listOf(
|
||||
Opcode.INVOKE_DIRECT,
|
||||
Opcode.NEW_INSTANCE,
|
||||
Opcode.INVOKE_DIRECT,
|
||||
Opcode.IPUT_OBJECT,
|
||||
Opcode.NEW_INSTANCE,
|
||||
Opcode.CONST_4,
|
||||
Opcode.INVOKE_DIRECT,
|
||||
Opcode.IPUT_OBJECT,
|
||||
Opcode.NEW_INSTANCE,
|
||||
Opcode.INVOKE_DIRECT,
|
||||
Opcode.IPUT_OBJECT,
|
||||
Opcode.IPUT_OBJECT,
|
||||
Opcode.IPUT_OBJECT,
|
||||
Opcode.CONST_4,
|
||||
Opcode.IPUT_BOOLEAN,
|
||||
Opcode.RETURN_VOID
|
||||
)
|
||||
)
|
||||
)
|
||||
) {
|
||||
override fun execute(cache: Cache): PatchResult {
|
||||
val map = cache.methodMap["show-video-ads-constructor"].findParentMethod(
|
||||
MethodSignature(
|
||||
"show-video-ads-method",
|
||||
SHARED_METADATA,
|
||||
"V",
|
||||
AccessFlags.PUBLIC or AccessFlags.FINAL,
|
||||
listOf("Z"),
|
||||
null
|
||||
)
|
||||
) ?: return PatchResultError("Could not find required method to patch")
|
||||
override fun execute(patcherData: PatcherData): PatchResult {
|
||||
val constructorSignature = signatures.first()
|
||||
var result = signatures.first().result
|
||||
result ?: return PatchResultError(
|
||||
"Could not resolve required signature ${constructorSignature.methodSignatureMetadata.name}"
|
||||
)
|
||||
|
||||
val responsibleMethodSignature = MethodSignature(
|
||||
methodSignatureMetadata = MethodSignatureMetadata(
|
||||
name = "show-video-ads-method",
|
||||
methodMetadata = MethodMetadata(
|
||||
definingClass = "zai",
|
||||
name = null // unknown
|
||||
),
|
||||
patternScanMethod = PatternScanMethod.Direct(),
|
||||
compatiblePackages = compatiblePackages,
|
||||
description = "Signature to find the method, which is responsible for showing the video ads",
|
||||
version = "0.0.1"
|
||||
),
|
||||
returnType = "V",
|
||||
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
|
||||
methodParameters = listOf("Z"),
|
||||
opcodes = null
|
||||
)
|
||||
|
||||
result = result.findParentMethod(
|
||||
responsibleMethodSignature
|
||||
) ?: return PatchResultError(
|
||||
"Could not find parent method with signature ${responsibleMethodSignature.methodSignatureMetadata.name}"
|
||||
)
|
||||
|
||||
// Override the parameter by calling shouldShowAds and setting the parameter to the result
|
||||
map.method.implementation!!.addInstructions(
|
||||
result.method.implementation!!.addInstructions(
|
||||
0,
|
||||
"""
|
||||
invoke-static { }, Lfi/vanced/libraries/youtube/whitelisting/Whitelist;->shouldShowAds()Z
|
||||
|
@ -1,39 +1,99 @@
|
||||
package app.revanced.patches.misc
|
||||
|
||||
import app.revanced.patcher.cache.Cache
|
||||
import app.revanced.patcher.PatcherData
|
||||
import app.revanced.patcher.extensions.AccessFlagExtensions.Companion.or
|
||||
import app.revanced.patcher.extensions.addInstructions
|
||||
import app.revanced.patcher.patch.Patch
|
||||
import app.revanced.patcher.patch.PatchMetadata
|
||||
import app.revanced.patcher.patch.PatchResult
|
||||
import app.revanced.patcher.patch.PatchResultSuccess
|
||||
import app.revanced.patcher.patch.*
|
||||
import app.revanced.patcher.proxy.mutableTypes.MutableMethod.Companion.toMutable
|
||||
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.smali.asInstructions
|
||||
import org.jf.dexlib2.AccessFlags
|
||||
import org.jf.dexlib2.Opcode
|
||||
import org.jf.dexlib2.immutable.ImmutableMethod
|
||||
import org.jf.dexlib2.immutable.ImmutableMethodImplementation
|
||||
|
||||
private val compatiblePackages = arrayOf("com.google.android.youtube")
|
||||
|
||||
class IntegrationsPatch : Patch(
|
||||
PatchMetadata(
|
||||
metadata = PatchMetadata(
|
||||
"integrations",
|
||||
"TODO",
|
||||
"TODO"
|
||||
"Inject integrations",
|
||||
"Applies mandatory patches to implement the ReVanced integrations into the application",
|
||||
compatiblePackages,
|
||||
"1.0.0"
|
||||
),
|
||||
signatures = listOf(
|
||||
MethodSignature(
|
||||
methodSignatureMetadata = MethodSignatureMetadata(
|
||||
name = "integrations-patch",
|
||||
methodMetadata = MethodMetadata(null, null), // unknown
|
||||
patternScanMethod = PatternScanMethod.Fuzzy(2), // FIXME: Test this threshold and find the best value.
|
||||
compatiblePackages = compatiblePackages,
|
||||
description = "Inject the integrations into the application with the method of this signature",
|
||||
version = "0.0.1"
|
||||
),
|
||||
returnType = "V",
|
||||
accessFlags = AccessFlags.PUBLIC.value,
|
||||
methodParameters = listOf(),
|
||||
opcodes = listOf(
|
||||
Opcode.SGET_OBJECT,
|
||||
Opcode.NEW_INSTANCE,
|
||||
Opcode.INVOKE_DIRECT,
|
||||
Opcode.IGET_OBJECT,
|
||||
Opcode.CONST_STRING,
|
||||
Opcode.IF_NEZ,
|
||||
Opcode.IGET_OBJECT,
|
||||
Opcode.IGET_OBJECT,
|
||||
Opcode.IGET_OBJECT,
|
||||
Opcode.IGET_OBJECT,
|
||||
Opcode.MOVE_OBJECT,
|
||||
Opcode.CHECK_CAST,
|
||||
Opcode.MOVE_OBJECT,
|
||||
Opcode.CHECK_CAST,
|
||||
Opcode.CONST_4,
|
||||
Opcode.CONST_STRING,
|
||||
Opcode.INVOKE_INTERFACE_RANGE,
|
||||
Opcode.MOVE_RESULT_OBJECT,
|
||||
Opcode.INVOKE_STATIC,
|
||||
Opcode.MOVE_RESULT_OBJECT,
|
||||
Opcode.SPUT_OBJECT,
|
||||
Opcode.SGET_OBJECT,
|
||||
Opcode.INVOKE_STATIC,
|
||||
Opcode.INVOKE_STATIC,
|
||||
Opcode.MOVE_RESULT_OBJECT,
|
||||
Opcode.IGET_OBJECT,
|
||||
Opcode.INVOKE_INTERFACE,
|
||||
Opcode.MOVE_RESULT_OBJECT,
|
||||
Opcode.CHECK_CAST,
|
||||
Opcode.INVOKE_VIRTUAL,
|
||||
Opcode.INVOKE_SUPER,
|
||||
Opcode.INVOKE_VIRTUAL
|
||||
)
|
||||
)
|
||||
)
|
||||
) {
|
||||
override fun execute(cache: Cache): PatchResult {
|
||||
val map = cache.methodMap["integrations-patch"]
|
||||
val implementation = map.method.implementation!!
|
||||
override fun execute(patcherData: PatcherData): PatchResult {
|
||||
val signature = signatures.first()
|
||||
val result = signatures.first().result
|
||||
result ?: return PatchResultError(
|
||||
"Could not resolve required signature ${signature.methodSignatureMetadata.name}"
|
||||
)
|
||||
|
||||
val implementation = result.method.implementation!!
|
||||
val count = implementation.registerCount - 1
|
||||
|
||||
implementation.addInstructions(
|
||||
map.scanData.endIndex,
|
||||
result.scanData.endIndex,
|
||||
"""
|
||||
invoke-static {v$count}, Lpl/jakubweg/StringRef;->setContext(Landroid/content/Context;)V
|
||||
sput-object v$count, Lapp/revanced/integrations/Globals;->context:Landroid/content/Context;
|
||||
""".trimIndent().asInstructions()
|
||||
)
|
||||
|
||||
val classDef = map.definingClassProxy.resolve()
|
||||
val classDef = result.definingClassProxy.resolve()
|
||||
classDef.methods.add(
|
||||
ImmutableMethod(
|
||||
classDef.type,
|
||||
|
@ -5,9 +5,6 @@ import app.revanced.patches.ad.VideoAdsPatch
|
||||
import app.revanced.patches.interaction.EnableSeekbarTappingPatch
|
||||
import app.revanced.patches.layout.*
|
||||
import app.revanced.patches.misc.IntegrationsPatch
|
||||
import app.revanced.signatures.SignatureSupplier
|
||||
import app.revanced.signatures.ad.VideoAdsSignature
|
||||
import app.revanced.signatures.misc.IntegrationsSignature
|
||||
|
||||
/**
|
||||
* Index contains all the patches and signatures.
|
||||
@ -28,13 +25,4 @@ object Index {
|
||||
::OldQualityLayoutPatch,
|
||||
::EnableSeekbarTappingPatch
|
||||
)
|
||||
|
||||
/**
|
||||
* Array of signatures.
|
||||
* New signatures should be added to the array.
|
||||
*/
|
||||
val signatures: Array<() -> SignatureSupplier> = arrayOf(
|
||||
::IntegrationsSignature,
|
||||
::VideoAdsSignature,
|
||||
)
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package app.revanced.signatures
|
||||
|
||||
import app.revanced.patcher.signature.MethodSignature
|
||||
|
||||
interface SignatureSupplier {
|
||||
fun get(): MethodSignature
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
package app.revanced.signatures.ad
|
||||
|
||||
import app.revanced.patcher.extensions.AccessFlagExtensions.Companion.or
|
||||
import app.revanced.patcher.signature.*
|
||||
import app.revanced.signatures.SignatureSupplier
|
||||
import org.jf.dexlib2.AccessFlags
|
||||
import org.jf.dexlib2.Opcode
|
||||
|
||||
class VideoAdsSignature : SignatureSupplier {
|
||||
override fun get() = MethodSignature(
|
||||
"show-video-ads-constructor",
|
||||
SignatureMetadata(
|
||||
method = MethodMetadata(
|
||||
definingClass = "zai",
|
||||
methodName = "<init>",
|
||||
comment = "YouTube v17.03.38"
|
||||
),
|
||||
patcher = PatcherMetadata(
|
||||
// FIXME: Test this threshold and find the best value.
|
||||
resolverMethod = ResolverMethod.Fuzzy(2)
|
||||
)
|
||||
),
|
||||
"V",
|
||||
AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
|
||||
listOf("L", "L", "L"),
|
||||
listOf(
|
||||
Opcode.INVOKE_DIRECT,
|
||||
Opcode.NEW_INSTANCE,
|
||||
Opcode.INVOKE_DIRECT,
|
||||
Opcode.IPUT_OBJECT,
|
||||
Opcode.NEW_INSTANCE,
|
||||
Opcode.CONST_4,
|
||||
Opcode.INVOKE_DIRECT,
|
||||
Opcode.IPUT_OBJECT,
|
||||
Opcode.NEW_INSTANCE,
|
||||
Opcode.INVOKE_DIRECT,
|
||||
Opcode.IPUT_OBJECT,
|
||||
Opcode.IPUT_OBJECT,
|
||||
Opcode.IPUT_OBJECT,
|
||||
Opcode.CONST_4,
|
||||
Opcode.IPUT_BOOLEAN,
|
||||
Opcode.RETURN_VOID
|
||||
)
|
||||
)
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
package app.revanced.signatures.misc
|
||||
|
||||
import app.revanced.patcher.signature.*
|
||||
import app.revanced.signatures.SignatureSupplier
|
||||
import org.jf.dexlib2.AccessFlags
|
||||
import org.jf.dexlib2.Opcode
|
||||
|
||||
class IntegrationsSignature : SignatureSupplier {
|
||||
override fun get() = MethodSignature(
|
||||
"integrations-patch",
|
||||
SignatureMetadata(
|
||||
method = MethodMetadata(
|
||||
definingClass = "???", // TODO: Fill this in.
|
||||
methodName = "???", // TODO: Fill this in.
|
||||
comment = "YouTube v17.03.38"
|
||||
),
|
||||
patcher = PatcherMetadata(
|
||||
// FIXME: Test this threshold and find the best value.
|
||||
resolverMethod = ResolverMethod.Fuzzy(2)
|
||||
)
|
||||
),
|
||||
"V",
|
||||
AccessFlags.PUBLIC.value,
|
||||
listOf(),
|
||||
listOf(
|
||||
Opcode.SGET_OBJECT,
|
||||
Opcode.NEW_INSTANCE,
|
||||
Opcode.INVOKE_DIRECT,
|
||||
Opcode.IGET_OBJECT,
|
||||
Opcode.CONST_STRING,
|
||||
Opcode.IF_NEZ,
|
||||
Opcode.IGET_OBJECT,
|
||||
Opcode.IGET_OBJECT,
|
||||
Opcode.IGET_OBJECT,
|
||||
Opcode.IGET_OBJECT,
|
||||
Opcode.MOVE_OBJECT,
|
||||
Opcode.CHECK_CAST,
|
||||
Opcode.MOVE_OBJECT,
|
||||
Opcode.CHECK_CAST,
|
||||
Opcode.CONST_4,
|
||||
Opcode.CONST_STRING,
|
||||
Opcode.INVOKE_INTERFACE_RANGE,
|
||||
Opcode.MOVE_RESULT_OBJECT,
|
||||
Opcode.INVOKE_STATIC,
|
||||
Opcode.MOVE_RESULT_OBJECT,
|
||||
Opcode.SPUT_OBJECT,
|
||||
Opcode.SGET_OBJECT,
|
||||
Opcode.INVOKE_STATIC,
|
||||
Opcode.INVOKE_STATIC,
|
||||
Opcode.MOVE_RESULT_OBJECT,
|
||||
Opcode.IGET_OBJECT,
|
||||
Opcode.INVOKE_INTERFACE,
|
||||
Opcode.MOVE_RESULT_OBJECT,
|
||||
Opcode.CHECK_CAST,
|
||||
Opcode.INVOKE_VIRTUAL,
|
||||
Opcode.INVOKE_SUPER,
|
||||
Opcode.INVOKE_VIRTUAL
|
||||
)
|
||||
)
|
||||
}
|
Loading…
Reference in New Issue
Block a user