feat(Instagram): Add Rename package patch#1261
Conversation
Renames the patched app's package and label so the patched build installs alongside the original Instagram instead of replacing it. Manifest + launcher labels are rewritten, and matching string literals across every dex file are rewritten as well, with the patch sparing reflection class refs by indexing every com.instagram.* type descriptor in the dex first. The user picks the new package name and label via two patch options (default com.pikogram.android / Pikogram). Package must have at least three segments; the patch derives a namespace prefix by stripping the last segment and applies it to every word-boundary com.instagram match. That covers the app package, custom permissions, FileProvider authorities, intent actions, notification channel ids, and sibling sub-namespaces (com.instagram.fileprovider, com.instagram.barcelona.*, com.instagram.contentprovider.*, etc.), which is what unblocks side-by-side install with the Play Store Instagram. Tested on com.instagram.android v426.0.0.37.68 on a Galaxy S25 Ultra: patching completes, the clone launches, login works, official Instagram installs alongside without conflicts, and the story regression flow (view, post, notification, tap-to-open, reply) passes.
|
Tested the existing Change package name patch (default morphe) with all three options enabled (Update permissions, Update providers, Update providers strings). After patching with it, the official Instagram from the Play Store still fails to install — Android rejects it because ContentProvider authorities under com.instagram.* sibling namespaces are still claimed by the patched app. The existing patch renames the app package and its directly-declared provider names (anything under com.instagram.android.). It doesn't touch sibling sub-namespaces like com.instagram.fileprovider, com.instagram.contentprovider. (4 of them), com.instagram.barcelona., com.instagram.liteprovider., com.instagram.quicksnap.seenstate, com.instagram.foabackuptoken., com.instagram.creation.drafts., and com.instagram.growth.xav.*. Those are 13 ContentProvider authorities Instagram declares outside the app's own package, and Android treats every authority as system-wide-unique. As long as the patched app holds them, Play Store Instagram can't claim them. The patch in this PR derives a namespace prefix from the user's package (strips the last segment) and applies it to every word-boundary com.instagram match across both manifest and dex. That's what specifically unblocks side-by-side install. Verified on device: official IG installs cleanly with the clone present. |
|
Noticed a bug, app crashing while swiping across 5 or more stories at once. I'll check and open a new PR. Closing this for now. |
|
This patch contains too many unnecessary changes. Actually, I was also investigating changing Instagram's package name. For example, regarding the strings in the dex files, it's sufficient to simply replace the exact string "com.instagram.android" with the new package name. Furthermore, there's no need to edit strings.xml, nor is there any need to require more than three segments in the new package name. |
|
Will push a slimmer version that drops the strings.xml edit and the 3 segment requirement. |
What this adds
A new Instagram patch — Rename package — that lets the user install the patched build alongside the original Play Store Instagram, by renaming the package and label at patch time.
Two patch options:
packageName(defaultcom.pikogram.android) — must be a valid Java package with at least 3 segmentsappLabel(defaultPikogram) — display nameHow it works
The patch derives a namespace prefix from the user's package by stripping the last segment (
com.pikogram.android→com.pikogram) and applies it to every word-boundarycom.instagramreference. That covers:com.instagram.android.*)com.instagram.fileprovider,com.instagram.barcelona.*,com.instagram.contentprovider.*,com.instagram.quicksnap.*, etc.) — these are system-wide-unique ContentProvider authorities; renaming them is what unblocks side-by-side install with Play Store IGImplementation splits into a user-facing
bytecodePatch(carries the options, rewrites dex string literals) and an internalresourcePatch(rewrites the manifest infinalize{}, derives the application-label string-resource name dynamically from<application android:label>).Smali / dex behaviour (re: "is this just a package name change?")
It does rewrite at the smali level — every
const-stringliteral across every dex file is checked against the namespace regex, with one important exception. A pre-pass indexes everycom.instagram.*class type descriptor in the dex (Lcom/instagram/X/Y;), and the rewriter skips any string literal that exactly matches one of those dotted names. Without that skip, reflection calls likeClass.forName("com.instagram.process.instagram.InstagramApplicationForMainProcess")(whichInstagramAppShell.onCreateactually does) would crash at startup, because we never rename type descriptors — only literals.What the patch does not add is method-body hooks (intercepting
getPackageName(), bypassing signature checks, replacing method bodies, injecting helpers). Held off on those because adding hooks without a known failure is speculative. Happy to add targeted hooks if the maintainers see something specific that breaks.Manifest-side selectivity
Class-reference attributes are skipped during the manifest rewrite, since the actual Java classes stay at their original
com.instagram.*paths in dex:<application>—android:name,android:backupAgent,android:appComponentFactory,android:zygotePreloadName<activity>—android:name,android:parentActivityName<service>,<receiver>,<provider>,<instrumentation>—android:name<activity-alias>—android:targetActivity<meta-data>—android:value(commonly a class ref for libraries like Google Cast)<activity-alias android:name>intentionally stays in the rewrite — that's a logical component identifier, not a real Java class.Tested
com.instagram.androidv426.0.0.37.68 on a Galaxy S25 Ultra:WaitingForStringsActivity, reaches sign-in, login worksKnown caveats
com.instagram.androidexternally) may degrade silently — not crashesWhat's left out