|
1 | 1 | package app.revanced.patches.strava.media.upload |
2 | 2 |
|
| 3 | +import app.revanced.patcher.extensions.InstructionExtensions.addInstructions |
3 | 4 | import app.revanced.patcher.patch.bytecodePatch |
4 | 5 | import app.revanced.patcher.patch.intOption |
5 | 6 | import app.revanced.patcher.patch.longOption |
| 7 | +import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable |
6 | 8 | import app.revanced.util.returnEarly |
| 9 | +import com.android.tools.smali.dexlib2.AccessFlags |
| 10 | +import com.android.tools.smali.dexlib2.builder.MutableMethodImplementation |
| 11 | +import com.android.tools.smali.dexlib2.immutable.ImmutableMethod |
7 | 12 |
|
8 | 13 | @Suppress("unused") |
9 | 14 | val overwriteMediaUploadParametersPatch = bytecodePatch( |
@@ -38,7 +43,41 @@ val overwriteMediaUploadParametersPatch = bytecodePatch( |
38 | 43 | } |
39 | 44 |
|
40 | 45 | maxDuration?.let { maxDuration -> |
41 | | - getMaxDurationFingerprint.match(mediaUploadParametersClass).method.returnEarly(maxDuration) |
| 46 | + val getMaxDurationMethod = getMaxDurationFingerprint.match(mediaUploadParametersClass).method |
| 47 | + |
| 48 | + if (getMaxDurationMethod.returnType == "J") { |
| 49 | + getMaxDurationMethod.returnEarly(maxDuration) |
| 50 | + return@let |
| 51 | + } |
| 52 | + |
| 53 | + val helperMethod = ImmutableMethod( |
| 54 | + getMaxDurationMethod.definingClass, |
| 55 | + "${getMaxDurationMethod.name}\$helper", |
| 56 | + listOf(), |
| 57 | + getMaxDurationMethod.returnType, |
| 58 | + AccessFlags.PRIVATE.value or AccessFlags.STATIC.value, |
| 59 | + setOf(), |
| 60 | + setOf(), |
| 61 | + MutableMethodImplementation(2) |
| 62 | + ).toMutable().apply { |
| 63 | + addInstructions( |
| 64 | + """ |
| 65 | + const-wide v0, ${maxDuration}L |
| 66 | + invoke-static { v0, v1 }, Ljava/lang/Long;->valueOf(J)Ljava/lang/Long; |
| 67 | + move-result-object v0 |
| 68 | + return-object v0 |
| 69 | + """ |
| 70 | + ) |
| 71 | + } |
| 72 | + |
| 73 | + getMaxDurationMethod.addInstructions( |
| 74 | + 0, |
| 75 | + """ |
| 76 | + invoke-static { }, $helperMethod |
| 77 | + move-result-object v0 |
| 78 | + return-object v0 |
| 79 | + """ |
| 80 | + ) |
42 | 81 | } |
43 | 82 |
|
44 | 83 | maxSize?.let { |
|
0 commit comments