forked from ReVanced/revanced-patcher
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
- Loading branch information
Showing
4 changed files
with
39 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/kotlin/app/revanced/patcher/util/patch/PatchLoader.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package app.revanced.patcher.util.patch | ||
|
||
import app.revanced.patcher.patch.base.Patch | ||
import java.io.File | ||
import java.net.URLClassLoader | ||
import java.util.jar.JarFile | ||
|
||
object PatchLoader { | ||
/** | ||
* This method loads patches from a given jar file containing [Patch]es | ||
* @return the loaded patches represented as a list of [Patch] classes | ||
*/ | ||
fun loadFromFile(patchesJar: File) = buildList { | ||
val jarFile = JarFile(patchesJar) | ||
val classLoader = URLClassLoader(arrayOf(patchesJar.toURI().toURL())) | ||
|
||
val entries = jarFile.entries() | ||
while (entries.hasMoreElements()) { | ||
val entry = entries.nextElement() | ||
if (!entry.name.endsWith(".class") || entry.name.contains("$")) continue | ||
|
||
val clazz = classLoader.loadClass(entry.realName.replace('/', '.').replace(".class", "")) | ||
|
||
if (!clazz.isAnnotationPresent(app.revanced.patcher.patch.annotations.Patch::class.java)) continue | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
val patch = clazz as Class<Patch<*>> | ||
|
||
// TODO: include declared classes from patch | ||
|
||
this.add(patch) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters