Skip to content

Commit

Permalink
update: Improved the hooking of the recyclerview methods. also fixes …
Browse files Browse the repository at this point in the history
…the crash when opening feature flags.
  • Loading branch information
crimera committed Jun 11, 2024
1 parent ca5535d commit 25e5bc4
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import app.revanced.patcher.patch.annotation.CompatiblePackage
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.shared.misc.integrations.fingerprint.IntegrationsUtilsFingerprint
import com.android.tools.smali.dexlib2.Opcode
import crimera.patches.twitter.featureFlag.fingerprints.CustomAdapterFingerprint
import crimera.patches.twitter.featureFlag.fingerprints.FeatureFlagFingerprint
import crimera.patches.twitter.featureFlag.fingerprints.RecyclerViewGetCountFingerprint
import crimera.patches.twitter.featureFlag.fingerprints.*
import crimera.patches.twitter.misc.settings.SettingsPatch
import crimera.patches.twitter.misc.settings.fingerprints.SettingsStatusLoadFingerprint

Expand All @@ -29,7 +27,9 @@ object FeatureFlagPatch : BytecodePatch(
IntegrationsUtilsFingerprint,
SettingsStatusLoadFingerprint,
CustomAdapterFingerprint,
RecyclerViewGetCountFingerprint
GetCountFingerprint,
OnCreateViewHolderFingerprint,
OnBindViewHolderFingerprint
)
) {
override fun execute(context: BytecodeContext) {
Expand All @@ -54,10 +54,18 @@ object FeatureFlagPatch : BytecodePatch(
)

// Change the getCount override method name
val getCountMethod = CustomAdapterFingerprint.result?.mutableMethod
val customAdapter = CustomAdapterFingerprint.result
?: throw PatchException("getCount Method of CustomAdapter not found")

getCountMethod.name = RecyclerViewGetCountFingerprint.result?.method?.name
customAdapter.mutableMethod.name = GetCountFingerprint.result?.method?.name
?: throw PatchException("getCount Method of RecyclerView not found")

// onCreateViewHolder
customAdapter.mutableClass.methods.first { it.name == "onCreateViewHolder" }.name = OnCreateViewHolderFingerprint.result?.method?.name
?: throw PatchException("onCreateViewHolder Method of RecyclerView not found")

// onBindViewHolder
customAdapter.mutableClass.methods.first { it.name == "onBindViewHolder" }.name = OnBindViewHolderFingerprint.result?.method?.name
?: throw PatchException("onBindViewHolder Method of RecyclerView not found")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package crimera.patches.twitter.featureFlag.fingerprints

import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import com.android.tools.smali.dexlib2.AccessFlags

object GetCountFingerprint: MethodFingerprint(
accessFlags = AccessFlags.PUBLIC or AccessFlags.ABSTRACT,
returnType = "I",
customFingerprint = { methodDef, _ ->
methodDef.definingClass.endsWith("Landroidx/recyclerview/widget/RecyclerView\$e;")
}
)

object OnCreateViewHolderFingerprint: MethodFingerprint(
accessFlags = AccessFlags.PUBLIC or AccessFlags.ABSTRACT,
returnType = "Landroidx/recyclerview/widget/RecyclerView\$c0;",
customFingerprint = { methodDef, _ ->
methodDef.definingClass.endsWith("Landroidx/recyclerview/widget/RecyclerView\$e;")
}
)

object OnBindViewHolderFingerprint: MethodFingerprint(
accessFlags = AccessFlags.PUBLIC or AccessFlags.ABSTRACT,
returnType = "V",
customFingerprint = { methodDef, _ ->
methodDef.definingClass.endsWith("Landroidx/recyclerview/widget/RecyclerView\$e;")
}
)

This file was deleted.

0 comments on commit 25e5bc4

Please sign in to comment.