Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package app.revanced.patches.strava.media.upload

import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patcher.patch.intOption
import app.revanced.patcher.patch.longOption
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable
import app.revanced.util.returnEarly
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.builder.MutableMethodImplementation
import com.android.tools.smali.dexlib2.immutable.ImmutableMethod

@Suppress("unused")
val overwriteMediaUploadParametersPatch = bytecodePatch(
Expand Down Expand Up @@ -38,7 +43,41 @@ val overwriteMediaUploadParametersPatch = bytecodePatch(
}

maxDuration?.let { maxDuration ->
getMaxDurationFingerprint.match(mediaUploadParametersClass).method.returnEarly(maxDuration)
val getMaxDurationMethod = getMaxDurationFingerprint.match(mediaUploadParametersClass).method

if (getMaxDurationMethod.returnType == "J") {
getMaxDurationMethod.returnEarly(maxDuration)
return@let
}

val helperMethod = ImmutableMethod(
getMaxDurationMethod.definingClass,
"${getMaxDurationMethod.name}\$helper",
listOf(),
getMaxDurationMethod.returnType,
AccessFlags.PRIVATE.value or AccessFlags.STATIC.value,
setOf(),
setOf(),
MutableMethodImplementation(2)
).toMutable().apply {
addInstructions(
"""
const-wide v0, ${maxDuration}L
invoke-static { v0, v1 }, Ljava/lang/Long;->valueOf(J)Ljava/lang/Long;
move-result-object v0
return-object v0
"""
)
}

getMaxDurationMethod.addInstructions(
0,
"""
invoke-static { }, $helperMethod
move-result-object v0
return-object v0
"""
)
}

maxSize?.let {
Expand Down
6 changes: 4 additions & 2 deletions patches/src/main/kotlin/app/revanced/util/BytecodeUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1182,9 +1182,10 @@ private fun MutableMethod.overrideReturnValue(value: EncodedValue?, returnLate:
return-wide v0
"""
} else {
check(implementation!!.registerCount >= 2) { "`long` literal doesn't fit into method $this (${implementation!!.registerCount} < 2)." }
"""
const-wide v0, $encodedValue
invoke-static { v0 }, Ljava/lang/Long;->valueOf(J)Ljava/lang/Long;
invoke-static { v0, v1 }, Ljava/lang/Long;->valueOf(J)Ljava/lang/Long;
move-result-object v0
return-object v0
"""
Expand All @@ -1198,9 +1199,10 @@ private fun MutableMethod.overrideReturnValue(value: EncodedValue?, returnLate:
return-wide v0
"""
} else {
check(implementation!!.registerCount >= 2) { "`double` literal doesn't fit into method $this (${implementation!!.registerCount} < 2)." }
"""
const-wide v0, $encodedValue
invoke-static { v0 }, Ljava/lang/Double;->valueOf(D)Ljava/lang/Double;
invoke-static { v0, v1 }, Ljava/lang/Double;->valueOf(D)Ljava/lang/Double;
move-result-object v0
return-object v0
"""
Expand Down