From ae4c7b29f211c461de460f97f3a8656e795adafb Mon Sep 17 00:00:00 2001 From: Lucaskyy Date: Thu, 14 Apr 2022 19:19:43 +0200 Subject: [PATCH] feat: Add (WIP) Signature Checker --- .gitignore | 5 ++- .../app/revanced/patches/SignatureChecker.kt | 39 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 src/test/kotlin/app/revanced/patches/SignatureChecker.kt diff --git a/.gitignore b/.gitignore index 55e6dfc0..48d035ac 100644 --- a/.gitignore +++ b/.gitignore @@ -111,4 +111,7 @@ gradle-app.setting .gradletasknamecache # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 -# gradle/wrapper/gradle-wrapper.properties \ No newline at end of file +# gradle/wrapper/gradle-wrapper.properties + +# Potentially copyrighted test APK +stock.apk \ No newline at end of file diff --git a/src/test/kotlin/app/revanced/patches/SignatureChecker.kt b/src/test/kotlin/app/revanced/patches/SignatureChecker.kt new file mode 100644 index 00000000..28cc27d6 --- /dev/null +++ b/src/test/kotlin/app/revanced/patches/SignatureChecker.kt @@ -0,0 +1,39 @@ +package app.revanced.patches + +import app.revanced.patcher.Patcher +import app.revanced.patcher.signature.MethodSignature +import app.revanced.patcher.signature.PatternScanMethod +import org.junit.Test +import java.io.File + +internal class SignatureChecker { + @Test + fun checkSignatures() { + val file = File("stock.apk") + if (!file.exists()) { + throw IllegalStateException("Missing stock.apk! To run this test, please place stock.apk here: ${file.absolutePath}") + } + val patcher = Patcher(file) + patcher.addPatches(Index.patches.map { it() }) + val unresolved = mutableListOf() + for (signature in patcher.resolveSignatures()) { + if (!signature.resolved) unresolved.add(signature) + + val patternScanMethod = signature.metadata.patternScanMethod + if (patternScanMethod is PatternScanMethod.Fuzzy) { + val warnings = patternScanMethod.warnings + println("Signature ${signature.metadata.name} had ${warnings.size} warnings!") + for (warning in warnings) { + println(warning.toString()) + } + } + } + if (unresolved.isNotEmpty()) { + val base = Exception("${unresolved.size} signatures were not resolved.") + for (signature in unresolved) { + base.addSuppressed(Exception("Signature ${signature.metadata.name} was not resolved!")) + } + throw base + } + } +} \ No newline at end of file