Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Instagram): Added few patches #3604

Draft
wants to merge 20 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
2a4c2dc
feat(Instagram): Added `Enable developer menu` patch
swakwork Sep 1, 2024
ab1690f
feat(Instagram): Added `Max media quality` patch
swakwork Sep 1, 2024
535a50a
feat(Instagram): Added `Selectable bio` patch
swakwork Sep 1, 2024
6a54ffb
feat(Instagram): Added `Sanitize sharing links` patch
swakwork Sep 1, 2024
685c7c8
feat(Instagram): Added `Open links in external browser` patch
swakwork Sep 1, 2024
71657ac
upd(Instagram): Code correction for `Enable developer menu` patch
swakwork Sep 2, 2024
7589cef
upd(Instagram): Code correction for `Selectable bio` patch
swakwork Sep 2, 2024
0968783
upd(Instagram): Code correction for `Max media quality` patch
swakwork Sep 2, 2024
1eb6017
upd(Instagram): Code correction for `Sanitize sharing links` patch
swakwork Sep 2, 2024
bf5762b
upd(Instagram): Code correction for `Open links in external browser` …
swakwork Sep 2, 2024
af9fc80
upd(Instagram): Code correction for `Enable developer menu` patch
swakwork Sep 2, 2024
4ec9a28
upd(Instagram): Code correction for `Open links in external browser` …
swakwork Sep 2, 2024
7ab6003
upd(Instagram): Code correction for `Sanitize sharing links` patch
swakwork Sep 2, 2024
c36a50f
upd(Instagram): Code correction for `Selectable bio` patch
swakwork Sep 2, 2024
b6e2e8a
upd(Instagram): Code correction for `Max media quality` patch
swakwork Sep 2, 2024
ddb9ed8
upd(Instagram): updated descriptions.
swakwork Sep 2, 2024
606f571
upd(Instagram): Added profile & highlights link `Sanitize sharing lin…
swakwork Sep 2, 2024
8788b4e
upd(Instagram): Better patch description for `Max media quality`
swakwork Sep 6, 2024
4603458
upd(Instagram): Better patch description for `Max media quality`
swakwork Sep 6, 2024
12ef5c9
refactor
oSumAtrIX Sep 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions api/revanced-patches.api
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,10 @@ public final class app/revanced/patches/inshorts/ad/HideAdsPatch : app/revanced/
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
}

public final class app/revanced/patches/instagram/misc/integrations/IntegrationsPatch : app/revanced/patches/shared/misc/integrations/BaseIntegrationsPatch {
public static final field INSTANCE Lapp/revanced/patches/instagram/misc/integrations/IntegrationsPatch;
}

public final class app/revanced/patches/instagram/patches/ad/HideAdsPatch : app/revanced/patcher/patch/BytecodePatch {
public static final field INSTANCE Lapp/revanced/patches/instagram/patches/ad/HideAdsPatch;
public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V
Expand All @@ -361,6 +365,52 @@ public final class app/revanced/patches/instagram/patches/ads/timeline/HideTimel
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
}

public final class app/revanced/patches/instagram/patches/developerMenu/EnableDeveloperMenuPatch : app/revanced/patcher/patch/BytecodePatch {
public static final field INSTANCE Lapp/revanced/patches/instagram/patches/developerMenu/EnableDeveloperMenuPatch;
public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
}

public final class app/revanced/patches/instagram/patches/links/openInExternalBrowser/OpenLinksInExternalBrowser : app/revanced/patcher/patch/BytecodePatch {
public static final field INSTANCE Lapp/revanced/patches/instagram/patches/links/openInExternalBrowser/OpenLinksInExternalBrowser;
public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
}

public final class app/revanced/patches/instagram/patches/links/openInExternalBrowser/fingerprints/OpenLinksInExternalBrowserFingerprint : app/revanced/patcher/fingerprint/MethodFingerprint {
public static final field INSTANCE Lapp/revanced/patches/instagram/patches/links/openInExternalBrowser/fingerprints/OpenLinksInExternalBrowserFingerprint;
}

public final class app/revanced/patches/instagram/patches/links/sanitizeSharingLinks/SanitizeSharingLinksPatch : app/revanced/patcher/patch/BytecodePatch {
public static final field INSTANCE Lapp/revanced/patches/instagram/patches/links/sanitizeSharingLinks/SanitizeSharingLinksPatch;
public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
}

public final class app/revanced/patches/instagram/patches/links/sanitizeSharingLinks/fingerprints/LiveShareUrlFingerprint : app/revanced/patcher/fingerprint/MethodFingerprint {
public static final field INSTANCE Lapp/revanced/patches/instagram/patches/links/sanitizeSharingLinks/fingerprints/LiveShareUrlFingerprint;
}

public final class app/revanced/patches/instagram/patches/links/sanitizeSharingLinks/fingerprints/PostShareClassFinderFingerprint : app/revanced/patcher/fingerprint/MethodFingerprint {
public static final field INSTANCE Lapp/revanced/patches/instagram/patches/links/sanitizeSharingLinks/fingerprints/PostShareClassFinderFingerprint;
}

public final class app/revanced/patches/instagram/patches/links/sanitizeSharingLinks/fingerprints/StoryShareUrlFingerprint : app/revanced/patcher/fingerprint/MethodFingerprint {
public static final field INSTANCE Lapp/revanced/patches/instagram/patches/links/sanitizeSharingLinks/fingerprints/StoryShareUrlFingerprint;
}

public final class app/revanced/patches/instagram/patches/maxQuality/MaxMediaQualityPatch : app/revanced/patcher/patch/BytecodePatch {
public static final field INSTANCE Lapp/revanced/patches/instagram/patches/maxQuality/MaxMediaQualityPatch;
public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
}

public final class app/revanced/patches/instagram/patches/selectableBio/SelectableBioPatch : app/revanced/patcher/patch/BytecodePatch {
public static final field INSTANCE Lapp/revanced/patches/instagram/patches/selectableBio/SelectableBioPatch;
public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
}

public final class app/revanced/patches/irplus/ad/RemoveAdsPatch : app/revanced/patcher/patch/BytecodePatch {
public static final field INSTANCE Lapp/revanced/patches/irplus/ad/RemoveAdsPatch;
public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package app.revanced.patches.instagram.misc.integrations

import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.instagram.misc.integrations.fingerprints.InitFingerprint
import app.revanced.patches.shared.misc.integrations.BaseIntegrationsPatch

@Patch(
requiresIntegrations = true,
)
swakwork marked this conversation as resolved.
Show resolved Hide resolved
object IntegrationsPatch : BaseIntegrationsPatch(
setOf(InitFingerprint),
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package app.revanced.patches.instagram.misc.integrations.fingerprints

import app.revanced.patches.instagram.misc.integrations.fingerprints.InitFingerprint.getApplicationContextIndex
import app.revanced.patches.shared.misc.integrations.BaseIntegrationsPatch.IntegrationsFingerprint
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction35c
import com.android.tools.smali.dexlib2.iface.reference.MethodReference

internal object InitFingerprint : IntegrationsFingerprint(
customFingerprint = { methodDef, _ ->
methodDef.name == "onCreate" && methodDef.definingClass == "Lcom/instagram/app/InstagramAppShell;"
},
insertIndexResolver = { method ->
getApplicationContextIndex = method.indexOfFirstInstructionOrThrow {
getReference<MethodReference>()?.name == "onCreate"
}

getApplicationContextIndex + 1 // Below the invoke-super instruction.
},
contextRegisterResolver = { method ->
val moveResultInstruction = method.implementation!!.instructions.elementAt(getApplicationContextIndex)
as BuilderInstruction35c
moveResultInstruction.registerC
},
) {
private var getApplicationContextIndex = -1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package app.revanced.patches.instagram.patches.developerMenu

import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.extensions.InstructionExtensions.getInstructions
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotation.CompatiblePackage
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.instagram.patches.developerMenu.fingerprints.ShouldAddPrefTTLFingerprint
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction35c
import com.android.tools.smali.dexlib2.dexbacked.reference.DexBackedMethodReference

@Patch(
name = "Enable developer menu",
compatiblePackages = [CompatiblePackage("com.instagram.android")],
use = false,
)
@Suppress("unused")
object EnableDeveloperMenuPatch : BytecodePatch(
setOf(ShouldAddPrefTTLFingerprint),
) {
override fun execute(context: BytecodeContext) {
ShouldAddPrefTTLFingerprint.resultOrThrow().let { methodFingerprintResult ->
methodFingerprintResult.mutableMethod.apply {
// finding the method which calls the developer flag check method.
val developerMethodCallIndex = getInstructions().first { it.opcode == Opcode.INVOKE_STATIC }.location.index
val developerMethodReference = (getInstruction<BuilderInstruction35c>(developerMethodCallIndex).reference as DexBackedMethodReference)
// the class and method name were the developer flag check happens.
val className = developerMethodReference.definingClass
val methodName = developerMethodReference.name

// locating the developer flag check method.
val developerFlagCheckMethod = context.findClass(className)!!.mutableClass.methods.first { it.name == methodName }

// make the method return true always.
swakwork marked this conversation as resolved.
Show resolved Hide resolved
developerFlagCheckMethod.addInstructions(
0,
"""
const v0, 0x1
return v0
""".trimIndent(),
swakwork marked this conversation as resolved.
Show resolved Hide resolved
)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package app.revanced.patches.instagram.patches.developerMenu.fingerprints

import app.revanced.patcher.fingerprint.MethodFingerprint

internal object ShouldAddPrefTTLFingerprint : MethodFingerprint(
customFingerprint = { methodDef, _ ->
methodDef.name == "shouldAddPrefTTL" && methodDef.definingClass == "Lcom/instagram/debug/whoptions/WhitehatOptionsFragment;"
},
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package app.revanced.patches.instagram.patches.links.openInExternalBrowser

import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
import app.revanced.patcher.extensions.InstructionExtensions.getInstructions
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotation.CompatiblePackage
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.instagram.misc.integrations.IntegrationsPatch
import app.revanced.patches.instagram.patches.links.openInExternalBrowser.fingerprints.OpenLinksInExternalBrowserFingerprint
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode

@Patch(
name = "Open links in external browser",
dependencies = [IntegrationsPatch::class],
compatiblePackages = [CompatiblePackage("com.instagram.android")],
use = false,
requiresIntegrations = true,
swakwork marked this conversation as resolved.
Show resolved Hide resolved
)
@Suppress("unused")
object OpenLinksInExternalBrowser : BytecodePatch(
setOf(OpenLinksInExternalBrowserFingerprint),
) {
private const val FUNC_CALL = """
swakwork marked this conversation as resolved.
Show resolved Hide resolved
invoke-static{v0}, Lapp/revanced/integrations/instagram/links/ExternalBrowser;->openInExternalBrowser(Ljava/lang/String;)Z
move-result v0
"""

override fun execute(context: BytecodeContext) {
OpenLinksInExternalBrowserFingerprint.resultOrThrow().let { it ->
it.mutableClass.apply {
val className = it.classDef.type

// get the method that returns the url.
val getUrlMethod = methods.first { it.returnType == "Ljava/lang/String;" && it.parameters.size == 0 }.name
val getUrlMethodCall = """
swakwork marked this conversation as resolved.
Show resolved Hide resolved
invoke-virtual {p0}, $className->$getUrlMethod()Ljava/lang/String;
move-result-object v0
""".trimIndent()
swakwork marked this conversation as resolved.
Show resolved Hide resolved

// Hooking the call method.
// finding the method with browser call happens.
val browserCallMethod = methods.last { it.returnType == "V" && it.parameters.size == 0 }
val const4 = browserCallMethod.getInstructions().first { it.opcode == Opcode.CONST_4 }
swakwork marked this conversation as resolved.
Show resolved Hide resolved

// call the openInExternalBrowser method.
// if it returns true, return void.
// if it returns false, proceed as usual.
browserCallMethod.addInstructionsWithLabels(
0,
"""
$getUrlMethodCall
$FUNC_CALL
if-eqz v0, :revanced
return-void
""".trimIndent(),
ExternalLabel("revanced", const4),
)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package app.revanced.patches.instagram.patches.links.openInExternalBrowser.fingerprints

import app.revanced.patcher.fingerprint.MethodFingerprint

object OpenLinksInExternalBrowserFingerprint : MethodFingerprint(
strings = listOf("TrackingInfo.ARG_HIDE_SYSTEM_BAR", "TrackingInfo.ARG_MODULE_NAME"),
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package app.revanced.patches.instagram.patches.links.sanitizeSharingLinks

import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.extensions.InstructionExtensions.getInstructions
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotation.CompatiblePackage
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patches.instagram.patches.links.sanitizeSharingLinks.fingerprints.LiveShareUrlFingerprint
import app.revanced.patches.instagram.patches.links.sanitizeSharingLinks.fingerprints.PostShareClassFinderFingerprint
import app.revanced.patches.instagram.patches.links.sanitizeSharingLinks.fingerprints.StoryShareUrlFingerprint
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction21c
import com.android.tools.smali.dexlib2.dexbacked.reference.DexBackedTypeReference
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction

@Patch(
name = "Sanitize sharing links",
description = "Removes the tracking query parameters from links before they are shared.",
compatiblePackages = [CompatiblePackage("com.instagram.android")],
use = false,
requiresIntegrations = true,
)
@Suppress("unused")
object SanitizeSharingLinksPatch : BytecodePatch(
setOf(StoryShareUrlFingerprint, LiveShareUrlFingerprint, PostShareClassFinderFingerprint),
) {
private const val FUNC_CALL = "Lapp/revanced/integrations/instagram/links/ShareLink;->sanitizeUrl(Ljava/lang/String;)Ljava/lang/String;"

override fun execute(context: BytecodeContext) {
fun addFunction(method: MutableMethod) {
swakwork marked this conversation as resolved.
Show resolved Hide resolved
val index = method.getInstructions().first { it.opcode == Opcode.IPUT_OBJECT }.location.index - 2
// link register.
val register = method.getInstruction<OneRegisterInstruction>(index).registerA
swakwork marked this conversation as resolved.
Show resolved Hide resolved

method.addInstructions(
index + 1,
"""
invoke-static{v$register}, $FUNC_CALL
move-result-object v$register
swakwork marked this conversation as resolved.
Show resolved Hide resolved
""".trimIndent(),
)
}

// sanitize share link of stories.
addFunction(StoryShareUrlFingerprint.resultOrThrow().mutableMethod)
// sanitize share link of live.
addFunction(LiveShareUrlFingerprint.resultOrThrow().mutableMethod)
swakwork marked this conversation as resolved.
Show resolved Hide resolved

// finding post share url class.
PostShareClassFinderFingerprint.resultOrThrow().let { it ->
it.mutableMethod.apply {
val classIndex = getInstructions().last { it.opcode == Opcode.CONST_CLASS }.location.index
val className = (getInstruction<BuilderInstruction21c>(classIndex).reference as DexBackedTypeReference).type
val parseJsonMethod = context.findClass(className)!!.mutableClass.methods.first { it.name == "parseFromJson" }
// sanitize share link of posts & reels.
addFunction(parseJsonMethod)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package app.revanced.patches.instagram.patches.links.sanitizeSharingLinks.fingerprints

import app.revanced.patcher.fingerprint.MethodFingerprint

object LiveShareUrlFingerprint : MethodFingerprint(
strings = listOf("live_to_share_url"),
customFingerprint = { methodDef, _ ->
methodDef.name == "parseFromJson"
},
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package app.revanced.patches.instagram.patches.links.sanitizeSharingLinks.fingerprints

import app.revanced.patcher.fingerprint.MethodFingerprint

object PostShareClassFinderFingerprint : MethodFingerprint(
strings = listOf("media/%s/permalink"),
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package app.revanced.patches.instagram.patches.links.sanitizeSharingLinks.fingerprints

import app.revanced.patcher.fingerprint.MethodFingerprint

object StoryShareUrlFingerprint : MethodFingerprint(
strings = listOf("story_item_to_share_url"),
customFingerprint = { methodDef, _ ->
methodDef.name == "parseFromJson"
},
)
Loading