mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-06-12 21:27:43 +02:00
refactor: fix patch structure
This commit is contained in:
@ -17,6 +17,7 @@ import com.android.tools.smali.dexlib2.Opcode
|
||||
import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction21c
|
||||
import com.android.tools.smali.dexlib2.iface.Method
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.Instruction
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.WideLiteralInstruction
|
||||
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
|
||||
@ -82,6 +83,68 @@ fun MutableMethod.injectHideViewCall(
|
||||
"invoke-static { v$viewRegister }, $classDescriptor->$targetMethod(Landroid/view/View;)V"
|
||||
)
|
||||
|
||||
fun MethodFingerprint.literalInstructionBooleanHook(
|
||||
literal: Int,
|
||||
descriptor: String
|
||||
) = literalInstructionBooleanHook(literal.toLong(), descriptor)
|
||||
|
||||
fun MethodFingerprint.literalInstructionBooleanHook(
|
||||
literal: Int,
|
||||
descriptor: String,
|
||||
message: String
|
||||
) = literalInstructionBooleanHook(literal.toLong(), descriptor, message)
|
||||
|
||||
fun MethodFingerprint.literalInstructionBooleanHook(
|
||||
literal: Long,
|
||||
descriptor: String
|
||||
) = literalInstructionBooleanHook(literal, descriptor, "")
|
||||
|
||||
fun MethodFingerprint.literalInstructionBooleanHook(
|
||||
literal: Long,
|
||||
descriptor: String,
|
||||
message: String
|
||||
) {
|
||||
val method = result?.mutableMethod
|
||||
?: if (message.isEmpty())
|
||||
throw exception
|
||||
else
|
||||
throw PatchException("This version is not supported. $message")
|
||||
|
||||
method.apply {
|
||||
val literalIndex = getWideLiteralInstructionIndex(literal)
|
||||
val targetIndex = getTargetIndex(literalIndex, Opcode.MOVE_RESULT)
|
||||
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
|
||||
|
||||
val smaliInstruction = if (descriptor.endsWith("(Z)Z"))
|
||||
"invoke-static {v$targetRegister}, $descriptor"
|
||||
else
|
||||
"invoke-static {}, $descriptor"
|
||||
|
||||
addInstructions(
|
||||
targetIndex + 1, """
|
||||
$smaliInstruction
|
||||
move-result v$targetRegister
|
||||
"""
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun MethodFingerprint.literalInstructionViewHook(
|
||||
literal: Long,
|
||||
descriptor: String
|
||||
) {
|
||||
result?.mutableMethod?.apply {
|
||||
val literalIndex = getWideLiteralInstructionIndex(literal)
|
||||
val targetIndex = getTargetIndex(literalIndex, Opcode.MOVE_RESULT_OBJECT)
|
||||
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
|
||||
|
||||
addInstruction(
|
||||
targetIndex + 1,
|
||||
"invoke-static {v$targetRegister}, $descriptor"
|
||||
)
|
||||
} ?: throw exception
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the index of the first wide literal instruction with the given value.
|
||||
*
|
||||
@ -155,7 +218,7 @@ fun Method.indexOfFirstInstruction(predicate: Instruction.() -> Boolean) =
|
||||
fun MutableMethod.getTargetIndex(opcode: Opcode) = getTargetIndex(0, opcode)
|
||||
|
||||
fun MutableMethod.getTargetIndexReversed(opcode: Opcode) =
|
||||
getTargetIndex(implementation!!.instructions.size - 1, opcode)
|
||||
getTargetIndexReversed(implementation!!.instructions.size - 1, opcode)
|
||||
|
||||
fun MutableMethod.getTargetIndex(startIndex: Int, opcode: Opcode) =
|
||||
implementation!!.instructions.let {
|
||||
|
@ -1,3 +1,5 @@
|
||||
@file:Suppress("DEPRECATION", "MemberVisibilityCanBePrivate", "SpellCheckingInspection")
|
||||
|
||||
package app.revanced.util
|
||||
|
||||
import app.revanced.patcher.data.ResourceContext
|
||||
|
23
src/main/kotlin/app/revanced/util/patch/BaseBytecodePatch.kt
Normal file
23
src/main/kotlin/app/revanced/util/patch/BaseBytecodePatch.kt
Normal file
@ -0,0 +1,23 @@
|
||||
package app.revanced.util.patch
|
||||
|
||||
import app.revanced.patcher.PatchClass
|
||||
import app.revanced.patcher.fingerprint.MethodFingerprint
|
||||
import app.revanced.patcher.patch.BytecodePatch
|
||||
|
||||
abstract class BaseBytecodePatch(
|
||||
name: String? = null,
|
||||
description: String? = null,
|
||||
dependencies: Set<PatchClass>? = null,
|
||||
compatiblePackages: Set<CompatiblePackage>? = null,
|
||||
fingerprints: Set<MethodFingerprint> = emptySet(),
|
||||
requiresIntegrations: Boolean = false,
|
||||
use: Boolean = true,
|
||||
) : BytecodePatch(
|
||||
name = name,
|
||||
description = description,
|
||||
dependencies = dependencies,
|
||||
compatiblePackages = compatiblePackages,
|
||||
fingerprints = fingerprints,
|
||||
requiresIntegrations = requiresIntegrations,
|
||||
use = use
|
||||
)
|
20
src/main/kotlin/app/revanced/util/patch/BaseResourcePatch.kt
Normal file
20
src/main/kotlin/app/revanced/util/patch/BaseResourcePatch.kt
Normal file
@ -0,0 +1,20 @@
|
||||
package app.revanced.util.patch
|
||||
|
||||
import app.revanced.patcher.PatchClass
|
||||
import app.revanced.patcher.patch.ResourcePatch
|
||||
|
||||
abstract class BaseResourcePatch(
|
||||
name: String? = null,
|
||||
description: String? = null,
|
||||
dependencies: Set<PatchClass>? = null,
|
||||
compatiblePackages: Set<CompatiblePackage>? = null,
|
||||
requiresIntegrations: Boolean = false,
|
||||
use: Boolean = true
|
||||
) : ResourcePatch(
|
||||
name = name,
|
||||
description = description,
|
||||
dependencies = dependencies,
|
||||
compatiblePackages = compatiblePackages,
|
||||
requiresIntegrations = requiresIntegrations,
|
||||
use = use
|
||||
)
|
Reference in New Issue
Block a user