mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-04 23:45:23 +00:00
Only desugar ZipEntry's methods
This commit is contained in:
parent
a34c04f999
commit
06616659b8
@ -9,19 +9,21 @@ import org.objectweb.asm.Opcodes.ASM9
|
|||||||
|
|
||||||
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 = "(Ljava/util/zip/ZipEntry;)Ljava/nio/file/attribute/FileTime;"
|
private const val DESUGAR_GET_TIME_DESC =
|
||||||
|
"(Ljava/util/zip/ZipEntry;)Ljava/nio/file/attribute/FileTime;"
|
||||||
|
|
||||||
abstract class DesugarClassVisitorFactory : AsmClassVisitorFactory<InstrumentationParameters.None> {
|
abstract class DesugarClassVisitorFactory : AsmClassVisitorFactory<InstrumentationParameters.None> {
|
||||||
override fun createClassVisitor(
|
override fun createClassVisitor(
|
||||||
classContext: ClassContext,
|
classContext: ClassContext,
|
||||||
nextClassVisitor: ClassVisitor
|
nextClassVisitor: ClassVisitor
|
||||||
): ClassVisitor {
|
): ClassVisitor {
|
||||||
return DesugarClassVisitor(nextClassVisitor)
|
return DesugarClassVisitor(classContext, nextClassVisitor)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isInstrumentable(classData: ClassData) = classData.className != DESUGAR_CLASS_NAME
|
override fun isInstrumentable(classData: ClassData) = classData.className != DESUGAR_CLASS_NAME
|
||||||
|
|
||||||
class DesugarClassVisitor(cv: ClassVisitor) : ClassVisitor(ASM9, cv) {
|
class DesugarClassVisitor(private val classContext: ClassContext, cv: ClassVisitor) :
|
||||||
|
ClassVisitor(ASM9, cv) {
|
||||||
override fun visitMethod(
|
override fun visitMethod(
|
||||||
access: Int,
|
access: Int,
|
||||||
name: String?,
|
name: String?,
|
||||||
@ -29,11 +31,13 @@ abstract class DesugarClassVisitorFactory : AsmClassVisitorFactory<Instrumentati
|
|||||||
signature: String?,
|
signature: String?,
|
||||||
exceptions: Array<out String>?
|
exceptions: Array<out String>?
|
||||||
): MethodVisitor {
|
): MethodVisitor {
|
||||||
return DesugarMethodVisitor(super.visitMethod(access, name, descriptor, signature, exceptions))
|
return DesugarMethodVisitor(
|
||||||
}
|
super.visitMethod(access, name, descriptor, signature, exceptions)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
class DesugarMethodVisitor(mv: MethodVisitor?) : MethodVisitor(ASM9, mv) {
|
inner class DesugarMethodVisitor(mv: MethodVisitor?) :
|
||||||
|
MethodVisitor(ASM9, mv) {
|
||||||
override fun visitMethodInsn(
|
override fun visitMethodInsn(
|
||||||
opcode: Int,
|
opcode: Int,
|
||||||
owner: String,
|
owner: String,
|
||||||
@ -41,7 +45,9 @@ abstract class DesugarClassVisitorFactory : AsmClassVisitorFactory<Instrumentati
|
|||||||
descriptor: String,
|
descriptor: String,
|
||||||
isInterface: Boolean
|
isInterface: Boolean
|
||||||
) {
|
) {
|
||||||
if (!process(name, descriptor)) {
|
if (!classContext.loadClassData(owner.replace("/", "."))?.superClasses.orEmpty()
|
||||||
|
.contains("java.util.zip.ZipEntry") || !process(name, descriptor)
|
||||||
|
) {
|
||||||
super.visitMethodInsn(opcode, owner, name, descriptor, isInterface)
|
super.visitMethodInsn(opcode, owner, name, descriptor, isInterface)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -49,7 +55,7 @@ abstract class DesugarClassVisitorFactory : AsmClassVisitorFactory<Instrumentati
|
|||||||
private fun process(name: String, descriptor: String): Boolean {
|
private fun process(name: String, descriptor: String): Boolean {
|
||||||
if (descriptor != ZIP_ENTRY_GET_TIME_DESC)
|
if (descriptor != ZIP_ENTRY_GET_TIME_DESC)
|
||||||
return false
|
return false
|
||||||
when (name) {
|
return when (name) {
|
||||||
"getLastModifiedTime", "getLastAccessTime", "getCreationTime" -> {
|
"getLastModifiedTime", "getLastAccessTime", "getCreationTime" -> {
|
||||||
mv.visitMethodInsn(
|
mv.visitMethodInsn(
|
||||||
Opcodes.INVOKESTATIC,
|
Opcodes.INVOKESTATIC,
|
||||||
@ -58,10 +64,11 @@ abstract class DesugarClassVisitorFactory : AsmClassVisitorFactory<Instrumentati
|
|||||||
DESUGAR_GET_TIME_DESC,
|
DESUGAR_GET_TIME_DESC,
|
||||||
false
|
false
|
||||||
)
|
)
|
||||||
|
true
|
||||||
|
}
|
||||||
|
else -> false
|
||||||
}
|
}
|
||||||
else -> return false
|
|
||||||
}
|
}
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user