-
Notifications
You must be signed in to change notification settings - Fork 56
/
AddFieldDemo.kt
30 lines (23 loc) · 1021 Bytes
/
AddFieldDemo.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package com.andoter.asm_example.part2
import com.andoter.asm_example.utils.ClassOutputUtil
import org.objectweb.asm.ClassReader
import org.objectweb.asm.ClassWriter
import org.objectweb.asm.Opcodes
class AddFieldDemo {
private var name:String = ""
fun getName():String{
return this.name
}
}
fun main() {
val classReader = ClassReader("com.andoter.asm_example.part2.AddFieldDemo")
val classWriter = ClassWriter(classReader, ClassWriter.COMPUTE_MAXS)
val classVisitor = AddFieldAdapter(Opcodes.ASM7, classWriter, "age",Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "Ljava/lang/String")
classReader.accept(classVisitor, ClassReader.SKIP_CODE)
println("===== 处理后的信息 ======")
val printVisitor = ClassPrintVisitor(Opcodes.ASM7)
val printReader = ClassReader(classWriter.toByteArray())
printReader.accept(printVisitor, ClassReader.SKIP_CODE)
//输出文件查看
ClassOutputUtil.byte2File("asm_example/files/AddFiled.class", classWriter.toByteArray())
}