mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-06-12 05:07:41 +02:00
bump hide-create-button
patch
This commit is contained in:
@ -1,14 +1,20 @@
|
||||
package app.revanced.patches.youtube.layout.general.pivotbar.createbutton.bytecode.fingerprints
|
||||
|
||||
import app.revanced.patcher.extensions.or
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourcdIdPatch
|
||||
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction
|
||||
import org.jf.dexlib2.AccessFlags
|
||||
import org.jf.dexlib2.Opcode
|
||||
|
||||
object PivotBarCreateButtonViewFingerprint : MethodFingerprint(
|
||||
opcodes = listOf(
|
||||
Opcode.INVOKE_DIRECT_RANGE, // unique instruction anchor
|
||||
Opcode.CONST_4,
|
||||
Opcode.INVOKE_VIRTUAL,
|
||||
Opcode.MOVE_RESULT_OBJECT,
|
||||
Opcode.INVOKE_STATIC
|
||||
)
|
||||
returnType = "V",
|
||||
access = AccessFlags.PUBLIC or AccessFlags.FINAL,
|
||||
parameters = listOf("Z"),
|
||||
customFingerprint = { methodDef ->
|
||||
methodDef.implementation?.instructions?.any { instruction ->
|
||||
instruction.opcode.ordinal == Opcode.CONST.ordinal &&
|
||||
(instruction as? WideLiteralInstruction)?.wideLiteral == SharedResourcdIdPatch.imageOnlyTabId
|
||||
} == true
|
||||
}
|
||||
)
|
@ -3,24 +3,26 @@ package app.revanced.patches.youtube.layout.general.pivotbar.createbutton.byteco
|
||||
import app.revanced.patcher.annotation.Name
|
||||
import app.revanced.patcher.annotation.Version
|
||||
import app.revanced.patcher.data.BytecodeContext
|
||||
import app.revanced.patcher.extensions.MethodFingerprintExtensions.name
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve
|
||||
import app.revanced.patcher.patch.annotations.DependsOn
|
||||
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.general.pivotbar.createbutton.bytecode.fingerprints.PivotBarCreateButtonViewFingerprint
|
||||
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourcdIdPatch
|
||||
import app.revanced.shared.annotation.YouTubeCompatibility
|
||||
import app.revanced.shared.fingerprints.PivotBarFingerprint
|
||||
import app.revanced.shared.util.integrations.Constants.GENERAL_LAYOUT
|
||||
import app.revanced.shared.util.pivotbar.InjectionUtils.injectHook
|
||||
import app.revanced.shared.util.pivotbar.InjectionUtils.REGISTER_TEMPLATE_REPLACEMENT
|
||||
import org.jf.dexlib2.dexbacked.reference.DexBackedMethodReference
|
||||
import org.jf.dexlib2.iface.instruction.ReferenceInstruction
|
||||
|
||||
@Name("hide-create-button-bytecode-patch")
|
||||
@DependsOn([SharedResourcdIdPatch::class])
|
||||
@YouTubeCompatibility
|
||||
@Version("0.0.1")
|
||||
class CreateButtonRemoverBytecodePatch : BytecodePatch(
|
||||
listOf(PivotBarFingerprint)
|
||||
listOf(PivotBarCreateButtonViewFingerprint)
|
||||
) {
|
||||
override fun execute(context: BytecodeContext): PatchResult {
|
||||
|
||||
@ -28,23 +30,40 @@ class CreateButtonRemoverBytecodePatch : BytecodePatch(
|
||||
* Resolve fingerprints
|
||||
*/
|
||||
|
||||
val pivotBarResult = PivotBarFingerprint.result ?: return PatchResultError("PivotBarFingerprint failed")
|
||||
val createButtonResult = PivotBarCreateButtonViewFingerprint.result ?: return PatchResultError("PivotBarCreateButtonViewFingerprint failed")
|
||||
val createButtonMethod = createButtonResult.mutableMethod
|
||||
val createButtonInstructions = createButtonMethod.implementation!!.instructions
|
||||
|
||||
if (!PivotBarCreateButtonViewFingerprint.resolve(context, pivotBarResult.mutableMethod, pivotBarResult.mutableClass))
|
||||
return PatchResultError("${PivotBarCreateButtonViewFingerprint.name} failed")
|
||||
createButtonInstructions.filter { instruction ->
|
||||
val fieldReference = (instruction as? ReferenceInstruction)?.reference as? DexBackedMethodReference
|
||||
fieldReference?.let { it.definingClass == "Lcom/google/android/apps/youtube/app/ui/pivotbar/PivotBar;" && it.name == "c" } == true
|
||||
}.forEach { instruction ->
|
||||
if (!isSeondary) {
|
||||
isSeondary = true;
|
||||
return@forEach
|
||||
}
|
||||
|
||||
val createButtonResult = PivotBarCreateButtonViewFingerprint.result!!
|
||||
val insertIndex = createButtonResult.scanResult.patternScanResult!!.endIndex
|
||||
insertIndex = createButtonInstructions.indexOf(instruction) + 2
|
||||
|
||||
/*
|
||||
* Inject hooks
|
||||
*/
|
||||
/*
|
||||
* Inject hooks
|
||||
*/
|
||||
|
||||
val hook =
|
||||
"invoke-static { v$REGISTER_TEMPLATE_REPLACEMENT }, $GENERAL_LAYOUT->hideCreateButton(Landroid/view/View;)V"
|
||||
createButtonMethod.injectHook(hook, insertIndex)
|
||||
|
||||
createButtonResult.mutableMethod.injectHook(hook, insertIndex)
|
||||
return PatchResultSuccess()
|
||||
}
|
||||
|
||||
return PatchResultSuccess()
|
||||
return PatchResultError("Could not find the method to hook.")
|
||||
}
|
||||
|
||||
internal companion object {
|
||||
const val hook =
|
||||
"invoke-static { v$REGISTER_TEMPLATE_REPLACEMENT }, $GENERAL_LAYOUT" +
|
||||
"->" +
|
||||
"hideCreateButton(Landroid/view/View;)V"
|
||||
|
||||
private var insertIndex: Int = 0
|
||||
private var isSeondary: Boolean = false
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user