diff --git a/patches/api/patches.api b/patches/api/patches.api index aae1502c1..fd788e221 100644 --- a/patches/api/patches.api +++ b/patches/api/patches.api @@ -264,6 +264,10 @@ public final class app/revanced/patches/instagram/ads/HideAdsPatchKt { public static final fun getHideAdsPatch ()Lapp/revanced/patcher/patch/BytecodePatch; } +public final class app/revanced/patches/instagram/hide/navigation/HideNavigationButtonsKt { + public static final fun getHideNavigationButtonsPatch ()Lapp/revanced/patcher/patch/BytecodePatch; +} + public final class app/revanced/patches/instagram/misc/signature/SignatureCheckPatchKt { public static final fun getSignatureCheckPatch ()Lapp/revanced/patcher/patch/BytecodePatch; } diff --git a/patches/src/main/kotlin/app/revanced/patches/instagram/hide/navigation/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/instagram/hide/navigation/Fingerprints.kt new file mode 100644 index 000000000..3b401a842 --- /dev/null +++ b/patches/src/main/kotlin/app/revanced/patches/instagram/hide/navigation/Fingerprints.kt @@ -0,0 +1,29 @@ + +package app.revanced.patches.instagram.hide.navigation + +import app.revanced.patcher.fingerprint +import com.android.tools.smali.dexlib2.Opcode + +internal val tabCreateButtonsLoopStartFingerprint = fingerprint { + returns("V") + strings("InstagramMainActivity.createTabButtons") + opcodes( + //Loop Start + Opcode.IF_GE, // Check if index is finished (index, size) + //Injection + Opcode.INVOKE_INTERFACE, + Opcode.MOVE_RESULT_OBJECT + ) +} + +internal val tabCreateButtonsLoopEndFingerprint = fingerprint { + returns("V") + strings("InstagramMainActivity.createTabButtons") + opcodes( + Opcode.IPUT_OBJECT, + // Injection Jump + Opcode.ADD_INT_LIT8, //Increase Index + Opcode.GOTO_16 // Jump to loopStart + // LoopEnd + ) +} diff --git a/patches/src/main/kotlin/app/revanced/patches/instagram/hide/navigation/HideNavigationButtons.kt b/patches/src/main/kotlin/app/revanced/patches/instagram/hide/navigation/HideNavigationButtons.kt new file mode 100644 index 000000000..f63d55b62 --- /dev/null +++ b/patches/src/main/kotlin/app/revanced/patches/instagram/hide/navigation/HideNavigationButtons.kt @@ -0,0 +1,78 @@ +package app.revanced.patches.instagram.hide.navigation + +import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels +import app.revanced.patcher.extensions.InstructionExtensions.getInstruction +import app.revanced.patcher.patch.booleanOption +import app.revanced.patcher.patch.bytecodePatch +import app.revanced.patcher.util.smali.ExternalLabel +import app.revanced.util.findFreeRegister +import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction +import java.util.logging.Logger + +@Suppress("unused") +val hideNavigationButtonsPatch = bytecodePatch( + name = "Hide navigation buttons", + description = "Hides navigation bar buttons, such as the Reels and Create button.", + use = false +) { + compatibleWith("com.instagram.android") + + val hideReels by booleanOption( + key = "hideReels", + default = true, + title = "Hide Reels" + ) + + val hideCreate by booleanOption( + key = "hideCreate", + default = true, + title = "Hide Create" + ) + + execute { + if (!hideReels!! && !hideCreate!!) { + return@execute Logger.getLogger(this::class.java.name).warning( + "No hide navigation buttons options are enabled. No changes made." + ) + } + + tabCreateButtonsLoopStartFingerprint.method.apply { + // Check the current loop index, and skip over adding the + // navigation button view if the index matches a given button. + + val startIndex = tabCreateButtonsLoopStartFingerprint.patternMatch!!.startIndex + val endIndex = tabCreateButtonsLoopEndFingerprint.patternMatch!!.endIndex + val insertIndex = startIndex + 1 + val loopIndexRegister = getInstruction(startIndex).registerA + val freeRegister = findFreeRegister(insertIndex, loopIndexRegister) + val instruction = getInstruction(endIndex - 1) + + var instructions = buildString { + if (hideCreate!!) { + appendLine( + """ + const v$freeRegister, 0x2 + if-eq v$freeRegister, v$loopIndexRegister, :skipAddView + """ + ) + } + + if (hideReels!!) { + appendLine( + """ + const v$freeRegister, 0x3 + if-eq v$freeRegister, v$loopIndexRegister, :skipAddView + """ + ) + } + } + + addInstructionsWithLabels( + insertIndex, + instructions, + ExternalLabel("skipAddView", instruction) + ) + } + } + } +