mirror of
https://github.com/revanced/revanced-patcher
synced 2025-04-26 05:39:56 +02:00
refactor: migrate signature schema changes to Patcher
also updated Extensions, for good measure.
This commit is contained in:
parent
6b8b0573d4
commit
18853f70a4
src
main/kotlin/app/revanced/patcher
test/kotlin/app/revanced/patcher
@ -4,7 +4,12 @@ import org.jf.dexlib2.AccessFlags
|
|||||||
import org.jf.dexlib2.builder.BuilderInstruction
|
import org.jf.dexlib2.builder.BuilderInstruction
|
||||||
import org.jf.dexlib2.builder.MutableMethodImplementation
|
import org.jf.dexlib2.builder.MutableMethodImplementation
|
||||||
|
|
||||||
|
class AccessFlagExtensions {
|
||||||
|
companion object {
|
||||||
infix fun AccessFlags.or(other: AccessFlags) = this.value or other.value
|
infix fun AccessFlags.or(other: AccessFlags) = this.value or other.value
|
||||||
|
infix fun Int.or(other: AccessFlags) = this or other.value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun MutableMethodImplementation.addInstructions(index: Int, instructions: List<BuilderInstruction>) {
|
fun MutableMethodImplementation.addInstructions(index: Int, instructions: List<BuilderInstruction>) {
|
||||||
for (i in instructions.lastIndex downTo 0) {
|
for (i in instructions.lastIndex downTo 0) {
|
||||||
|
@ -5,16 +5,61 @@ import org.jf.dexlib2.Opcode
|
|||||||
/**
|
/**
|
||||||
* Represents a method signature.
|
* Represents a method signature.
|
||||||
* @param name A suggestive name for the method which the signature was created for.
|
* @param name A suggestive name for the method which the signature was created for.
|
||||||
|
* @param metadata Metadata about this signature.
|
||||||
* @param returnType The return type of the method.
|
* @param returnType The return type of the method.
|
||||||
|
* @param accessFlags The access flags of the method.
|
||||||
* @param methodParameters The parameters of the method.
|
* @param methodParameters The parameters of the method.
|
||||||
* @param opcodes A list of opcodes of the method.
|
* @param opcodes A list of opcodes of the method.
|
||||||
* @param accessFlags The access flags of the method.
|
|
||||||
*/
|
*/
|
||||||
@Suppress("ArrayInDataClass")
|
@Suppress("ArrayInDataClass")
|
||||||
data class MethodSignature(
|
data class MethodSignature(
|
||||||
val name: String,
|
val name: String,
|
||||||
|
val metadata: SignatureMetadata,
|
||||||
val returnType: String?,
|
val returnType: String?,
|
||||||
val accessFlags: Int?,
|
val accessFlags: Int?,
|
||||||
val methodParameters: Iterable<String>?,
|
val methodParameters: Iterable<String>?,
|
||||||
val opcodes: Iterable<Opcode>?
|
val opcodes: Iterable<Opcode>?
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Metadata about the signature.
|
||||||
|
* @param method Metadata about the method for this signature.
|
||||||
|
* @param patcher Metadata for the Patcher, this contains things like how the Patcher should interpret this signature.
|
||||||
|
*/
|
||||||
|
data class SignatureMetadata(
|
||||||
|
val method: MethodMetadata,
|
||||||
|
val patcher: PatcherMetadata
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Metadata about the method for this signature.
|
||||||
|
* @param definingClass The defining class name of the original method.
|
||||||
|
* @param methodName The name of the original method.
|
||||||
|
* @param comment A comment about this method and the data above.
|
||||||
|
* For example, the version this signature was originally made for.
|
||||||
|
*/
|
||||||
|
data class MethodMetadata(
|
||||||
|
val definingClass: String?,
|
||||||
|
val methodName: String?,
|
||||||
|
val comment: String
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Metadata for the Patcher, this contains things like how the Patcher should interpret this signature.
|
||||||
|
* @param method The method the Patcher should use to resolve the signature.
|
||||||
|
*/
|
||||||
|
data class PatcherMetadata(
|
||||||
|
val method: PatcherMethod
|
||||||
|
)
|
||||||
|
|
||||||
|
interface PatcherMethod {
|
||||||
|
/**
|
||||||
|
* When comparing the signature, if one or more of the opcodes do not match, skip.
|
||||||
|
*/
|
||||||
|
class Direct : PatcherMethod
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When comparing the signature, if [threshold] or more of the opcodes do not match, skip.
|
||||||
|
*/
|
||||||
|
class Fuzzy(val threshold: Int) : PatcherMethod
|
||||||
|
}
|
@ -1,14 +1,14 @@
|
|||||||
package app.revanced.patcher
|
package app.revanced.patcher
|
||||||
|
|
||||||
import app.revanced.patcher.cache.Cache
|
import app.revanced.patcher.cache.Cache
|
||||||
|
import app.revanced.patcher.extensions.AccessFlagExtensions.Companion.or
|
||||||
import app.revanced.patcher.extensions.addInstructions
|
import app.revanced.patcher.extensions.addInstructions
|
||||||
import app.revanced.patcher.extensions.or
|
|
||||||
import app.revanced.patcher.patch.Patch
|
import app.revanced.patcher.patch.Patch
|
||||||
import app.revanced.patcher.patch.PatchResult
|
import app.revanced.patcher.patch.PatchResult
|
||||||
import app.revanced.patcher.patch.PatchResultSuccess
|
import app.revanced.patcher.patch.PatchResultSuccess
|
||||||
import app.revanced.patcher.proxy.mutableTypes.MutableField.Companion.toMutable
|
import app.revanced.patcher.proxy.mutableTypes.MutableField.Companion.toMutable
|
||||||
import app.revanced.patcher.proxy.mutableTypes.MutableMethod.Companion.toMutable
|
import app.revanced.patcher.proxy.mutableTypes.MutableMethod.Companion.toMutable
|
||||||
import app.revanced.patcher.signature.MethodSignature
|
import app.revanced.patcher.signature.*
|
||||||
import app.revanced.patcher.smali.asInstruction
|
import app.revanced.patcher.smali.asInstruction
|
||||||
import app.revanced.patcher.smali.asInstructions
|
import app.revanced.patcher.smali.asInstructions
|
||||||
import com.google.common.collect.ImmutableList
|
import com.google.common.collect.ImmutableList
|
||||||
@ -31,8 +31,18 @@ internal class PatcherTest {
|
|||||||
val testSignatures = listOf(
|
val testSignatures = listOf(
|
||||||
MethodSignature(
|
MethodSignature(
|
||||||
"main-method",
|
"main-method",
|
||||||
|
SignatureMetadata(
|
||||||
|
method = MethodMetadata(
|
||||||
|
definingClass = "TestClass",
|
||||||
|
methodName = "main",
|
||||||
|
comment = "Main method of TestClass. Version 1.0.0"
|
||||||
|
),
|
||||||
|
patcher = PatcherMetadata(
|
||||||
|
method = PatcherMethod.Fuzzy(2)
|
||||||
|
)
|
||||||
|
),
|
||||||
"V",
|
"V",
|
||||||
AccessFlags.PUBLIC or AccessFlags.STATIC,
|
AccessFlags.PUBLIC or AccessFlags.STATIC or AccessFlags.STATIC,
|
||||||
listOf("[L"),
|
listOf("[L"),
|
||||||
listOf(
|
listOf(
|
||||||
Opcode.CONST_STRING,
|
Opcode.CONST_STRING,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user