Skip to content

Commit

Permalink
fix(songpal): make patches more resilient (#2386)
Browse files Browse the repository at this point in the history
Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
  • Loading branch information
1fexd and oSumAtrIX committed Jun 11, 2023
1 parent 4177930 commit 947bf42
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -1,31 +1,26 @@
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.patches.songpal.badge.patch.BadgeTabPatch
import org.jf.dexlib2.AccessFlags
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)
@FuzzyPatternScanMethod(2)
object CreateTabsFingerprint : MethodFingerprint(
"L",
"Ljava/util/List",
accessFlags = AccessFlags.PRIVATE.value,
opcodes = listOf(
Opcode.INVOKE_STATIC,
Opcode.MOVE_RESULT_OBJECT,
Opcode.INVOKE_STATIC,
Opcode.MOVE_RESULT_OBJECT,
Opcode.SGET_OBJECT,
Opcode.INVOKE_INTERFACE,
Opcode.MOVE_RESULT_OBJECT,
Opcode.SGET_OBJECT,
Opcode.INVOKE_INTERFACE,
Opcode.MOVE_RESULT_OBJECT,
Opcode.INVOKE_STATIC,
Opcode.MOVE_RESULT_OBJECT,
Opcode.INVOKE_INTERFACE,
Opcode.MOVE_RESULT_OBJECT,
Opcode.CHECK_CAST,
Opcode.RETURN_OBJECT
)
customFingerprint = { methodDef, _ ->
methodDef.implementation?.instructions?.any { instruction ->
if (instruction.opcode != Opcode.INVOKE_STATIC) return@any false

val reference = (instruction as ReferenceInstruction).reference as MethodReference

if (reference.parameterTypes.isNotEmpty()) return@any false
if (reference.definingClass != BadgeTabPatch.ACTIVITY_TAB_DESCRIPTOR) return@any false
if (reference.returnType != "[${BadgeTabPatch.ACTIVITY_TAB_DESCRIPTOR}") return@any false
true
} ?: false
}
)
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
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.patches.songpal.badge.fingerprints.ShowNotificationFingerprint.expectedReference
import org.jf.dexlib2.AccessFlags
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)
@FuzzyPatternScanMethod(2)
object ShowNotificationFingerprint : MethodFingerprint(
"V",
accessFlags = AccessFlags.PUBLIC.value,
opcodes = listOf(
Opcode.IGET_OBJECT,
Opcode.IGET,
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT_OBJECT,
Opcode.IGET_OBJECT,
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT_OBJECT,
Opcode.CONST,
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT,
Opcode.INVOKE_VIRTUAL,
Opcode.IGET_BOOLEAN,
Opcode.INVOKE_VIRTUAL,
Opcode.CONST,
Opcode.INVOKE_VIRTUAL,
Opcode.RETURN_VOID
customFingerprint = custom@{ methodDef, _ ->
methodDef.implementation?.instructions?.any { instruction ->
if (instruction.opcode != Opcode.INVOKE_VIRTUAL) return@any false

with(expectedReference) {
val currentReference = (instruction as ReferenceInstruction).reference as MethodReference
currentReference.let {
if (it.definingClass != definingClass) return@any false
if (it.parameterTypes != parameterTypes) return@any false
if (it.returnType != returnType) return@any false
}
}
true
} ?: false
}
) {
val expectedReference = ImmutableMethodReference(
"Lcom/google/android/material/bottomnavigation/BottomNavigationView;",
"getOrCreateBadge", // Non-obfuscated placeholder method name.
listOf("I"),
"Lcom/google/android/material/badge/BadgeDrawable;",
)
)
}

0 comments on commit 947bf42

Please sign in to comment.