mirror of
https://github.com/revanced/revanced-patches.git
synced 2025-12-07 01:51:27 +01:00
feat(Instagram): Add Custom share domain patch (#5998)
This commit is contained in:
@@ -0,0 +1,33 @@
|
|||||||
|
package app.revanced.extension.instagram.misc.share.domain;
|
||||||
|
|
||||||
|
import android.net.Uri;
|
||||||
|
import app.revanced.extension.shared.Logger;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public final class ChangeLinkSharingDomainPatch {
|
||||||
|
|
||||||
|
private static String getCustomShareDomain() {
|
||||||
|
// Method is modified during patching.
|
||||||
|
throw new IllegalStateException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Injection point.
|
||||||
|
*/
|
||||||
|
public static String setCustomShareDomain(String url) {
|
||||||
|
try {
|
||||||
|
Uri uri = Uri.parse(url);
|
||||||
|
Uri.Builder builder = uri
|
||||||
|
.buildUpon()
|
||||||
|
.authority(getCustomShareDomain())
|
||||||
|
.clearQuery();
|
||||||
|
|
||||||
|
String patchedUrl = builder.build().toString();
|
||||||
|
Logger.printInfo(() -> "Domain change from : " + url + " to: " + patchedUrl);
|
||||||
|
return patchedUrl;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
Logger.printException(() -> "setCustomShareDomain failure with " + url, ex);
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package app.revanced.extension.instagram.misc.share.privacy;
|
||||||
|
|
||||||
|
import app.revanced.extension.shared.privacy.LinkSanitizer;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public final class SanitizeSharingLinksPatch {
|
||||||
|
private static final LinkSanitizer sanitizer = new LinkSanitizer("igsh");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Injection point.
|
||||||
|
*/
|
||||||
|
public static String sanitizeSharingLink(String url) {
|
||||||
|
return sanitizer.sanitizeUrlString(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -292,6 +292,14 @@ public final class app/revanced/patches/instagram/misc/privacy/SanitizeSharingLi
|
|||||||
public static final fun getSanitizeSharingLinksPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
|
public static final fun getSanitizeSharingLinksPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final class app/revanced/patches/instagram/misc/share/domain/ChangeLinkSharingDomainPatchKt {
|
||||||
|
public static final fun getChangeLinkSharingDomainPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final class app/revanced/patches/instagram/misc/share/privacy/SanitizeSharingLinksPatchKt {
|
||||||
|
public static final fun getSanitizeSharingLinksPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
|
||||||
|
}
|
||||||
|
|
||||||
public final class app/revanced/patches/instagram/misc/signature/SignatureCheckPatchKt {
|
public final class app/revanced/patches/instagram/misc/signature/SignatureCheckPatchKt {
|
||||||
public static final fun getSignatureCheckPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
|
public static final fun getSignatureCheckPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,50 +1,12 @@
|
|||||||
package app.revanced.patches.instagram.misc.privacy
|
package app.revanced.patches.instagram.misc.privacy
|
||||||
|
|
||||||
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.bytecodePatch
|
||||||
import app.revanced.patches.instagram.misc.extension.sharedExtensionPatch
|
|
||||||
import app.revanced.patches.shared.PATCH_DESCRIPTION_SANITIZE_SHARING_LINKS
|
|
||||||
import app.revanced.patches.shared.PATCH_NAME_SANITIZE_SHARING_LINKS
|
|
||||||
import app.revanced.util.indexOfFirstInstructionOrThrow
|
|
||||||
import com.android.tools.smali.dexlib2.Opcode
|
|
||||||
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
|
|
||||||
|
|
||||||
private const val EXTENSION_CLASS_DESCRIPTOR =
|
|
||||||
"Lapp/revanced/extension/instagram/misc/privacy/SanitizeSharingLinksPatch;"
|
|
||||||
|
|
||||||
|
@Deprecated(
|
||||||
|
"Patch was moved to a different package",
|
||||||
|
ReplaceWith("app.revanced.patches.instagram.misc.share.privacy.sanitizeSharingLinksPatch")
|
||||||
|
)
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
val sanitizeSharingLinksPatch = bytecodePatch(
|
val sanitizeSharingLinksPatch = bytecodePatch {
|
||||||
name = PATCH_NAME_SANITIZE_SHARING_LINKS,
|
dependsOn(app.revanced.patches.instagram.misc.share.privacy.sanitizeSharingLinksPatch)
|
||||||
description = PATCH_DESCRIPTION_SANITIZE_SHARING_LINKS,
|
|
||||||
) {
|
|
||||||
compatibleWith("com.instagram.android")
|
|
||||||
|
|
||||||
dependsOn(sharedExtensionPatch)
|
|
||||||
|
|
||||||
execute {
|
|
||||||
arrayOf(
|
|
||||||
permalinkResponseJsonParserFingerprint,
|
|
||||||
storyUrlResponseJsonParserFingerprint,
|
|
||||||
profileUrlResponseJsonParserFingerprint,
|
|
||||||
liveUrlResponseJsonParserFingerprint
|
|
||||||
).forEach { fingerprint ->
|
|
||||||
fingerprint.method.apply {
|
|
||||||
val putSharingUrlIndex = indexOfFirstInstructionOrThrow(
|
|
||||||
fingerprint.stringMatches!!.first().index,
|
|
||||||
Opcode.IPUT_OBJECT
|
|
||||||
)
|
|
||||||
|
|
||||||
val sharingUrlRegister = getInstruction<TwoRegisterInstruction>(putSharingUrlIndex).registerA
|
|
||||||
|
|
||||||
addInstructions(
|
|
||||||
putSharingUrlIndex,
|
|
||||||
"""
|
|
||||||
invoke-static { v$sharingUrlRegister }, $EXTENSION_CLASS_DESCRIPTOR->sanitizeSharingLink(Ljava/lang/String;)Ljava/lang/String;
|
|
||||||
move-result-object v$sharingUrlRegister
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package app.revanced.patches.instagram.misc.share
|
||||||
|
|
||||||
|
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
|
||||||
|
import app.revanced.patcher.patch.BytecodePatchContext
|
||||||
|
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
||||||
|
import app.revanced.util.indexOfFirstInstruction
|
||||||
|
import com.android.tools.smali.dexlib2.Opcode
|
||||||
|
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
|
||||||
|
|
||||||
|
context(BytecodePatchContext)
|
||||||
|
internal fun editShareLinksPatch(block: MutableMethod.(index: Int, register: Int) -> Unit) {
|
||||||
|
val fingerprintsToPatch = arrayOf(
|
||||||
|
permalinkResponseJsonParserFingerprint,
|
||||||
|
storyUrlResponseJsonParserFingerprint,
|
||||||
|
profileUrlResponseJsonParserFingerprint,
|
||||||
|
liveUrlResponseJsonParserFingerprint
|
||||||
|
)
|
||||||
|
|
||||||
|
for (fingerprint in fingerprintsToPatch) {
|
||||||
|
fingerprint.method.apply {
|
||||||
|
val putSharingUrlIndex = indexOfFirstInstruction(
|
||||||
|
permalinkResponseJsonParserFingerprint.stringMatches!!.first().index,
|
||||||
|
Opcode.IPUT_OBJECT
|
||||||
|
)
|
||||||
|
|
||||||
|
val sharingUrlRegister = getInstruction<TwoRegisterInstruction>(putSharingUrlIndex).registerA
|
||||||
|
|
||||||
|
block(putSharingUrlIndex, sharingUrlRegister)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package app.revanced.patches.instagram.misc.privacy
|
package app.revanced.patches.instagram.misc.share
|
||||||
|
|
||||||
import app.revanced.patcher.fingerprint
|
import app.revanced.patcher.fingerprint
|
||||||
|
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package app.revanced.patches.instagram.misc.share.domain
|
||||||
|
|
||||||
|
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
|
||||||
|
import app.revanced.patcher.patch.bytecodePatch
|
||||||
|
import app.revanced.patcher.patch.stringOption
|
||||||
|
import app.revanced.patches.instagram.misc.extension.sharedExtensionPatch
|
||||||
|
import app.revanced.patches.instagram.misc.share.editShareLinksPatch
|
||||||
|
import app.revanced.patches.shared.PATCH_DESCRIPTION_CHANGE_LINK_SHARING_DOMAIN
|
||||||
|
import app.revanced.patches.shared.PATCH_NAME_CHANGE_LINK_SHARING_DOMAIN
|
||||||
|
import app.revanced.util.returnEarly
|
||||||
|
|
||||||
|
@Suppress("unused")
|
||||||
|
val changeLinkSharingDomainPatch = bytecodePatch(
|
||||||
|
name = PATCH_NAME_CHANGE_LINK_SHARING_DOMAIN,
|
||||||
|
description = PATCH_DESCRIPTION_CHANGE_LINK_SHARING_DOMAIN,
|
||||||
|
use = false
|
||||||
|
) {
|
||||||
|
compatibleWith("com.instagram.android")
|
||||||
|
|
||||||
|
dependsOn(sharedExtensionPatch)
|
||||||
|
|
||||||
|
execute {
|
||||||
|
val customDomainHost by stringOption(
|
||||||
|
key = "domainName",
|
||||||
|
default = "imginn.com",
|
||||||
|
title = "Domain name",
|
||||||
|
description = "The domain name to use when sharing links."
|
||||||
|
)
|
||||||
|
|
||||||
|
getCustomShareDomainFingerprint.method.returnEarly(customDomainHost!!)
|
||||||
|
|
||||||
|
editShareLinksPatch { index, register ->
|
||||||
|
addInstructions(
|
||||||
|
index,
|
||||||
|
"""
|
||||||
|
invoke-static { v$register }, $EXTENSION_CLASS_DESCRIPTOR->setCustomShareDomain(Ljava/lang/String;)Ljava/lang/String;
|
||||||
|
move-result-object v$register
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package app.revanced.patches.instagram.misc.share.domain
|
||||||
|
|
||||||
|
import app.revanced.patcher.fingerprint
|
||||||
|
import com.android.tools.smali.dexlib2.AccessFlags
|
||||||
|
|
||||||
|
internal const val EXTENSION_CLASS_DESCRIPTOR =
|
||||||
|
"Lapp/revanced/extension/instagram/misc/share/domain/ChangeLinkSharingDomainPatch;"
|
||||||
|
|
||||||
|
internal val getCustomShareDomainFingerprint = fingerprint {
|
||||||
|
accessFlags(AccessFlags.PRIVATE, AccessFlags.STATIC)
|
||||||
|
returns("Ljava/lang/String;")
|
||||||
|
parameters()
|
||||||
|
custom { method, classDef ->
|
||||||
|
method.name == "getCustomShareDomain" && classDef.type == EXTENSION_CLASS_DESCRIPTOR
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package app.revanced.patches.instagram.misc.share.privacy
|
||||||
|
|
||||||
|
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
|
||||||
|
import app.revanced.patcher.patch.bytecodePatch
|
||||||
|
import app.revanced.patches.instagram.misc.extension.sharedExtensionPatch
|
||||||
|
import app.revanced.patches.instagram.misc.share.editShareLinksPatch
|
||||||
|
import app.revanced.patches.shared.PATCH_DESCRIPTION_SANITIZE_SHARING_LINKS
|
||||||
|
import app.revanced.patches.shared.PATCH_NAME_SANITIZE_SHARING_LINKS
|
||||||
|
|
||||||
|
private const val EXTENSION_CLASS_DESCRIPTOR =
|
||||||
|
"Lapp/revanced/extension/instagram/misc/share/privacy/SanitizeSharingLinksPatch;"
|
||||||
|
|
||||||
|
@Suppress("unused")
|
||||||
|
val sanitizeSharingLinksPatch = bytecodePatch(
|
||||||
|
name = PATCH_NAME_SANITIZE_SHARING_LINKS,
|
||||||
|
description = PATCH_DESCRIPTION_SANITIZE_SHARING_LINKS,
|
||||||
|
) {
|
||||||
|
compatibleWith("com.instagram.android")
|
||||||
|
|
||||||
|
dependsOn(sharedExtensionPatch)
|
||||||
|
|
||||||
|
execute {
|
||||||
|
editShareLinksPatch { index, register ->
|
||||||
|
addInstructions(
|
||||||
|
index,
|
||||||
|
"""
|
||||||
|
invoke-static { v$register }, $EXTENSION_CLASS_DESCRIPTOR->sanitizeSharingLink(Ljava/lang/String;)Ljava/lang/String;
|
||||||
|
move-result-object v$register
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,3 +9,6 @@ internal const val PATCH_DESCRIPTION_REMOVE_ROOT_DETECTION = "Removes the check
|
|||||||
|
|
||||||
internal const val PATCH_NAME_SANITIZE_SHARING_LINKS = "Sanitize sharing links"
|
internal const val PATCH_NAME_SANITIZE_SHARING_LINKS = "Sanitize sharing links"
|
||||||
internal const val PATCH_DESCRIPTION_SANITIZE_SHARING_LINKS = "Removes the tracking query parameters from shared links."
|
internal const val PATCH_DESCRIPTION_SANITIZE_SHARING_LINKS = "Removes the tracking query parameters from shared links."
|
||||||
|
|
||||||
|
internal const val PATCH_NAME_CHANGE_LINK_SHARING_DOMAIN = "Change link sharing domain"
|
||||||
|
internal const val PATCH_DESCRIPTION_CHANGE_LINK_SHARING_DOMAIN = "Replaces the domain name of shared links."
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
|
|||||||
import app.revanced.patcher.patch.bytecodePatch
|
import app.revanced.patcher.patch.bytecodePatch
|
||||||
import app.revanced.patcher.patch.resourcePatch
|
import app.revanced.patcher.patch.resourcePatch
|
||||||
import app.revanced.patcher.patch.stringOption
|
import app.revanced.patcher.patch.stringOption
|
||||||
|
import app.revanced.patches.shared.PATCH_DESCRIPTION_CHANGE_LINK_SHARING_DOMAIN
|
||||||
|
import app.revanced.patches.shared.PATCH_NAME_CHANGE_LINK_SHARING_DOMAIN
|
||||||
import app.revanced.patches.shared.misc.mapping.get
|
import app.revanced.patches.shared.misc.mapping.get
|
||||||
import app.revanced.patches.shared.misc.mapping.resourceMappingPatch
|
import app.revanced.patches.shared.misc.mapping.resourceMappingPatch
|
||||||
import app.revanced.patches.shared.misc.mapping.resourceMappings
|
import app.revanced.patches.shared.misc.mapping.resourceMappings
|
||||||
@@ -29,8 +31,8 @@ private const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/twitter/patches/li
|
|||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
val changeLinkSharingDomainPatch = bytecodePatch(
|
val changeLinkSharingDomainPatch = bytecodePatch(
|
||||||
name = "Change link sharing domain",
|
name = PATCH_NAME_CHANGE_LINK_SHARING_DOMAIN,
|
||||||
description = "Replaces the domain name of Twitter links when sharing them.",
|
description = PATCH_DESCRIPTION_CHANGE_LINK_SHARING_DOMAIN
|
||||||
) {
|
) {
|
||||||
dependsOn(
|
dependsOn(
|
||||||
changeLinkSharingDomainResourcePatch,
|
changeLinkSharingDomainResourcePatch,
|
||||||
|
|||||||
Reference in New Issue
Block a user