generated from ReVanced/revanced-patches-template
-
-
Notifications
You must be signed in to change notification settings - Fork 617
feat(Instagram): Add Hide reshare button patch
#6303
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
Open
brosssh
wants to merge
7
commits into
ReVanced:dev
Choose a base branch
from
brosssh:feat/instagram/remove-reshare
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+106
−0
Open
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
32 changes: 32 additions & 0 deletions
32
patches/src/main/kotlin/app/revanced/patches/instagram/hide/reshare/Fingerprints.kt
This file contains hidden or 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,32 @@ | ||
| package app.revanced.patches.instagram.hide.reshare | ||
|
|
||
| import app.revanced.patcher.fingerprint | ||
| import app.revanced.util.indexOfFirstInstruction | ||
| import com.android.tools.smali.dexlib2.AccessFlags | ||
| import com.android.tools.smali.dexlib2.Opcode | ||
| import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction31i | ||
| import com.android.tools.smali.dexlib2.iface.instruction.formats.SparseSwitchPayload | ||
|
|
||
| // The hash code of the field of interest. It is used as the key of a hashmap | ||
| internal val hashedFieldInteger = "enable_media_notes_production".hashCode() | ||
|
|
||
| internal val feedResponseMediaParserFingerprint = fingerprint { | ||
| strings("array_out_of_bounds_exception", "null_pointer_exception", "MediaDict") | ||
| custom { method, _ -> | ||
| method.indexOfFirstInstruction { | ||
| opcode == Opcode.SPARSE_SWITCH_PAYLOAD && | ||
| (this as SparseSwitchPayload).switchElements.any { it.key == hashedFieldInteger } | ||
| } >= 0 | ||
| } | ||
| } | ||
|
|
||
| internal val reelPostsResponseMediaParserFingerprint = fingerprint { | ||
| accessFlags(AccessFlags.PUBLIC, AccessFlags.STATIC) | ||
| parameters("L", "L", "L", "[I") | ||
| returns("L") | ||
| custom { method, _ -> | ||
| method.indexOfFirstInstruction { | ||
| opcode == Opcode.CONST && (this as Instruction31i).narrowLiteral == hashedFieldInteger | ||
| } >= 0 | ||
| } | ||
| } |
80 changes: 80 additions & 0 deletions
80
...hes/src/main/kotlin/app/revanced/patches/instagram/hide/reshare/HideReshareButtonPatch.kt
This file contains hidden or 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,80 @@ | ||
| package app.revanced.patches.instagram.hide.reshare | ||
|
|
||
| import app.revanced.patcher.extensions.InstructionExtensions.addInstruction | ||
| import app.revanced.patcher.extensions.InstructionExtensions.getInstruction | ||
| import app.revanced.patcher.patch.bytecodePatch | ||
| import app.revanced.util.getReference | ||
| import app.revanced.util.indexOfFirstInstructionOrThrow | ||
| import com.android.tools.smali.dexlib2.Opcode | ||
| import com.android.tools.smali.dexlib2.builder.instruction.BuilderSparseSwitchPayload | ||
| import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction | ||
| import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction31i | ||
| import com.android.tools.smali.dexlib2.iface.reference.MethodReference | ||
|
|
||
| @Suppress("unused") | ||
| val hideReshareButtonPatch = bytecodePatch( | ||
| name = "Hide reshare button", | ||
| description = "Hides the reshare button from both posts and reels.", | ||
| use = false | ||
| ) { | ||
| compatibleWith("com.instagram.android") | ||
|
|
||
| execute { | ||
| feedResponseMediaParserFingerprint.method.apply { | ||
| // Each json field is parsed in a switch statement, where the case of the switch is the hashed field name. | ||
|
|
||
| /** | ||
| * First, find the switch payload where our field of interest is being processed. So find the payload that | ||
| * has a key == to our field of interest. | ||
| */ | ||
| val switchPayload = implementation!!.instructions.first { ins -> | ||
| ins.opcode == Opcode.SPARSE_SWITCH_PAYLOAD && | ||
| (ins as BuilderSparseSwitchPayload).switchElements.any { it.key == hashedFieldInteger } | ||
| } as BuilderSparseSwitchPayload | ||
|
|
||
| // Get the target label, so find the instruction offset where the switch case is pointing to | ||
| val switchTargetLabel = switchPayload.switchElements | ||
| .first { it.key == hashedFieldInteger } | ||
| .target | ||
|
|
||
| // From that label, navigate forward until our field os interest is being instantiated | ||
| val moveResultIndex = indexOfFirstInstructionOrThrow( | ||
| switchTargetLabel.location.index, | ||
| Opcode.MOVE_RESULT_OBJECT | ||
| ) | ||
|
|
||
| // Get its register | ||
brosssh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| val moveResultRegister = getInstruction<OneRegisterInstruction>(moveResultIndex).registerA | ||
|
|
||
| // Override it | ||
| addInstruction( | ||
| moveResultIndex + 1, | ||
| "sget-object v$moveResultRegister, Ljava/lang/Boolean;->FALSE:Ljava/lang/Boolean;" | ||
| ) | ||
| } | ||
|
|
||
| reelPostsResponseMediaParserFingerprint.method.apply { | ||
| // Each json field is parsed in a series of if statements, where the if comparison is done comparing the hashed field name. | ||
|
|
||
| // Get index of "const v*, -0x207dadd2" | ||
| val switchIndex = indexOfFirstInstructionOrThrow { | ||
| opcode == Opcode.CONST && (this as Instruction31i).narrowLiteral == hashedFieldInteger | ||
brosssh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| // Here an internal Instagram native library is used to handle settings of experiments, using hash codes of the fields | ||
| // Find where our field of interest is being instantiated | ||
| val moveBooleanResultIndex = indexOfFirstInstructionOrThrow(switchIndex) { | ||
| getReference<MethodReference>()?.name == "getOptionalBooleanValueByHashCode" | ||
| } + 1 | ||
|
|
||
| // Its register | ||
| val moveBooleanResultRegister = getInstruction<OneRegisterInstruction>(moveBooleanResultIndex).registerA | ||
|
|
||
| // Override | ||
| addInstruction( | ||
| moveBooleanResultIndex, | ||
| "sget-object v$moveBooleanResultRegister, Ljava/lang/Boolean;->FALSE:Ljava/lang/Boolean;" | ||
brosssh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.