refactor(sponsorblock): use better patch method

This commit is contained in:
inotia00 2023-02-23 16:56:19 +09:00
parent 4e9eff5de2
commit bb16f48ba3
2 changed files with 22 additions and 25 deletions

View File

@ -1,5 +1,6 @@
package app.revanced.patches.youtube.misc.sponsorblock.bytecode.patch
import app.revanced.extensions.toErrorResult
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext
@ -21,7 +22,6 @@ import org.jf.dexlib2.Opcode
import org.jf.dexlib2.builder.BuilderInstruction
import org.jf.dexlib2.iface.instruction.FiveRegisterInstruction
import org.jf.dexlib2.iface.instruction.ReferenceInstruction
import org.jf.dexlib2.iface.instruction.formats.Instruction22c
import org.jf.dexlib2.iface.instruction.formats.Instruction35c
import org.jf.dexlib2.iface.reference.MethodReference
@ -58,11 +58,10 @@ class SponsorBlockBytecodePatch : BytecodePatch(
Get the instance of the seekbar rectangle
*/
for ((index, instruction) in insertInstructions.withIndex()) {
if (instruction.opcode != Opcode.IGET_OBJECT) continue
val seekbarRegister = (instruction as Instruction22c).registerB
if (instruction.opcode != Opcode.INVOKE_DIRECT_RANGE) continue
insertMethod.addInstruction(
index - 1,
"invoke-static {v$seekbarRegister}, $INTEGRATIONS_PLAYER_CONTROLLER_CLASS_DESCRIPTOR->setSponsorBarRect(Ljava/lang/Object;)V"
index,
"invoke-static/range {p0 .. p0}, $INTEGRATIONS_PLAYER_CONTROLLER_CLASS_DESCRIPTOR->setSponsorBarRect(Ljava/lang/Object;)V"
)
break
}
@ -124,10 +123,10 @@ class SponsorBlockBytecodePatch : BytecodePatch(
// set SegmentHelperLayout.context to the player layout instance
val instanceRegister = 0
NextGenWatchLayoutFingerprint.result!!.mutableMethod.addInstruction(
3, // after super call
NextGenWatchLayoutFingerprint.result?.mutableMethod?.addInstruction(
3,
"invoke-static/range {p$instanceRegister}, $INTEGRATIONS_PLAYER_CONTROLLER_CLASS_DESCRIPTOR->addSkipSponsorView15(Landroid/view/View;)V"
)
) ?: return NextGenWatchLayoutFingerprint.toErrorResult()
context.injectInit("FirstRun", "initializationSB")
context.updatePatchStatus("Sponsorblock")

View File

@ -25,9 +25,9 @@ import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.Opcode
import org.jf.dexlib2.builder.MutableMethodImplementation
import org.jf.dexlib2.builder.instruction.BuilderInstruction35c
import org.jf.dexlib2.dexbacked.reference.DexBackedMethodReference
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
import org.jf.dexlib2.iface.instruction.ReferenceInstruction
import org.jf.dexlib2.iface.instruction.formats.Instruction21c
import org.jf.dexlib2.iface.instruction.formats.Instruction31i
import org.jf.dexlib2.iface.reference.FieldReference
import org.jf.dexlib2.iface.reference.MethodReference
@ -145,31 +145,29 @@ class MainstreamVideoIdPatch : BytecodePatch(
with (HookTimebarPatch.emptyColorMethod) {
val timebarResult = TimebarFingerprint.result ?: return TimebarFingerprint.toErrorResult()
val timebarInstructions = timebarResult.method.implementation!!.instructions
val methodReference =
(timebarInstructions.elementAt(2) as ReferenceInstruction).reference as MethodReference
val timeBarResult = TimebarFingerprint.result ?: return TimebarFingerprint.toErrorResult()
val timeBarInstructions = timeBarResult.method.implementation!!.instructions
val timeBarReference =
(timeBarInstructions.elementAt(2) as ReferenceInstruction).reference as MethodReference
val instructions = implementation!!.instructions
reactReference =
((instructions.elementAt(instructions.count() - 3) as ReferenceInstruction).reference as FieldReference).name
for ((index, instruction) in instructions.withIndex()) {
if (instruction.opcode != Opcode.CHECK_CAST) continue
val primaryRegister = (instruction as Instruction21c).registerA + 1
val fieldReference = (instruction as? ReferenceInstruction)?.reference as? DexBackedMethodReference
if (fieldReference?.let { it.name == timeBarReference.name } == true) {
val primaryRegister = (instructions.elementAt(index + 1) as OneRegisterInstruction).registerA
val secondaryRegister = primaryRegister + 1
addInstructions(
index, """
invoke-virtual {p0}, $methodReference
move-result-wide v$primaryRegister
invoke-static {v$primaryRegister, v$secondaryRegister}, $VideoInformation->setCurrentVideoLength(J)V
"""
addInstruction(
index + 3,
"invoke-static {v$primaryRegister, v$secondaryRegister}, $VideoInformation->setCurrentVideoLength(J)V"
)
break
}
}
}
PlayerControllerFingerprint.result?.mutableMethod?.let {