mirror of
https://github.com/revanced/revanced-patcher.git
synced 2025-05-01 13:44:25 +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.
|
* 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> {
|
fun resolveSignatures(): List<MethodSignature> {
|
||||||
if (signaturesResolved) {
|
if (signaturesResolved) {
|
||||||
throw IllegalStateException("Signatures have already been resolved.")
|
throw IllegalStateException("Signatures have already been resolved.")
|
||||||
}
|
}
|
||||||
|
|
||||||
val signatures = patcherData.patches.flatMap { it.signatures }
|
val signatures = patcherData.patches.flatMap { it.signatures }
|
||||||
if (signatures.isEmpty()) {
|
|
||||||
throw IllegalStateException("No signatures found to resolve.")
|
|
||||||
}
|
|
||||||
SignatureResolver(patcherData.classes.internalClasses, signatures).resolve(patcherData)
|
SignatureResolver(patcherData.classes.internalClasses, signatures).resolve(patcherData)
|
||||||
signaturesResolved = true
|
signaturesResolved = true
|
||||||
return signatures
|
return signatures
|
||||||
@ -120,14 +118,13 @@ class Patcher(
|
|||||||
* @return A map of [PatchResultSuccess]. If the [Patch] was successfully applied,
|
* @return A map of [PatchResultSuccess]. If the [Patch] was successfully applied,
|
||||||
* [PatchResultSuccess] will always be returned to the wrapping Result object.
|
* [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.
|
* 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(
|
fun applyPatches(
|
||||||
stopOnError: Boolean = false,
|
stopOnError: Boolean = false,
|
||||||
callback: (String) -> Unit = {}
|
callback: (String) -> Unit = {}
|
||||||
): Map<PatchMetadata, Result<PatchResultSuccess>> {
|
): Map<PatchMetadata, Result<PatchResultSuccess>> {
|
||||||
if (!signaturesResolved && patcherData.patches.isNotEmpty()) {
|
if (!signaturesResolved && patcherData.patches.isNotEmpty()) {
|
||||||
throw IllegalStateException("Signatures not yet resolved, please invoke Patcher#resolveSignatures() first.")
|
resolveSignatures()
|
||||||
}
|
}
|
||||||
return buildMap {
|
return buildMap {
|
||||||
for (patch in patcherData.patches) {
|
for (patch in patcherData.patches) {
|
||||||
|
@ -16,8 +16,8 @@ internal class SignatureResolver(
|
|||||||
private val methodSignatures: Iterable<MethodSignature>
|
private val methodSignatures: Iterable<MethodSignature>
|
||||||
) {
|
) {
|
||||||
fun resolve(patcherData: PatcherData) {
|
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) {
|
for (method in classDef.methods) {
|
||||||
val patternScanData = compareSignatureToMethod(signature, method) ?: continue
|
val patternScanData = compareSignatureToMethod(signature, method) ?: continue
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user