minor improve

This commit is contained in:
inotia00 2023-01-07 17:01:39 +09:00
parent c71611282f
commit be62437ab3
5 changed files with 66 additions and 30 deletions

View File

@ -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
}
)

View File

@ -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.Name
import app.revanced.patcher.annotation.Version import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultError import app.revanced.patcher.patch.PatchResultError
import app.revanced.patcher.patch.PatchResultSuccess 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.patches.youtube.misc.resourceid.patch.SharedResourcdIdPatch
import app.revanced.shared.annotation.YouTubeCompatibility 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.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.REGISTER_TEMPLATE_REPLACEMENT
import app.revanced.shared.util.pivotbar.InjectionUtils.injectHook
import org.jf.dexlib2.dexbacked.reference.DexBackedMethodReference import org.jf.dexlib2.dexbacked.reference.DexBackedMethodReference
import org.jf.dexlib2.iface.instruction.ReferenceInstruction import org.jf.dexlib2.iface.instruction.ReferenceInstruction
@ -22,7 +23,10 @@ import org.jf.dexlib2.iface.instruction.ReferenceInstruction
@YouTubeCompatibility @YouTubeCompatibility
@Version("0.0.1") @Version("0.0.1")
class CreateButtonRemoverBytecodePatch : BytecodePatch( class CreateButtonRemoverBytecodePatch : BytecodePatch(
listOf(PivotBarCreateButtonViewFingerprint) listOf(
PivotBarCreateButtonViewFingerprint,
PivotBarFingerprint
)
) { ) {
override fun execute(context: BytecodeContext): PatchResult { override fun execute(context: BytecodeContext): PatchResult {
@ -30,32 +34,36 @@ class CreateButtonRemoverBytecodePatch : BytecodePatch(
* Resolve fingerprints * Resolve fingerprints
*/ */
val createButtonResult = PivotBarCreateButtonViewFingerprint.result ?: return PatchResultError("PivotBarCreateButtonViewFingerprint failed") PivotBarFingerprint.result?.let { result ->
val createButtonMethod = createButtonResult.mutableMethod val startIndex = result.scanResult.patternScanResult!!.startIndex
val createButtonInstructions = createButtonMethod.implementation!!.instructions val pivotBarInstructions = result.mutableMethod.implementation!!.instructions
createRef = (pivotBarInstructions.elementAt(startIndex) as ReferenceInstruction).reference as DexBackedMethodReference
} ?: return PivotBarFingerprint.toErrorResult()
PivotBarCreateButtonViewFingerprint.result?.let { result ->
with (result.mutableMethod){
val createButtonInstructions = implementation!!.instructions
createButtonInstructions.filter { instruction -> createButtonInstructions.filter { instruction ->
val fieldReference = (instruction as? ReferenceInstruction)?.reference as? DexBackedMethodReference 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 fieldReference?.let { it.definingClass == createRef.definingClass && it.name == createRef.name } == true
}.forEach { instruction -> }.forEach { instruction ->
if (!isSeondary) { if (!isSeondary) {
isSeondary = true; isSeondary = true;
return@forEach return@forEach
} }
insertIndex = createButtonInstructions.indexOf(instruction) + 2
/* /*
* Inject hooks * Inject hooks
*/ */
createButtonMethod.injectHook(hook, insertIndex) injectHook(hook, createButtonInstructions.indexOf(instruction) + 2)
return PatchResultSuccess() return PatchResultSuccess()
} }
return PatchResultError("Could not find the method to hook.") return PatchResultError("Could not find the method to hook.")
} }
} ?: return PivotBarCreateButtonViewFingerprint.toErrorResult()
}
internal companion object { internal companion object {
const val hook = const val hook =
@ -63,7 +71,8 @@ class CreateButtonRemoverBytecodePatch : BytecodePatch(
"->" + "->" +
"hideCreateButton(Landroid/view/View;)V" "hideCreateButton(Landroid/view/View;)V"
private var insertIndex: Int = 0 private lateinit var createRef: DexBackedMethodReference
private var isSeondary: Boolean = false private var isSeondary: Boolean = false
} }
} }

View File

@ -1,6 +1,5 @@
package app.revanced.patches.youtube.misc.doublebacktoclose.patch package app.revanced.patches.youtube.misc.doublebacktoclose.patch
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.data.BytecodeContext

View File

@ -25,6 +25,7 @@ class SharedResourcdIdPatch : ResourcePatch {
var educationTextViewResourceId: Long = -1 var educationTextViewResourceId: Long = -1
var emptycolorLabelId: Long = -1 var emptycolorLabelId: Long = -1
var imageOnlyTabId: Long = -1 var imageOnlyTabId: Long = -1
var imageWithTextTabId: Long = -1
var layoutCircle: Long = -1 var layoutCircle: Long = -1
var layoutIcon: Long = -1 var layoutIcon: Long = -1
var layoutVideo: Long = -1 var layoutVideo: Long = -1
@ -47,6 +48,7 @@ class SharedResourcdIdPatch : ResourcePatch {
educationTextViewResourceId = findSharedResourceId("id", "user_education_text_view") educationTextViewResourceId = findSharedResourceId("id", "user_education_text_view")
emptycolorLabelId = findSharedResourceId("color", "inline_time_bar_colorized_bar_empty_color_dark") emptycolorLabelId = findSharedResourceId("color", "inline_time_bar_colorized_bar_empty_color_dark")
imageOnlyTabId = findSharedResourceId("layout", "image_only_tab") imageOnlyTabId = findSharedResourceId("layout", "image_only_tab")
imageWithTextTabId = findSharedResourceId("layout", "image_with_text_tab")
layoutCircle = findSharedResourceId("layout", "endscreen_element_layout_circle") layoutCircle = findSharedResourceId("layout", "endscreen_element_layout_circle")
layoutIcon = findSharedResourceId("layout", "endscreen_element_layout_icon") layoutIcon = findSharedResourceId("layout", "endscreen_element_layout_icon")
layoutVideo = findSharedResourceId("layout", "endscreen_element_layout_video") layoutVideo = findSharedResourceId("layout", "endscreen_element_layout_video")

View File

@ -11,6 +11,7 @@ import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patches.youtube.misc.swiperefresh.fingerprint.SwipeRefreshLayoutFingerprint import app.revanced.patches.youtube.misc.swiperefresh.fingerprint.SwipeRefreshLayoutFingerprint
import app.revanced.shared.annotation.YouTubeCompatibility import app.revanced.shared.annotation.YouTubeCompatibility
import app.revanced.shared.extensions.toErrorResult
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
@Name("enable-swipe-refresh") @Name("enable-swipe-refresh")
@ -23,7 +24,7 @@ class SwipeRefreshPatch : BytecodePatch(
) )
) { ) {
override fun execute(context: BytecodeContext): PatchResult { override fun execute(context: BytecodeContext): PatchResult {
val result = SwipeRefreshLayoutFingerprint.result!! val result = SwipeRefreshLayoutFingerprint.result ?:return SwipeRefreshLayoutFingerprint.toErrorResult()
val method = result.mutableMethod val method = result.mutableMethod
val index = result.scanResult.patternScanResult!!.endIndex val index = result.scanResult.patternScanResult!!.endIndex
val register = (method.instruction(index) as OneRegisterInstruction).registerA val register = (method.instruction(index) as OneRegisterInstruction).registerA