Skip to content

Commit

Permalink
fix: Make it work on Android by not using APIs from JVM unavailable t…
Browse files Browse the repository at this point in the history
…o Android.
  • Loading branch information
oSumAtrIX committed Oct 7, 2024
1 parent 348d007 commit 2be6e97
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/main/kotlin/app/revanced/patcher/patch/Patch.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import lanchon.multidexlib2.BasicDexFileNamer
import lanchon.multidexlib2.MultiDexIO
import java.io.File
import java.io.InputStream
import java.lang.reflect.Member
import java.lang.reflect.Method
import java.lang.reflect.Modifier
import java.net.URLClassLoader
import java.util.jar.JarFile
import kotlin.reflect.KProperty
Expand Down Expand Up @@ -636,7 +639,7 @@ sealed class PatchLoader private constructor(
*/
private val Class<*>.patchFields
get() = fields.filter { field ->
field.type.isPatch && field.canAccess(null)
field.type.isPatch && field.canAccess()
}.map { field ->
field.get(null) as Patch<*>
}
Expand All @@ -646,7 +649,7 @@ sealed class PatchLoader private constructor(
*/
private val Class<*>.patchMethods
get() = methods.filter { method ->
method.returnType.isPatch && method.parameterCount == 0 && method.canAccess(null)
method.returnType.isPatch && method.parameterCount == 0 && method.canAccess()
}.map { method ->
method.invoke(null) as Patch<*>
}
Expand All @@ -670,6 +673,12 @@ sealed class PatchLoader private constructor(
it.name != null
}.toSet()
}

private fun Member.canAccess(): Boolean {
if (this is Method && parameterCount != 0) return false

return Modifier.isStatic(modifiers) && Modifier.isPublic(modifiers)
}
}
}

Expand Down

0 comments on commit 2be6e97

Please sign in to comment.