mirror of
https://github.com/revanced/revanced-patches.git
synced 2025-12-14 13:21:02 +01:00
fix(Instagram - Hide navigation buttons): Remove button based on name (#5971)
This commit is contained in:
@@ -0,0 +1,33 @@
|
|||||||
|
package app.revanced.extension.instagram.hide.navigation;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public class HideNavigationButtonsPatch {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Injection point.
|
||||||
|
* @param navigationButtonsList the list of navigation buttons, as an (obfuscated) Enum type
|
||||||
|
* @param buttonNameToRemove the name of the button we want to remove
|
||||||
|
* @param enumNameField the field in the nav button enum class which contains the name of the button
|
||||||
|
* @return the patched list of navigation buttons
|
||||||
|
*/
|
||||||
|
public static List<Object> removeNavigationButtonByName(
|
||||||
|
List<Object> navigationButtonsList,
|
||||||
|
String buttonNameToRemove,
|
||||||
|
String enumNameField
|
||||||
|
)
|
||||||
|
throws IllegalAccessException, NoSuchFieldException {
|
||||||
|
for (Object button : navigationButtonsList) {
|
||||||
|
Field f = button.getClass().getDeclaredField(enumNameField);
|
||||||
|
String currentButtonEnumName = (String) f.get(button);
|
||||||
|
|
||||||
|
if (buttonNameToRemove.equals(currentButtonEnumName)) {
|
||||||
|
navigationButtonsList.remove(button);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return navigationButtonsList;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,28 +2,22 @@
|
|||||||
package app.revanced.patches.instagram.hide.navigation
|
package app.revanced.patches.instagram.hide.navigation
|
||||||
|
|
||||||
import app.revanced.patcher.fingerprint
|
import app.revanced.patcher.fingerprint
|
||||||
import com.android.tools.smali.dexlib2.Opcode
|
import app.revanced.patcher.patch.BytecodePatchContext
|
||||||
|
|
||||||
internal val tabCreateButtonsLoopStartFingerprint = fingerprint {
|
internal val initializeNavigationButtonsListFingerprint = fingerprint {
|
||||||
returns("V")
|
strings("Nav3")
|
||||||
strings("InstagramMainActivity.createTabButtons")
|
parameters("Lcom/instagram/common/session/UserSession;", "Z")
|
||||||
opcodes(
|
returns("Ljava/util/List;")
|
||||||
//Loop Start
|
|
||||||
Opcode.IF_GE, // Check if index is finished (index, size)
|
|
||||||
//Injection
|
|
||||||
Opcode.INVOKE_INTERFACE,
|
|
||||||
Opcode.MOVE_RESULT_OBJECT
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal val tabCreateButtonsLoopEndFingerprint = fingerprint {
|
private val navigationButtonsEnumClassDef = fingerprint {
|
||||||
returns("V")
|
strings("FEED", "fragment_feed", "SEARCH", "fragment_search")
|
||||||
strings("InstagramMainActivity.createTabButtons")
|
}
|
||||||
opcodes(
|
|
||||||
Opcode.IPUT_OBJECT,
|
context(BytecodePatchContext)
|
||||||
// Injection Jump
|
internal val navigationButtonsEnumInitFingerprint get() = fingerprint {
|
||||||
Opcode.ADD_INT_LIT8, //Increase Index
|
custom { method, classDef ->
|
||||||
Opcode.GOTO // Jump to loopStart
|
method.name == "<init>"
|
||||||
// LoopEnd
|
&& classDef == navigationButtonsEnumClassDef.classDef
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,28 @@
|
|||||||
package app.revanced.patches.instagram.hide.navigation
|
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.extensions.InstructionExtensions.getInstruction
|
||||||
import app.revanced.patcher.patch.booleanOption
|
import app.revanced.patcher.patch.booleanOption
|
||||||
import app.revanced.patcher.patch.bytecodePatch
|
import app.revanced.patcher.patch.bytecodePatch
|
||||||
import app.revanced.patcher.util.smali.ExternalLabel
|
import app.revanced.util.addInstructionsAtControlFlowLabel
|
||||||
import app.revanced.util.findFreeRegister
|
import app.revanced.util.findFreeRegister
|
||||||
|
import app.revanced.util.getReference
|
||||||
|
import app.revanced.util.indexOfFirstInstructionOrThrow
|
||||||
|
import com.android.tools.smali.dexlib2.Opcode
|
||||||
|
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
||||||
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
|
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
|
||||||
|
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
|
||||||
import java.util.logging.Logger
|
import java.util.logging.Logger
|
||||||
|
|
||||||
|
private const val EXTENSION_CLASS_DESCRIPTOR =
|
||||||
|
"Lapp/revanced/extension/instagram/hide/navigation/HideNavigationButtonsPatch;"
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
val hideNavigationButtonsPatch = bytecodePatch(
|
val hideNavigationButtonsPatch = bytecodePatch(
|
||||||
name = "Hide navigation buttons",
|
name = "Hide navigation buttons",
|
||||||
description = "Hides navigation bar buttons, such as the Reels and Create button.",
|
description = "Hides navigation bar buttons, such as the Reels and Create button.",
|
||||||
use = false
|
use = false
|
||||||
) {
|
) {
|
||||||
compatibleWith("com.instagram.android"("397.1.0.52.81"))
|
compatibleWith("com.instagram.android")
|
||||||
|
|
||||||
val hideReels by booleanOption(
|
val hideReels by booleanOption(
|
||||||
key = "hideReels",
|
key = "hideReels",
|
||||||
@@ -38,43 +45,44 @@ val hideNavigationButtonsPatch = bytecodePatch(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
tabCreateButtonsLoopStartFingerprint.method.apply {
|
val enumNameField: String
|
||||||
// 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
|
// Get the field name which contains the name of the enum for the navigation button ("fragment_clips", "fragment_share", ...)
|
||||||
val endIndex = tabCreateButtonsLoopEndFingerprint.patternMatch!!.endIndex
|
with(navigationButtonsEnumInitFingerprint.method) {
|
||||||
val insertIndex = startIndex + 1
|
enumNameField = indexOfFirstInstructionOrThrow {
|
||||||
val loopIndexRegister = getInstruction<TwoRegisterInstruction>(startIndex).registerA
|
opcode == Opcode.IPUT_OBJECT &&
|
||||||
val freeRegister = findFreeRegister(insertIndex, loopIndexRegister)
|
(this as TwoRegisterInstruction).registerA == 2 // The p2 register
|
||||||
val instruction = getInstruction(endIndex - 1)
|
}.let {
|
||||||
|
getInstruction(it).getReference<FieldReference>()!!.name
|
||||||
val 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)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
initializeNavigationButtonsListFingerprint.method.apply {
|
||||||
|
val returnIndex = indexOfFirstInstructionOrThrow(Opcode.RETURN_OBJECT)
|
||||||
|
val buttonsListRegister = getInstruction<OneRegisterInstruction>(returnIndex).registerA
|
||||||
|
val freeRegister = findFreeRegister(returnIndex)
|
||||||
|
val freeRegister2 = findFreeRegister(returnIndex, freeRegister)
|
||||||
|
|
||||||
|
fun instructionsRemoveButtonByName(buttonEnumName: String): String {
|
||||||
|
return """
|
||||||
|
const-string v$freeRegister, "$buttonEnumName"
|
||||||
|
const-string v$freeRegister2, "$enumNameField"
|
||||||
|
invoke-static { v$buttonsListRegister, v$freeRegister, v$freeRegister2 }, $EXTENSION_CLASS_DESCRIPTOR->removeNavigationButtonByName(Ljava/util/List;Ljava/lang/String;Ljava/lang/String;)Ljava/util/List;
|
||||||
|
move-result-object v$buttonsListRegister
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hideReels!!)
|
||||||
|
addInstructionsAtControlFlowLabel(
|
||||||
|
returnIndex,
|
||||||
|
instructionsRemoveButtonByName("fragment_clips")
|
||||||
|
)
|
||||||
|
|
||||||
|
if (hideCreate!!)
|
||||||
|
addInstructionsAtControlFlowLabel(
|
||||||
|
returnIndex,
|
||||||
|
instructionsRemoveButtonByName("fragment_share")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user