1
mirror of https://github.com/revanced/revanced-patcher synced 2024-11-24 05:16:22 +01:00

refactor: migrate signature schema changes to Patcher

also updated Extensions, for good measure.
This commit is contained in:
Lucaskyy 2022-04-13 19:42:50 +02:00 committed by oSumAtrIX
parent 6b8b0573d4
commit 18853f70a4
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
3 changed files with 66 additions and 6 deletions

View File

@ -4,7 +4,12 @@ import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.builder.BuilderInstruction
import org.jf.dexlib2.builder.MutableMethodImplementation
infix fun AccessFlags.or(other: AccessFlags) = this.value or other.value
class AccessFlagExtensions {
companion object {
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>) {
for (i in instructions.lastIndex downTo 0) {

View File

@ -5,16 +5,61 @@ import org.jf.dexlib2.Opcode
/**
* Represents a method signature.
* @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 accessFlags The access flags of the method.
* @param methodParameters The parameters of the method.
* @param opcodes A list of opcodes of the method.
* @param accessFlags The access flags of the method.
*/
@Suppress("ArrayInDataClass")
data class MethodSignature(
val name: String,
val metadata: SignatureMetadata,
val returnType: String?,
val accessFlags: Int?,
val methodParameters: Iterable<String>?,
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
}

View File

@ -1,14 +1,14 @@
package app.revanced.patcher
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.or
import app.revanced.patcher.patch.Patch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.proxy.mutableTypes.MutableField.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.asInstructions
import com.google.common.collect.ImmutableList
@ -31,8 +31,18 @@ internal class PatcherTest {
val testSignatures = listOf(
MethodSignature(
"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",
AccessFlags.PUBLIC or AccessFlags.STATIC,
AccessFlags.PUBLIC or AccessFlags.STATIC or AccessFlags.STATIC,
listOf("[L"),
listOf(
Opcode.CONST_STRING,