mirror of
https://github.com/ReVanced/revanced-cli.git
synced 2026-01-23 11:21:01 +00:00
Patches are now loaded dynamically and the CLI now links to the patches library. Also decided to use the CLI library from kotlinx, since that's friendlier than whatever we had before.
25 lines
873 B
Kotlin
25 lines
873 B
Kotlin
package app.revanced.cli.utils
|
|
|
|
import java.io.File
|
|
import java.net.URL
|
|
import java.net.URLClassLoader
|
|
|
|
class PatchLoader {
|
|
companion object {
|
|
fun injectPatches(file: File) {
|
|
// This function will fail on Java 9 and above.
|
|
try {
|
|
val url = file.toURI().toURL()
|
|
val classLoader = Thread.currentThread().contextClassLoader as URLClassLoader
|
|
val method = URLClassLoader::class.java.getDeclaredMethod("addURL", URL::class.java)
|
|
method.isAccessible = true
|
|
method.invoke(classLoader, url)
|
|
} catch (e: Exception) {
|
|
throw Exception(
|
|
"Failed to inject patches! The CLI does NOT work on Java 9 and above, please use Java 8!",
|
|
e // propagate exception
|
|
)
|
|
}
|
|
}
|
|
}
|
|
} |