mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-01-07 14:27:49 +00:00
Cleanup DesugarClassVisitorFactory
This commit is contained in:
parent
09c7ac754b
commit
df6b808f49
@ -7,11 +7,14 @@ import org.objectweb.asm.MethodVisitor
|
|||||||
import org.objectweb.asm.Opcodes
|
import org.objectweb.asm.Opcodes
|
||||||
import org.objectweb.asm.Opcodes.ASM9
|
import org.objectweb.asm.Opcodes.ASM9
|
||||||
|
|
||||||
|
private const val ZIP_ENTRY_CLASS_NAME = "java.util.zip.ZipEntry"
|
||||||
private const val DESUGAR_CLASS_NAME = "com.topjohnwu.magisk.core.utils.Desugar"
|
private const val DESUGAR_CLASS_NAME = "com.topjohnwu.magisk.core.utils.Desugar"
|
||||||
private const val ZIP_ENTRY_GET_TIME_DESC = "()Ljava/nio/file/attribute/FileTime;"
|
private const val ZIP_ENTRY_GET_TIME_DESC = "()Ljava/nio/file/attribute/FileTime;"
|
||||||
private const val DESUGAR_GET_TIME_DESC =
|
private const val DESUGAR_GET_TIME_DESC =
|
||||||
"(Ljava/util/zip/ZipEntry;)Ljava/nio/file/attribute/FileTime;"
|
"(Ljava/util/zip/ZipEntry;)Ljava/nio/file/attribute/FileTime;"
|
||||||
|
|
||||||
|
private fun ClassData.isTypeOf(name: String) = className == name || superClasses.contains(name)
|
||||||
|
|
||||||
abstract class DesugarClassVisitorFactory : AsmClassVisitorFactory<InstrumentationParameters.None> {
|
abstract class DesugarClassVisitorFactory : AsmClassVisitorFactory<InstrumentationParameters.None> {
|
||||||
override fun createClassVisitor(
|
override fun createClassVisitor(
|
||||||
classContext: ClassContext,
|
classContext: ClassContext,
|
||||||
@ -45,14 +48,15 @@ abstract class DesugarClassVisitorFactory : AsmClassVisitorFactory<Instrumentati
|
|||||||
descriptor: String,
|
descriptor: String,
|
||||||
isInterface: Boolean
|
isInterface: Boolean
|
||||||
) {
|
) {
|
||||||
if (!classContext.loadClassData(owner.replace("/", "."))?.superClasses.orEmpty()
|
if (!process(owner, name, descriptor)) {
|
||||||
.contains("java.util.zip.ZipEntry") || !process(name, descriptor)
|
|
||||||
) {
|
|
||||||
super.visitMethodInsn(opcode, owner, name, descriptor, isInterface)
|
super.visitMethodInsn(opcode, owner, name, descriptor, isInterface)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun process(name: String, descriptor: String): Boolean {
|
private fun process(owner: String, name: String, descriptor: String): Boolean {
|
||||||
|
val classData = classContext.loadClassData(owner.replace("/", ".")) ?: return false
|
||||||
|
if (!classData.isTypeOf(ZIP_ENTRY_CLASS_NAME))
|
||||||
|
return false
|
||||||
if (descriptor != ZIP_ENTRY_GET_TIME_DESC)
|
if (descriptor != ZIP_ENTRY_GET_TIME_DESC)
|
||||||
return false
|
return false
|
||||||
return when (name) {
|
return when (name) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user