This commit is contained in:
inotia00
2023-01-10 04:30:54 +09:00
parent 1b83a30a56
commit 7db88c2dc8
77 changed files with 807 additions and 663 deletions

View File

@ -8,9 +8,9 @@ import org.jf.dexlib2.Opcode
object ScrubbingLabelFingerprint : MethodFingerprint(
opcodes = listOf(Opcode.IPUT_BOOLEAN),
customFingerprint = { methodDef ->
methodDef.implementation?.instructions?.any { instruction ->
instruction.opcode.ordinal == Opcode.CONST.ordinal &&
(instruction as? WideLiteralInstruction)?.wideLiteral == SharedResourcdIdPatch.scrubbingLabelId
methodDef.implementation?.instructions?.any {
it.opcode.ordinal == Opcode.CONST.ordinal &&
(it as? WideLiteralInstruction)?.wideLiteral == SharedResourcdIdPatch.scrubbingLabelId
} == true
}
)

View File

@ -7,14 +7,16 @@ import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.extensions.removeInstruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultError
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patches.youtube.layout.fullscreen.flimstripoverlay.bytecode.fingerprints.ScrubbingLabelFingerprint
import app.revanced.shared.annotation.YouTubeCompatibility
import app.revanced.shared.extensions.toErrorResult
import app.revanced.shared.util.integrations.Constants.FULLSCREEN_LAYOUT
import org.jf.dexlib2.Opcode
import org.jf.dexlib2.iface.instruction.ReferenceInstruction
import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction
import org.jf.dexlib2.iface.reference.FieldReference
import org.jf.dexlib2.Opcode
@Name("hide-filmstrip-overlay-bytecode-patch")
@YouTubeCompatibility
@ -25,32 +27,33 @@ class HideFilmstripOverlayBytecodePatch : BytecodePatch(
)
) {
override fun execute(context: BytecodeContext): PatchResult {
val scrubbingLabelResult = ScrubbingLabelFingerprint.result!!
val scrubbingLabelMethod = scrubbingLabelResult.mutableMethod
val scrubbingLabelMethodInstructions = scrubbingLabelMethod.implementation!!.instructions
ScrubbingLabelFingerprint.result?.mutableMethod?.let {
with (it.implementation!!.instructions) {
for ((index, instruction) in this.withIndex()) {
if (instruction.opcode != Opcode.IPUT_BOOLEAN) continue
val primaryRegister = (instruction as TwoRegisterInstruction).registerA
val secondaryRegister = (instruction as TwoRegisterInstruction).registerB
val dummyRegister = primaryRegister + 2
val fieldReference = (instruction as ReferenceInstruction).reference as FieldReference
for ((index, instruction) in scrubbingLabelMethodInstructions.withIndex()) {
if (instruction.opcode != Opcode.IPUT_BOOLEAN) continue
val scrubbingLabelRegisterA = (instruction as TwoRegisterInstruction).registerA
val scrubbingLabelRegisterB = scrubbingLabelRegisterA + 2
val scrubbingLabelRegisterC = (instruction as TwoRegisterInstruction).registerB
val scrubbingLabelReference = (instruction as ReferenceInstruction).reference as FieldReference
it.addInstructions(
index + 1, """
invoke-static {}, $FULLSCREEN_LAYOUT->hideFilmstripOverlay()Z
move-result v$dummyRegister
if-eqz v$dummyRegister, :show
const/4 v$primaryRegister, 0x0
:show
iput-boolean v$primaryRegister, v$secondaryRegister, ${fieldReference.definingClass}->${fieldReference.name}:${fieldReference.type}
"""
)
scrubbingLabelMethod.addInstructions(
index + 1, """
invoke-static {}, $FULLSCREEN_LAYOUT->hideFilmstripOverlay()Z
move-result v$scrubbingLabelRegisterB
if-eqz v$scrubbingLabelRegisterB, :show
const/4 v$scrubbingLabelRegisterA, 0x0
:show
iput-boolean v$scrubbingLabelRegisterA, v$scrubbingLabelRegisterC, ${scrubbingLabelReference.definingClass}->${scrubbingLabelReference.name}:${scrubbingLabelReference.type}
"""
)
it.removeInstruction(index)
scrubbingLabelMethod.removeInstruction(index)
break
}
return PatchResultSuccess()
}
}
} ?: return ScrubbingLabelFingerprint.toErrorResult()
return PatchResultSuccess()
return PatchResultError("Could not find the method to hook.")
}
}

