mirror of
https://github.com/revanced/revanced-patches
synced 2025-01-07 12:15:53 +01:00
refactor: Simplify extensions register declaration (#3084)
This commit is contained in:
parent
cf8104bfb4
commit
beb643678d
@ -20,7 +20,7 @@ internal val startActivityInitHook = extensionHook(
|
|||||||
contextRegisterResolver = { method ->
|
contextRegisterResolver = { method ->
|
||||||
val moveResultInstruction = method.implementation!!.instructions.elementAt(getApplicationContextIndex + 1)
|
val moveResultInstruction = method.implementation!!.instructions.elementAt(getApplicationContextIndex + 1)
|
||||||
as OneRegisterInstruction
|
as OneRegisterInstruction
|
||||||
moveResultInstruction.registerA
|
"v${moveResultInstruction.registerA}"
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
opcodes(
|
opcodes(
|
||||||
|
@ -20,7 +20,7 @@ internal val homeActivityInitHook = extensionHook(
|
|||||||
contextRegisterResolver = { method ->
|
contextRegisterResolver = { method ->
|
||||||
val moveResultInstruction = method.implementation!!.instructions.elementAt(getApplicationContextIndex + 1)
|
val moveResultInstruction = method.implementation!!.instructions.elementAt(getApplicationContextIndex + 1)
|
||||||
as OneRegisterInstruction
|
as OneRegisterInstruction
|
||||||
moveResultInstruction.registerA
|
"v${moveResultInstruction.registerA}"
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
opcodes(
|
opcodes(
|
||||||
|
@ -7,7 +7,7 @@ import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
|
|||||||
import app.revanced.patcher.fingerprint
|
import app.revanced.patcher.fingerprint
|
||||||
import app.revanced.patcher.patch.PatchException
|
import app.revanced.patcher.patch.PatchException
|
||||||
import app.revanced.patcher.patch.bytecodePatch
|
import app.revanced.patcher.patch.bytecodePatch
|
||||||
import app.revanced.util.exception
|
import app.revanced.util.matchOrThrow
|
||||||
import com.android.tools.smali.dexlib2.iface.Method
|
import com.android.tools.smali.dexlib2.iface.Method
|
||||||
import java.net.URLDecoder
|
import java.net.URLDecoder
|
||||||
import java.util.jar.JarFile
|
import java.util.jar.JarFile
|
||||||
@ -77,24 +77,24 @@ fun sharedExtensionPatch(
|
|||||||
class ExtensionHook internal constructor(
|
class ExtensionHook internal constructor(
|
||||||
val fingerprint: Fingerprint,
|
val fingerprint: Fingerprint,
|
||||||
private val insertIndexResolver: ((Method) -> Int),
|
private val insertIndexResolver: ((Method) -> Int),
|
||||||
private val contextRegisterResolver: (Method) -> Int,
|
private val contextRegisterResolver: (Method) -> String,
|
||||||
) {
|
) {
|
||||||
operator fun invoke(extensionClassDescriptor: String) {
|
operator fun invoke(extensionClassDescriptor: String) {
|
||||||
fingerprint.match?.mutableMethod?.let { method ->
|
fingerprint.matchOrThrow.mutableMethod.let { method ->
|
||||||
val insertIndex = insertIndexResolver(method)
|
val insertIndex = insertIndexResolver(method)
|
||||||
val contextRegister = contextRegisterResolver(method)
|
val contextRegister = contextRegisterResolver(method)
|
||||||
|
|
||||||
method.addInstruction(
|
method.addInstruction(
|
||||||
insertIndex,
|
insertIndex,
|
||||||
"invoke-static/range { v$contextRegister .. v$contextRegister }, " +
|
"invoke-static/range { $contextRegister .. $contextRegister }, " +
|
||||||
"$extensionClassDescriptor->setContext(Landroid/content/Context;)V",
|
"$extensionClassDescriptor->setContext(Landroid/content/Context;)V",
|
||||||
)
|
)
|
||||||
} ?: throw fingerprint.exception
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun extensionHook(
|
fun extensionHook(
|
||||||
insertIndexResolver: ((Method) -> Int) = { 0 },
|
insertIndexResolver: ((Method) -> Int) = { 0 },
|
||||||
contextRegisterResolver: (Method) -> Int = { it.implementation!!.registerCount - 1 },
|
contextRegisterResolver: (Method) -> String = { "p0" },
|
||||||
fingerprintBuilderBlock: FingerprintBuilder.() -> Unit,
|
fingerprintBuilderBlock: FingerprintBuilder.() -> Unit,
|
||||||
) = ExtensionHook(fingerprint(block = fingerprintBuilderBlock), insertIndexResolver, contextRegisterResolver)
|
) = ExtensionHook(fingerprint(block = fingerprintBuilderBlock), insertIndexResolver, contextRegisterResolver)
|
||||||
|
@ -239,7 +239,6 @@ object PreferenceScreen : BasePreferenceScreen() {
|
|||||||
val SHORTS = Screen(
|
val SHORTS = Screen(
|
||||||
key = "revanced_settings_screen_06_shorts",
|
key = "revanced_settings_screen_06_shorts",
|
||||||
summaryKey = null,
|
summaryKey = null,
|
||||||
sorting = Sorting.UNSORTED,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Don't sort, because title sorting scatters the custom color preferences.
|
// Don't sort, because title sorting scatters the custom color preferences.
|
||||||
|
Loading…
Reference in New Issue
Block a user