Skip to content

Commit

Permalink
feat(reddit/hide-navigation-buttons): supports the latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
inotia00 committed Jul 23, 2023
1 parent dea655e commit 6b826bd
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 36 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import org.jf.dexlib2.Opcode
object BottomNavScreenFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("L", "L", "Z", "L", "L"),
parameters = emptyList(),
opcodes = listOf(
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT_OBJECT,
Opcode.INVOKE_INTERFACE,
Opcode.MOVE_RESULT_OBJECT
Opcode.RETURN_VOID
),
customFingerprint = { _, classDef -> classDef.type.startsWith("Lcom/reddit/launch/bottomnav/BottomNavScreen\$") }
customFingerprint = { methodDef, classDef ->
methodDef.name == "onGlobalLayout"
&& classDef.type.startsWith("Lcom/reddit/launch/bottomnav/BottomNavScreen\$") }
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patches.reddit.layout.navigation.annotations.NavigationButtonsCompatibility
import app.revanced.patches.reddit.layout.navigation.patch.NavigationButtonsPatch.Companion.setValue
import app.revanced.patches.reddit.utils.annotations.RedditCompatibility
import app.revanced.patches.reddit.utils.settings.bytecode.patch.SettingsBytecodePatch.Companion.updateSettingsStatus
import app.revanced.patches.reddit.utils.settings.resource.patch.SettingsPatch

Expand All @@ -23,7 +23,7 @@ import app.revanced.patches.reddit.utils.settings.resource.patch.SettingsPatch
SettingsPatch::class
]
)
@NavigationButtonsCompatibility
@RedditCompatibility
@Version("0.0.1")
class CreateButtonPatch : BytecodePatch() {
override fun execute(context: BytecodeContext): PatchResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patches.reddit.layout.navigation.annotations.NavigationButtonsCompatibility
import app.revanced.patches.reddit.layout.navigation.patch.NavigationButtonsPatch.Companion.setValue
import app.revanced.patches.reddit.utils.annotations.RedditCompatibility
import app.revanced.patches.reddit.utils.settings.bytecode.patch.SettingsBytecodePatch.Companion.updateSettingsStatus
import app.revanced.patches.reddit.utils.settings.resource.patch.SettingsPatch

Expand All @@ -23,7 +23,7 @@ import app.revanced.patches.reddit.utils.settings.resource.patch.SettingsPatch
SettingsPatch::class
]
)
@NavigationButtonsCompatibility
@RedditCompatibility
@Version("0.0.1")
class DiscoverButtonPatch : BytecodePatch() {
override fun execute(context: BytecodeContext): PatchResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@ package app.revanced.patches.reddit.layout.navigation.patch
import app.revanced.extensions.toErrorResult
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultError
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patches.reddit.layout.navigation.fingerprints.BottomNavScreenFingerprint
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
import org.jf.dexlib2.iface.instruction.ReferenceInstruction
import org.jf.dexlib2.iface.instruction.FiveRegisterInstruction

class NavigationButtonsPatch : BytecodePatch(
listOf(BottomNavScreenFingerprint)
Expand All @@ -21,21 +18,12 @@ class NavigationButtonsPatch : BytecodePatch(
BottomNavScreenFingerprint.result?.let {
it.mutableMethod.apply {
val startIndex = it.scanResult.patternScanResult!!.startIndex
val reference =
getInstruction<ReferenceInstruction>(startIndex).reference.toString()
val targetRegister =
getInstruction<FiveRegisterInstruction>(startIndex).registerC

if (!reference.endsWith("Ljava/util/List;"))
return PatchResultError("Invalid reference: $reference")

val insertIndex = startIndex + 2
val insertRegister =
getInstruction<OneRegisterInstruction>(startIndex + 1).registerA

addInstructions(
insertIndex, """
invoke-static {v$insertRegister}, $INTEGRATIONS_METHOD_DESCRIPTOR
move-result-object v$insertRegister
"""
addInstruction(
startIndex + 1,
"invoke-static {v$targetRegister}, $INTEGRATIONS_METHOD_DESCRIPTOR"
)
}
} ?: return BottomNavScreenFingerprint.toErrorResult()
Expand All @@ -46,7 +34,7 @@ class NavigationButtonsPatch : BytecodePatch(
companion object {
const val INTEGRATIONS_METHOD_DESCRIPTOR =
"Lapp/revanced/reddit/patches/NavigationButtonsPatch;" +
"->hideNavigationButtons(Ljava/util/List;)Ljava/util/List;"
"->hideNavigationButtons(Landroid/view/ViewGroup;)V"

internal fun BytecodeContext.setValue(patch: String) {
this.classes.forEach { classDef ->
Expand Down

0 comments on commit 6b826bd

Please sign in to comment.