View File

@ -6,13 +6,14 @@ import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.extensions.instruction
import app.revanced.patcher.extensions.removeInstruction
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprintResult
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.youtube.layout.fullscreen.hapticfeedback.bytecode.fingerprints.*
import app.revanced.shared.annotation.YouTubeCompatibility
import app.revanced.shared.extensions.toErrorResult
import app.revanced.shared.util.integrations.Constants.FULLSCREEN_LAYOUT
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
@ -29,27 +30,36 @@ class HapticFeedBackBytecodePatch : BytecodePatch(
) {
override fun execute(context: BytecodeContext): PatchResult {
SeekHapticsFingerprint.disableHaptics("disableSeekVibrate")
ScrubbingHapticsFingerprint.voidHaptics("disableScrubbingVibrate")
MarkerHapticsFingerprint.voidHaptics("disableChapterVibrate")
ZoomHapticsFingerprint.voidHaptics("disableZoomVibrate")
arrayOf(
SeekHapticsFingerprint to "disableSeekVibrate",
ScrubbingHapticsFingerprint to "disableScrubbingVibrate",
MarkerHapticsFingerprint to "disableChapterVibrate",
ZoomHapticsFingerprint to "disableZoomVibrate"
).map { (fingerprint, name) ->
fingerprint.result?.let {
if (fingerprint == SeekHapticsFingerprint)
it.disableHaptics(name)
else
it.voidHaptics(name)
} ?: return fingerprint.toErrorResult()
}
return PatchResultSuccess()
}
private companion object {
fun MethodFingerprint.disableHaptics(targetMethodName: String) {
with(this.result!!) {
val startIndex = scanResult.patternScanResult!!.startIndex
val endIndex = scanResult.patternScanResult!!.endIndex
val insertIndex = endIndex + 4
val targetRegister = (method.implementation!!.instructions.elementAt(insertIndex) as OneRegisterInstruction).registerA
val dummyRegister = targetRegister + 1
fun MethodFingerprintResult.disableHaptics(targetMethodName: String) {
val startIndex = scanResult.patternScanResult!!.startIndex
val endIndex = scanResult.patternScanResult!!.endIndex
val insertIndex = endIndex + 4
val targetRegister = (method.implementation!!.instructions.elementAt(insertIndex) as OneRegisterInstruction).registerA
val dummyRegister = targetRegister + 1
mutableMethod.removeInstruction(insertIndex)
with (mutableMethod) {
removeInstruction(insertIndex)
mutableMethod.addInstructions(
insertIndex, """
addInstructions(
insertIndex, """
invoke-static {}, $FULLSCREEN_LAYOUT->$targetMethodName()Z
move-result v$dummyRegister
if-eqz v$dummyRegister, :vibrate
@ -57,31 +67,30 @@ class HapticFeedBackBytecodePatch : BytecodePatch(
goto :exit
:vibrate
const-wide/16 v$targetRegister, 0x19
""", listOf(ExternalLabel("exit", mutableMethod.instruction(insertIndex)))
)
""", listOf(ExternalLabel("exit", mutableMethod.instruction(insertIndex)))
)
mutableMethod.addInstructions(
startIndex, """
addInstructions(
startIndex, """
invoke-static {}, $FULLSCREEN_LAYOUT->$targetMethodName()Z
move-result v$dummyRegister
if-eqz v$dummyRegister, :vibrate
return-void
""", listOf(ExternalLabel("vibrate", mutableMethod.instruction(startIndex)))
)
""", listOf(ExternalLabel("vibrate", mutableMethod.instruction(startIndex)))
)
}
}
fun MethodFingerprint.voidHaptics(targetMethodName: String) {
with(this.result!!) {
mutableMethod.addInstructions(
0, """
fun MethodFingerprintResult.voidHaptics(targetMethodName: String) {
mutableMethod.addInstructions(
0, """
invoke-static {}, $FULLSCREEN_LAYOUT->$targetMethodName()Z
move-result v0
if-eqz v0, :vibrate
return-void
""", listOf(ExternalLabel("vibrate", mutableMethod.instruction(0)))
)
}
""", listOf(ExternalLabel("vibrate", mutableMethod.instruction(0)))
)
}
}
}
}