Skip to content

Commit

Permalink
feat(YouTube - Hook Download Button): Hook playlist download button
Browse files Browse the repository at this point in the history
  • Loading branch information
YT-Advanced committed Mar 5, 2024
1 parent 5f166fd commit eced84a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,21 @@ 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.PlaylistOfflineDownloadOnClickFingerprint
import app.revanced.patches.youtube.utils.integrations.Constants.UTILS_PATH
import app.revanced.util.exception
import app.revanced.util.getReference
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction35c
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
import com.android.tools.smali.dexlib2.Opcode

object DownloadButtonHookPatch : BytecodePatch(
setOf(
DownloadActionsFingerprint,
DownloadActionsCommandFingerprint
DownloadActionsCommandFingerprint,
PlaylistOfflineDownloadOnClickFingerprint
)
) {
override fun execute(context: BytecodeContext) {
Expand All @@ -38,7 +43,7 @@ object DownloadButtonHookPatch : BytecodePatch(
}
} ?: throw DownloadActionsFingerprint.exception

// Get videoId and startDownloadActivity
// Get videoId and startVideoDownloadActivity
DownloadActionsCommandFingerprint.result?.let {
it.mutableMethod.apply {
val insertMethod = it.mutableClass.methods.find { method -> method.name == "run" }
Expand All @@ -59,11 +64,29 @@ object DownloadButtonHookPatch : BytecodePatch(

addInstruction(
index + 2,
"invoke-static {v$register}, $UTILS_PATH/HookDownloadButtonPatch;->startDownloadActivity(Ljava/lang/String;)V"
"invoke-static {v$register}, $UTILS_PATH/HookDownloadButtonPatch;->startVideoDownloadActivity(Ljava/lang/String;)V"
)
}
} ?: throw PatchException("Failed to find Runnable method")
}
} ?: throw DownloadActionsCommandFingerprint.exception

// Get playlistId and startPlaylistDownloadActivity
PlaylistOfflineDownloadOnClickFingerprint.result?.let {
it.mutableMethod.apply {
val insertIndex = implementation!!.instructions.indexOfFirst { instruction ->
instruction.opcode == Opcode.INVOKE_STATIC
&& instruction.getReference<MethodReference>()?.name == "isEmpty"
}

val insertRegister = getInstruction<Instruction35c>(insertIndex).registerC

addInstruction(
insertIndex,
"invoke-static {v$insertRegister}, $UTILS_PATH/HookDownloadButtonPatch;->startPlaylistDownloadActivity(Ljava/lang/String;)V"
)
}
} ?: throw DownloadActionsCommandFingerprint.exception

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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

object PlaylistOfflineDownloadOnClickFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("Landroid/view/View;"),
opcodes = listOf(
Opcode.IGET_OBJECT,
Opcode.INVOKE_STATIC,
Opcode.MOVE_RESULT,
Opcode.IF_EQZ,
Opcode.GOTO
),
customFingerprint = { methodDef, classDef ->
methodDef.name == "onClick"
&& classDef.methods.count() == 2
}
)

0 comments on commit eced84a

Please sign in to comment.