mirror of
https://github.com/ReVanced/revanced-patches.git
synced 2026-01-19 17:13:59 +00:00
refactor(openinghours): FixCrashPatch
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
package app.revanced.patches.openinghours.misc.fix.crash
|
||||
|
||||
import app.revanced.patcher.fingerprint
|
||||
import app.revanced.patcher.BytecodePatchContextMethodMatching.gettingFirstMutableMethodDeclaratively
|
||||
import app.revanced.patcher.definingClass
|
||||
import app.revanced.patcher.name
|
||||
import app.revanced.patcher.parameterTypes
|
||||
import app.revanced.patcher.patch.BytecodePatchContext
|
||||
import app.revanced.patcher.returnType
|
||||
|
||||
internal val setPlaceFingerprint = fingerprint {
|
||||
returns("V")
|
||||
parameters("Lde/simon/openinghours/models/Place;")
|
||||
custom { method, _ ->
|
||||
method.name == "setPlace" &&
|
||||
method.definingClass == "Lde/simon/openinghours/views/custom/PlaceCard;"
|
||||
}
|
||||
internal val BytecodePatchContext.setPlaceMethod by gettingFirstMutableMethodDeclaratively {
|
||||
name("setPlace")
|
||||
definingClass("Lde/simon/openinghours/views/custom/PlaceCard;")
|
||||
returnType("V")
|
||||
parameterTypes("Lde/simon/openinghours/models/Place;")
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package app.revanced.patches.openinghours.misc.fix.crash
|
||||
|
||||
import app.revanced.patcher.extensions.instructions
|
||||
import app.revanced.patcher.extensions.replaceInstruction
|
||||
import app.revanced.patcher.extensions.newLabel
|
||||
import app.revanced.patcher.patch.bytecodePatch
|
||||
import app.revanced.patcher.extensions.replaceInstruction
|
||||
import app.revanced.patcher.patch.creatingBytecodePatch
|
||||
import app.revanced.util.getReference
|
||||
import com.android.tools.smali.dexlib2.Opcode
|
||||
import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction21t
|
||||
@@ -11,14 +11,14 @@ import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.Instruction
|
||||
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
|
||||
|
||||
@Suppress("unused")
|
||||
val fixCrashPatch = bytecodePatch(
|
||||
name = "Fix crash",
|
||||
@Suppress("unused", "ObjectPropertyName")
|
||||
val `Fix crash` by creatingBytecodePatch(
|
||||
description = "Fixes a crash when opening a place.",
|
||||
) {
|
||||
compatibleWith("de.simon.openinghours"("1.0"))
|
||||
|
||||
apply {
|
||||
val indexedInstructions = setPlaceFingerprint.method.instructions.withIndex().toList()
|
||||
val indexedInstructions = setPlaceMethod.instructions.withIndex().toList()
|
||||
|
||||
/**
|
||||
* This function replaces all `checkNotNull` instructions in the integer interval
|
||||
@@ -27,7 +27,7 @@ val fixCrashPatch = bytecodePatch(
|
||||
* the value is indeed null, we jump to a newly created label at `endIndex + 1`.
|
||||
*/
|
||||
fun avoidNullPointerException(startIndex: Int, endIndex: Int) {
|
||||
val continueLabel = setPlaceFingerprint.method.newLabel(endIndex + 1)
|
||||
val continueLabel = setPlaceMethod.newLabel(endIndex + 1)
|
||||
|
||||
for (index in startIndex..endIndex) {
|
||||
val instruction = indexedInstructions[index].value
|
||||
@@ -39,7 +39,7 @@ val fixCrashPatch = bytecodePatch(
|
||||
val checkNotNullInstruction = instruction as FiveRegisterInstruction
|
||||
val originalRegister = checkNotNullInstruction.registerC
|
||||
|
||||
setPlaceFingerprint.method.replaceInstruction(
|
||||
setPlaceMethod.replaceInstruction(
|
||||
index,
|
||||
BuilderInstruction21t(
|
||||
Opcode.IF_EQZ,
|
||||
|
||||
Reference in New Issue
Block a user