Skip to content

Commit

Permalink
fix(YouTube - Spoof client): Partial fix for watch history issue of b…
Browse files Browse the repository at this point in the history
…rand accounts on iOS clients
  • Loading branch information
inotia00 authored and Francesco146 committed Aug 7, 2024
1 parent 0ef9a65 commit 2294ffb
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,39 +1,25 @@
package app.revanced.patches.youtube.misc.watchhistory

import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patches.youtube.misc.watchhistory.fingerprints.TrackingUrlModelFingerprint
import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE
import app.revanced.patches.youtube.utils.integrations.Constants.MISC_PATH
import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.patches.youtube.utils.trackingurlhook.TrackingUrlHookPatch
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction

@Suppress("unused")
object WatchHistoryPatch : BaseBytecodePatch(
name = "Spoof watch history",
description = "Adds an option to change the domain of the watch history or check its status.",
dependencies = setOf(SettingsPatch::class),
dependencies = setOf(
SettingsPatch::class,
TrackingUrlHookPatch::class
),
compatiblePackages = COMPATIBLE_PACKAGE,
fingerprints = setOf(TrackingUrlModelFingerprint)
) {
override fun execute(context: BytecodeContext) {

TrackingUrlModelFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val targetIndex = it.scanResult.patternScanResult!!.startIndex
val targetRegister = getInstruction<TwoRegisterInstruction>(targetIndex).registerA

addInstructions(
targetIndex + 1, """
invoke-static {v$targetRegister}, $MISC_PATH/WatchHistoryPatch;->replaceTrackingUrl(Ljava/lang/String;)Ljava/lang/String;
move-result-object v$targetRegister
"""
)
}
}
TrackingUrlHookPatch.hookTrackingUrl("$MISC_PATH/WatchHistoryPatch;->replaceTrackingUrl(Landroid/net/Uri;)Landroid/net/Uri;")

/**
* Add settings
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.extensions.InstructionExtensions.getInstructions
import app.revanced.patcher.extensions.or
import app.revanced.patcher.patch.PatchException
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable
import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.shared.fingerprints.CreatePlayerRequestBodyWithModelFingerprint
Expand All @@ -17,12 +18,14 @@ import app.revanced.patches.youtube.utils.compatibility.Constants
import app.revanced.patches.youtube.utils.fingerprints.PlaybackRateBottomSheetBuilderFingerprint
import app.revanced.patches.youtube.utils.fix.client.fingerprints.BackgroundPlaybackPlayerResponseFingerprint
import app.revanced.patches.youtube.utils.fix.client.fingerprints.BuildInitPlaybackRequestFingerprint
import app.revanced.patches.youtube.utils.fix.client.fingerprints.BuildPlaybackStatsRequestURIFingerprint
import app.revanced.patches.youtube.utils.fix.client.fingerprints.BuildPlayerRequestURIFingerprint
import app.revanced.patches.youtube.utils.fix.client.fingerprints.CreatePlaybackSpeedMenuItemFingerprint
import app.revanced.patches.youtube.utils.fix.client.fingerprints.CreatePlayerRequestBodyFingerprint
import app.revanced.patches.youtube.utils.fix.client.fingerprints.CreatePlayerRequestBodyWithVersionReleaseFingerprint
import app.revanced.patches.youtube.utils.fix.client.fingerprints.CreatePlayerRequestBodyWithVersionReleaseFingerprint.indexOfBuildInstruction
import app.revanced.patches.youtube.utils.fix.client.fingerprints.NerdsStatsVideoFormatBuilderFingerprint
import app.revanced.patches.youtube.utils.fix.client.fingerprints.OrganicPlaybackContextModelFingerprint
import app.revanced.patches.youtube.utils.fix.client.fingerprints.PlayerGestureConfigSyntheticFingerprint
import app.revanced.patches.youtube.utils.fix.client.fingerprints.SetPlayerRequestClientTypeFingerprint
import app.revanced.patches.youtube.utils.fix.client.fingerprints.UserAgentHeaderBuilderFingerprint
Expand All @@ -31,6 +34,7 @@ import app.revanced.patches.youtube.utils.integrations.Constants.PATCH_STATUS_CL
import app.revanced.patches.youtube.utils.playertype.PlayerTypeHookPatch
import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.patches.youtube.utils.storyboard.StoryboardHookPatch
import app.revanced.patches.youtube.utils.trackingurlhook.TrackingUrlHookPatch
import app.revanced.patches.youtube.video.information.VideoInformationPatch
import app.revanced.patches.youtube.video.playerresponse.PlayerResponseMethodHookPatch
import app.revanced.util.getReference
Expand Down Expand Up @@ -59,6 +63,7 @@ object SpoofClientPatch : BaseBytecodePatch(
BackgroundPlaybackPatch::class,
PlayerTypeHookPatch::class,

TrackingUrlHookPatch::class,
PlayerResponseMethodHookPatch::class,
SettingsPatch::class,
VideoInformationPatch::class,
Expand All @@ -79,6 +84,10 @@ object SpoofClientPatch : BaseBytecodePatch(
// Background playback in live stream.
BackgroundPlaybackPlayerResponseFingerprint,

// Watch history.
BuildPlaybackStatsRequestURIFingerprint,
OrganicPlaybackContextModelFingerprint,

// Player gesture config.
PlayerGestureConfigSyntheticFingerprint,

Expand Down Expand Up @@ -415,6 +424,37 @@ object SpoofClientPatch : BaseBytecodePatch(

// endregion

// region watch history if spoofing to iOS

BuildPlaybackStatsRequestURIFingerprint.resultOrThrow().let {
val walkerMethod = context.toMethodWalker(it.method)
.nextMethod(it.scanResult.patternScanResult!!.startIndex, true)
.getMethod() as MutableMethod

walkerMethod.addInstructions(
0, """
invoke-static {p0}, $INTEGRATIONS_CLASS_DESCRIPTOR->overrideTrackingUrl(Landroid/net/Uri;)Landroid/net/Uri;
move-result-object p0
"""
)
}

OrganicPlaybackContextModelFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val insertIndex = it.scanResult.patternScanResult!!.endIndex
val insertRegister = getInstruction<TwoRegisterInstruction>(insertIndex).registerA

addInstruction(
insertIndex,
"invoke-static { v$insertRegister }, $INTEGRATIONS_CLASS_DESCRIPTOR->setCpn(Ljava/lang/String;)V"
)
}
}

TrackingUrlHookPatch.hookTrackingUrl("$INTEGRATIONS_CLASS_DESCRIPTOR->setTrackingUriParameter(Landroid/net/Uri;)V")

// endregion

// region append spoof info.

NerdsStatsVideoFormatBuilderFingerprint.resultOrThrow().mutableMethod.apply {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package app.revanced.patches.youtube.utils.fix.client.fingerprints

import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode

internal object BuildPlaybackStatsRequestURIFingerprint : MethodFingerprint(
accessFlags = AccessFlags.PUBLIC or AccessFlags.STATIC,
returnType = "L",
opcodes = listOf(
Opcode.INVOKE_STATIC,
Opcode.MOVE_RESULT_OBJECT,
Opcode.CONST_STRING,
),
strings = listOf("event", "streamingstats"),
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package app.revanced.patches.youtube.utils.fix.client.fingerprints

import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode

internal object OrganicPlaybackContextModelFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
parameters = listOf(
"Ljava/lang/String;", // cpn
"Z",
"Z",
"Z",
"Z"
),
opcodes = listOf(
Opcode.INVOKE_DIRECT,
Opcode.IF_EQZ,
Opcode.IPUT_OBJECT,
),
strings = listOf("Null contentCpn")
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package app.revanced.patches.youtube.utils.trackingurlhook

import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patches.youtube.utils.trackingurlhook.fingerprints.TrackingUrlModelFingerprint
import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction

object TrackingUrlHookPatch : BytecodePatch(
setOf(TrackingUrlModelFingerprint)
) {
private lateinit var trackingUrlMethod: MutableMethod

override fun execute(context: BytecodeContext) {
trackingUrlMethod = TrackingUrlModelFingerprint.resultOrThrow().mutableMethod
}

internal fun hookTrackingUrl(
descriptor: String
) = trackingUrlMethod.apply {
val targetIndex = getTargetIndexWithMethodReferenceNameOrThrow("parse") + 1
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA

var smaliInstruction = "invoke-static {v$targetRegister}, $descriptor"

if (!descriptor.endsWith("V")) {
smaliInstruction += """
move-result-object v$targetRegister
""".trimIndent()
}

addInstructions(
targetIndex + 1,
smaliInstruction
)
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package app.revanced.patches.youtube.misc.watchhistory.fingerprints
package app.revanced.patches.youtube.utils.trackingurlhook.fingerprints

import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
Expand Down

0 comments on commit 2294ffb

Please sign in to comment.