From e40bff50c2a83380a2aab9e14cfcea5249a8d3d3 Mon Sep 17 00:00:00 2001 From: epicsampler <102923070+epicsampler@users.noreply.github.com> Date: Sat, 27 Aug 2022 00:05:21 +0200 Subject: [PATCH] feat: `client-spoof` patch Signed-off-by: oSumAtrIX --- .../annotations/ClientSpoofCompatibility.kt | 14 +++++++ .../UserAgentHeaderBuilderFingerprint.kt | 20 ++++++++++ .../clientspoof/patch/ClientSpoofPatch.kt | 38 +++++++++++++++++++ .../patch/bytecode/MicroGBytecodePatch.kt | 2 + 4 files changed, 74 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/misc/clientspoof/annotations/ClientSpoofCompatibility.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/misc/clientspoof/fingerprints/UserAgentHeaderBuilderFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/misc/clientspoof/patch/ClientSpoofPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/clientspoof/annotations/ClientSpoofCompatibility.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/clientspoof/annotations/ClientSpoofCompatibility.kt new file mode 100644 index 000000000..928af5964 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/clientspoof/annotations/ClientSpoofCompatibility.kt @@ -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 \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/clientspoof/fingerprints/UserAgentHeaderBuilderFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/clientspoof/fingerprints/UserAgentHeaderBuilderFingerprint.kt new file mode 100644 index 000000000..aebc83503 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/clientspoof/fingerprints/UserAgentHeaderBuilderFingerprint.kt @@ -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 "), +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/clientspoof/patch/ClientSpoofPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/clientspoof/patch/ClientSpoofPatch.kt new file mode 100644 index 000000000..208c6ca3f --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/clientspoof/patch/ClientSpoofPatch.kt @@ -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() + } +} diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/microg/patch/bytecode/MicroGBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/microg/patch/bytecode/MicroGBytecodePatch.kt index c52da8ae8..d531f7480 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/microg/patch/bytecode/MicroGBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/microg/patch/bytecode/MicroGBytecodePatch.kt @@ -14,6 +14,7 @@ import app.revanced.patcher.patch.annotations.Patch import app.revanced.patcher.patch.impl.BytecodePatch import app.revanced.patcher.util.proxy.mutableTypes.MutableClass 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.fingerprints.* import app.revanced.patches.youtube.misc.microg.patch.resource.MicroGResourcePatch @@ -32,6 +33,7 @@ import org.jf.dexlib2.immutable.reference.ImmutableStringReference [ MicroGResourcePatch::class, HideCastButtonPatch::class, + ClientSpoofPatch::class ] ) @Name("microg-support")