refactor(youtube): move to correct package
Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
+13
@@ -0,0 +1,13 @@
|
||||
package app.revanced.patches.youtube.layout.searchbar.annotations
|
||||
|
||||
import app.revanced.patcher.annotation.Compatibility
|
||||
import app.revanced.patcher.annotation.Package
|
||||
|
||||
@Compatibility(
|
||||
[Package(
|
||||
"com.google.android.youtube", arrayOf("17.49.37", "18.03.36")
|
||||
)]
|
||||
)
|
||||
@Target(AnnotationTarget.CLASS)
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
internal annotation class WideSearchbarCompatibility
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package app.revanced.patches.youtube.layout.searchbar.fingerprints
|
||||
|
||||
import app.revanced.patcher.extensions.or
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||
import org.jf.dexlib2.AccessFlags
|
||||
import org.jf.dexlib2.Opcode
|
||||
|
||||
object DrawActionBarFingerprint : MethodFingerprint(
|
||||
"V",
|
||||
AccessFlags.PRIVATE or AccessFlags.FINAL,
|
||||
listOf("I", "I"),
|
||||
listOf(
|
||||
Opcode.INVOKE_STATIC,
|
||||
Opcode.MOVE_RESULT_OBJECT,
|
||||
Opcode.INVOKE_VIRTUAL,
|
||||
Opcode.MOVE_RESULT_OBJECT,
|
||||
Opcode.SGET_OBJECT,
|
||||
Opcode.INVOKE_VIRTUAL,
|
||||
Opcode.IGET_OBJECT,
|
||||
Opcode.INVOKE_VIRTUAL,
|
||||
Opcode.IGET_OBJECT,
|
||||
Opcode.CONST,
|
||||
Opcode.INVOKE_VIRTUAL,
|
||||
Opcode.IGET_OBJECT,
|
||||
Opcode.INVOKE_STATIC,
|
||||
),
|
||||
)
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package app.revanced.patches.youtube.layout.searchbar.fingerprints
|
||||
|
||||
import app.revanced.patcher.extensions.or
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||
import org.jf.dexlib2.AccessFlags
|
||||
import org.jf.dexlib2.Opcode
|
||||
|
||||
object SetWordmarkHeaderFingerprint : MethodFingerprint(
|
||||
"V", AccessFlags.PUBLIC or AccessFlags.FINAL, listOf("L"),
|
||||
opcodes = listOf(
|
||||
Opcode.IGET_OBJECT,
|
||||
Opcode.INVOKE_STATIC,
|
||||
Opcode.MOVE_RESULT,
|
||||
Opcode.IF_NEZ,
|
||||
Opcode.IGET_BOOLEAN,
|
||||
Opcode.IF_EQZ,
|
||||
Opcode.IGET_OBJECT,
|
||||
Opcode.CONST,
|
||||
Opcode.INVOKE_STATIC,
|
||||
),
|
||||
customFingerprint = { methodDef -> methodDef.parameterTypes.first() == "Landroid/widget/ImageView;" }
|
||||
)
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
package app.revanced.patches.youtube.layout.searchbar.patch
|
||||
|
||||
import app.revanced.extensions.toErrorResult
|
||||
import app.revanced.patcher.annotation.Description
|
||||
import app.revanced.patcher.annotation.Name
|
||||
import app.revanced.patcher.annotation.Version
|
||||
import app.revanced.patcher.data.BytecodeContext
|
||||
import app.revanced.patcher.data.toMethodWalker
|
||||
import app.revanced.patcher.extensions.addInstructions
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||
import app.revanced.patcher.patch.BytecodePatch
|
||||
import app.revanced.patcher.patch.PatchResult
|
||||
import app.revanced.patcher.patch.PatchResultSuccess
|
||||
import app.revanced.patcher.patch.annotations.DependsOn
|
||||
import app.revanced.patcher.patch.annotations.Patch
|
||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
||||
import app.revanced.patches.shared.settings.preference.impl.StringResource
|
||||
import app.revanced.patches.shared.settings.preference.impl.SwitchPreference
|
||||
import app.revanced.patches.youtube.layout.searchbar.annotations.WideSearchbarCompatibility
|
||||
import app.revanced.patches.youtube.layout.searchbar.fingerprints.DrawActionBarFingerprint
|
||||
import app.revanced.patches.youtube.layout.searchbar.fingerprints.SetWordmarkHeaderFingerprint
|
||||
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch
|
||||
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch
|
||||
|
||||
@Patch
|
||||
@DependsOn([IntegrationsPatch::class, SettingsPatch::class])
|
||||
@Name("enable-wide-searchbar")
|
||||
@Description("Replaces the search icon with a wide search bar. This will hide the YouTube logo when active.")
|
||||
@WideSearchbarCompatibility
|
||||
@Version("0.0.1")
|
||||
class WideSearchbarPatch : BytecodePatch(
|
||||
listOf(
|
||||
SetWordmarkHeaderFingerprint, DrawActionBarFingerprint
|
||||
)
|
||||
) {
|
||||
private companion object {
|
||||
/**
|
||||
* Walk a fingerprints method at a given index mutably.
|
||||
*
|
||||
* @param index The index to walk at.
|
||||
* @param fromFingerprint The fingerprint to walk the method on.
|
||||
* @return The [MutableMethod] which was walked on.
|
||||
*/
|
||||
fun BytecodeContext.walkMutable(index: Int, fromFingerprint: MethodFingerprint) =
|
||||
fromFingerprint.result?.let {
|
||||
toMethodWalker(it.method).nextMethod(index, true).getMethod() as MutableMethod
|
||||
} ?: throw SetWordmarkHeaderFingerprint.toErrorResult()
|
||||
|
||||
|
||||
/**
|
||||
* Injects instructions required for certain methods.
|
||||
*
|
||||
*/
|
||||
fun MutableMethod.injectSearchBarHook() {
|
||||
addInstructions(
|
||||
implementation!!.instructions.size - 1,
|
||||
"""
|
||||
invoke-static {}, Lapp/revanced/integrations/patches/NewActionbarPatch;->getNewActionBar()Z
|
||||
move-result p0
|
||||
"""
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun execute(context: BytecodeContext): PatchResult {
|
||||
SettingsPatch.PreferenceScreen.LAYOUT.addPreferences(
|
||||
SwitchPreference(
|
||||
"revanced_wide_searchbar",
|
||||
StringResource("revanced_wide_searchbar_enabled_title", "Enable wide search bar"),
|
||||
false,
|
||||
StringResource("revanced_wide_searchbar_summary_on", "Wide search bar is enabled"),
|
||||
StringResource("revanced_wide_searchbar_summary_off", "Wide search bar is disabled")
|
||||
)
|
||||
)
|
||||
|
||||
val result = DrawActionBarFingerprint.result ?: return DrawActionBarFingerprint.toErrorResult()
|
||||
|
||||
// patch methods
|
||||
mapOf(
|
||||
SetWordmarkHeaderFingerprint to 1,
|
||||
DrawActionBarFingerprint to result.scanResult.patternScanResult!!.endIndex
|
||||
).forEach { (fingerprint, callIndex) ->
|
||||
context.walkMutable(callIndex, fingerprint).injectSearchBarHook()
|
||||
}
|
||||
|
||||
return PatchResultSuccess()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user