refactor(protobuf-spoof): automatic spoofing protobuf

This commit is contained in:
inotia00 2023-04-02 18:36:19 +09:00
parent f690160996
commit 805e57b049
3 changed files with 32 additions and 3 deletions

View File

@ -0,0 +1,11 @@
package app.revanced.patches.youtube.misc.protobufpoof.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.Opcode
object BadResponseFingerprint : MethodFingerprint(
opcodes = listOf(
Opcode.CONST_16
),
strings = listOf("Response code: ")
)

View File

@ -6,6 +6,7 @@ import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.data.toMethodWalker
import app.revanced.patcher.extensions.addInstruction
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
@ -14,21 +15,31 @@ import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.youtube.misc.protobufpoof.fingerprints.ProtobufParameterBuilderFingerprint
import app.revanced.patches.youtube.misc.playertype.patch.PlayerTypeHookPatch
import app.revanced.patches.youtube.misc.protobufpoof.fingerprints.*
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
import app.revanced.util.integrations.Constants.MISC_PATH
@Patch
@Name("protobuf-spoof")
@Description("Spoofs the protobuf to prevent playback issues.")
@DependsOn([SettingsPatch::class])
@DependsOn(
[
PlayerTypeHookPatch::class,
SettingsPatch::class
]
)
@YouTubeCompatibility
@Version("0.0.1")
class ProtobufSpoofPatch : BytecodePatch(
listOf(ProtobufParameterBuilderFingerprint)
listOf(
BadResponseFingerprint,
ProtobufParameterBuilderFingerprint
)
) {
override fun execute(context: BytecodeContext): PatchResult {
// hook parameter
ProtobufParameterBuilderFingerprint.result?.let {
with (context
.toMethodWalker(it.method)
@ -47,6 +58,12 @@ class ProtobufSpoofPatch : BytecodePatch(
}
} ?: return ProtobufParameterBuilderFingerprint.toErrorResult()
// hook video playback result
BadResponseFingerprint.result?.mutableMethod?.addInstruction(
0,
"invoke-static {}, $MISC_PATH/ProtobufSpoofPatch;->switchProtobufSpoof()V"
) ?: return BadResponseFingerprint.toErrorResult()
/*
* Add settings
*/

View File

@ -511,6 +511,7 @@ Please do not report any issues you encounter while using this feature."</string
<string name="revanced_patches_information_summary">Information about applied patches</string>
<string name="revanced_player_flyout_panel_title">Player flyout panel</string>
<string name="revanced_player">Player</string>
<string name="revanced_protobuf_spoof_notice">Spoofing protobuf to prevent playback issues</string>
<string name="revanced_reboot_warning_general">"As this is still an experimental feature, there may be other unknown issues.
Are you sure you want to continue though?"</string>
<string name="revanced_reboot_warning_phone">"Tricks the dpi to change some layouts to phone layouts.