ASM中的visitMethod不访问Scala中的方法。
创始人
2024-11-11 12:01:18
0

要让ASM的visitMethod在访问Scala中的方法时起作用,需要使用Scala ASM库。示例代码如下:

import org.objectweb.asm.Opcodes import org.objectweb.asm.ClassWriter import org.objectweb.asm.MethodVisitor import scala.tools.asm.ScalaSigAttributeParsers import scala.tools.asm.ClassReader import org.objectweb.asm.ClassVisitor

/**

  • Example class with a method to visit using ASM in Scala. */ class MyClass {

/**

  • Example method to visit. */ def visitMe(): Unit = { println("Visited method using ASM in Scala") }

/**

  • Using ASM to visit the method. */ def visitMethod(): Unit = { val classWriter = new ClassWriter(0) classWriter.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC, "MyClass", null, "java/lang/Object", null)
val methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC, "visitMe", "()V", null, null)
methodVisitor.visitCode()
methodVisitor.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;")
methodVisitor.visitLdcInsn("Visited method using ASM in Scala")
methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false)
methodVisitor.visitInsn(Opcodes.RETURN)
methodVisitor.visitMaxs(0, 0)
methodVisitor.visitEnd()

val classReader = new ClassReader(classWriter.toByteArray())
val classVisitor = new ClassVisitor(Opcodes.ASM5) {
  override def visitMethod(access: Int, name: String, descriptor: String, signature: String, exceptions: Array[String]): MethodVisitor = {
    if (name == "visitMe") {
      methodVisitor
    } else {
      super.visitMethod(access, name, descriptor, signature, exceptions)
    }
  }
}
classReader.accept(classVisitor, 0)

} }

val myClass = new MyClass() myClass.visitMethod() // call ASM to visit the method

相关内容

热门资讯

透视新版!wepoker透视是... 透视新版!wepoker透视是真的吗(透视)确实真的是有辅助插件(有挂助手)-哔哩哔哩该软件可以轻松...
为了进一步!wepoker可以... 为了进一步!wepoker可以透视码(透视)切实真的有辅助下载(真是有挂)-哔哩哔哩1、实时wepo...
据文件显示!德州透视是真的假的... 据文件显示!德州透视是真的假的(透视)一贯存在有辅助插件(竟然有挂)-哔哩哔哩1、点击下载安装,德州...
透视了解!epoker底牌透视... 透视了解!epoker底牌透视(透视)真是是真的辅助神器(有挂实锤)-哔哩哔哩1、玩家可以在epok...
透视安卓版!wepoker透视... 透视安卓版!wepoker透视脚本免费下载pc(透视)一直有辅助app(证实有挂)-哔哩哔哩wepo...
截至目前!aapoker怎么设... 截至目前!aapoker怎么设置提高好牌几率(透视)都是是真的辅助app(有挂猫腻)-哔哩哔哩1、a...
透视中牌率!德普之星透视(透视... 透视中牌率!德普之星透视(透视)真是是有辅助安装(确实有挂)-哔哩哔哩在进入德普之星透视软件靠谱后,...
透视app!德普之星透视软件免... 透视app!德普之星透视软件免费入口官网(透视)都是是真的辅助工具(有挂讲解)-哔哩哔哩1、德普之星...
透视透视!wepoker辅助软... 透视透视!wepoker辅助软件视频(透视)切实有辅助辅助器(有挂攻略)-哔哩哔哩一、wepoker...
于此同时!pokerworld... 于此同时!pokerworld软件(透视)一直是有辅助辅助器(果真有挂)-哔哩哔哩1、pokerwo...