fix(songpal): make patches more resilient (#2386)

Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
fe 2023-06-11 15:53:33 +02:00 committed by GitHub
parent 41779305d5
commit 947bf42b7c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 41 deletions

View file

@ -1,31 +1,26 @@
package app.revanced.patches.songpal.badge.fingerprints package app.revanced.patches.songpal.badge.fingerprints
import app.revanced.patcher.fingerprint.method.annotation.FuzzyPatternScanMethod
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.songpal.badge.patch.BadgeTabPatch
import org.jf.dexlib2.AccessFlags import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.Opcode import org.jf.dexlib2.Opcode
import org.jf.dexlib2.iface.instruction.ReferenceInstruction
import org.jf.dexlib2.iface.reference.MethodReference
// Located @ ub.i0.h#p (9.5.0) // Located @ ub.i0.h#p (9.5.0)
@FuzzyPatternScanMethod(2)
object CreateTabsFingerprint : MethodFingerprint( object CreateTabsFingerprint : MethodFingerprint(
"L", "Ljava/util/List",
accessFlags = AccessFlags.PRIVATE.value, accessFlags = AccessFlags.PRIVATE.value,
opcodes = listOf( customFingerprint = { methodDef, _ ->
Opcode.INVOKE_STATIC, methodDef.implementation?.instructions?.any { instruction ->
Opcode.MOVE_RESULT_OBJECT, if (instruction.opcode != Opcode.INVOKE_STATIC) return@any false
Opcode.INVOKE_STATIC,
Opcode.MOVE_RESULT_OBJECT, val reference = (instruction as ReferenceInstruction).reference as MethodReference
Opcode.SGET_OBJECT,
Opcode.INVOKE_INTERFACE, if (reference.parameterTypes.isNotEmpty()) return@any false
Opcode.MOVE_RESULT_OBJECT, if (reference.definingClass != BadgeTabPatch.ACTIVITY_TAB_DESCRIPTOR) return@any false
Opcode.SGET_OBJECT, if (reference.returnType != "[${BadgeTabPatch.ACTIVITY_TAB_DESCRIPTOR}") return@any false
Opcode.INVOKE_INTERFACE, true
Opcode.MOVE_RESULT_OBJECT, } ?: false
Opcode.INVOKE_STATIC, }
Opcode.MOVE_RESULT_OBJECT,
Opcode.INVOKE_INTERFACE,
Opcode.MOVE_RESULT_OBJECT,
Opcode.CHECK_CAST,
Opcode.RETURN_OBJECT
)
) )

View file

@ -1,31 +1,37 @@
package app.revanced.patches.songpal.badge.fingerprints package app.revanced.patches.songpal.badge.fingerprints
import app.revanced.patcher.fingerprint.method.annotation.FuzzyPatternScanMethod
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.songpal.badge.fingerprints.ShowNotificationFingerprint.expectedReference
import org.jf.dexlib2.AccessFlags import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.Opcode import org.jf.dexlib2.Opcode
import org.jf.dexlib2.iface.instruction.ReferenceInstruction
import org.jf.dexlib2.iface.reference.MethodReference
import org.jf.dexlib2.immutable.reference.ImmutableMethodReference
// Located @ com.sony.songpal.mdr.vim.activity.MdrRemoteBaseActivity.e#run (9.5.0) // Located @ com.sony.songpal.mdr.vim.activity.MdrRemoteBaseActivity.e#run (9.5.0)
@FuzzyPatternScanMethod(2)
object ShowNotificationFingerprint : MethodFingerprint( object ShowNotificationFingerprint : MethodFingerprint(
"V", "V",
accessFlags = AccessFlags.PUBLIC.value, accessFlags = AccessFlags.PUBLIC.value,
opcodes = listOf( customFingerprint = custom@{ methodDef, _ ->
Opcode.IGET_OBJECT, methodDef.implementation?.instructions?.any { instruction ->
Opcode.IGET, if (instruction.opcode != Opcode.INVOKE_VIRTUAL) return@any false
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT_OBJECT, with(expectedReference) {
Opcode.IGET_OBJECT, val currentReference = (instruction as ReferenceInstruction).reference as MethodReference
Opcode.INVOKE_VIRTUAL, currentReference.let {
Opcode.MOVE_RESULT_OBJECT, if (it.definingClass != definingClass) return@any false
Opcode.CONST, if (it.parameterTypes != parameterTypes) return@any false
Opcode.INVOKE_VIRTUAL, if (it.returnType != returnType) return@any false
Opcode.MOVE_RESULT, }
Opcode.INVOKE_VIRTUAL, }
Opcode.IGET_BOOLEAN, true
Opcode.INVOKE_VIRTUAL, } ?: false
Opcode.CONST, }
Opcode.INVOKE_VIRTUAL, ) {
Opcode.RETURN_VOID val expectedReference = ImmutableMethodReference(
"Lcom/google/android/material/bottomnavigation/BottomNavigationView;",
"getOrCreateBadge", // Non-obfuscated placeholder method name.
listOf("I"),
"Lcom/google/android/material/badge/BadgeDrawable;",
) )
) }