mirror of
https://github.com/revanced/revanced-patcher.git
synced 2025-05-01 05:44:24 +02:00
refactor: resolve signatures automatically
Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
parent
f58a498849
commit
beff1df9b0
@ -99,16 +99,14 @@ class Patcher(
|
||||
|
||||
/**
|
||||
* Resolves all signatures.
|
||||
* @throws IllegalStateException if no patches were added or signatures have already been resolved.
|
||||
* @throws IllegalStateException if signatures have already been resolved.
|
||||
*/
|
||||
fun resolveSignatures(): List<MethodSignature> {
|
||||
if (signaturesResolved) {
|
||||
throw IllegalStateException("Signatures have already been resolved.")
|
||||
}
|
||||
|
||||
val signatures = patcherData.patches.flatMap { it.signatures }
|
||||
if (signatures.isEmpty()) {
|
||||
throw IllegalStateException("No signatures found to resolve.")
|
||||
}
|
||||
SignatureResolver(patcherData.classes.internalClasses, signatures).resolve(patcherData)
|
||||
signaturesResolved = true
|
||||
return signatures
|
||||
@ -120,14 +118,13 @@ class Patcher(
|
||||
* @return A map of [PatchResultSuccess]. If the [Patch] was successfully applied,
|
||||
* [PatchResultSuccess] will always be returned to the wrapping Result object.
|
||||
* If the [Patch] failed to apply, an Exception will always be returned to the wrapping Result object.
|
||||
* @throws IllegalStateException if signatures have not been resolved.
|
||||
*/
|
||||
fun applyPatches(
|
||||
stopOnError: Boolean = false,
|
||||
callback: (String) -> Unit = {}
|
||||
): Map<PatchMetadata, Result<PatchResultSuccess>> {
|
||||
if (!signaturesResolved && patcherData.patches.isNotEmpty()) {
|
||||
throw IllegalStateException("Signatures not yet resolved, please invoke Patcher#resolveSignatures() first.")
|
||||
resolveSignatures()
|
||||
}
|
||||
return buildMap {
|
||||
for (patch in patcherData.patches) {
|
||||
|
@ -16,8 +16,8 @@ internal class SignatureResolver(
|
||||
private val methodSignatures: Iterable<MethodSignature>
|
||||
) {
|
||||
fun resolve(patcherData: PatcherData) {
|
||||
for (classDef in classes) {
|
||||
for (signature in methodSignatures) {
|
||||
for (signature in methodSignatures) {
|
||||
for (classDef in classes) {
|
||||
for (method in classDef.methods) {
|
||||
val patternScanData = compareSignatureToMethod(signature, method) ?: continue
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user