forked from ReVanced/revanced-patcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MethodSignatureResolverResult.kt
75 lines (68 loc) 路 2.52 KB
/
MethodSignatureResolverResult.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package app.revanced.patcher.signature.implementation.method.resolver
import app.revanced.patcher.extensions.softCompareTo
import app.revanced.patcher.signature.implementation.method.MethodSignature
import app.revanced.patcher.util.proxy.ClassProxy
import org.jf.dexlib2.Opcode
import org.jf.dexlib2.iface.Method
/**
* Represents the result of a [MethodSignatureResolver].
* @param definingClassProxy The [ClassProxy] that the matching method was found in.
* @param resolvedMethod The actual matching method.
* @param scanResult Opcodes pattern scan result.
*/
data class SignatureResolverResult(
val definingClassProxy: ClassProxy,
val scanResult: PatternScanResult,
private val resolvedMethod: Method,
) {
/**
* Returns the **mutable** method by the [resolvedMethod] from the [definingClassProxy].
*
* Please note, this method allocates a [ClassProxy].
* Use [immutableMethod] where possible.
*/
val method
get() = definingClassProxy.resolve().methods.first {
it.softCompareTo(resolvedMethod)
}
/**
* Returns the **immutable** method by the [resolvedMethod] from the [definingClassProxy].
*
* If you need to modify the method, use [method] instead.
*/
@Suppress("MemberVisibilityCanBePrivate")
val immutableMethod: Method
get() = definingClassProxy.immutableClass.methods.first {
it.softCompareTo(resolvedMethod)
}
fun findParentMethod(signature: MethodSignature): SignatureResolverResult? {
return MethodSignatureResolver.resolveFromProxy(definingClassProxy, signature)
}
}
data class PatternScanResult(
val startIndex: Int,
val endIndex: Int
) {
/**
* A list of warnings the resolver found.
*
* This list will be allocated when the signature has been found.
* Meaning, if the signature was not found,
* or the signature was not yet resolved,
* the list will be null.
*/
var warnings: List<Warning>? = null
/**
* Represents a resolver warning.
* @param correctOpcode The opcode the instruction list has.
* @param wrongOpcode The opcode the pattern list of the signature currently has.
* @param instructionIndex The index of the opcode relative to the instruction list.
* @param patternIndex The index of the opcode relative to the pattern list from the signature.
*/
data class Warning(
val correctOpcode: Opcode,
val wrongOpcode: Opcode,
val instructionIndex: Int,
val patternIndex: Int,
)
}