generated from ReVanced/revanced-patches-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Gboard): Add
Always-incognito mode for Gboard
patch
- Loading branch information
1 parent
32ca598
commit 2a98c21
Showing
7 changed files
with
142 additions
and
8 deletions.
There are no files selected for viewing
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
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
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
35 changes: 35 additions & 0 deletions
35
src/main/kotlin/dev/jkcarino/revanced/patches/gboard/AlwaysIncognitoModePatch.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,35 @@ | ||
package dev.jkcarino.revanced.patches.gboard | ||
|
||
import app.revanced.patcher.data.BytecodeContext | ||
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions | ||
import app.revanced.patcher.patch.BytecodePatch | ||
import app.revanced.patcher.patch.annotation.CompatiblePackage | ||
import app.revanced.patcher.patch.annotation.Patch | ||
import dev.jkcarino.revanced.patches.all.signature.pmshook.BypassSignatureChecksPatch | ||
import dev.jkcarino.revanced.patches.gboard.fingerprints.IsIncognitoModeFingerprint | ||
import dev.jkcarino.revanced.util.exception | ||
|
||
@Patch( | ||
name = "Always-incognito mode for Gboard", | ||
description = "Always opens Gboard in incognito mode to disable typing history collection and personalization. " + | ||
"This requires the original, unmodified app to work properly.", | ||
dependencies = [ | ||
BypassSignatureChecksPatch::class, | ||
], | ||
compatiblePackages = [CompatiblePackage("com.google.android.inputmethod.latin")], | ||
use = false | ||
) | ||
@Suppress("unused") | ||
object AlwaysIncognitoModePatch : BytecodePatch( | ||
setOf(IsIncognitoModeFingerprint) | ||
) { | ||
override fun execute(context: BytecodeContext) { | ||
IsIncognitoModeFingerprint.result?.mutableMethod?.addInstructions( | ||
index = 0, | ||
smaliInstructions = """ | ||
const/4 v0, 0x1 | ||
return v0 | ||
""" | ||
) ?: throw IsIncognitoModeFingerprint.exception | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...in/kotlin/dev/jkcarino/revanced/patches/gboard/fingerprints/IsIncognitoModeFingerprint.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,24 @@ | ||
package dev.jkcarino.revanced.patches.gboard.fingerprints | ||
|
||
import app.revanced.patcher.extensions.or | ||
import com.android.tools.smali.dexlib2.AccessFlags | ||
import com.android.tools.smali.dexlib2.Opcode | ||
import dev.jkcarino.revanced.util.patch.LiteralValueFingerprint | ||
|
||
internal object IsIncognitoModeFingerprint : LiteralValueFingerprint( | ||
returnType = "Z", | ||
accessFlags = AccessFlags.PUBLIC or AccessFlags.STATIC, | ||
parameters = listOf("Landroid/view/inputmethod/EditorInfo;"), | ||
opcodes = listOf( | ||
Opcode.IF_EQZ, | ||
Opcode.IGET, | ||
Opcode.CONST_HIGH16, | ||
Opcode.AND_INT_2ADDR, | ||
Opcode.IF_EQZ, | ||
Opcode.CONST_4, | ||
Opcode.RETURN, | ||
Opcode.CONST_4, | ||
Opcode.RETURN, | ||
), | ||
literalSupplier = { 0x1000000 } // EditorInfo.IME_FLAG_NO_PERSONALIZED_LEARNING | ||
) |
25 changes: 25 additions & 0 deletions
25
src/main/kotlin/dev/jkcarino/revanced/util/BytecodeUtils.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
34 changes: 34 additions & 0 deletions
34
src/main/kotlin/dev/jkcarino/revanced/util/patch/LiteralValueFingerprint.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,34 @@ | ||
package dev.jkcarino.revanced.util.patch | ||
|
||
import app.revanced.patcher.fingerprint.MethodFingerprint | ||
import com.android.tools.smali.dexlib2.Opcode | ||
import dev.jkcarino.revanced.util.containsWideLiteralInstructionValue | ||
|
||
/** | ||
* A fingerprint to resolve methods that contain a specific literal value. | ||
* | ||
* @param returnType The method's return type compared using String.startsWith. | ||
* @param accessFlags The method's exact access flags using values of AccessFlags. | ||
* @param parameters The parameters of the method. Partial matches allowed and follow the same rules as returnType. | ||
* @param opcodes An opcode pattern of the method's instructions. Wildcard or unknown opcodes can be specified by null. | ||
* @param strings A list of the method's strings compared each using String.contains. | ||
* @param literalSupplier A supplier for the literal value to check for. | ||
*/ | ||
abstract class LiteralValueFingerprint( | ||
returnType: String? = null, | ||
accessFlags: Int? = null, | ||
parameters: Iterable<String>? = null, | ||
opcodes: Iterable<Opcode>? = null, | ||
strings: Iterable<String>? = null, | ||
// Has to be a supplier because the fingerprint is created before patches can set literals. | ||
literalSupplier: () -> Long | ||
) : MethodFingerprint( | ||
returnType = returnType, | ||
accessFlags = accessFlags, | ||
parameters = parameters, | ||
opcodes = opcodes, | ||
strings = strings, | ||
customFingerprint = { methodDef, _ -> | ||
methodDef.containsWideLiteralInstructionValue(literalSupplier()) | ||
} | ||
) |