Skip to content

Commit

Permalink
fix(Hook Download Button): Not worked when spoofing to older version
Browse files Browse the repository at this point in the history
  • Loading branch information
YT-Advanced committed Mar 9, 2024
1 parent d3033f1 commit 5162ceb
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 36 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ReX Patches.
| `Alternative thumbnails` | Adds options to replace video thumbnails using the DeArrow API or image captures from the video. | 18.25.40 ~ 19.05.36 |
| `Ambient mode switch` | Adds an option to bypass the restrictions of ambient mode or disable it completely. | 18.25.40 ~ 19.05.36 |
| `Append time stamps information` | Adds an option to add the current video quality or playback speed in brackets next to the current time. | 18.25.40 ~ 19.05.36 |
| `Change player flyout panel toggles` | Adds an option to use text toggles instead of switch toggles within the additional settings menu. | 18.25.40 ~ 19.05.35 |
| `Change player flyout panel toggles` | Adds an option to use text toggles instead of switch toggles within the additional settings menu. | 18.25.40 ~ 19.05.36 |
| `Change start page` | Adds an option to set which page the app opens in instead of the homepage. | 18.25.40 ~ 19.05.36 |
| `Custom branding heading` | Applies a custom heading in the top left corner within the app. | 18.25.40 ~ 19.05.36 |
| `Custom branding icon YouTube` | Change the YouTube launcher icon to the icon specified in options.json. | 18.25.40 ~ 19.05.36 |
Expand Down
2 changes: 1 addition & 1 deletion patches.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchException
import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.youtube.overlaybutton.download.hook.fingerprints.DownloadActionsFingerprint
import app.revanced.patches.youtube.overlaybutton.download.hook.fingerprints.DownloadActionsCommandFingerprint
import app.revanced.patches.youtube.overlaybutton.download.hook.fingerprints.LegacyDownloadCommandFingerprint
import app.revanced.patches.youtube.overlaybutton.download.hook.fingerprints.PlaylistOfflineDownloadOnClickFingerprint
import app.revanced.patches.youtube.utils.integrations.Constants.UTILS_PATH
import app.revanced.util.exception
Expand All @@ -21,28 +21,12 @@ import com.android.tools.smali.dexlib2.Opcode

object DownloadButtonHookPatch : BytecodePatch(
setOf(
DownloadActionsFingerprint,
DownloadActionsCommandFingerprint,
LegacyDownloadCommandFingerprint,
PlaylistOfflineDownloadOnClickFingerprint
)
) {
override fun execute(context: BytecodeContext) {
// Remove the Default Download dialog of YouTube (called before loading videoId)
DownloadActionsFingerprint.result?.let {
it.mutableMethod.apply {
val targetIndex = it.scanResult.patternScanResult!!.startIndex

addInstructionsWithLabels(
targetIndex, """
invoke-static {}, $UTILS_PATH/HookDownloadButtonPatch;->shouldHookDownloadButton()Z
move-result v0
if-eqz v0, :default
return-void
""", ExternalLabel("default", getInstruction(targetIndex))
)
}
} ?: throw DownloadActionsFingerprint.exception

// Get videoId and startVideoDownloadActivity
DownloadActionsCommandFingerprint.result?.let {
it.mutableMethod.apply {
Expand Down Expand Up @@ -71,6 +55,19 @@ object DownloadButtonHookPatch : BytecodePatch(
}
} ?: throw DownloadActionsCommandFingerprint.exception

// Legacy fingerprint is used for old spoofed versions,
// or if download playlist is pressed on any version.
// Downloading playlists is not yet supported,
// as the code this hooks does not easily expost the playlist id.
LegacyDownloadCommandFingerprint.result?.let {
it.mutableMethod.apply {
addInstruction(
0,
"invoke-static/range {p1 .. p1}, $UTILS_PATH/HookDownloadButtonPatch;->startVideoDownloadActivity(Ljava/lang/String;)V"
)
}
}?: throw LegacyDownloadCommandFingerprint.exception

// Get playlistId and startPlaylistDownloadActivity
PlaylistOfflineDownloadOnClickFingerprint.result?.let {
it.mutableMethod.apply {
Expand All @@ -86,7 +83,6 @@ object DownloadButtonHookPatch : BytecodePatch(
"invoke-static {v$insertRegister}, $UTILS_PATH/HookDownloadButtonPatch;->startPlaylistDownloadActivity(Ljava/lang/String;)V"
)
}
} ?: throw DownloadActionsCommandFingerprint.exception

} // Do not throw exception
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package app.revanced.patches.youtube.overlaybutton.download.hook.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

/**
* For spoofing to older versions. Also called if download playlist is pressed for any version.
*/
internal object LegacyDownloadCommandFingerprint : MethodFingerprint(
accessFlags = AccessFlags.PRIVATE or AccessFlags.FINAL,
returnType = "V",
parameters = listOf("Ljava/lang/String;", "Ljava/lang/String;", "L", "L"),
strings = listOf(""),
opcodes = listOf(
Opcode.MOVE_OBJECT_FROM16,
Opcode.MOVE_OBJECT_FROM16,
Opcode.NEW_INSTANCE,
Opcode.INVOKE_DIRECT,
Opcode.IGET_OBJECT,
Opcode.IF_NEZ,
)
)

0 comments on commit 5162ceb

Please sign in to comment.