From ffc74be8222cd51c4aa47a377b63b62139bd125b Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Tue, 15 Apr 2025 17:38:47 +0200 Subject: [PATCH] refactor(Spotify - Spoof package info): Replace installer package name of legacy target (#4797) --- .../patches/spotify/misc/fix/Fingerprints.kt | 8 ---- .../spotify/misc/fix/SpoofPackageInfoPatch.kt | 47 ++++++++----------- 2 files changed, 19 insertions(+), 36 deletions(-) diff --git a/patches/src/main/kotlin/app/revanced/patches/spotify/misc/fix/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/spotify/misc/fix/Fingerprints.kt index f8959ae64..6b25bc630 100644 --- a/patches/src/main/kotlin/app/revanced/patches/spotify/misc/fix/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/spotify/misc/fix/Fingerprints.kt @@ -3,15 +3,7 @@ package app.revanced.patches.spotify.misc.fix import app.revanced.patcher.fingerprint internal val getPackageInfoFingerprint = fingerprint { - strings( - "Failed to get the application signatures", - "Failed to get installer package" - ) -} - -internal val getPackageInfoLegacyFingerprint = fingerprint { strings( "Failed to get the application signatures" ) } - diff --git a/patches/src/main/kotlin/app/revanced/patches/spotify/misc/fix/SpoofPackageInfoPatch.kt b/patches/src/main/kotlin/app/revanced/patches/spotify/misc/fix/SpoofPackageInfoPatch.kt index c06f2a04c..2836a4872 100644 --- a/patches/src/main/kotlin/app/revanced/patches/spotify/misc/fix/SpoofPackageInfoPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/spotify/misc/fix/SpoofPackageInfoPatch.kt @@ -1,14 +1,15 @@ package app.revanced.patches.spotify.misc.fix +import app.revanced.patcher.extensions.InstructionExtensions.addInstruction import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction import app.revanced.patcher.patch.bytecodePatch -import app.revanced.patches.spotify.misc.extension.IS_SPOTIFY_LEGACY_APP_TARGET -import app.revanced.util.addInstructionsAtControlFlowLabel -import app.revanced.util.indexOfFirstInstructionOrThrow +import app.revanced.util.findInstructionIndicesReversedOrThrow +import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstructionReversedOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.MethodReference @Suppress("unused") val spoofPackageInfoPatch = bytecodePatch( @@ -18,18 +19,11 @@ val spoofPackageInfoPatch = bytecodePatch( compatibleWith("com.spotify.music") execute { - val getPackageInfoFingerprint = if (IS_SPOTIFY_LEGACY_APP_TARGET) { - getPackageInfoLegacyFingerprint - } else { - getPackageInfoFingerprint - } - getPackageInfoFingerprint.method.apply { - val stringMatches = getPackageInfoFingerprint.stringMatches!! - // region Spoof signature. - val failedToGetSignaturesStringIndex = stringMatches.first().index + val failedToGetSignaturesStringIndex = + getPackageInfoFingerprint.stringMatches!!.first().index val concatSignaturesIndex = indexOfFirstInstructionReversedOrThrow( failedToGetSignaturesStringIndex, @@ -45,26 +39,23 @@ val spoofPackageInfoPatch = bytecodePatch( // region Spoof installer name. - if (IS_SPOTIFY_LEGACY_APP_TARGET) { - // Installer name is not used in the legacy app target. - return@execute - } - val expectedInstallerName = "com.android.vending" - val returnInstallerNameIndex = indexOfFirstInstructionOrThrow( - stringMatches.last().index, - Opcode.RETURN_OBJECT - ) + findInstructionIndicesReversedOrThrow { + val reference = getReference() + reference?.name == "getInstallerPackageName" || reference?.name == "getInstallingPackageName" + }.forEach { index -> + val returnObjectIndex = index + 1 - val installerNameRegister = getInstruction( - returnInstallerNameIndex - ).registerA + val installerPackageNameRegister = getInstruction( + returnObjectIndex + ).registerA - addInstructionsAtControlFlowLabel( - returnInstallerNameIndex, - "const-string v$installerNameRegister, \"$expectedInstallerName\"" - ) + addInstruction( + returnObjectIndex + 1, + "const-string v$installerPackageNameRegister, \"$expectedInstallerName\"" + ) + } // endregion }