forked from ReVanced/revanced-patches
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
496 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/kotlin/app/revanced/patches/instagram/misc/integrations/IntegrationsPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package app.revanced.patches.instagram.misc.integrations | ||
|
||
import app.revanced.patcher.patch.annotation.Patch | ||
import app.revanced.patches.instagram.misc.integrations.fingerprints.MainActivityOnCreateFingerprint | ||
import app.revanced.patches.shared.misc.integrations.BaseIntegrationsPatch | ||
|
||
@Patch(requiresIntegrations = true) | ||
object IntegrationsPatch : BaseIntegrationsPatch( | ||
setOf(MainActivityOnCreateFingerprint), | ||
) |
28 changes: 28 additions & 0 deletions
28
...anced/patches/instagram/misc/integrations/fingerprints/MainActivityOnCreateFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.MainActivityOnCreateFingerprint.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 MainActivityOnCreateFingerprint : 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 | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/kotlin/app/revanced/patches/instagram/patches/interaction/bio/SelectableBioPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package app.revanced.patches.instagram.patches.interaction.bio | ||
|
||
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.interaction.bio.fingerprints.SelectableBioFingerprint | ||
import app.revanced.util.resultOrThrow | ||
import com.android.tools.smali.dexlib2.Opcode | ||
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction | ||
|
||
@Patch( | ||
name = "Selectable bio", | ||
description = "Make the user's bio selectable.", | ||
compatiblePackages = [CompatiblePackage("com.instagram.android")], | ||
) | ||
@Suppress("unused") | ||
object SelectableBioPatch : BytecodePatch( | ||
setOf(SelectableBioFingerprint), | ||
) { | ||
override fun execute(context: BytecodeContext) { | ||
SelectableBioFingerprint.resultOrThrow().mutableMethod.apply { | ||
val setBioTextIndex = getInstructions().first { it.opcode == Opcode.INVOKE_VIRTUAL }.location.index | ||
val setTextViewInstruction = getInstruction<FiveRegisterInstruction>(setBioTextIndex) | ||
val textViewRegister = setTextViewInstruction.registerC | ||
val textRegister = setTextViewInstruction.registerD | ||
|
||
// Make the textview selectable. | ||
addInstructions( | ||
setBioTextIndex + 1, | ||
""" | ||
const/4 v$textRegister, 0x1 | ||
invoke-virtual { v$textViewRegister, v$textRegister }, Landroid/widget/TextView;->setTextIsSelectable(Z)V | ||
""", | ||
) | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...vanced/patches/instagram/patches/interaction/bio/fingerprints/SelectableBioFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package app.revanced.patches.instagram.patches.interaction.bio.fingerprints | ||
|
||
import app.revanced.patcher.fingerprint.MethodFingerprint | ||
|
||
internal object SelectableBioFingerprint : MethodFingerprint( | ||
strings = listOf("is_bio_visible"), | ||
returnType = "V", | ||
) |
54 changes: 54 additions & 0 deletions
54
...evanced/patches/instagram/patches/interaction/links/browser/OpenLinksInExternalBrowser.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package app.revanced.patches.instagram.patches.interaction.links.browser | ||
|
||
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.interaction.links.browser.fingerprints.OpenLinksInExternalBrowserFingerprint | ||
import app.revanced.util.resultOrThrow | ||
|
||
@Patch( | ||
name = "Open links in external browser", | ||
dependencies = [IntegrationsPatch::class], | ||
compatiblePackages = [CompatiblePackage("com.instagram.android")], | ||
) | ||
@Suppress("unused") | ||
object OpenLinksInExternalBrowser : BytecodePatch( | ||
setOf(OpenLinksInExternalBrowserFingerprint), | ||
) { | ||
override fun execute(context: BytecodeContext) { | ||
OpenLinksInExternalBrowserFingerprint.resultOrThrow().let { it -> | ||
// Get the method that returns the url. | ||
val getUrlMethod = it.mutableClass.methods.first { | ||
it.returnType == "Ljava/lang/String;" && it.parameters.size == 0 | ||
}.name | ||
|
||
// Patch the method that opens the link in the internal browser. | ||
it.mutableClass.methods.last { it.returnType == "V" && it.parameters.size == 0 }.apply { | ||
val continueInstruction = getInstructions().first() | ||
|
||
// Call the openInExternalBrowser method. | ||
// If it returns true, return void. | ||
// If it returns false, proceed as usual. | ||
addInstructionsWithLabels( | ||
0, | ||
""" | ||
invoke-virtual { p0 }, ${it.classDef}->$getUrlMethod()Ljava/lang/String; | ||
move-result-object v0 | ||
invoke-static { v0 }, Lapp/revanced/integrations/instagram/links/ExternalBrowser;->openInExternalBrowser(Ljava/lang/String;)Z | ||
move-result v0 | ||
if-eqz v0, :not_opened | ||
return-void | ||
""", | ||
ExternalLabel("not_opened", continueInstruction), | ||
) | ||
} | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...m/patches/interaction/links/browser/fingerprints/OpenLinksInExternalBrowserFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package app.revanced.patches.instagram.patches.interaction.links.browser.fingerprints | ||
|
||
import app.revanced.patcher.fingerprint.MethodFingerprint | ||
|
||
internal object OpenLinksInExternalBrowserFingerprint : MethodFingerprint( | ||
strings = listOf("TrackingInfo.ARG_HIDE_SYSTEM_BAR", "TrackingInfo.ARG_MODULE_NAME"), | ||
) |
74 changes: 74 additions & 0 deletions
74
...evanced/patches/instagram/patches/interaction/links/tracking/SanitizeSharingLinksPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package app.revanced.patches.instagram.patches.interaction.links.tracking | ||
|
||
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.fingerprint.MethodFingerprint | ||
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.interaction.links.tracking.fingerprints.* | ||
import app.revanced.util.getReference | ||
import app.revanced.util.resultOrThrow | ||
import com.android.tools.smali.dexlib2.Opcode | ||
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction | ||
import com.android.tools.smali.dexlib2.iface.reference.TypeReference | ||
|
||
@Patch( | ||
name = "Sanitize sharing links", | ||
description = "Removes the tracking query parameters from links before they are shared.", | ||
compatiblePackages = [CompatiblePackage("com.instagram.android")], | ||
requiresIntegrations = true, | ||
) | ||
@Suppress("unused") | ||
object SanitizeSharingLinksPatch : BytecodePatch( | ||
setOf( | ||
StoryShareUrlFingerprint, | ||
LiveShareUrlFingerprint, | ||
PostShareClassFinderFingerprint, | ||
ProfileShareUrlFingerprint, | ||
HighlightsShareUrlFingerprint, | ||
), | ||
) { | ||
private const val INVOKE_INTEGRATIONS_METHOD_INSTRUCTION = | ||
"Lapp/revanced/integrations/instagram/links/ShareLink;->sanitizeUrl(Ljava/lang/String;)Ljava/lang/String;" | ||
|
||
override fun execute(context: BytecodeContext) { | ||
fun sanitizeUrl(method: MutableMethod) = method.apply { | ||
val index = getInstructions().first { it.opcode == Opcode.IPUT_OBJECT }.location.index - 2 | ||
// Register where the link is present. | ||
val register = getInstruction<OneRegisterInstruction>(index).registerA | ||
|
||
addInstructions( | ||
index + 1, | ||
""" | ||
invoke-static{ v$register }, $INVOKE_INTEGRATIONS_METHOD_INSTRUCTION | ||
move-result-object v$register | ||
""", | ||
) | ||
} | ||
|
||
fun sanitizeUrl(fingerprint: MethodFingerprint) = sanitizeUrl(fingerprint.resultOrThrow().mutableMethod) | ||
|
||
// Sanitize share link of stories. | ||
sanitizeUrl(StoryShareUrlFingerprint) | ||
// Sanitize share link of live. | ||
sanitizeUrl(LiveShareUrlFingerprint) | ||
// Sanitize share link of profile. | ||
sanitizeUrl(ProfileShareUrlFingerprint) | ||
// Sanitize share link of highlights. | ||
sanitizeUrl(HighlightsShareUrlFingerprint) | ||
// Sanitize share link of posts & reels. | ||
PostShareClassFinderFingerprint.resultOrThrow().mutableMethod.let { method -> | ||
val classIndex = method.getInstructions().last { it.opcode == Opcode.CONST_CLASS }.location.index | ||
val className = method.getInstruction(classIndex).getReference<TypeReference>()!!.type | ||
val parseJsonMethod = context.findClass(className)!!.mutableClass.methods.first { | ||
it.name == "parseFromJson" | ||
} | ||
|
||
sanitizeUrl(parseJsonMethod) | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...nstagram/patches/interaction/links/tracking/fingerprints/HighlightsShareUrlFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package app.revanced.patches.instagram.patches.interaction.links.tracking.fingerprints | ||
|
||
import app.revanced.patcher.fingerprint.MethodFingerprint | ||
|
||
internal object HighlightsShareUrlFingerprint : MethodFingerprint( | ||
strings = listOf("story_highlights_to_share_url"), | ||
customFingerprint = { methodDef, _ -> | ||
methodDef.name == "parseFromJson" | ||
}, | ||
) |
10 changes: 10 additions & 0 deletions
10
...ches/instagram/patches/interaction/links/tracking/fingerprints/LiveShareUrlFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package app.revanced.patches.instagram.patches.interaction.links.tracking.fingerprints | ||
|
||
import app.revanced.patcher.fingerprint.MethodFingerprint | ||
|
||
internal object LiveShareUrlFingerprint : MethodFingerprint( | ||
strings = listOf("live_to_share_url"), | ||
customFingerprint = { methodDef, _ -> | ||
methodDef.name == "parseFromJson" | ||
}, | ||
) |
7 changes: 7 additions & 0 deletions
7
...tagram/patches/interaction/links/tracking/fingerprints/PostShareClassFinderFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package app.revanced.patches.instagram.patches.interaction.links.tracking.fingerprints | ||
|
||
import app.revanced.patcher.fingerprint.MethodFingerprint | ||
|
||
internal object PostShareClassFinderFingerprint : MethodFingerprint( | ||
strings = listOf("media/%s/permalink"), | ||
) |
10 changes: 10 additions & 0 deletions
10
...s/instagram/patches/interaction/links/tracking/fingerprints/ProfileShareUrlFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package app.revanced.patches.instagram.patches.interaction.links.tracking.fingerprints | ||
|
||
import app.revanced.patcher.fingerprint.MethodFingerprint | ||
|
||
internal object ProfileShareUrlFingerprint : MethodFingerprint( | ||
strings = listOf("profile_to_share_url"), | ||
customFingerprint = { methodDef, _ -> | ||
methodDef.name == "parseFromJson" | ||
}, | ||
) |
10 changes: 10 additions & 0 deletions
10
...hes/instagram/patches/interaction/links/tracking/fingerprints/StoryShareUrlFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package app.revanced.patches.instagram.patches.interaction.links.tracking.fingerprints | ||
|
||
import app.revanced.patcher.fingerprint.MethodFingerprint | ||
|
||
internal object StoryShareUrlFingerprint : MethodFingerprint( | ||
strings = listOf("story_item_to_share_url"), | ||
customFingerprint = { methodDef, _ -> | ||
methodDef.name == "parseFromJson" | ||
}, | ||
) |
40 changes: 40 additions & 0 deletions
40
.../app/revanced/patches/instagram/patches/layout/menu/developer/EnableDeveloperMenuPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package app.revanced.patches.instagram.patches.layout.menu.developer | ||
|
||
import app.revanced.patcher.data.BytecodeContext | ||
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions | ||
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.layout.menu.developer.fingerprints.ShouldAddPrefTTLFingerprint | ||
import app.revanced.util.resultOrThrow | ||
import com.android.tools.smali.dexlib2.Opcode | ||
|
||
@Patch( | ||
name = "Enable developer menu", | ||
compatiblePackages = [CompatiblePackage("com.instagram.android")], | ||
) | ||
@Suppress("unused") | ||
object EnableDeveloperMenuPatch : BytecodePatch( | ||
setOf(ShouldAddPrefTTLFingerprint), | ||
) { | ||
override fun execute(context: BytecodeContext) { | ||
ShouldAddPrefTTLFingerprint.resultOrThrow().mutableMethod.let { method -> | ||
val isDeveloperMethodCallIndex = method.getInstructions().first { | ||
it.opcode == Opcode.INVOKE_STATIC | ||
}.location.index | ||
|
||
val isDeveloperMethod = context.toMethodWalker(method).nextMethod(isDeveloperMethodCallIndex, true) | ||
.getMethod() as MutableMethod | ||
|
||
isDeveloperMethod.addInstructions( | ||
0, | ||
""" | ||
const v0, 0x1 | ||
return v0 | ||
""", | ||
) | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...tches/instagram/patches/layout/menu/developer/fingerprints/ShouldAddPrefTTLFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package app.revanced.patches.instagram.patches.layout.menu.developer.fingerprints | ||
|
||
import app.revanced.patcher.fingerprint.MethodFingerprint | ||
|
||
internal object ShouldAddPrefTTLFingerprint : MethodFingerprint( | ||
customFingerprint = { methodDef, _ -> | ||
methodDef.name == "shouldAddPrefTTL" && methodDef.definingClass == "Lcom/instagram/debug/whoptions/WhitehatOptionsFragment;" | ||
}, | ||
) |
Oops, something went wrong.