generated from ReVanced/revanced-patches-template
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Twitter): Added
Feature Flag Hook
- Loading branch information
Showing
4 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
src/main/kotlin/crimera/patches/twitter/featureFlag/FeatureFlagPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/crimera/patches/twitter/featureFlag/fingerprints/FeatureFlagFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
) |
10 changes: 10 additions & 0 deletions
10
...ain/kotlin/crimera/patches/twitter/featureFlag/fingerprints/FeatureFlagLoadFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters