mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-06-12 21:27:43 +02:00
fix(YouTube/Spoof client): restore playback speed menu when spoofing to an iOS, Android TV, Android Testsuite client 95f290f113
This commit is contained in:
@ -14,7 +14,7 @@ import app.revanced.patches.shared.litho.fingerprints.EmptyComponentsFingerprint
|
||||
import app.revanced.patches.shared.litho.fingerprints.LithoFilterPatchConstructorFingerprint
|
||||
import app.revanced.patches.shared.litho.fingerprints.PathBuilderFingerprint
|
||||
import app.revanced.patches.shared.litho.fingerprints.SetByteBufferFingerprint
|
||||
import app.revanced.util.getEmptyStringInstructionIndex
|
||||
import app.revanced.util.getStringInstructionIndex
|
||||
import app.revanced.util.getTargetIndex
|
||||
import app.revanced.util.getTargetIndexReversed
|
||||
import app.revanced.util.getTargetIndexWithFieldReferenceType
|
||||
@ -140,7 +140,7 @@ object LithoFilterPatch : BytecodePatch(
|
||||
val stringBuilderRegister =
|
||||
getInstruction<TwoRegisterInstruction>(stringBuilderIndex).registerA
|
||||
|
||||
val emptyStringIndex = getEmptyStringInstructionIndex()
|
||||
val emptyStringIndex = getStringInstructionIndex("")
|
||||
|
||||
val identifierIndex = getTargetIndexReversed(emptyStringIndex, Opcode.IPUT_OBJECT)
|
||||
val identifierRegister =
|
||||
|
@ -8,13 +8,14 @@ import app.revanced.patches.shared.transformation.IMethodCall
|
||||
import app.revanced.patches.shared.transformation.Instruction35cInfo
|
||||
import app.revanced.patches.shared.transformation.filterMapInstruction35c
|
||||
import app.revanced.util.getReference
|
||||
import app.revanced.util.indexOfFirstInstruction
|
||||
import com.android.tools.smali.dexlib2.Opcode
|
||||
import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction21c
|
||||
import com.android.tools.smali.dexlib2.iface.ClassDef
|
||||
import com.android.tools.smali.dexlib2.iface.Method
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.Instruction
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
||||
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
|
||||
import com.android.tools.smali.dexlib2.iface.reference.StringReference
|
||||
|
||||
abstract class BaseSpoofUserAgentPatch(
|
||||
private val packageName: String
|
||||
@ -36,45 +37,39 @@ abstract class BaseSpoofUserAgentPatch(
|
||||
|
||||
// Replace the result of context.getPackageName(), if it is used in a user agent string.
|
||||
mutableMethod.apply {
|
||||
var isTargetMethod = true
|
||||
// After context.getPackageName() the result is moved to a register.
|
||||
val targetRegister = (
|
||||
getInstruction(instructionIndex + 1)
|
||||
as? OneRegisterInstruction ?: return
|
||||
).registerA
|
||||
|
||||
for ((index, instruction) in implementation!!.instructions.withIndex()) {
|
||||
if (instruction.opcode != Opcode.CONST_STRING)
|
||||
continue
|
||||
// IndexOutOfBoundsException is possible here,
|
||||
// but no such occurrences are present in the app.
|
||||
val referee =
|
||||
getInstruction(instructionIndex + 2).getReference<MethodReference>()?.toString()
|
||||
|
||||
val constString = getInstruction<BuilderInstruction21c>(index).reference.toString()
|
||||
|
||||
if (constString != "android.resource://" && constString != "gcore_")
|
||||
continue
|
||||
|
||||
isTargetMethod = false
|
||||
break
|
||||
// Only replace string builder usage.
|
||||
if (referee != USER_AGENT_STRING_BUILDER_APPEND_METHOD_REFERENCE) {
|
||||
return
|
||||
}
|
||||
|
||||
if (isTargetMethod) {
|
||||
// After context.getPackageName() the result is moved to a register.
|
||||
val targetRegister = (
|
||||
getInstruction(instructionIndex + 1)
|
||||
as? OneRegisterInstruction ?: return
|
||||
).registerA
|
||||
|
||||
// IndexOutOfBoundsException is not possible here,
|
||||
// but no such occurrences are present in the app.
|
||||
val referee =
|
||||
getInstruction(instructionIndex + 2).getReference<MethodReference>()?.toString()
|
||||
|
||||
// This can technically also match non-user agent string builder append methods,
|
||||
// but no such occurrences are present in the app.
|
||||
if (referee != "Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;") {
|
||||
return
|
||||
}
|
||||
|
||||
// Overwrite the result of context.getPackageName() with the original package name.
|
||||
replaceInstruction(
|
||||
instructionIndex + 1,
|
||||
"const-string v$targetRegister, \"$packageName\"",
|
||||
)
|
||||
// Do not change the package name in methods that use resources, or for methods that use GmsCore.
|
||||
// Changing these package names will result in playback limitations,
|
||||
// particularly Android VR background audio only playback.
|
||||
val resourceOrGmsStringInstructionIndex = indexOfFirstInstruction {
|
||||
val reference = getReference<StringReference>()
|
||||
opcode == Opcode.CONST_STRING &&
|
||||
(reference?.string == "android.resource://" || reference?.string == "gcore_")
|
||||
}
|
||||
if (resourceOrGmsStringInstructionIndex >= 0) {
|
||||
return
|
||||
}
|
||||
|
||||
// Overwrite the result of context.getPackageName() with the original package name.
|
||||
replaceInstruction(
|
||||
instructionIndex + 1,
|
||||
"const-string v$targetRegister, \"$packageName\"",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -92,4 +87,9 @@ abstract class BaseSpoofUserAgentPatch(
|
||||
"Ljava/lang/String;",
|
||||
),
|
||||
}
|
||||
|
||||
private companion object {
|
||||
private const val USER_AGENT_STRING_BUILDER_APPEND_METHOD_REFERENCE =
|
||||
"Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user