refactor(boostforreddit): FixAudioMissingInDownloadsPatch
This commit is contained in:
parent
68a57901d8
commit
24cb9d987b
2 changed files with 22 additions and 14 deletions
|
|
@ -1,7 +1,9 @@
|
|||
package app.revanced.patches.reddit.customclients.boostforreddit.fix.downloads
|
||||
|
||||
import app.revanced.patcher.fingerprint
|
||||
import app.revanced.patcher.BytecodePatchContextMethodMatching.gettingFirstMutableMethodDeclaratively
|
||||
import app.revanced.patcher.patch.BytecodePatchContext
|
||||
|
||||
internal val downloadAudioFingerprint = fingerprint {
|
||||
strings("/DASH_audio.mp4", "/audio")
|
||||
}
|
||||
internal val BytecodePatchContext.downloadAudioMethod by gettingFirstMutableMethodDeclaratively(
|
||||
"/DASH_audio.mp4",
|
||||
"/audio"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -2,12 +2,15 @@ package app.revanced.patches.reddit.customclients.boostforreddit.fix.downloads
|
|||
|
||||
import app.revanced.patcher.extensions.getInstruction
|
||||
import app.revanced.patcher.extensions.replaceInstruction
|
||||
import app.revanced.patcher.patch.bytecodePatch
|
||||
import app.revanced.patcher.patch.creatingBytecodePatch
|
||||
import app.revanced.util.findInstructionIndicesReversed
|
||||
import app.revanced.util.getReference
|
||||
import com.android.tools.smali.dexlib2.Opcode
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
||||
import com.android.tools.smali.dexlib2.iface.reference.StringReference
|
||||
|
||||
@Suppress("unused")
|
||||
val fixAudioMissingInDownloadsPatch = bytecodePatch(
|
||||
name = "Fix missing audio in video downloads",
|
||||
@Suppress("unused", "ObjectPropertyName")
|
||||
val `Fix missing audio in video downloads` by creatingBytecodePatch(
|
||||
description = "Fixes audio missing in videos downloaded from v.redd.it.",
|
||||
) {
|
||||
compatibleWith("com.rubenmayayo.reddit")
|
||||
|
|
@ -18,12 +21,15 @@ val fixAudioMissingInDownloadsPatch = bytecodePatch(
|
|||
"/audio" to "/DASH_AUDIO_64.mp4",
|
||||
)
|
||||
|
||||
downloadAudioFingerprint.method.apply {
|
||||
downloadAudioFingerprint.stringMatches.forEach { match ->
|
||||
val replacement = endpointReplacements[match.string]
|
||||
val register = getInstruction<OneRegisterInstruction>(match.index).registerA
|
||||
|
||||
replaceInstruction(match.index, "const-string v$register, \"$replacement\"")
|
||||
downloadAudioMethod.apply {
|
||||
endpointReplacements.forEach { (target, replacement) ->
|
||||
// Find all occurrences of the target string in the method
|
||||
findInstructionIndicesReversed {
|
||||
opcode == Opcode.CONST_STRING && getReference<StringReference>()?.string == target
|
||||
}.forEach { index ->
|
||||
val register = getInstruction<OneRegisterInstruction>(index).registerA
|
||||
replaceInstruction(index, "const-string v$register, \"$replacement\"")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue