forked from ReVanced/revanced-patches-template
-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(YouTube/Return YouTube Dislike): add support for RollingNumber
- Loading branch information
Showing
5 changed files
with
166 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
120 changes: 120 additions & 0 deletions
120
...outube/utils/returnyoutubedislike/rollingnumber/ReturnYouTubeDislikeRollingNumberPatch.kt
This file contains 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,120 @@ | ||
package app.revanced.patches.youtube.utils.returnyoutubedislike.rollingnumber | ||
|
||
import app.revanced.extensions.exception | ||
import app.revanced.patcher.data.BytecodeContext | ||
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction | ||
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions | ||
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction | ||
import app.revanced.patcher.patch.BytecodePatch | ||
import app.revanced.patcher.patch.PatchException | ||
import app.revanced.patcher.patch.annotation.Patch | ||
import app.revanced.patches.youtube.utils.returnyoutubedislike.rollingnumber.fingerprints.RollingNumberTextViewFingerprint | ||
import app.revanced.patches.youtube.utils.returnyoutubedislike.rollingnumber.fingerprints.RollingNumberTypeFingerprint | ||
import app.revanced.patches.youtube.utils.settings.SettingsPatch | ||
import app.revanced.util.integrations.Constants.UTILS_PATH | ||
import com.android.tools.smali.dexlib2.Opcode | ||
import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction21c | ||
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction | ||
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction | ||
import com.android.tools.smali.dexlib2.iface.reference.FieldReference | ||
import com.android.tools.smali.dexlib2.iface.reference.MethodReference | ||
|
||
@Patch(dependencies = [SettingsPatch::class]) | ||
object ReturnYouTubeDislikeRollingNumberPatch : BytecodePatch( | ||
setOf( | ||
RollingNumberTextViewFingerprint, | ||
RollingNumberTypeFingerprint | ||
) | ||
) { | ||
private const val CONVERSION_CONTEXT_PARAMETER = 2 | ||
|
||
private const val INTEGRATIONS_RYD_CLASS_DESCRIPTOR = | ||
"$UTILS_PATH/ReturnYouTubeDislikePatch;" | ||
|
||
override fun execute(context: BytecodeContext) { | ||
/** | ||
* RollingNumber is applied to YouTube v18.41.39+. | ||
* | ||
* In order to maintain compatibility with YouTube v18.40.34 or previous versions, | ||
* This patch is applied only to the version after YouTube v18.41.39 | ||
* | ||
* Resolves following issue: | ||
* https://github.com/revanced/revanced-patches/issues/2904 | ||
*/ | ||
if (SettingsPatch.upward1841) { | ||
|
||
RollingNumberTypeFingerprint.result?.let { | ||
it.mutableMethod.apply { | ||
val rollingNumberClassIndex = it.scanResult.patternScanResult!!.startIndex | ||
val rollingNumberClassReference = | ||
getInstruction<BuilderInstruction21c>(rollingNumberClassIndex).reference | ||
val rollingNumberClass = | ||
context.findClass(rollingNumberClassReference.toString())!!.mutableClass | ||
|
||
/** | ||
* This class handles RollingNumber. | ||
* Pass an instance of this class to integrations to use Java Reflection. | ||
*/ | ||
rollingNumberClass.methods.find { method -> method.name == "<init>" } | ||
?.apply { | ||
val rollingNumberFieldIndex = | ||
implementation!!.instructions.indexOfFirst { instruction -> | ||
instruction.opcode == Opcode.IPUT_OBJECT | ||
} | ||
val rollingNumberFieldName = | ||
(getInstruction<ReferenceInstruction>(rollingNumberFieldIndex).reference as FieldReference).name | ||
|
||
addInstructions( | ||
1, """ | ||
const-string v0, "$rollingNumberFieldName" | ||
invoke-static {p0, v0}, $INTEGRATIONS_RYD_CLASS_DESCRIPTOR->initialize(Ljava/lang/Object;Ljava/lang/String;)V | ||
""" | ||
) | ||
} ?: throw PatchException("RollingNumberClass not found!") | ||
|
||
/** | ||
* RollingNumber is initialized in this method. | ||
* This method also contains information about ConversionContext. | ||
*/ | ||
addInstruction( | ||
1, | ||
"invoke-static {p$CONVERSION_CONTEXT_PARAMETER}, $INTEGRATIONS_RYD_CLASS_DESCRIPTOR->onRollingNumberTextLoaded(Ljava/lang/Object;)V" | ||
) | ||
} | ||
} ?: throw RollingNumberTypeFingerprint.exception | ||
|
||
/** | ||
* TextView with RollingNumber. | ||
* Apply spanned text to TextView. | ||
*/ | ||
RollingNumberTextViewFingerprint.result?.let { | ||
// Initial TextView is set in this method. | ||
val initiallyCreatedTextViewMethod = it.mutableMethod | ||
|
||
// Video less than 24 hours after uploaded, like counts will be updated in real time. | ||
// Whenever like counts are updated, TextView is set in this method. | ||
val realTimeUpdateTextViewMethod = it.mutableClass.methods.find { | ||
method -> method.parameterTypes.first() == "Landroid/graphics/Bitmap;" | ||
} ?: throw PatchException("Failed to find realTimeUpdateTextViewMethod") | ||
|
||
arrayOf( | ||
initiallyCreatedTextViewMethod, | ||
realTimeUpdateTextViewMethod | ||
).forEach { insertMethod -> | ||
insertMethod.apply { | ||
val setTextIndex = implementation!!.instructions.indexOfFirst { instruction -> | ||
((instruction as? ReferenceInstruction)?.reference as? MethodReference)?.name == "setText" | ||
} | ||
val textViewRegister = | ||
getInstruction<FiveRegisterInstruction>(setTextIndex).registerC | ||
|
||
addInstruction( | ||
setTextIndex + 1, | ||
"invoke-static {v$textViewRegister}, $INTEGRATIONS_RYD_CLASS_DESCRIPTOR->updateRollingNumberTextView(Landroid/widget/TextView;)V" | ||
) | ||
} | ||
} | ||
} ?: throw RollingNumberTextViewFingerprint.exception | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...utils/returnyoutubedislike/rollingnumber/fingerprints/RollingNumberTextViewFingerprint.kt
This file contains 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,26 @@ | ||
package app.revanced.patches.youtube.utils.returnyoutubedislike.rollingnumber.fingerprints | ||
|
||
import app.revanced.patcher.extensions.or | ||
import app.revanced.patcher.fingerprint.MethodFingerprint | ||
import com.android.tools.smali.dexlib2.AccessFlags | ||
import com.android.tools.smali.dexlib2.Opcode | ||
|
||
/** | ||
* This fingerprint is compatible with YouTube v18.32.39+ | ||
*/ | ||
object RollingNumberTextViewFingerprint : MethodFingerprint( | ||
returnType = "V", | ||
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, | ||
parameters = listOf("L", "F", "F"), | ||
opcodes = listOf( | ||
Opcode.IPUT, | ||
null, // invoke-direct or invoke-virtual | ||
Opcode.IPUT_OBJECT, | ||
Opcode.IGET_OBJECT, | ||
Opcode.INVOKE_VIRTUAL, | ||
Opcode.RETURN_VOID | ||
), | ||
customFingerprint = custom@{ _, classDef -> | ||
classDef.methods.count() == 4 | ||
} | ||
) |
16 changes: 16 additions & 0 deletions
16
...ube/utils/returnyoutubedislike/rollingnumber/fingerprints/RollingNumberTypeFingerprint.kt
This file contains 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,16 @@ | ||
package app.revanced.patches.youtube.utils.returnyoutubedislike.rollingnumber.fingerprints | ||
|
||
import app.revanced.patcher.fingerprint.MethodFingerprint | ||
import com.android.tools.smali.dexlib2.Opcode | ||
|
||
/** | ||
* This fingerprint is compatible with YouTube v18.29.38+ | ||
*/ | ||
object RollingNumberTypeFingerprint : MethodFingerprint( | ||
opcodes = listOf( | ||
Opcode.CHECK_CAST, | ||
Opcode.IGET, | ||
Opcode.AND_INT_LIT8 | ||
), | ||
strings = listOf("RollingNumberType required properties missing! Need updateCount, fontName, color and fontSize.") | ||
) |
This file contains 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