From 152bb7c3ee7cf36bc07460e7a3444631ec540441 Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Fri, 11 Apr 2025 21:40:17 +0200 Subject: [PATCH] fix(Google Photos - Restore hidden 'Back up while charging' toggle): Constrain to last working app target (#4761) --- ...oreHiddenBackUpWhileChargingTogglePatch.kt | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/patches/src/main/kotlin/app/revanced/patches/googlephotos/misc/preferences/RestoreHiddenBackUpWhileChargingTogglePatch.kt b/patches/src/main/kotlin/app/revanced/patches/googlephotos/misc/preferences/RestoreHiddenBackUpWhileChargingTogglePatch.kt index 04fe29715..beac5b6a4 100644 --- a/patches/src/main/kotlin/app/revanced/patches/googlephotos/misc/preferences/RestoreHiddenBackUpWhileChargingTogglePatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/googlephotos/misc/preferences/RestoreHiddenBackUpWhileChargingTogglePatch.kt @@ -3,23 +3,29 @@ package app.revanced.patches.googlephotos.misc.preferences import app.revanced.patcher.extensions.InstructionExtensions.addInstruction import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.patch.bytecodePatch +import app.revanced.util.indexOfFirstInstructionOrThrow +import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @Suppress("unused") val restoreHiddenBackUpWhileChargingTogglePatch = bytecodePatch( name = "Restore hidden 'Back up while charging' toggle", description = "Restores a hidden toggle to only run backups when the device is charging.", + use = false ) { - compatibleWith("com.google.android.apps.photos") + compatibleWith("com.google.android.apps.photos"("7.11.0.705590205")) execute { // Patches 'backup_prefs_had_backup_only_when_charging_enabled' to always be true. - val chargingPrefStringIndex = backupPreferencesFingerprint.stringMatches!!.first().index - backupPreferencesFingerprint.method.apply { - // Get the register of move-result. - val resultRegister = getInstruction(chargingPrefStringIndex + 2).registerA - // Insert const after move-result to override register as true. - addInstruction(chargingPrefStringIndex + 3, "const/4 v$resultRegister, 0x1") + backupPreferencesFingerprint.let { + it.method.apply { + val index = indexOfFirstInstructionOrThrow( + it.stringMatches!!.first().index, + Opcode.MOVE_RESULT + ) + val register = getInstruction(index).registerA + addInstruction(index + 1, "const/4 v$register, 0x1") + } } } }