refactor: Only check literal instead of additionally the opcode
This commit is contained in:
parent
5ace3bb568
commit
c4cb1e6f99
|
@ -7,7 +7,6 @@ import app.revanced.patcher.patch.PatchException
|
||||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableClass
|
import app.revanced.patcher.util.proxy.mutableTypes.MutableClass
|
||||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
||||||
import app.revanced.patches.shared.mapping.misc.ResourceMappingPatch
|
import app.revanced.patches.shared.mapping.misc.ResourceMappingPatch
|
||||||
import com.android.tools.smali.dexlib2.Opcode
|
|
||||||
import com.android.tools.smali.dexlib2.iface.Method
|
import com.android.tools.smali.dexlib2.iface.Method
|
||||||
import com.android.tools.smali.dexlib2.iface.instruction.WideLiteralInstruction
|
import com.android.tools.smali.dexlib2.iface.instruction.WideLiteralInstruction
|
||||||
import com.android.tools.smali.dexlib2.util.MethodUtil
|
import com.android.tools.smali.dexlib2.util.MethodUtil
|
||||||
|
@ -58,38 +57,38 @@ fun MutableMethod.injectHideViewCall(
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the index of the first constant instruction with the id of the given resource name.
|
* Find the index of the first instruction with the id of the given resource name.
|
||||||
*
|
*
|
||||||
* @param resourceName the name of the resource to find the id for.
|
* @param resourceName the name of the resource to find the id for.
|
||||||
* @return the index of the first constant instruction with the id of the given resource name, or -1 if not found.
|
* @return the index of the first instruction with the id of the given resource name, or -1 if not found.
|
||||||
*/
|
*/
|
||||||
fun Method.findIndexForIdResource(resourceName: String): Int {
|
fun Method.findIndexForIdResource(resourceName: String): Int {
|
||||||
fun getIdResourceId(resourceName: String) = ResourceMappingPatch.resourceMappings.single {
|
fun getIdResourceId(resourceName: String) = ResourceMappingPatch.resourceMappings.single {
|
||||||
it.type == "id" && it.name == resourceName
|
it.type == "id" && it.name == resourceName
|
||||||
}.id
|
}.id
|
||||||
|
|
||||||
return indexOfFirstConstantInstructionValue(getIdResourceId(resourceName))
|
return indexOfFirstWideLiteralInstructionValue(getIdResourceId(resourceName))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the index of the first constant instruction with the given value.
|
* Find the index of the first wide literal instruction with the given value.
|
||||||
*
|
*
|
||||||
* @return the first constant instruction with the value, or -1 if not found.
|
* @return the first literal instruction with the value, or -1 if not found.
|
||||||
*/
|
*/
|
||||||
fun Method.indexOfFirstConstantInstructionValue(constantValue: Long) = implementation?.let {
|
fun Method.indexOfFirstWideLiteralInstructionValue(literal: Long) = implementation?.let {
|
||||||
it.instructions.indexOfFirst { instruction ->
|
it.instructions.indexOfFirst { instruction ->
|
||||||
instruction.opcode == Opcode.CONST && (instruction as WideLiteralInstruction).wideLiteral == constantValue
|
(instruction as? WideLiteralInstruction)?.wideLiteral == literal
|
||||||
}
|
}
|
||||||
} ?: -1
|
} ?: -1
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the method contains a constant with the given value.
|
* Check if the method contains a literal with the given value.
|
||||||
*
|
*
|
||||||
* @return if the method contains a constant with the given value.
|
* @return if the method contains a literal with the given value.
|
||||||
*/
|
*/
|
||||||
fun Method.containsConstantInstructionValue(constantValue: Long) =
|
fun Method.containsWideLiteralInstructionValue(literal: Long) =
|
||||||
indexOfFirstConstantInstructionValue(constantValue) >= 0
|
indexOfFirstWideLiteralInstructionValue(literal) >= 0
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package app.revanced.patches.youtube.layout.player.overlay
|
package app.revanced.patches.youtube.layout.player.overlay
|
||||||
|
|
||||||
import app.revanced.extensions.exception
|
import app.revanced.extensions.exception
|
||||||
import app.revanced.extensions.indexOfFirstConstantInstructionValue
|
import app.revanced.extensions.indexOfFirstWideLiteralInstructionValue
|
||||||
import app.revanced.patcher.data.BytecodeContext
|
import app.revanced.patcher.data.BytecodeContext
|
||||||
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
|
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
|
||||||
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
|
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
|
||||||
|
@ -27,7 +27,7 @@ object CustomPlayerOverlayOpacityPatch : BytecodePatch(setOf(CreatePlayerOvervie
|
||||||
CreatePlayerOverviewFingerprint.result?.let { result ->
|
CreatePlayerOverviewFingerprint.result?.let { result ->
|
||||||
result.mutableMethod.apply {
|
result.mutableMethod.apply {
|
||||||
val viewRegisterIndex =
|
val viewRegisterIndex =
|
||||||
indexOfFirstConstantInstructionValue(CustomPlayerOverlayOpacityResourcePatch.scrimOverlayId) + 3
|
indexOfFirstWideLiteralInstructionValue(CustomPlayerOverlayOpacityResourcePatch.scrimOverlayId) + 3
|
||||||
val viewRegister =
|
val viewRegister =
|
||||||
getInstruction<OneRegisterInstruction>(viewRegisterIndex).registerA
|
getInstruction<OneRegisterInstruction>(viewRegisterIndex).registerA
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package app.revanced.patches.youtube.layout.player.overlay.fingerprints
|
package app.revanced.patches.youtube.layout.player.overlay.fingerprints
|
||||||
|
|
||||||
import app.revanced.extensions.containsConstantInstructionValue
|
import app.revanced.extensions.containsWideLiteralInstructionValue
|
||||||
import app.revanced.patcher.extensions.or
|
import app.revanced.patcher.extensions.or
|
||||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||||
import app.revanced.patches.youtube.layout.player.overlay.CustomPlayerOverlayOpacityResourcePatch
|
import app.revanced.patches.youtube.layout.player.overlay.CustomPlayerOverlayOpacityResourcePatch
|
||||||
|
@ -17,6 +17,6 @@ object CreatePlayerOverviewFingerprint : MethodFingerprint(
|
||||||
Opcode.CHECK_CAST
|
Opcode.CHECK_CAST
|
||||||
),
|
),
|
||||||
customFingerprint = { methodDef, _ ->
|
customFingerprint = { methodDef, _ ->
|
||||||
methodDef.containsConstantInstructionValue(CustomPlayerOverlayOpacityResourcePatch.scrimOverlayId)
|
methodDef.containsWideLiteralInstructionValue(CustomPlayerOverlayOpacityResourcePatch.scrimOverlayId)
|
||||||
}
|
}
|
||||||
)
|
)
|
|
@ -1,7 +1,7 @@
|
||||||
package app.revanced.patches.youtube.layout.seekbar
|
package app.revanced.patches.youtube.layout.seekbar
|
||||||
|
|
||||||
import app.revanced.extensions.exception
|
import app.revanced.extensions.exception
|
||||||
import app.revanced.extensions.indexOfFirstConstantInstructionValue
|
import app.revanced.extensions.indexOfFirstWideLiteralInstructionValue
|
||||||
import app.revanced.patcher.data.BytecodeContext
|
import app.revanced.patcher.data.BytecodeContext
|
||||||
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
|
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
|
||||||
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
|
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
|
||||||
|
@ -30,7 +30,7 @@ object SeekbarColorBytecodePatch : BytecodePatch(
|
||||||
|
|
||||||
override fun execute(context: BytecodeContext) {
|
override fun execute(context: BytecodeContext) {
|
||||||
fun MutableMethod.addColorChangeInstructions(resourceId: Long) {
|
fun MutableMethod.addColorChangeInstructions(resourceId: Long) {
|
||||||
val registerIndex = indexOfFirstConstantInstructionValue(resourceId) + 2
|
val registerIndex = indexOfFirstWideLiteralInstructionValue(resourceId) + 2
|
||||||
val colorRegister = getInstruction<OneRegisterInstruction>(registerIndex).registerA
|
val colorRegister = getInstruction<OneRegisterInstruction>(registerIndex).registerA
|
||||||
addInstructions(
|
addInstructions(
|
||||||
registerIndex + 1,
|
registerIndex + 1,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package app.revanced.patches.youtube.layout.seekbar.fingerprints
|
package app.revanced.patches.youtube.layout.seekbar.fingerprints
|
||||||
|
|
||||||
import app.revanced.extensions.containsConstantInstructionValue
|
import app.revanced.extensions.containsWideLiteralInstructionValue
|
||||||
import app.revanced.patcher.extensions.or
|
import app.revanced.patcher.extensions.or
|
||||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||||
import app.revanced.patches.youtube.layout.seekbar.SeekbarColorResourcePatch
|
import app.revanced.patches.youtube.layout.seekbar.SeekbarColorResourcePatch
|
||||||
|
@ -9,7 +9,7 @@ import com.android.tools.smali.dexlib2.AccessFlags
|
||||||
object PlayerSeekbarColorFingerprint : MethodFingerprint(
|
object PlayerSeekbarColorFingerprint : MethodFingerprint(
|
||||||
accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
|
accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
|
||||||
customFingerprint = { method, _ ->
|
customFingerprint = { method, _ ->
|
||||||
method.containsConstantInstructionValue(SeekbarColorResourcePatch.inlineTimeBarColorizedBarPlayedColorDarkId)
|
method.containsWideLiteralInstructionValue(SeekbarColorResourcePatch.inlineTimeBarColorizedBarPlayedColorDarkId)
|
||||||
&& method.containsConstantInstructionValue(SeekbarColorResourcePatch.inlineTimeBarPlayedNotHighlightedColorId)
|
&& method.containsWideLiteralInstructionValue(SeekbarColorResourcePatch.inlineTimeBarPlayedNotHighlightedColorId)
|
||||||
}
|
}
|
||||||
)
|
)
|
|
@ -1,6 +1,6 @@
|
||||||
package app.revanced.patches.youtube.misc.fix.playback.fingerprints
|
package app.revanced.patches.youtube.misc.fix.playback.fingerprints
|
||||||
|
|
||||||
import app.revanced.extensions.containsConstantInstructionValue
|
import app.revanced.extensions.containsWideLiteralInstructionValue
|
||||||
import app.revanced.patcher.extensions.or
|
import app.revanced.patcher.extensions.or
|
||||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||||
import com.android.tools.smali.dexlib2.AccessFlags
|
import com.android.tools.smali.dexlib2.AccessFlags
|
||||||
|
@ -18,6 +18,6 @@ object PlayerResponseModelImplFingerprint : MethodFingerprint(
|
||||||
customFingerprint = handler@{ methodDef, _ ->
|
customFingerprint = handler@{ methodDef, _ ->
|
||||||
if (!methodDef.definingClass.endsWith("/PlayerResponseModelImpl;")) return@handler false
|
if (!methodDef.definingClass.endsWith("/PlayerResponseModelImpl;")) return@handler false
|
||||||
|
|
||||||
methodDef.containsConstantInstructionValue(55735497)
|
methodDef.containsWideLiteralInstructionValue(55735497)
|
||||||
}
|
}
|
||||||
)
|
)
|
|
@ -1,6 +1,6 @@
|
||||||
package app.revanced.util.patch
|
package app.revanced.util.patch
|
||||||
|
|
||||||
import app.revanced.extensions.containsConstantInstructionValue
|
import app.revanced.extensions.containsWideLiteralInstructionValue
|
||||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||||
import com.android.tools.smali.dexlib2.Opcode
|
import com.android.tools.smali.dexlib2.Opcode
|
||||||
|
|
||||||
|
@ -19,6 +19,6 @@ abstract class LiteralValueFingerprint(
|
||||||
opcodes = opcodes,
|
opcodes = opcodes,
|
||||||
strings = strings,
|
strings = strings,
|
||||||
customFingerprint = { methodDef, _ ->
|
customFingerprint = { methodDef, _ ->
|
||||||
methodDef.containsConstantInstructionValue(literalSupplier())
|
methodDef.containsWideLiteralInstructionValue(literalSupplier())
|
||||||
}
|
}
|
||||||
)
|
)
|
Loading…
Reference in a new issue