mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-06-12 05:07:41 +02:00
minor improve
This commit is contained in:
@ -0,0 +1,25 @@
|
||||
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 PivotBarFingerprint : MethodFingerprint(
|
||||
returnType = "L",
|
||||
access = AccessFlags.PUBLIC or AccessFlags.FINAL,
|
||||
opcodes = listOf(
|
||||
Opcode.INVOKE_VIRTUAL,
|
||||
Opcode.MOVE_RESULT_OBJECT,
|
||||
Opcode.RETURN_OBJECT
|
||||
),
|
||||
customFingerprint = { methodDef ->
|
||||
methodDef.definingClass == "Lcom/google/android/apps/youtube/app/ui/pivotbar/PivotBar;" &&
|
||||
methodDef.implementation?.instructions?.any { instruction ->
|
||||
instruction.opcode.ordinal == Opcode.CONST.ordinal &&
|
||||
(instruction as? WideLiteralInstruction)?.wideLiteral == SharedResourcdIdPatch.imageWithTextTabId
|
||||
} == true
|
||||
}
|
||||
)
|
@ -3,17 +3,18 @@ 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.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.patcher.patch.annotations.DependsOn
|
||||
import app.revanced.patches.youtube.layout.general.pivotbar.createbutton.bytecode.fingerprints.*
|
||||
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourcdIdPatch
|
||||
import app.revanced.shared.annotation.YouTubeCompatibility
|
||||
import app.revanced.shared.extensions.toErrorResult
|
||||
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 app.revanced.shared.util.pivotbar.InjectionUtils.injectHook
|
||||
import org.jf.dexlib2.dexbacked.reference.DexBackedMethodReference
|
||||
import org.jf.dexlib2.iface.instruction.ReferenceInstruction
|
||||
|
||||
@ -22,7 +23,10 @@ import org.jf.dexlib2.iface.instruction.ReferenceInstruction
|
||||
@YouTubeCompatibility
|
||||
@Version("0.0.1")
|
||||
class CreateButtonRemoverBytecodePatch : BytecodePatch(
|
||||
listOf(PivotBarCreateButtonViewFingerprint)
|
||||
listOf(
|
||||
PivotBarCreateButtonViewFingerprint,
|
||||
PivotBarFingerprint
|
||||
)
|
||||
) {
|
||||
override fun execute(context: BytecodeContext): PatchResult {
|
||||
|
||||
@ -30,31 +34,35 @@ class CreateButtonRemoverBytecodePatch : BytecodePatch(
|
||||
* Resolve fingerprints
|
||||
*/
|
||||
|
||||
val createButtonResult = PivotBarCreateButtonViewFingerprint.result ?: return PatchResultError("PivotBarCreateButtonViewFingerprint failed")
|
||||
val createButtonMethod = createButtonResult.mutableMethod
|
||||
val createButtonInstructions = createButtonMethod.implementation!!.instructions
|
||||
PivotBarFingerprint.result?.let { result ->
|
||||
val startIndex = result.scanResult.patternScanResult!!.startIndex
|
||||
val pivotBarInstructions = result.mutableMethod.implementation!!.instructions
|
||||
createRef = (pivotBarInstructions.elementAt(startIndex) as ReferenceInstruction).reference as DexBackedMethodReference
|
||||
} ?: return PivotBarFingerprint.toErrorResult()
|
||||
|
||||
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
|
||||
PivotBarCreateButtonViewFingerprint.result?.let { result ->
|
||||
with (result.mutableMethod){
|
||||
val createButtonInstructions = implementation!!.instructions
|
||||
createButtonInstructions.filter { instruction ->
|
||||
val fieldReference = (instruction as? ReferenceInstruction)?.reference as? DexBackedMethodReference
|
||||
fieldReference?.let { it.definingClass == createRef.definingClass && it.name == createRef.name } == true
|
||||
}.forEach { instruction ->
|
||||
if (!isSeondary) {
|
||||
isSeondary = true;
|
||||
return@forEach
|
||||
}
|
||||
|
||||
/*
|
||||
* Inject hooks
|
||||
*/
|
||||
|
||||
injectHook(hook, createButtonInstructions.indexOf(instruction) + 2)
|
||||
|
||||
return PatchResultSuccess()
|
||||
}
|
||||
return PatchResultError("Could not find the method to hook.")
|
||||
}
|
||||
|
||||
insertIndex = createButtonInstructions.indexOf(instruction) + 2
|
||||
|
||||
/*
|
||||
* Inject hooks
|
||||
*/
|
||||
|
||||
createButtonMethod.injectHook(hook, insertIndex)
|
||||
|
||||
return PatchResultSuccess()
|
||||
}
|
||||
|
||||
return PatchResultError("Could not find the method to hook.")
|
||||
} ?: return PivotBarCreateButtonViewFingerprint.toErrorResult()
|
||||
}
|
||||
|
||||
internal companion object {
|
||||
@ -63,7 +71,8 @@ class CreateButtonRemoverBytecodePatch : BytecodePatch(
|
||||
"->" +
|
||||
"hideCreateButton(Landroid/view/View;)V"
|
||||
|
||||
private var insertIndex: Int = 0
|
||||
private lateinit var createRef: DexBackedMethodReference
|
||||
|
||||
private var isSeondary: Boolean = false
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user