Skip to content

Commit 2679fad

Browse files
pisekoSumAtrIX
andauthored
feat(Mi Fitness): Add Force English locale and Fix login patch (#2734)
Co-authored-by: oSumAtrIX <[email protected]>
1 parent 08c4468 commit 2679fad

File tree

5 files changed

+112
-0
lines changed

5 files changed

+112
-0
lines changed

api/revanced-patches.api

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,18 @@ public final class app/revanced/patches/messenger/inputfield/patch/DisableTyping
284284
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
285285
}
286286

287+
public final class app/revanced/patches/mifitness/misc/locale/ForceEnglishLocalePatch : app/revanced/patcher/patch/BytecodePatch {
288+
public static final field INSTANCE Lapp/revanced/patches/mifitness/misc/locale/ForceEnglishLocalePatch;
289+
public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V
290+
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
291+
}
292+
293+
public final class app/revanced/patches/mifitness/misc/login/FixLoginPatch : app/revanced/patcher/patch/BytecodePatch {
294+
public static final field INSTANCE Lapp/revanced/patches/mifitness/misc/login/FixLoginPatch;
295+
public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V
296+
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
297+
}
298+
287299
public final class app/revanced/patches/moneymanager/UnlockProPatch : app/revanced/patcher/patch/BytecodePatch {
288300
public static final field INSTANCE Lapp/revanced/patches/moneymanager/UnlockProPatch;
289301
public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package app.revanced.patches.mifitness.misc.locale
2+
3+
import app.revanced.patcher.data.BytecodeContext
4+
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
5+
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
6+
import app.revanced.patcher.patch.BytecodePatch
7+
import app.revanced.patcher.patch.annotation.CompatiblePackage
8+
import app.revanced.patcher.patch.annotation.Patch
9+
import app.revanced.patches.mifitness.misc.locale.fingerprints.SyncBluetoothLanguageFingerprint
10+
import app.revanced.patches.mifitness.misc.login.FixLoginPatch
11+
import app.revanced.util.exception
12+
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
13+
14+
@Patch(
15+
name = "Force English locale",
16+
description = "Forces wearable devices to use the English locale.",
17+
compatiblePackages = [CompatiblePackage("com.xiaomi.wearable")],
18+
dependencies = [FixLoginPatch::class],
19+
)
20+
@Suppress("unused")
21+
object ForceEnglishLocalePatch : BytecodePatch(
22+
setOf(SyncBluetoothLanguageFingerprint),
23+
) {
24+
override fun execute(context: BytecodeContext) {
25+
SyncBluetoothLanguageFingerprint.result?.let {
26+
val resolvePhoneLocaleInstruction = it.scanResult.patternScanResult!!.startIndex
27+
28+
it.mutableMethod.apply {
29+
val registerIndexToUpdate =
30+
getInstruction<OneRegisterInstruction>(resolvePhoneLocaleInstruction).registerA
31+
32+
replaceInstruction(
33+
resolvePhoneLocaleInstruction,
34+
"const-string v$registerIndexToUpdate, \"en_gb\"",
35+
)
36+
}
37+
} ?: throw SyncBluetoothLanguageFingerprint.exception
38+
}
39+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package app.revanced.patches.mifitness.misc.locale.fingerprints
2+
3+
import app.revanced.patcher.fingerprint.MethodFingerprint
4+
import com.android.tools.smali.dexlib2.Opcode
5+
6+
internal object SyncBluetoothLanguageFingerprint : MethodFingerprint(
7+
customFingerprint = { methodDef, _ ->
8+
methodDef.definingClass == "Lcom/xiaomi/fitness/devicesettings/DeviceSettingsSyncer;" &&
9+
methodDef.name == "syncBluetoothLanguage"
10+
},
11+
opcodes = listOf(Opcode.MOVE_RESULT_OBJECT),
12+
)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package app.revanced.patches.mifitness.misc.login
2+
3+
import app.revanced.patcher.data.BytecodeContext
4+
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
5+
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
6+
import app.revanced.patcher.patch.BytecodePatch
7+
import app.revanced.patcher.patch.annotation.CompatiblePackage
8+
import app.revanced.patcher.patch.annotation.Patch
9+
import app.revanced.patches.mifitness.misc.login.fingerprints.XiaomiAccountManagerConstructorFingerprint
10+
import app.revanced.util.exception
11+
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
12+
13+
@Patch(
14+
name = "Fix login",
15+
description = "Fixes login for uncertified Mi Fitness app",
16+
compatiblePackages = [CompatiblePackage("com.xiaomi.wearable")],
17+
)
18+
@Suppress("unused")
19+
object FixLoginPatch : BytecodePatch(
20+
setOf(XiaomiAccountManagerConstructorFingerprint),
21+
) {
22+
override fun execute(context: BytecodeContext) {
23+
XiaomiAccountManagerConstructorFingerprint.result?.let {
24+
it.mutableMethod.apply {
25+
val isCertifiedIndex = it.scanResult.patternScanResult!!.startIndex
26+
val isCertifiedRegister = getInstruction<OneRegisterInstruction>(isCertifiedIndex).registerA
27+
28+
addInstruction(
29+
isCertifiedIndex,
30+
"const/4 p$isCertifiedRegister, 0x0",
31+
)
32+
}
33+
} ?: throw XiaomiAccountManagerConstructorFingerprint.exception
34+
}
35+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package app.revanced.patches.mifitness.misc.login.fingerprints
2+
3+
import app.revanced.patcher.extensions.or
4+
import app.revanced.patcher.fingerprint.MethodFingerprint
5+
import com.android.tools.smali.dexlib2.AccessFlags
6+
import com.android.tools.smali.dexlib2.Opcode
7+
8+
internal object XiaomiAccountManagerConstructorFingerprint : MethodFingerprint(
9+
accessFlags = AccessFlags.PRIVATE or AccessFlags.CONSTRUCTOR,
10+
customFingerprint = { methodDef, _ ->
11+
methodDef.definingClass == "Lcom/xiaomi/passport/accountmanager/XiaomiAccountManager;"
12+
},
13+
opcodes = listOf(Opcode.IF_NEZ),
14+
)

0 commit comments

Comments
 (0)