feat: client-spoof patch

Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
epicsampler 2022-08-27 00:05:21 +02:00 committed by oSumAtrIX
parent 97000c67ae
commit e40bff50c2
4 changed files with 74 additions and 0 deletions

View File

@ -0,0 +1,14 @@
package app.revanced.patches.youtube.misc.clientspoof.annotations
import app.revanced.patcher.annotation.Compatibility
import app.revanced.patcher.annotation.Package
@Compatibility(
[
Package("com.google.android.youtube", arrayOf()),
Package("com.vanced.android", arrayOf())
]
)
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
internal annotation class ClientSpoofCompatibility

View File

@ -0,0 +1,20 @@
package app.revanced.patches.youtube.misc.clientspoof.fingerprints
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.fingerprint.method.annotation.DirectPatternScanMethod
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.youtube.misc.clientspoof.annotations.ClientSpoofCompatibility
import org.jf.dexlib2.Opcode
@Name("user-agent-header-builder-fingerprint")
@ClientSpoofCompatibility
@DirectPatternScanMethod
@Version("0.0.1")
object UserAgentHeaderBuilderFingerprint : MethodFingerprint(
null,
null,
listOf("L", "L", "L"),
listOf(Opcode.MOVE_RESULT_OBJECT, Opcode.INVOKE_VIRTUAL),
listOf("(Linux; U; Android "),
)

View File

@ -0,0 +1,38 @@
package app.revanced.patches.youtube.misc.clientspoof.patch
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.impl.BytecodeData
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.annotations.DependsOn
import app.revanced.patcher.patch.impl.BytecodePatch
import app.revanced.patches.youtube.misc.clientspoof.annotations.ClientSpoofCompatibility
import app.revanced.patches.youtube.misc.clientspoof.fingerprints.UserAgentHeaderBuilderFingerprint
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch
import org.jf.dexlib2.iface.instruction.FiveRegisterInstruction
@Name("client-spoof")
@Description("Spoofs the YouTube or Vanced client to prevent playback issues.")
@DependsOn([IntegrationsPatch::class])
@ClientSpoofCompatibility
@Version("0.0.1")
class ClientSpoofPatch : BytecodePatch(
listOf(UserAgentHeaderBuilderFingerprint)
) {
override fun execute(data: BytecodeData): PatchResult {
val result = UserAgentHeaderBuilderFingerprint.result!!
val method = result.mutableMethod
val insertIndex = result.patternScanResult!!.endIndex
val packageNameRegister = (method.instruction(insertIndex) as FiveRegisterInstruction).registerD
val originalPackageName = "com.google.android.youtube"
method.addInstructions(insertIndex, "const-string v$packageNameRegister, \"$originalPackageName\"")
return PatchResultSuccess()
}
}

View File

@ -14,6 +14,7 @@ import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patcher.patch.impl.BytecodePatch import app.revanced.patcher.patch.impl.BytecodePatch
import app.revanced.patcher.util.proxy.mutableTypes.MutableClass import app.revanced.patcher.util.proxy.mutableTypes.MutableClass
import app.revanced.patches.youtube.layout.castbutton.patch.HideCastButtonPatch import app.revanced.patches.youtube.layout.castbutton.patch.HideCastButtonPatch
import app.revanced.patches.youtube.misc.clientspoof.patch.ClientSpoofPatch
import app.revanced.patches.youtube.misc.microg.annotations.MicroGPatchCompatibility import app.revanced.patches.youtube.misc.microg.annotations.MicroGPatchCompatibility
import app.revanced.patches.youtube.misc.microg.fingerprints.* import app.revanced.patches.youtube.misc.microg.fingerprints.*
import app.revanced.patches.youtube.misc.microg.patch.resource.MicroGResourcePatch import app.revanced.patches.youtube.misc.microg.patch.resource.MicroGResourcePatch
@ -32,6 +33,7 @@ import org.jf.dexlib2.immutable.reference.ImmutableStringReference
[ [
MicroGResourcePatch::class, MicroGResourcePatch::class,
HideCastButtonPatch::class, HideCastButtonPatch::class,
ClientSpoofPatch::class
] ]
) )
@Name("microg-support") @Name("microg-support")