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

View File

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