From 849616dc2b6e30ec1fa1d8a8f9c1f881fc11676a Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Fri, 27 May 2022 14:26:06 +0200 Subject: [PATCH] fix: `JarPatchBundle` loading non-class files to class loader --- .github/workflows/release.yml | 1 + .../patch/implementation/JarPatchBundle.kt | 22 ++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 424c8e09..09de4c15 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,5 +1,6 @@ name: Release on: + workflow_dispatch: push: branches: - main diff --git a/src/main/kotlin/app/revanced/patcher/util/patch/implementation/JarPatchBundle.kt b/src/main/kotlin/app/revanced/patcher/util/patch/implementation/JarPatchBundle.kt index 3d76fb2b..7e18c4ad 100644 --- a/src/main/kotlin/app/revanced/patcher/util/patch/implementation/JarPatchBundle.kt +++ b/src/main/kotlin/app/revanced/patcher/util/patch/implementation/JarPatchBundle.kt @@ -10,9 +10,21 @@ import java.util.jar.JarFile * @param patchBundlePath The path to the patch bundle. */ class JarPatchBundle(patchBundlePath: String) : PatchBundle(patchBundlePath) { - fun loadPatches() = loadPatches(URLClassLoader(arrayOf(this.toURI().toURL()), null), StringIterator( - JarFile(this).entries().iterator() - ) { - it.realName.replace('/', '.').replace(".class", "") - }) + fun loadPatches() = loadPatches( + URLClassLoader( + arrayOf(this.toURI().toURL()), + Thread.currentThread().contextClassLoader // TODO: find out why this is required + ), + StringIterator( + JarFile(this) + .entries() + .toList() // TODO: find a cleaner solution than that to filter non class files + .filter { + it.name.endsWith(".class") && !it.name.contains("$") + } + .iterator() + ) { + it.realName.replace('/', '.').replace(".class", "") + } + ) }