-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(YouTube): Add
Hide accessibility controls dialog
patch
- Loading branch information
Showing
4 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
...hes/src/main/kotlin/app/revanced/patches/youtube/misc/accessibility/AccessibilityPatch.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,48 @@ | ||
package app.revanced.patches.youtube.misc.accessibility | ||
|
||
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction | ||
import app.revanced.patcher.patch.bytecodePatch | ||
import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE | ||
import app.revanced.patches.youtube.utils.patch.PatchList.HIDE_ACCESSIBILITY_CONTROLS_DIALOG | ||
import app.revanced.patches.youtube.utils.settings.ResourceUtils.addPreference | ||
import app.revanced.patches.youtube.utils.settings.settingsPatch | ||
import app.revanced.util.findMethodOrThrow | ||
import app.revanced.util.fingerprint.mutableClassOrThrow | ||
import app.revanced.util.indexOfFirstInstruction | ||
import app.revanced.util.indexOfFirstInstructionReversedOrThrow | ||
import app.revanced.util.or | ||
import app.revanced.util.returnEarly | ||
import com.android.tools.smali.dexlib2.AccessFlags | ||
import com.android.tools.smali.dexlib2.Opcode | ||
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction | ||
|
||
@Suppress("unused") | ||
val accessibilityPatch = bytecodePatch( | ||
HIDE_ACCESSIBILITY_CONTROLS_DIALOG.title, | ||
HIDE_ACCESSIBILITY_CONTROLS_DIALOG.summary, | ||
) { | ||
compatibleWith(COMPATIBLE_PACKAGE) | ||
|
||
dependsOn(settingsPatch) | ||
|
||
execute { | ||
|
||
playerAccessibilitySettingsEduControllerParentFingerprint | ||
.mutableClassOrThrow() | ||
.methods | ||
.first { method -> method.name == "<init>" } | ||
.apply { | ||
val lifecycleObserverIndex = indexOfFirstInstructionReversedOrThrow(Opcode.NEW_INSTANCE) | ||
val lifecycleObserverClass = getInstruction<ReferenceInstruction>(lifecycleObserverIndex).reference.toString() | ||
|
||
findMethodOrThrow(lifecycleObserverClass) { | ||
accessFlags == AccessFlags.PUBLIC or AccessFlags.FINAL && | ||
parameterTypes.size == 1 && | ||
indexOfFirstInstruction(Opcode.INVOKE_DIRECT) >= 0 | ||
}.returnEarly() | ||
} | ||
|
||
addPreference(HIDE_ACCESSIBILITY_CONTROLS_DIALOG) | ||
|
||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
patches/src/main/kotlin/app/revanced/patches/youtube/misc/accessibility/Fingerprints.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,49 @@ | ||
package app.revanced.patches.youtube.misc.accessibility | ||
|
||
import app.revanced.util.fingerprint.legacyFingerprint | ||
import app.revanced.util.or | ||
import com.android.tools.smali.dexlib2.AccessFlags | ||
import com.android.tools.smali.dexlib2.Opcode | ||
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction | ||
import com.android.tools.smali.dexlib2.iface.reference.FieldReference | ||
|
||
/** | ||
* The name of the class to find is 'Lcom/google/android/apps/youtube/app/player/overlay/accessibility/PlayerAccessibilitySettingsEduController$LifecycleObserver;'. | ||
* It is one of the types of fields in the class. | ||
* This class name has been obfuscated since YouTube 18.25.40. | ||
* This class is always the same structure despite not a synthetic class. | ||
* (Same field and method, checked in YouTube 17.34.36 ~ 20.02.41). | ||
*/ | ||
internal val playerAccessibilitySettingsEduControllerParentFingerprint = legacyFingerprint( | ||
name = "playerAccessibilitySettingsEduControllerParentFingerprint", | ||
returnType = "V", | ||
accessFlags = AccessFlags.STATIC or AccessFlags.CONSTRUCTOR, | ||
parameters = emptyList(), | ||
opcodes = listOf( | ||
Opcode.SGET_OBJECT, | ||
Opcode.CONST_WIDE_16, | ||
Opcode.INVOKE_VIRTUAL, | ||
Opcode.MOVE_RESULT_WIDE, | ||
Opcode.SPUT_WIDE, | ||
Opcode.RETURN_VOID, | ||
), | ||
customFingerprint = custom@{ method, classDef -> | ||
// The number of fields is always 12. | ||
if (classDef.fields.count() != 12) { | ||
return@custom false | ||
} | ||
// The number of methods is always 2 or 3. | ||
if (classDef.methods.count() > 3) { | ||
return@custom false | ||
} | ||
val implementation = method.implementation | ||
?: return@custom false | ||
val instructions = implementation.instructions | ||
val instructionCount = instructions.count() | ||
if (instructionCount != 6) { | ||
return@custom false | ||
} | ||
|
||
((instructions.elementAt(0) as? ReferenceInstruction)?.reference as? FieldReference)?.toString() == "Ljava/util/concurrent/TimeUnit;->DAYS:Ljava/util/concurrent/TimeUnit;" | ||
} | ||
) |
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
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