feat(Spoof streaming data): Disable PoToken service when is turned on

- Any app clients that use  do not need the PoToken generated by DroidGuard
-  is fetched even when  is turned on
- DroidGuard VM tries to solve , but some functions are not fully implemented in DroidGuard, resulting in spam logs: https://github.com/microg/GmsCore/issues/2584
This commit is contained in:
inotia00
2025-01-15 22:02:07 +09:00
parent bda2ef23cc
commit ed6acc6197
4 changed files with 78 additions and 75 deletions

View File

@ -21,6 +21,7 @@ import app.revanced.util.fingerprint.matchOrThrow
import app.revanced.util.fingerprint.methodOrThrow
import app.revanced.util.fingerprint.mutableClassOrThrow
import app.revanced.util.getReference
import app.revanced.util.getWalkerMethod
import app.revanced.util.indexOfFirstInstructionOrThrow
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
@ -103,9 +104,9 @@ fun baseSpoofStreamingDataPatch(
"fetchStreams(Ljava/lang/String;Ljava/util/Map;)V"
if (entrySetIndex < 0) smaliInstructions = """
move-object/from16 v$mapRegister, p1
""" + smaliInstructions
move-object/from16 v$mapRegister, p1
""" + smaliInstructions
// Copy request headers for streaming data fetch.
addInstructions(newRequestBuilderIndex + 2, smaliInstructions)
@ -366,25 +367,38 @@ fun baseSpoofStreamingDataPatch(
// endregion
// region Set DroidGuard poToken.
poTokenToStringFingerprint.mutableClassOrThrow().let {
val poTokenClass = it.fields.find { field ->
field.accessFlags == AccessFlags.PRIVATE.value && field.type.startsWith("L")
}!!.type
findMethodOrThrow(poTokenClass) {
name == "<init>" &&
parameters == listOf("[B")
}.addInstruction(
1,
"invoke-static { p1 }, $EXTENSION_CLASS_DESCRIPTOR->setDroidGuardPoToken([B)V"
)
}
// endregion
executeBlock()
}
finalize {
gmsServiceBrokerFingerprint.methodOrThrow()
.addInstructionsWithLabels(
0, """
invoke-static {}, $EXTENSION_CLASS_DESCRIPTOR->isSpoofingEnabled()Z
move-result v0
if-eqz v0, :ignore
return-void
:ignore
nop
"""
)
gmsServiceBrokerExceptionFingerprint.matchOrThrow().let {
val walkerIndex = it.patternMatch!!.startIndex
val walkerMethod = it.getWalkerMethod(walkerIndex)
walkerMethod.apply {
val insertIndex = indexOfFirstInstructionOrThrow(Opcode.CHECK_CAST)
val insertRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA
addInstructions(
insertIndex + 1, """
invoke-static {v$insertRegister}, $EXTENSION_CLASS_DESCRIPTOR->isSpoofingEnabled(Ljava/lang/Object;)Ljava/lang/Object;
move-result-object v$insertRegister
"""
)
}
}
}
}

View File

@ -198,21 +198,20 @@ internal val hlsCurrentTimeFingerprint = legacyFingerprint(
literals = listOf(HLS_CURRENT_TIME_FEATURE_FLAG),
)
internal val poTokenToStringFingerprint = legacyFingerprint(
name = "poTokenToStringFingerprint",
returnType = "Ljava/lang/String;",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = emptyList(),
strings = listOf("UTF-8"),
customFingerprint = { method, classDef ->
method.name == "toString" &&
classDef.fields.find { it.type == "[B" } != null &&
// In YouTube, this field's type is 'Lcom/google/android/gms/potokens/PoToken;'.
// In YouTube Music, this class name is obfuscated.
classDef.fields.find {
it.accessFlags == AccessFlags.PRIVATE.value && it.type.startsWith(
"L"
)
} != null
},
internal val gmsServiceBrokerFingerprint = legacyFingerprint(
name = "gmsServiceBrokerFingerprint",
returnType = "V",
strings = listOf("mServiceBroker is null, client disconnected")
)
internal val gmsServiceBrokerExceptionFingerprint = legacyFingerprint(
name = "gmsServiceBrokerExceptionFingerprint",
returnType = "V",
parameters = listOf("Ljava/lang/Exception;"),
opcodes = listOf(
Opcode.INVOKE_VIRTUAL,
Opcode.RETURN_VOID
),
strings = listOf("Exception must not be null")
)