-
-
Notifications
You must be signed in to change notification settings - Fork 481
feat(Reddit Is Fun): Add Unlock Platinum
patch and use public Imgur API
#4787
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,18 @@ | ||||||||||
package app.revanced.patches.reddit.customclients.redditisfun.ads | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Package should be misc not ads |
||||||||||
|
||||||||||
import app.revanced.patcher.patch.bytecodePatch | ||||||||||
import app.revanced.util.returnEarly | ||||||||||
|
||||||||||
// Based on: https://github.com/ReVanced/revanced-patches/issues/661#issuecomment-2549674017 | ||||||||||
val fakePremiumPatch = bytecodePatch( | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The patch should be named unlockPlatinumPatch |
||||||||||
name = "Fake reddit premium", | ||||||||||
description = "Allows using pro features without ads." | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The description can be removed. |
||||||||||
) { | ||||||||||
compatibleWith( | ||||||||||
"com.andrewshu.android.reddit", | ||||||||||
) | ||||||||||
Comment on lines
+11
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
execute { | ||||||||||
userPremiumFingerprint.method.returnEarly(true) | ||||||||||
} | ||||||||||
} |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,18 @@ | ||||||||
package app.revanced.patches.reddit.customclients.redditisfun.ads | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Package should be misc |
||||||||
|
||||||||
import app.revanced.patcher.fingerprint | ||||||||
import com.android.tools.smali.dexlib2.AccessFlags | ||||||||
|
||||||||
// Should usually match: o5/i0.a() | ||||||||
internal val userPremiumFingerprint = fingerprint { | ||||||||
Comment on lines
+6
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Obfuscated names will change for versions
Suggested change
|
||||||||
accessFlags(AccessFlags.PUBLIC, AccessFlags.STATIC) | ||||||||
returns("Z") | ||||||||
parameters() | ||||||||
custom { _, classDef -> | ||||||||
// Expect the class to have exactly one static field of type HashSet. | ||||||||
val sfIter = classDef.staticFields.iterator() | ||||||||
sfIter.hasNext() | ||||||||
&& sfIter.next().type == "Ljava/util/HashSet;" | ||||||||
&& !sfIter.hasNext() | ||||||||
} | ||||||||
} |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -29,3 +29,11 @@ internal val getUserAgentFingerprint = fingerprint { | |||||||
Opcode.CONST, | ||||||||
) | ||||||||
} | ||||||||
|
||||||||
// Should usually match: g2/c.x() | ||||||||
internal val imgurApiFingerprint = fingerprint { | ||||||||
Comment on lines
+33
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
accessFlags(AccessFlags.PRIVATE, AccessFlags.STATIC) | ||||||||
returns("Landroid/net/Uri;") | ||||||||
parameters("Ljava/lang/String;", "Z") | ||||||||
strings("https", "api", "imgur", "3", "gallery", "album") | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are all those fingerprint params necessary? Some of the strings would probably be enough |
||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
package app.revanced.patches.reddit.customclients.redditisfun.api | ||
|
||
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions | ||
import app.revanced.patcher.extensions.InstructionExtensions.instructions | ||
import app.revanced.patcher.extensions.InstructionExtensions.removeInstructions | ||
import app.revanced.patcher.patch.bytecodePatch | ||
import app.revanced.patcher.patch.stringOption | ||
|
||
val imgurAlbumsPatch = bytecodePatch( | ||
name = "Use public imgur API", | ||
description = "Fix imgur albums not loading." | ||
) { | ||
Comment on lines
+9
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just like the other reddit app patches this patchs should be inlined into the fix patches |
||
compatibleWith( | ||
"com.andrewshu.android.reddit", | ||
"com.andrewshu.android.redditdonation", | ||
) | ||
|
||
val clientId by stringOption( | ||
key = "imgur-client-id", | ||
// Obtained from: https://s.imgur.com/desktop-assets/js/main.[snip].js | grep apiClientId | ||
default = "546c25a59c58ad7", | ||
Comment on lines
+20
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No Imgur API client id is probably needed. Imgur has a free public API, refer to Sync's imgur patch. |
||
title = "Imgur client ID", | ||
description = "The default value should work for most users", | ||
required = true, | ||
) | ||
|
||
execute { | ||
val m = imgurApiFingerprint.method | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dont use single letters for variables and use .appy and other idiomatic Kotlin APIs. |
||
m.removeInstructions(m.instructions.size) | ||
val androidNetUriBuilder = "android/net/Uri\$Builder" | ||
m.addInstructions(0, """ | ||
new-instance v0, L$androidNetUriBuilder; | ||
invoke-direct {v0}, L$androidNetUriBuilder;-><init>()V | ||
Comment on lines
+31
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code should be formatted. Refer to other patches as reference. |
||
const-string v1, "https" | ||
invoke-virtual {v0, v1}, L$androidNetUriBuilder;->scheme(Ljava/lang/String;)L$androidNetUriBuilder; | ||
move-result-object v0 | ||
const-string v1, "api.imgur.com" | ||
invoke-virtual {v0, v1}, L$androidNetUriBuilder;->authority(Ljava/lang/String;)L$androidNetUriBuilder; | ||
move-result-object v0 | ||
const-string v1, "3" | ||
invoke-virtual {v0, v1}, L$androidNetUriBuilder;->appendPath(Ljava/lang/String;)L$androidNetUriBuilder; | ||
move-result-object v0 | ||
if-eqz p1, :cond_0 | ||
const-string p1, "gallery" | ||
invoke-virtual {v0, p1}, L$androidNetUriBuilder;->appendPath(Ljava/lang/String;)L$androidNetUriBuilder; | ||
:cond_0 | ||
const-string p1, "album" | ||
invoke-virtual {v0, p1}, L$androidNetUriBuilder;->appendPath(Ljava/lang/String;)L$androidNetUriBuilder; | ||
move-result-object p1 | ||
invoke-virtual {p1, p0}, L$androidNetUriBuilder;->appendPath(Ljava/lang/String;)L$androidNetUriBuilder; | ||
move-result-object p0 | ||
const-string v0, "client_id" | ||
const-string v1, "$clientId" | ||
invoke-virtual {p0, v0, v1}, L$androidNetUriBuilder;->appendQueryParameter(Ljava/lang/String;Ljava/lang/String;)L$androidNetUriBuilder; | ||
move-result-object p0 | ||
invoke-virtual {p0}, L$androidNetUriBuilder;->build()Landroid/net/Uri; | ||
move-result-object p0 | ||
return-object p0 | ||
""".trimIndent()) | ||
Comment on lines
+32
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The patch is way too big. Complex patches should be moved into an extension as explained in the patcher docs. |
||
} | ||
} | ||
|
||
/* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment is not necessary/unconventional. Remove it |
||
The original contents of the method decodes an obfuscated string, you can use the following script | ||
to decode the value: | ||
|
||
import kotlin.math.pow | ||
object StringDecryptor { | ||
/** | ||
* Decrypts a string using a position-dependent Caesar-like cipher. | ||
* Handles lowercase, uppercase, and other characters differently. | ||
* Replaces '>' with '_' at the end. | ||
*/ | ||
fun w(input: String): String { | ||
val builder = StringBuilder() | ||
val length = input.length | ||
|
||
// Note: Smali loop starts from 1, accesses charAt(i-1), uses 'i' for shift | ||
for (i in 1..length) { | ||
val charIndex = i - 1 // Index of the character to process | ||
var charCode = input[charIndex].code // Get character's Unicode code point | ||
var base: Int | ||
val mod: Int | ||
|
||
when (input[charIndex]) { | ||
in 'a'..'z' -> { | ||
base = 'a'.code | ||
mod = 26 | ||
charCode -= base // Normalize to 0-25 | ||
} | ||
in 'A'..'Z' -> { | ||
base = 'A'.code | ||
mod = 26 | ||
charCode -= base // Normalize to 0-25 | ||
} | ||
else -> { | ||
// Handles other characters based on space ' ' | ||
// Corresponds to the Smali block L3 | ||
base = ' '.code | ||
mod = 33 | ||
charCode -= base // Normalize relative to space | ||
} | ||
} | ||
|
||
// Apply the position-dependent shift (subtracting loop counter 'i') | ||
// The formula (val - shift + mod) % mod handles potential negative results correctly | ||
val shiftedCode = (charCode - i + mod) % mod | ||
|
||
// Add the base back to get the final character code | ||
val finalCode = shiftedCode + base | ||
|
||
builder.append(finalCode.toChar()) | ||
} | ||
|
||
// Final replacement as seen in the Smali code | ||
return builder.toString().replace('>', '_') | ||
} | ||
|
||
/** | ||
* Unscrambles a string based on an index mapping array. | ||
* If input is "cba" and map is [2, 0, 1], output is "abc". | ||
*/ | ||
fun z(scrambledString: String, indexMap: IntArray): String { | ||
val length = indexMap.size | ||
// Create an inverse map: targetIndices[original_index] = current_index | ||
val targetIndices = IntArray(length) | ||
for (i in 0 until length) { | ||
targetIndices[indexMap[i]] = i | ||
} | ||
|
||
val builder = StringBuilder(length) | ||
// Build the unscrambled string using the inverse map | ||
for (i in 0 until length) { | ||
builder.append(scrambledString[targetIndices[i]]) | ||
} | ||
return builder.toString() | ||
} | ||
|
||
fun decode(s: String, offsets: IntArray): String { | ||
// Values produced by decompiler are offset | ||
val decompilerMult = 2.0.pow(24).toInt() | ||
// If you extract the values from the smali directly no offset is needed: | ||
//val decompilerMult = 1 | ||
|
||
// 1. Unscramble the string using z() | ||
val unscrambledString = z(s, offsets.map { it / decompilerMult }.toIntArray()) | ||
// 2. Decrypt the unscrambled string using w() | ||
return w(unscrambledString) | ||
} | ||
} | ||
|
||
StringDecryptor.decode("krltdwtl2eikrcbfsg>", intArrayOf( | ||
100663296, | ||
16777216, | ||
117440512, | ||
167772160, | ||
150994944, | ||
67108864, | ||
268435456, | ||
33554432, | ||
50331648, | ||
184549376, | ||
218103808, | ||
83886080, | ||
134217728, | ||
234881024, | ||
0, | ||
301989888, | ||
201326592, | ||
285212672, | ||
251658240, | ||
)) // Output: api.redditisfun.com | ||
*/ |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file should be called UnlockPlatinumPatch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is no ads the only premium feature? If so then
Hide ads
would be more descriptive.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if it were, the patch controls "Platinum", not ads, even though ads is what Platinum offers.