mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-04-30 06:34:37 +02:00
chore(Spoof streaming data): Match with ReVanced
This commit is contained in:
parent
4c24f4569c
commit
bb1946d9db
@ -1,14 +1,16 @@
|
|||||||
package app.revanced.patches.shared.spoof.streamingdata
|
package app.revanced.patches.shared.spoof.streamingdata
|
||||||
|
|
||||||
|
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
|
||||||
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
|
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
|
||||||
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
|
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
|
||||||
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
|
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
|
||||||
import app.revanced.patcher.extensions.InstructionExtensions.instructions
|
import app.revanced.patcher.extensions.InstructionExtensions.instructions
|
||||||
|
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
|
||||||
import app.revanced.patcher.patch.BytecodePatchBuilder
|
import app.revanced.patcher.patch.BytecodePatchBuilder
|
||||||
import app.revanced.patcher.patch.BytecodePatchContext
|
import app.revanced.patcher.patch.BytecodePatchContext
|
||||||
import app.revanced.patcher.patch.PatchException
|
import app.revanced.patcher.patch.PatchException
|
||||||
import app.revanced.patcher.patch.bytecodePatch
|
import app.revanced.patcher.patch.bytecodePatch
|
||||||
import app.revanced.patcher.util.smali.ExternalLabel
|
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable
|
||||||
import app.revanced.patches.shared.blockrequest.blockRequestPatch
|
import app.revanced.patches.shared.blockrequest.blockRequestPatch
|
||||||
import app.revanced.patches.shared.extension.Constants.SPOOF_PATH
|
import app.revanced.patches.shared.extension.Constants.SPOOF_PATH
|
||||||
import app.revanced.util.findInstructionIndicesReversedOrThrow
|
import app.revanced.util.findInstructionIndicesReversedOrThrow
|
||||||
@ -17,11 +19,17 @@ import app.revanced.util.fingerprint.injectLiteralInstructionBooleanCall
|
|||||||
import app.revanced.util.fingerprint.matchOrThrow
|
import app.revanced.util.fingerprint.matchOrThrow
|
||||||
import app.revanced.util.fingerprint.methodOrThrow
|
import app.revanced.util.fingerprint.methodOrThrow
|
||||||
import app.revanced.util.getReference
|
import app.revanced.util.getReference
|
||||||
|
import app.revanced.util.indexOfFirstInstructionReversedOrThrow
|
||||||
|
import com.android.tools.smali.dexlib2.AccessFlags
|
||||||
import com.android.tools.smali.dexlib2.Opcode
|
import com.android.tools.smali.dexlib2.Opcode
|
||||||
|
import com.android.tools.smali.dexlib2.builder.MutableMethodImplementation
|
||||||
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
|
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
|
||||||
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
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.TwoRegisterInstruction
|
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
|
||||||
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
|
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
|
||||||
|
import com.android.tools.smali.dexlib2.immutable.ImmutableMethod
|
||||||
|
import com.android.tools.smali.dexlib2.immutable.ImmutableMethodParameter
|
||||||
|
|
||||||
const val EXTENSION_CLASS_DESCRIPTOR =
|
const val EXTENSION_CLASS_DESCRIPTOR =
|
||||||
"$SPOOF_PATH/SpoofStreamingDataPatch;"
|
"$SPOOF_PATH/SpoofStreamingDataPatch;"
|
||||||
@ -71,6 +79,8 @@ fun baseSpoofStreamingDataPatch(
|
|||||||
|
|
||||||
createStreamingDataFingerprint.matchOrThrow(createStreamingDataParentFingerprint).let { result ->
|
createStreamingDataFingerprint.matchOrThrow(createStreamingDataParentFingerprint).let { result ->
|
||||||
result.method.apply {
|
result.method.apply {
|
||||||
|
val setStreamDataMethodName = "patch_setStreamingData"
|
||||||
|
val resultMethodType = result.classDef.type
|
||||||
val setStreamingDataIndex = result.patternMatch!!.startIndex
|
val setStreamingDataIndex = result.patternMatch!!.startIndex
|
||||||
val setStreamingDataField =
|
val setStreamingDataField =
|
||||||
getInstruction(setStreamingDataIndex).getReference<FieldReference>().toString()
|
getInstruction(setStreamingDataIndex).getReference<FieldReference>().toString()
|
||||||
@ -87,46 +97,59 @@ fun baseSpoofStreamingDataPatch(
|
|||||||
?: throw PatchException("Could not find getStreamingDataField")
|
?: throw PatchException("Could not find getStreamingDataField")
|
||||||
|
|
||||||
val videoDetailsIndex = result.patternMatch!!.endIndex
|
val videoDetailsIndex = result.patternMatch!!.endIndex
|
||||||
|
val videoDetailsRegister = getInstruction<TwoRegisterInstruction>(videoDetailsIndex).registerA
|
||||||
val videoDetailsClass =
|
val videoDetailsClass =
|
||||||
getInstruction(videoDetailsIndex).getReference<FieldReference>()!!.type
|
getInstruction(videoDetailsIndex).getReference<FieldReference>()!!.type
|
||||||
|
|
||||||
val insertIndex = videoDetailsIndex + 1
|
addInstruction(
|
||||||
val videoDetailsRegister =
|
videoDetailsIndex + 1,
|
||||||
getInstruction<TwoRegisterInstruction>(videoDetailsIndex).registerA
|
"invoke-direct { p0, v$videoDetailsRegister }, " +
|
||||||
|
"$resultMethodType->$setStreamDataMethodName($videoDetailsClass)V",
|
||||||
|
)
|
||||||
|
|
||||||
val overrideRegister = getInstruction<TwoRegisterInstruction>(insertIndex).registerA
|
result.classDef.methods.add(
|
||||||
val freeRegister = implementation!!.registerCount - parameters.size - 2
|
ImmutableMethod(
|
||||||
|
resultMethodType,
|
||||||
addInstructionsWithLabels(
|
setStreamDataMethodName,
|
||||||
insertIndex,
|
listOf(ImmutableMethodParameter(videoDetailsClass, annotations, "videoDetails")),
|
||||||
"""
|
"V",
|
||||||
invoke-static { }, $EXTENSION_CLASS_DESCRIPTOR->isSpoofingEnabled()Z
|
AccessFlags.PRIVATE.value or AccessFlags.FINAL.value,
|
||||||
move-result v$freeRegister
|
annotations,
|
||||||
if-eqz v$freeRegister, :disabled
|
null,
|
||||||
|
MutableMethodImplementation(9),
|
||||||
# Get video id.
|
).toMutable().apply {
|
||||||
# From YouTube 17.34.36 to YouTube 19.16.39, the field names and field types are the same.
|
addInstructionsWithLabels(
|
||||||
iget-object v$freeRegister, v$videoDetailsRegister, $videoDetailsClass->c:Ljava/lang/String;
|
0,
|
||||||
if-eqz v$freeRegister, :disabled
|
"""
|
||||||
|
invoke-static { }, $EXTENSION_CLASS_DESCRIPTOR->isSpoofingEnabled()Z
|
||||||
# Get streaming data.
|
move-result v0
|
||||||
invoke-static { v$freeRegister }, $EXTENSION_CLASS_DESCRIPTOR->getStreamingData(Ljava/lang/String;)Ljava/nio/ByteBuffer;
|
if-eqz v0, :disabled
|
||||||
move-result-object v$freeRegister
|
|
||||||
if-eqz v$freeRegister, :disabled
|
# Get video id.
|
||||||
|
iget-object v2, p1, $videoDetailsClass->c:Ljava/lang/String;
|
||||||
# Parse streaming data.
|
if-eqz v2, :disabled
|
||||||
sget-object v$overrideRegister, $playerProtoClass->a:$playerProtoClass
|
|
||||||
invoke-static { v$overrideRegister, v$freeRegister }, $protobufClass->parseFrom(${protobufClass}Ljava/nio/ByteBuffer;)$protobufClass
|
# Get streaming data.
|
||||||
move-result-object v$freeRegister
|
invoke-static { v2 }, $EXTENSION_CLASS_DESCRIPTOR->getStreamingData(Ljava/lang/String;)Ljava/nio/ByteBuffer;
|
||||||
check-cast v$freeRegister, $playerProtoClass
|
move-result-object v3
|
||||||
|
if-eqz v3, :disabled
|
||||||
# Set streaming data.
|
|
||||||
iget-object v$freeRegister, v$freeRegister, $getStreamingDataField
|
# Parse streaming data.
|
||||||
if-eqz v$freeRegister, :disabled
|
sget-object v4, $playerProtoClass->a:$playerProtoClass
|
||||||
iput-object v$freeRegister, p0, $setStreamingDataField
|
invoke-static { v4, v3 }, $protobufClass->parseFrom(${protobufClass}Ljava/nio/ByteBuffer;)$protobufClass
|
||||||
|
move-result-object v5
|
||||||
""",
|
check-cast v5, $playerProtoClass
|
||||||
ExternalLabel("disabled", getInstruction(insertIndex))
|
|
||||||
|
# Set streaming data.
|
||||||
|
iget-object v6, v5, $getStreamingDataField
|
||||||
|
if-eqz v6, :disabled
|
||||||
|
iput-object v6, p0, $setStreamingDataField
|
||||||
|
|
||||||
|
:disabled
|
||||||
|
return-void
|
||||||
|
""",
|
||||||
|
)
|
||||||
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user