Skip to content

Commit

Permalink
feat(Twitter): Added Feature Flag Hook
Browse files Browse the repository at this point in the history
  • Loading branch information
Swakshan committed Apr 9, 2024
1 parent 821112c commit 2328baf
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package crimera.patches.twitter.featureFlag

import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.extensions.InstructionExtensions.getInstructions
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchException
import crimera.patches.twitter.featureFlag.fingerprints.FeatureFlagFingerprint

import app.revanced.patcher.patch.annotation.CompatiblePackage
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable
import com.android.tools.smali.dexlib2.Opcode
import crimera.patches.twitter.misc.settings.SettingsPatch

@Patch(
name = "Hook feature flag",
compatiblePackages = [CompatiblePackage("com.twitter.android")],
use = true
)
@Suppress("unused")
object FeatureFlagPatch:BytecodePatch(
setOf(FeatureFlagFingerprint)
) {
override fun execute(context: BytecodeContext) {

val result = FeatureFlagFingerprint.result
?:throw PatchException("FeatureFlagFingerprint not found")

val methods = result.mutableClass.methods
val booleanMethod = methods.first { it.returnType == "Z" && it.parameters == listOf("Ljava/lang/String;","Z") }

val METHOD = """
invoke-static {p1,v0}, ${SettingsPatch.PATCHES_DESCRIPTOR}/FeatureSwitchPatch;->flagInfo(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;
move-result-object v0
""".trimIndent()

val loc = booleanMethod.getInstructions().first { it.opcode == Opcode.MOVE_RESULT_OBJECT }.location.index

booleanMethod.addInstructions(loc+1,METHOD)
//end
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package crimera.patches.twitter.featureFlag.fingerprints

import app.revanced.patcher.fingerprint.MethodFingerprint

object FeatureFlagFingerprint :MethodFingerprint(
strings = listOf("feature_switches_configs_crashlytics_enabled")
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package crimera.patches.twitter.featureFlag.fingerprints

import app.revanced.patcher.fingerprint.MethodFingerprint

object FeatureFlagLoadFingerprint:MethodFingerprint(
customFingerprint = { methodDef, _ ->
methodDef.definingClass.endsWith("Lapp/revanced/integrations/twitter/patches/FeatureSwitchPatch;") &&
methodDef.name == "load"
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ object SettingsPatch : BytecodePatch(
const val PATCHES_DESCRIPTOR = "$INTEGRATIONS_PACKAGE/patches"
private const val ADD_PREF_DESCRIPTOR = "$UTILS_DESCRIPTOR;->addPref([Ljava/lang/String;Ljava/lang/String;)[Ljava/lang/String;"
const val SSTS_DESCRIPTOR = "invoke-static {}, $INTEGRATIONS_PACKAGE/settings/SettingsStatus;"
const val FSTS_DESCRIPTOR = "invoke-static {}, $INTEGRATIONS_PACKAGE/patches/FeatureSwitchPatch;"
private const val START_ACTIVITY_DESCRIPTOR =
"invoke-static {}, $UTILS_DESCRIPTOR;->startSettingsActivity()V"

Expand Down

0 comments on commit 2328baf

Please sign in to comment.