From 945d03c220dad071ce15be18e3ae0e2262282add Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Wed, 15 Jan 2025 21:41:38 +0900 Subject: [PATCH] fix(Spoof user agent): Use original package name in query parameter of `api/stats` --- .../useragent/BaseSpoofUserAgentPatch.kt | 22 +++++++++++++++++++ .../shared/spoof/useragent/Fingerprints.kt | 14 ++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 patches/src/main/kotlin/app/revanced/patches/shared/spoof/useragent/Fingerprints.kt diff --git a/patches/src/main/kotlin/app/revanced/patches/shared/spoof/useragent/BaseSpoofUserAgentPatch.kt b/patches/src/main/kotlin/app/revanced/patches/shared/spoof/useragent/BaseSpoofUserAgentPatch.kt index 105472d90..2b1999dfe 100644 --- a/patches/src/main/kotlin/app/revanced/patches/shared/spoof/useragent/BaseSpoofUserAgentPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/shared/spoof/useragent/BaseSpoofUserAgentPatch.kt @@ -1,13 +1,19 @@ package app.revanced.patches.shared.spoof.useragent +import app.revanced.patcher.extensions.InstructionExtensions.addInstruction import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction import app.revanced.patches.shared.transformation.IMethodCall import app.revanced.patches.shared.transformation.filterMapInstruction35c import app.revanced.patches.shared.transformation.transformInstructionsPatch +import app.revanced.util.fingerprint.methodOrThrow import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstruction +import app.revanced.util.indexOfFirstInstructionOrThrow +import app.revanced.util.indexOfFirstInstructionReversedOrThrow +import app.revanced.util.indexOfFirstStringInstructionOrThrow import com.android.tools.smali.dexlib2.Opcode +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.reference.MethodReference import com.android.tools.smali.dexlib2.iface.reference.StringReference @@ -66,6 +72,22 @@ fun baseSpoofUserAgentPatch( ) } }, + executeBlock = { + apiStatsFingerprint.methodOrThrow().apply { + val stringIndex = indexOfFirstStringInstructionOrThrow(CLIENT_PACKAGE_NAME) + val putIndex = indexOfFirstInstructionOrThrow(stringIndex) { + opcode == Opcode.INVOKE_INTERFACE && + getReference()?.name == "put" + } + val packageNameRegister = getInstruction(putIndex).registerE + val insertIndex = indexOfFirstInstructionReversedOrThrow(putIndex, Opcode.INVOKE_STATIC) + + addInstruction( + insertIndex, + "const-string v$packageNameRegister, \"$packageName\"", + ) + } + }, ) @Suppress("unused") diff --git a/patches/src/main/kotlin/app/revanced/patches/shared/spoof/useragent/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/shared/spoof/useragent/Fingerprints.kt new file mode 100644 index 000000000..28a43f446 --- /dev/null +++ b/patches/src/main/kotlin/app/revanced/patches/shared/spoof/useragent/Fingerprints.kt @@ -0,0 +1,14 @@ +package app.revanced.patches.shared.spoof.useragent + +import app.revanced.util.fingerprint.legacyFingerprint +import app.revanced.util.or +import com.android.tools.smali.dexlib2.AccessFlags + +const val CLIENT_PACKAGE_NAME = "cbr" + +internal val apiStatsFingerprint = legacyFingerprint( + name = "apiStatsFingerprint", + accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR, + returnType = "V", + strings = listOf(CLIENT_PACKAGE_NAME), +)