mirror of
https://github.com/ReVanced/revanced-patcher.git
synced 2026-01-19 09:23:56 +00:00
Compare commits
3 Commits
feat/load-
...
dependabot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
29394d1a01 | ||
|
|
39aaf42b2b | ||
|
|
d2cf491ffc |
@@ -117,9 +117,9 @@ you can follow the [ReVanced documentation](https://github.com/ReVanced/revanced
|
||||
The documentation contains the fundamentals of ReVanced Patcher and how to use ReVanced Patcher to create patches.
|
||||
You can find it [here](https://github.com/ReVanced/revanced-patcher/tree/main/docs).
|
||||
|
||||
## 📜 Licence
|
||||
## 📜 License
|
||||
|
||||
ReVanced Patcher is licensed under the GPLv3 license. Please see the [licence file](LICENSE) for more information.
|
||||
ReVanced Patcher is licensed under the GPLv3 license. Please see the [license file](LICENSE) for more information.
|
||||
[tl;dr](https://www.tldrlegal.com/license/gnu-general-public-license-v3-gpl-3) you may copy, distribute and modify ReVanced Patcher as long as you track changes/dates in source files.
|
||||
Any modifications to ReVanced Patcher must also be made available under the GPL,
|
||||
along with build & install instructions.
|
||||
|
||||
@@ -342,12 +342,8 @@ public final class app/revanced/patcher/patch/PatchKt {
|
||||
public static final fun bytecodePatch (Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;)Lapp/revanced/patcher/patch/BytecodePatch;
|
||||
public static synthetic fun bytecodePatch$default (Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lapp/revanced/patcher/patch/BytecodePatch;
|
||||
public static final fun loadPatchesFromDex (Ljava/util/Set;Ljava/io/File;)Lapp/revanced/patcher/patch/PatchLoader$Dex;
|
||||
public static final fun loadPatchesFromDex (Ljava/util/Set;Ljava/io/File;Lkotlin/jvm/functions/Function2;)Lapp/revanced/patcher/patch/PatchLoader$Dex;
|
||||
public static synthetic fun loadPatchesFromDex$default (Ljava/util/Set;Ljava/io/File;ILjava/lang/Object;)Lapp/revanced/patcher/patch/PatchLoader$Dex;
|
||||
public static synthetic fun loadPatchesFromDex$default (Ljava/util/Set;Ljava/io/File;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lapp/revanced/patcher/patch/PatchLoader$Dex;
|
||||
public static final fun loadPatchesFromJar (Ljava/util/Set;)Lapp/revanced/patcher/patch/PatchLoader$Jar;
|
||||
public static final fun loadPatchesFromJar (Ljava/util/Set;Lkotlin/jvm/functions/Function2;)Lapp/revanced/patcher/patch/PatchLoader$Jar;
|
||||
public static synthetic fun loadPatchesFromJar$default (Ljava/util/Set;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lapp/revanced/patcher/patch/PatchLoader$Jar;
|
||||
public static final fun rawResourcePatch (Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;)Lapp/revanced/patcher/patch/RawResourcePatch;
|
||||
public static synthetic fun rawResourcePatch$default (Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lapp/revanced/patcher/patch/RawResourcePatch;
|
||||
public static final fun resourcePatch (Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;)Lapp/revanced/patcher/patch/ResourcePatch;
|
||||
@@ -356,7 +352,7 @@ public final class app/revanced/patcher/patch/PatchKt {
|
||||
|
||||
public abstract class app/revanced/patcher/patch/PatchLoader : java/util/Set, kotlin/jvm/internal/markers/KMappedMarker {
|
||||
public synthetic fun <init> (Ljava/util/Map;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
|
||||
public synthetic fun <init> (Ljava/util/Set;Lkotlin/jvm/functions/Function1;Ljava/lang/ClassLoader;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
|
||||
public synthetic fun <init> (Ljava/util/Set;Lkotlin/jvm/functions/Function1;Ljava/lang/ClassLoader;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
|
||||
public fun add (Lapp/revanced/patcher/patch/Patch;)Z
|
||||
public synthetic fun add (Ljava/lang/Object;)Z
|
||||
public fun addAll (Ljava/util/Collection;)Z
|
||||
@@ -377,9 +373,12 @@ public abstract class app/revanced/patcher/patch/PatchLoader : java/util/Set, ko
|
||||
}
|
||||
|
||||
public final class app/revanced/patcher/patch/PatchLoader$Dex : app/revanced/patcher/patch/PatchLoader {
|
||||
public fun <init> (Ljava/util/Set;Ljava/io/File;)V
|
||||
public synthetic fun <init> (Ljava/util/Set;Ljava/io/File;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
|
||||
}
|
||||
|
||||
public final class app/revanced/patcher/patch/PatchLoader$Jar : app/revanced/patcher/patch/PatchLoader {
|
||||
public fun <init> (Ljava/util/Set;)V
|
||||
}
|
||||
|
||||
public final class app/revanced/patcher/patch/PatchResult {
|
||||
|
||||
17
package-lock.json
generated
17
package-lock.json
generated
@@ -8,7 +8,7 @@
|
||||
"@saithodev/semantic-release-backmerge": "^4.0.1",
|
||||
"@semantic-release/changelog": "^6.0.3",
|
||||
"@semantic-release/git": "^10.0.1",
|
||||
"gradle-semantic-release-plugin": "^1.10.1",
|
||||
"gradle-semantic-release-plugin": "^1.10.3",
|
||||
"semantic-release": "^24.2.9"
|
||||
}
|
||||
},
|
||||
@@ -185,6 +185,7 @@
|
||||
"integrity": "sha512-hEb7Ma4cGJGEUNOAVmyfdB/3WirWMg5hDuNFVejGEDFqupeOysLc2sG6HJxY2etBp5YQu5Wtxwi020jS9xlUwg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@octokit/auth-token": "^5.0.0",
|
||||
"@octokit/graphql": "^8.0.0",
|
||||
@@ -400,6 +401,7 @@
|
||||
"integrity": "sha512-1LFfa/qnMQvEOAdzlQymH0ulepxbxnCYAKJZfMci/5XJyIHWgEYnDmgnKakbTh7CH2tFQ5O60oYDvns4i9RAIg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@octokit/auth-token": "^4.0.0",
|
||||
"@octokit/graphql": "^7.1.0",
|
||||
@@ -1049,6 +1051,7 @@
|
||||
"integrity": "sha512-jcByLnIFkd5gSXZmjNvS1TlmRhCXZjIzHYlaGkPlLIekG55JDR2Z4va9tZwCiP+/RDERiNhMOFu01xd6O5ct1Q==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"bin": {
|
||||
"marked": "bin/marked.js"
|
||||
},
|
||||
@@ -1167,6 +1170,7 @@
|
||||
"integrity": "sha512-0mhiCR/4sZb00RVFJIUlMuiBkW3NMpVIW2Gse7noqEMoFGkvfPPAImEQbkBV8xga4KOPP4FdTRYuLLy32R1fPw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@semantic-release/commit-analyzer": "^11.0.0",
|
||||
"@semantic-release/error": "^4.0.0",
|
||||
@@ -2874,9 +2878,9 @@
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/gradle-semantic-release-plugin": {
|
||||
"version": "1.10.1",
|
||||
"resolved": "https://registry.npmjs.org/gradle-semantic-release-plugin/-/gradle-semantic-release-plugin-1.10.1.tgz",
|
||||
"integrity": "sha512-Q4dLAFICjPouUyRRHEKK8cXNB75nraXoioYZDZlVQOg4sYKudnTDZ3ohLmV3k4cPGiiMCh1ckXETkx9JnuyKmA==",
|
||||
"version": "1.10.3",
|
||||
"resolved": "https://registry.npmjs.org/gradle-semantic-release-plugin/-/gradle-semantic-release-plugin-1.10.3.tgz",
|
||||
"integrity": "sha512-ik1qPcHvzl9AI0NzZpmKv89SAOpamuAQrbynWy0RjMBskpvHh97vPw0ywtfw5+u2O7oqxtG88xLJOFY0YaZCpg==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
@@ -2893,7 +2897,7 @@
|
||||
"node": ">=18"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"semantic-release": "^24.0.0"
|
||||
"semantic-release": "^24.0.0 || ^25.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/handlebars": {
|
||||
@@ -3465,6 +3469,7 @@
|
||||
"integrity": "sha512-8dD6FusOQSrpv9Z1rdNMdlSgQOIP880DHqnohobOmYLElGEqAL/JvxvuxZO16r4HtjTlfPRDC1hbvxC9dPN2nA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"bin": {
|
||||
"marked": "bin/marked.js"
|
||||
},
|
||||
@@ -6122,6 +6127,7 @@
|
||||
"dev": true,
|
||||
"inBundle": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
@@ -6920,6 +6926,7 @@
|
||||
"integrity": "sha512-phCkJ6pjDi9ANdhuF5ElS10GGdAKY6R1Pvt9lT3SFhOwM4T7QZE7MLpBDbNruUx/Q3gFD92/UOFringGipRqZA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@semantic-release/commit-analyzer": "^13.0.0-beta.1",
|
||||
"@semantic-release/error": "^4.0.0",
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"@saithodev/semantic-release-backmerge": "^4.0.1",
|
||||
"@semantic-release/changelog": "^6.0.3",
|
||||
"@semantic-release/git": "^10.0.1",
|
||||
"gradle-semantic-release-plugin": "^1.10.1",
|
||||
"gradle-semantic-release-plugin": "^1.10.3",
|
||||
"semantic-release": "^24.2.9"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ typealias Package = Pair<PackageName, Set<VersionName>?>
|
||||
* @param name The name of the patch.
|
||||
* If null, the patch is named "Patch" and will not be loaded by [PatchLoader].
|
||||
* @param description The description of the patch.
|
||||
* @param use Weather or not the patch should be used.
|
||||
* @param use Whether or not the patch should be used.
|
||||
* @param dependencies Other patches this patch depends on.
|
||||
* @param compatiblePackages The packages the patch is compatible with.
|
||||
* If null, the patch is compatible with all packages.
|
||||
@@ -87,7 +87,8 @@ sealed class Patch<C : PatchContext<*>>(
|
||||
finalizeBlock?.invoke(context)
|
||||
}
|
||||
|
||||
override fun toString() = name ?: "Patch@${System.identityHashCode(this)}"
|
||||
override fun toString() = name ?:
|
||||
"Patch@${System.identityHashCode(this)}"
|
||||
}
|
||||
|
||||
internal fun Patch<*>.anyRecursively(
|
||||
@@ -121,7 +122,7 @@ internal fun Iterable<Patch<*>>.forEachRecursively(
|
||||
* @param name The name of the patch.
|
||||
* If null, the patch is named "Patch" and will not be loaded by [PatchLoader].
|
||||
* @param description The description of the patch.
|
||||
* @param use Weather or not the patch should be used.
|
||||
* @param use Whether or not the patch should be used.
|
||||
* @param compatiblePackages The packages the patch is compatible with.
|
||||
* If null, the patch is compatible with all packages.
|
||||
* @param dependencies Other patches this patch depends on.
|
||||
@@ -170,7 +171,7 @@ class BytecodePatch internal constructor(
|
||||
* @param name The name of the patch.
|
||||
* If null, the patch is named "Patch" and will not be loaded by [PatchLoader].
|
||||
* @param description The description of the patch.
|
||||
* @param use Weather or not the patch should be used.
|
||||
* @param use Whether or not the patch should be used.
|
||||
* @param compatiblePackages The packages the patch is compatible with.
|
||||
* If null, the patch is compatible with all packages.
|
||||
* @param dependencies Other patches this patch depends on.
|
||||
@@ -213,7 +214,7 @@ class RawResourcePatch internal constructor(
|
||||
* @param name The name of the patch.
|
||||
* If null, the patch is named "Patch" and will not be loaded by [PatchLoader].
|
||||
* @param description The description of the patch.
|
||||
* @param use Weather or not the patch should be used.
|
||||
* @param use Whether or not the patch should be used.
|
||||
* @param compatiblePackages The packages the patch is compatible with.
|
||||
* If null, the patch is compatible with all packages.
|
||||
* @param dependencies Other patches this patch depends on.
|
||||
@@ -257,7 +258,7 @@ class ResourcePatch internal constructor(
|
||||
* @param name The name of the patch.
|
||||
* If null, the patch is named "Patch" and will not be loaded by [PatchLoader].
|
||||
* @param description The description of the patch.
|
||||
* @param use Weather or not the patch should be used.
|
||||
* @param use Whether or not the patch should be used.
|
||||
* @property compatiblePackages The packages the patch is compatible with.
|
||||
* If null, the patch is compatible with all packages.
|
||||
* @property dependencies Other patches this patch depends on.
|
||||
@@ -374,7 +375,7 @@ private fun <B : PatchBuilder<*>> B.buildPatch(block: B.() -> Unit = {}) = apply
|
||||
* @param name The name of the patch.
|
||||
* If null, the patch is named "Patch" and will not be loaded by [PatchLoader].
|
||||
* @param description The description of the patch.
|
||||
* @param use Weather or not the patch should be used.
|
||||
* @param use Whether or not the patch should be used.
|
||||
* @property extensionInputStream Getter for the extension input stream of the patch.
|
||||
* An extension is a precompiled DEX file that is merged into the patched app before this patch is executed.
|
||||
*
|
||||
@@ -424,7 +425,7 @@ class BytecodePatchBuilder internal constructor(
|
||||
* @param name The name of the patch.
|
||||
* If null, the patch is named "Patch" and will not be loaded by [PatchLoader].
|
||||
* @param description The description of the patch.
|
||||
* @param use Weather or not the patch should be used.
|
||||
* @param use Whether or not the patch should be used.
|
||||
* @param block The block to build the patch.
|
||||
*
|
||||
* @return The created [BytecodePatch].
|
||||
@@ -442,7 +443,7 @@ fun bytecodePatch(
|
||||
* @param name The name of the patch.
|
||||
* If null, the patch is named "Patch" and will not be loaded by [PatchLoader].
|
||||
* @param description The description of the patch.
|
||||
* @param use Weather or not the patch should be used.
|
||||
* @param use Whether or not the patch should be used.
|
||||
*
|
||||
* @constructor Create a new [RawResourcePatch] builder.
|
||||
*/
|
||||
@@ -469,7 +470,7 @@ class RawResourcePatchBuilder internal constructor(
|
||||
* @param name The name of the patch.
|
||||
* If null, the patch is named "Patch" and will not be loaded by [PatchLoader].
|
||||
* @param description The description of the patch.
|
||||
* @param use Weather or not the patch should be used.
|
||||
* @param use Whether or not the patch should be used.
|
||||
* @param block The block to build the patch.
|
||||
* @return The created [RawResourcePatch].
|
||||
*/
|
||||
@@ -486,7 +487,7 @@ fun rawResourcePatch(
|
||||
* @param name The name of the patch.
|
||||
* If null, the patch is named "Patch" and will not be loaded by [PatchLoader].
|
||||
* @param description The description of the patch.
|
||||
* @param use Weather or not the patch should be used.
|
||||
* @param use Whether or not the patch should be used.
|
||||
*
|
||||
* @constructor Create a new [ResourcePatch] builder.
|
||||
*/
|
||||
@@ -513,7 +514,7 @@ class ResourcePatchBuilder internal constructor(
|
||||
* @param name The name of the patch.
|
||||
* If null, the patch is named "Patch" and will not be loaded by [PatchLoader].
|
||||
* @param description The description of the patch.
|
||||
* @param use Weather or not the patch should be used.
|
||||
* @param use Whether or not the patch should be used.
|
||||
* @param block The block to build the patch.
|
||||
*
|
||||
* @return The created [ResourcePatch].
|
||||
@@ -528,11 +529,11 @@ fun resourcePatch(
|
||||
/**
|
||||
* An exception thrown when patching.
|
||||
*
|
||||
* @param message The exception message.
|
||||
* @param cause The cause of the exception.
|
||||
* @param errorMessage The exception message.
|
||||
* @param cause The corresponding [Throwable].
|
||||
*/
|
||||
class PatchException(message: String?, cause: Throwable?) : Exception(message, cause) {
|
||||
constructor(message: String) : this(message, null)
|
||||
class PatchException(errorMessage: String?, cause: Throwable?) : Exception(errorMessage, cause) {
|
||||
constructor(errorMessage: String) : this(errorMessage, null)
|
||||
constructor(cause: Throwable) : this(cause.message, cause)
|
||||
}
|
||||
|
||||
@@ -542,7 +543,6 @@ class PatchException(message: String?, cause: Throwable?) : Exception(message, c
|
||||
* @param patch The [Patch] that was executed.
|
||||
* @param exception The [PatchException] thrown, if any.
|
||||
*/
|
||||
@Deprecated("This class is not used anymore. Instead a callback is used")
|
||||
class PatchResult internal constructor(val patch: Patch<*>, val exception: PatchException? = null)
|
||||
|
||||
/**
|
||||
@@ -553,47 +553,36 @@ class PatchResult internal constructor(val patch: Patch<*>, val exception: Patch
|
||||
*
|
||||
* @param byPatchesFile The patches associated by the patches file they were loaded from.
|
||||
*/
|
||||
sealed class PatchLoader(
|
||||
sealed class PatchLoader private constructor(
|
||||
val byPatchesFile: Map<File, Set<Patch<*>>>,
|
||||
) : Set<Patch<*>> by byPatchesFile.values.flatten().toSet() {
|
||||
/**
|
||||
* @param patchesFiles A set of JAR or DEX files to load the patches from.
|
||||
* @param getBinaryClassNames A function that returns the binary names of all classes accessible by the class loader.
|
||||
* @param classLoader The [ClassLoader] to use for loading the classes.
|
||||
* @param onLoadPatchesException The callback for patches that could not be loaded.
|
||||
*/
|
||||
constructor(
|
||||
private constructor(
|
||||
patchesFiles: Set<File>,
|
||||
getBinaryClassNames: (patchesFile: File) -> List<String>,
|
||||
classLoader: ClassLoader,
|
||||
onLoadPatchesException: (message: String, cause: Throwable) -> Unit
|
||||
) : this(
|
||||
classLoader.loadPatches(
|
||||
patchesFiles.associateWith { getBinaryClassNames(it).toSet() },
|
||||
onLoadPatchesException
|
||||
)
|
||||
)
|
||||
) : this(classLoader.loadPatches(patchesFiles.associateWith { getBinaryClassNames(it).toSet() }))
|
||||
|
||||
/**
|
||||
* A [PatchLoader] for JAR files.
|
||||
*
|
||||
* @param patchesFiles The JAR files to load the patches from.
|
||||
* @param onLoadPatchesException The callback for patches that could not be loaded.
|
||||
*
|
||||
* @constructor Create a new [PatchLoader] for JAR files.
|
||||
*/
|
||||
class Jar internal constructor(
|
||||
patchesFiles: Set<File>,
|
||||
onLoadPatchesException: (message: String, cause: Throwable) -> Unit
|
||||
) : PatchLoader(
|
||||
patchesFiles,
|
||||
{ file ->
|
||||
JarFile(file).entries().toList().filter { it.name.endsWith(".class") }
|
||||
.map { it.name.substringBeforeLast('.').replace('/', '.') }
|
||||
},
|
||||
URLClassLoader(patchesFiles.map { it.toURI().toURL() }.toTypedArray()),
|
||||
onLoadPatchesException
|
||||
)
|
||||
class Jar(patchesFiles: Set<File>) :
|
||||
PatchLoader(
|
||||
patchesFiles,
|
||||
{ file ->
|
||||
JarFile(file).entries().toList().filter { it.name.endsWith(".class") }
|
||||
.map { it.name.substringBeforeLast('.').replace('/', '.') }
|
||||
},
|
||||
URLClassLoader(patchesFiles.map { it.toURI().toURL() }.toTypedArray()),
|
||||
)
|
||||
|
||||
/**
|
||||
* A [PatchLoader] for [Dex] files.
|
||||
@@ -601,30 +590,25 @@ sealed class PatchLoader(
|
||||
* @param patchesFiles The DEX files to load the patches from.
|
||||
* @param optimizedDexDirectory The directory to store optimized DEX files in.
|
||||
* This parameter is deprecated and has no effect since API level 26.
|
||||
* @param onLoadPatchesException The callback for patches that could not be loaded.
|
||||
*
|
||||
* @constructor Create a new [PatchLoader] for [Dex] files.
|
||||
*/
|
||||
class Dex internal constructor(
|
||||
patchesFiles: Set<File>,
|
||||
optimizedDexDirectory: File? = null,
|
||||
onLoadPatchesException: (message: String, cause: Throwable) -> Unit
|
||||
) : PatchLoader(
|
||||
patchesFiles,
|
||||
{ patchBundle ->
|
||||
MultiDexIO.readDexFile(true, patchBundle, BasicDexFileNamer(), null, null).classes
|
||||
.map { classDef ->
|
||||
classDef.type.substring(1, classDef.length - 1)
|
||||
}
|
||||
},
|
||||
DexClassLoader(
|
||||
patchesFiles.joinToString(File.pathSeparator) { it.absolutePath },
|
||||
optimizedDexDirectory?.absolutePath,
|
||||
null,
|
||||
this::class.java.classLoader,
|
||||
),
|
||||
onLoadPatchesException
|
||||
)
|
||||
class Dex(patchesFiles: Set<File>, optimizedDexDirectory: File? = null) :
|
||||
PatchLoader(
|
||||
patchesFiles,
|
||||
{ patchBundle ->
|
||||
MultiDexIO.readDexFile(true, patchBundle, BasicDexFileNamer(), null, null).classes
|
||||
.map { classDef ->
|
||||
classDef.type.substring(1, classDef.length - 1)
|
||||
}
|
||||
},
|
||||
DexClassLoader(
|
||||
patchesFiles.joinToString(File.pathSeparator) { it.absolutePath },
|
||||
optimizedDexDirectory?.absolutePath,
|
||||
null,
|
||||
this::class.java.classLoader,
|
||||
),
|
||||
)
|
||||
|
||||
// Companion object required for unit tests.
|
||||
private companion object {
|
||||
@@ -656,24 +640,19 @@ sealed class PatchLoader(
|
||||
*
|
||||
* @param binaryClassNamesByPatchesFile The binary class name of the classes to load the patches from
|
||||
* associated by the patches file.
|
||||
* @param onLoadPatchesException The callback for patches that could not be loaded.
|
||||
*
|
||||
* @return The loaded patches associated by the patches file.
|
||||
*/
|
||||
private fun ClassLoader.loadPatches(
|
||||
binaryClassNamesByPatchesFile: Map<File, Set<String>>,
|
||||
onLoadPatchesException: (message: String, cause: Throwable) -> Unit
|
||||
) = binaryClassNamesByPatchesFile.mapValues { (_, binaryClassNames) ->
|
||||
binaryClassNames.asSequence().mapNotNull {
|
||||
runCatching { loadClass(it) }.onFailure { exception ->
|
||||
onLoadPatchesException("Failed to load patch class $it", exception)
|
||||
}.getOrNull()
|
||||
}.flatMap {
|
||||
it.patchFields + it.patchMethods
|
||||
}.filter {
|
||||
it.name != null
|
||||
}.toSet()
|
||||
}
|
||||
private fun ClassLoader.loadPatches(binaryClassNamesByPatchesFile: Map<File, Set<String>>) =
|
||||
binaryClassNamesByPatchesFile.mapValues { (_, binaryClassNames) ->
|
||||
binaryClassNames.asSequence().map {
|
||||
loadClass(it)
|
||||
}.flatMap {
|
||||
it.patchFields + it.patchMethods
|
||||
}.filter {
|
||||
it.name != null
|
||||
}.toSet()
|
||||
}
|
||||
|
||||
private fun Member.canAccess(): Boolean {
|
||||
if (this is Method && parameterCount != 0) return false
|
||||
@@ -689,22 +668,11 @@ sealed class PatchLoader(
|
||||
* Patches with no name are not loaded.
|
||||
*
|
||||
* @param patchesFiles The JAR files to load the patches from.
|
||||
* @param onLoadPatchesException The callback for patches that could not be loaded.
|
||||
*
|
||||
* @return The loaded patches.
|
||||
*/
|
||||
fun loadPatchesFromJar(
|
||||
patchesFiles: Set<File>,
|
||||
onLoadPatchesException: ((message: String, cause: Throwable) -> Unit)? = null
|
||||
) = PatchLoader.Jar(patchesFiles, onLoadPatchesException ?: { message, cause -> })
|
||||
|
||||
@Deprecated(
|
||||
"Use the function with the onLoadPatchesException overload",
|
||||
replaceWith = ReplaceWith("loadPatchesFromJar(patchesFiles, null)")
|
||||
)
|
||||
fun loadPatchesFromJar(
|
||||
patchesFiles: Set<File>
|
||||
) = loadPatchesFromJar(patchesFiles, null)
|
||||
fun loadPatchesFromJar(patchesFiles: Set<File>) =
|
||||
PatchLoader.Jar(patchesFiles)
|
||||
|
||||
/**
|
||||
* Loads patches from DEX files declared as public static fields
|
||||
@@ -712,21 +680,8 @@ fun loadPatchesFromJar(
|
||||
* Patches with no name are not loaded.
|
||||
*
|
||||
* @param patchesFiles The DEX files to load the patches from.
|
||||
* @param onLoadPatchesException The callback for patches that could not be loaded.
|
||||
*
|
||||
* @return The loaded patches.
|
||||
*/
|
||||
fun loadPatchesFromDex(
|
||||
patchesFiles: Set<File>,
|
||||
optimizedDexDirectory: File? = null,
|
||||
onLoadPatchesException: ((message: String, cause: Throwable) -> Unit)? = null
|
||||
) = PatchLoader.Dex(patchesFiles, optimizedDexDirectory, onLoadPatchesException ?: { message, cause -> })
|
||||
|
||||
@Deprecated(
|
||||
"Use the function with the onLoadPatchesException overload",
|
||||
replaceWith = ReplaceWith("loadPatchesFromJar(patchesFiles, optimizedDexDirectory, null)")
|
||||
)
|
||||
fun loadPatchesFromDex(
|
||||
patchesFiles: Set<File>,
|
||||
optimizedDexDirectory: File? = null,
|
||||
) = loadPatchesFromDex(patchesFiles, optimizedDexDirectory, null)
|
||||
fun loadPatchesFromDex(patchesFiles: Set<File>, optimizedDexDirectory: File? = null) =
|
||||
PatchLoader.Dex(patchesFiles, optimizedDexDirectory)
|
||||
|
||||
@@ -71,7 +71,6 @@ internal object PatchLoaderTest {
|
||||
patchLoaderCompanionObject,
|
||||
TEST_PATCHES_CLASS_LOADER,
|
||||
mapOf(File("patchesFile") to setOf(TEST_PATCHES_CLASS)),
|
||||
null
|
||||
).values.first()
|
||||
|
||||
assertEquals(
|
||||
|
||||
Reference in New Issue
Block a user