mirror of
https://github.com/revanced/revanced-patcher.git
synced 2025-05-03 14:14:26 +02:00
Finish tests, add InsnList.setAt
, sr -> sd
Added some sweet explanation too.
This commit is contained in:
parent
61c0541ef5
commit
8c56d15823
@ -6,7 +6,7 @@ import org.objectweb.asm.tree.MethodNode
|
|||||||
data class PatchData(
|
data class PatchData(
|
||||||
val cls: ClassNode,
|
val cls: ClassNode,
|
||||||
val method: MethodNode,
|
val method: MethodNode,
|
||||||
val sr: ScanData
|
val sd: ScanData
|
||||||
)
|
)
|
||||||
|
|
||||||
data class ScanData(
|
data class ScanData(
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
package net.revanced.patcher.writer
|
package net.revanced.patcher.writer
|
||||||
|
|
||||||
|
import org.objectweb.asm.tree.AbstractInsnNode
|
||||||
import org.objectweb.asm.tree.InsnList
|
import org.objectweb.asm.tree.InsnList
|
||||||
|
|
||||||
object ASMWriter {
|
object ASMWriter {
|
||||||
fun InsnList.testingWow() {
|
fun InsnList.setAt(index: Int, node: AbstractInsnNode) {
|
||||||
|
this[this.get(index)] = node
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,9 +4,11 @@ import net.revanced.patcher.patch.Patch
|
|||||||
import net.revanced.patcher.patch.PatchResultSuccess
|
import net.revanced.patcher.patch.PatchResultSuccess
|
||||||
import net.revanced.patcher.signature.Signature
|
import net.revanced.patcher.signature.Signature
|
||||||
import net.revanced.patcher.util.ExtraTypes
|
import net.revanced.patcher.util.ExtraTypes
|
||||||
|
import net.revanced.patcher.writer.ASMWriter.setAt
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.objectweb.asm.Opcodes.*
|
import org.objectweb.asm.Opcodes.*
|
||||||
import org.objectweb.asm.Type
|
import org.objectweb.asm.Type
|
||||||
|
import org.objectweb.asm.tree.LdcInsnNode
|
||||||
|
|
||||||
internal class PatcherTest {
|
internal class PatcherTest {
|
||||||
private val testSigs: Array<Signature> = arrayOf(
|
private val testSigs: Array<Signature> = arrayOf(
|
||||||
@ -40,9 +42,19 @@ internal class PatcherTest {
|
|||||||
|
|
||||||
patcher.addPatches(
|
patcher.addPatches(
|
||||||
Patch ("TestPatch") {
|
Patch ("TestPatch") {
|
||||||
|
// Get the method from the resolver cache
|
||||||
val main = patcher.cache.methods["mainMethod"]
|
val main = patcher.cache.methods["mainMethod"]
|
||||||
|
// Get the instruction list
|
||||||
val insn = main.method.instructions!!
|
val insn = main.method.instructions!!
|
||||||
|
// Let's modify it, so it prints "Hello, ReVanced!"
|
||||||
|
// Get the start index of our signature
|
||||||
|
// This will be the index of the LDC instruction
|
||||||
|
val startIndex = main.sd.startIndex
|
||||||
|
insn.setAt(startIndex, LdcInsnNode("Hello, ReVanced!"))
|
||||||
|
// Finally, tell the patcher that this patch was a success.
|
||||||
|
// You can also return PatchResultError with a message.
|
||||||
|
// If an exception is thrown inside this function,
|
||||||
|
// a PatchResultError will be returned with the error message.
|
||||||
PatchResultSuccess()
|
PatchResultSuccess()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user