-
-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # CHANGELOG.md # gradle.properties
- Loading branch information
Showing
11 changed files
with
186 additions
and
113 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
kotlin.code.style = official | ||
version = 1.1.0 | ||
version = 1.1.0-dev.3 |
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
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,26 +1,2 @@ | ||
package app.revanced.patch | ||
|
||
import app.revanced.patcher.data.base.Data | ||
import app.revanced.patcher.patch.base.Patch | ||
import app.revanced.patches.Index | ||
import java.io.File | ||
import java.net.URLClassLoader | ||
|
||
internal object Patches { | ||
|
||
|
||
/** | ||
* This method loads patches from a given patch file | ||
* @return the loaded patches represented as a list of functions returning instances of [Patch] | ||
*/ | ||
internal fun load(patchFile: File): List<() -> Patch<Data>> { | ||
val url = patchFile.toURI().toURL() | ||
val classLoader = URLClassLoader(arrayOf(url)) | ||
return loadIndex(classLoader).patches | ||
} | ||
private fun loadIndex(classLoader: ClassLoader) = classLoader | ||
.loadClass(Index::class.java.canonicalName) | ||
.fields | ||
.first() | ||
.get(null) as Index | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package app.revanced.utils.patcher | ||
|
||
import app.revanced.cli.MainCommand | ||
import app.revanced.patcher.Patcher | ||
import app.revanced.patcher.annotation.Compatibility | ||
import app.revanced.patcher.annotation.Name | ||
import app.revanced.patcher.data.base.Data | ||
import app.revanced.patcher.extensions.findAnnotationRecursively | ||
import app.revanced.patcher.patch.base.Patch | ||
import app.revanced.patcher.util.patch.PatchLoader | ||
|
||
fun Patcher.addPatchesFiltered( | ||
packageCompatibilityFilter: Boolean = true, | ||
packageVersionCompatibilityFilter: Boolean = true, | ||
includeFilter: Boolean = false | ||
) { | ||
val packageName = this.packageName | ||
val packageVersion = this.packageVersion | ||
|
||
MainCommand.patchBundles.forEach { bundle -> | ||
val includedPatches = mutableListOf<Patch<Data>>() | ||
PatchLoader.loadFromFile(bundle).forEach patch@{ p -> | ||
val patch = p.getDeclaredConstructor().newInstance() | ||
|
||
val compatibilityAnnotation = patch.javaClass.findAnnotationRecursively(Compatibility::class.java) | ||
|
||
val patchName = patch.javaClass.findAnnotationRecursively(Name::class.java)?.name ?: Name::class.java.name | ||
|
||
val prefix = "[skipped] $patchName" | ||
|
||
if (includeFilter && !MainCommand.includedPatches.contains(patchName)) { | ||
println(prefix) | ||
return@patch | ||
} | ||
|
||
if (packageVersionCompatibilityFilter || packageCompatibilityFilter) { | ||
|
||
if (compatibilityAnnotation == null) { | ||
println("$prefix: Missing compatibility annotation.") | ||
return@patch | ||
} | ||
|
||
|
||
for (compatiblePackage in compatibilityAnnotation.compatiblePackages) { | ||
if (packageCompatibilityFilter && compatiblePackage.name != packageName) { | ||
println("$prefix: Package name not matching ${compatiblePackage.name}.") | ||
return@patch | ||
} | ||
|
||
if (!packageVersionCompatibilityFilter || compatiblePackage.versions.any { it == packageVersion }) continue | ||
println("$prefix: Unsupported version.") | ||
return@patch | ||
} | ||
} | ||
|
||
includedPatches.add(patch) | ||
println("[added] $patchName") | ||
} | ||
this.addPatches(includedPatches) | ||
} | ||
} | ||
|
||
fun Patcher.applyPatchesPrint() { | ||
for ((patch, result) in this.applyPatches()) { | ||
println("[${if (result.isFailure) "error" else "success"}] $patch") | ||
} | ||
} | ||
|
||
fun Patcher.mergeFiles() { | ||
this.addFiles(MainCommand.mergeFiles) | ||
} |
Oops, something went wrong.