使用ASM,我用另一种方法替换方法中的代码。该方法称为“checkIfShouldDisconnect”,并使用BytecodeOutline插件,我获得了我想要转换的源代码的ASM代码。但是,我得到一个ClassFormatError。我相信这是因为我的字节码没有正确格式化。我做错了什么?
编辑1:我的代码的目的是在运行时编辑外部JAR文件。我正在处理的插件在启动时将使用attach API启动我的代理(单独的JAR文件)。然后,代理将获取该类,并使用另一种方法替换该类中的方法。在之前的调试中,我已经通过记录器将字节码打印到swing控制台,并且我使用了ASM的类检查器来检查类中的代码。它仍然活跃,但它没有给我任何东西。解析为RBMethodVisitor的ClassVisitor和MethodVisitor不为空
问题是MethodVisitor试图插入代码,没有问题,但没有留下任何错误,除了ClassFormatError,它没有告诉我代码的问题。
我会在这里粘贴我的MethodVisitor: RBMethodVisitor.java
import HTMLReader
override func viewDidLoad() {
super.viewDidLoad()
loadHTML()
}
func loadHTML() {
let url = NSURL(string: "https://en.wikipedia.org/wiki/Main_Page")!
let request = NSURLRequest(URL: url)
let session = NSURLSession(configuration: NSURLSessionConfiguration.defaultSessionConfiguration())
let task = session.dataTaskWithRequest(request) { data, response, error in
guard error == nil else {
print(error!.localizedDescription)
return
}
guard let data = data else {
print("data is nil")
return
}
let html = HTMLDocument(data: data, contentTypeHeader: nil)
if let head = html.firstNodeMatchingSelector("head"),
didYouKnow = html.firstNodeMatchingSelector("#mp-dyk") {
let newHTML = "<html><head>\(head.innerHTML)</head><body>\(didYouKnow.innerHTML)</body></html>"
self.webView.loadHTMLString(newHTML, baseURL: url)
}
}
task.resume()
}
编辑2:这是我的班级访客:
package RainbowBansTransAgent;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
public class RBMethodVisitor extends MethodVisitor implements Opcodes{
ClassVisitor cv;
Logger logger;
public RBMethodVisitor(MethodVisitor mv, ClassVisitor cv) {
super(Opcodes.ASM5, mv);
this.mv = mv;
this.cv = cv;
logger = Logger.getLogger(false);
}
public void visitCode(){
logger.logString("overwriting checkIfShouldDisconnect method with new code");
mv = cv.visitMethod(ACC_PUBLIC, "checkIfShouldDisconnect", "(Ljava/net/SocketAddress;Lcom/mojang/authlib/GameProfile;)Ljava/lang/String;", null, null);
mv.visitCode();
Label l0 = new Label();
Label l1 = new Label();
Label l2 = new Label();
mv.visitTryCatchBlock(l0, l1, l2, "java/io/IOException");
Label l3 = new Label();
Label l4 = new Label();
Label l5 = new Label();
mv.visitTryCatchBlock(l3, l4, l5, "java/io/IOException");
Label l6 = new Label();
Label l7 = new Label();
Label l8 = new Label();
mv.visitTryCatchBlock(l6, l7, l8, "java/io/IOException");
Label l9 = new Label();
mv.visitLabel(l9);
mv.visitLineNumber(23, l9);
mv.visitVarInsn(ALOAD, 1);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "toString", "()Ljava/lang/String;", false);
mv.visitVarInsn(ALOAD, 1);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "toString", "()Ljava/lang/String;", false);
mv.visitIntInsn(BIPUSH, 47);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "indexOf", "(I)I", false);
mv.visitInsn(ICONST_1);
mv.visitInsn(IADD);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "substring", "(I)Ljava/lang/String;", false);
mv.visitVarInsn(ALOAD, 1);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "toString", "()Ljava/lang/String;", false);
mv.visitIntInsn(BIPUSH, 58);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "indexOf", "(I)I", false);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "substring", "(I)Ljava/lang/String;", false);
mv.visitVarInsn(ASTORE, 3);
Label l10 = new Label();
mv.visitLabel(l10);
mv.visitLineNumber(24, l10);
mv.visitTypeInsn(NEW, "java/io/File");
mv.visitInsn(DUP);
mv.visitLdcInsn("banned-players.json");
mv.visitMethodInsn(INVOKESPECIAL, "java/io/File", "<init>", "(Ljava/lang/String;)V", false);
mv.visitVarInsn(ASTORE, 4);
Label l11 = new Label();
mv.visitLabel(l11);
mv.visitLineNumber(25, l11);
mv.visitTypeInsn(NEW, "joebkt/BannedPlayers");
mv.visitInsn(DUP);
mv.visitVarInsn(ALOAD, 4);
mv.visitMethodInsn(INVOKESPECIAL, "joebkt/BannedPlayers", "<init>", "(Ljava/io/File;)V", false);
mv.visitVarInsn(ASTORE, 5);
Label l12 = new Label();
mv.visitLabel(l12);
mv.visitLineNumber(26, l12);
mv.visitTypeInsn(NEW, "java/util/concurrent/ConcurrentHashMap");
mv.visitInsn(DUP);
mv.visitMethodInsn(INVOKESPECIAL, "java/util/concurrent/ConcurrentHashMap", "<init>", "()V", false);
mv.visitVarInsn(ASTORE, 6);
Label l13 = new Label();
mv.visitLabel(l13);
mv.visitLineNumber(28, l13);
mv.visitFieldInsn(GETSTATIC, "joebkt/_JoeUtils", "DoReconnectDelay", "Z");
mv.visitJumpInsn(IFEQ, l0);
Label l14 = new Label();
mv.visitLabel(l14);
mv.visitLineNumber(30, l14);
mv.visitVarInsn(ALOAD, 2);
mv.visitMethodInsn(INVOKEVIRTUAL, "com/mojang/authlib/GameProfile", "getName", "()Ljava/lang/String;", false);
mv.visitVarInsn(ASTORE, 7);
Label l15 = new Label();
mv.visitLabel(l15);
mv.visitLineNumber(31, l15);
mv.visitMethodInsn(INVOKESTATIC, "java/lang/System", "currentTimeMillis", "()J", false);
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Long", "valueOf", "(J)Ljava/lang/Long;", false);
mv.visitVarInsn(ASTORE, 8);
Label l16 = new Label();
mv.visitLabel(l16);
mv.visitLineNumber(32, l16);
mv.visitVarInsn(ALOAD, 6);
mv.visitVarInsn(ALOAD, 7);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/concurrent/ConcurrentHashMap", "get", "(Ljava/lang/Object;)Ljava/lang/Object;", false);
mv.visitTypeInsn(CHECKCAST, "java/lang/Long");
mv.visitVarInsn(ASTORE, 9);
Label l17 = new Label();
mv.visitLabel(l17);
mv.visitLineNumber(33, l17);
mv.visitVarInsn(ALOAD, 9);
Label l18 = new Label();
mv.visitJumpInsn(IFNULL, l18);
mv.visitVarInsn(ALOAD, 8);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Long", "longValue", "()J", false);
mv.visitVarInsn(ALOAD, 9);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Long", "longValue", "()J", false);
mv.visitInsn(LSUB);
mv.visitFieldInsn(GETSTATIC, "joebkt/_JoeUtils", "ReconnectDelaySeconds", "I");
mv.visitIntInsn(SIPUSH, 1000);
mv.visitInsn(IMUL);
mv.visitInsn(I2L);
mv.visitInsn(LCMP);
mv.visitJumpInsn(IFGE, l18);
Label l19 = new Label();
mv.visitLabel(l19);
mv.visitLineNumber(35, l19);
mv.visitFieldInsn(GETSTATIC, "joebkt/_JoeUtils", "DebugMode", "Z");
Label l20 = new Label();
mv.visitJumpInsn(IFEQ, l20);
Label l21 = new Label();
mv.visitLabel(l21);
mv.visitLineNumber(36, l21);
mv.visitLdcInsn("====== Delaying rejoin for ====== %s -- msDelta: %d ================");
mv.visitInsn(ICONST_2);
mv.visitTypeInsn(ANEWARRAY, "java/lang/Object");
mv.visitInsn(DUP);
mv.visitInsn(ICONST_0);
mv.visitVarInsn(ALOAD, 7);
mv.visitInsn(AASTORE);
mv.visitInsn(DUP);
mv.visitInsn(ICONST_1);
mv.visitVarInsn(ALOAD, 8);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Long", "longValue", "()J", false);
mv.visitVarInsn(ALOAD, 9);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Long", "longValue", "()J", false);
mv.visitInsn(LSUB);
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Long", "valueOf", "(J)Ljava/lang/Long;", false);
mv.visitInsn(AASTORE);
mv.visitMethodInsn(INVOKESTATIC, "java/lang/String", "format", "(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;", false);
mv.visitMethodInsn(INVOKESTATIC, "joebkt/_JoeUtils", "ConsoleMsg", "(Ljava/lang/String;)V", false);
mv.visitLabel(l20);
mv.visitLineNumber(38, l20);
mv.visitFrame(Opcodes.F_FULL, 10, new Object[] {"Testers/ClassToVisit", "java/net/SocketAddress", "com/mojang/authlib/GameProfile", "java/lang/String", "java/io/File", "joebkt/BannedPlayers", "java/util/concurrent/ConcurrentHashMap", "java/lang/String", "java/lang/Long", "java/lang/Long"}, 0, new Object[] {});
mv.visitTypeInsn(NEW, "java/lang/StringBuilder");
mv.visitInsn(DUP);
mv.visitLdcInsn("There is a ");
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "(Ljava/lang/String;)V", false);
mv.visitFieldInsn(GETSTATIC, "joebkt/_JoeUtils", "ReconnectDelaySeconds", "I");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(I)Ljava/lang/StringBuilder;", false);
mv.visitLdcInsn("-second reconnect delay.");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false);
mv.visitInsn(ARETURN);
mv.visitLabel(l18);
mv.visitLineNumber(40, l18);
mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
mv.visitVarInsn(ALOAD, 6);
mv.visitVarInsn(ALOAD, 7);
mv.visitVarInsn(ALOAD, 8);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/concurrent/ConcurrentHashMap", "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", false);
mv.visitInsn(POP);
mv.visitLabel(l0);
mv.visitLineNumber(43, l0);
mv.visitFrame(Opcodes.F_CHOP,3, null, 0, null);
mv.visitVarInsn(ALOAD, 5);
mv.visitVarInsn(ALOAD, 2);
mv.visitMethodInsn(INVOKEVIRTUAL, "joebkt/BannedPlayers", "a", "(Lcom/mojang/authlib/GameProfile;)Z", false);
Label l22 = new Label();
mv.visitJumpInsn(IFEQ, l22);
Label l23 = new Label();
mv.visitLabel(l23);
mv.visitLineNumber(45, l23);
mv.visitVarInsn(ALOAD, 5);
mv.visitVarInsn(ALOAD, 2);
mv.visitMethodInsn(INVOKEVIRTUAL, "joebkt/BannedPlayers", "b", "(Ljava/lang/Object;)Ljoebkt/sr;", false);
mv.visitTypeInsn(CHECKCAST, "joebkt/sw_BanByNameUUID");
mv.visitVarInsn(ASTORE, 7);
Label l24 = new Label();
mv.visitLabel(l24);
mv.visitLineNumber(46, l24);
mv.visitTypeInsn(NEW, "java/io/File");
mv.visitInsn(DUP);
mv.visitTypeInsn(NEW, "java/lang/StringBuilder");
mv.visitInsn(DUP);
mv.visitLdcInsn("plugins_mod");
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "(Ljava/lang/String;)V", false);
mv.visitFieldInsn(GETSTATIC, "java/io/File", "separator", "Ljava/lang/String;");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
mv.visitLdcInsn("RainbowBans");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
mv.visitFieldInsn(GETSTATIC, "java/io/File", "separator", "Ljava/lang/String;");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
mv.visitLdcInsn("banmessage.txt");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false);
mv.visitMethodInsn(INVOKESPECIAL, "java/io/File", "<init>", "(Ljava/lang/String;)V", false);
mv.visitVarInsn(ASTORE, 8);
Label l25 = new Label();
mv.visitLabel(l25);
mv.visitLineNumber(47, l25);
mv.visitTypeInsn(NEW, "java/io/BufferedReader");
mv.visitInsn(DUP);
mv.visitTypeInsn(NEW, "java/io/FileReader");
mv.visitInsn(DUP);
mv.visitVarInsn(ALOAD, 8);
mv.visitMethodInsn(INVOKESPECIAL, "java/io/FileReader", "<init>", "(Ljava/io/File;)V", false);
mv.visitMethodInsn(INVOKESPECIAL, "java/io/BufferedReader", "<init>", "(Ljava/io/Reader;)V", false);
mv.visitVarInsn(ASTORE, 9);
Label l26 = new Label();
mv.visitLabel(l26);
mv.visitLineNumber(48, l26);
mv.visitVarInsn(ALOAD, 9);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/BufferedReader", "readLine", "()Ljava/lang/String;", false);
mv.visitVarInsn(ASTORE, 10);
Label l27 = new Label();
mv.visitLabel(l27);
mv.visitLineNumber(49, l27);
mv.visitVarInsn(ALOAD, 10);
mv.visitLdcInsn("%PLAYER%");
mv.visitVarInsn(ALOAD, 2);
mv.visitMethodInsn(INVOKEVIRTUAL, "com/mojang/authlib/GameProfile", "getName", "()Ljava/lang/String;", false);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "replaceAll", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", false);
mv.visitLdcInsn("%REASON%");
mv.visitVarInsn(ALOAD, 7);
mv.visitMethodInsn(INVOKEVIRTUAL, "joebkt/sw_BanByNameUUID", "d", "()Ljava/lang/String;", false);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "replaceAll", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", false);
mv.visitLdcInsn("%CURRENTTIME%");
mv.visitTypeInsn(NEW, "java/util/Date");
mv.visitInsn(DUP);
mv.visitMethodInsn(INVOKESPECIAL, "java/util/Date", "<init>", "()V", false);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/Date", "toString", "()Ljava/lang/String;", false);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "replaceAll", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", false);
mv.visitVarInsn(ASTORE, 11);
Label l28 = new Label();
mv.visitLabel(l28);
mv.visitLineNumber(50, l28);
mv.visitVarInsn(ALOAD, 9);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/BufferedReader", "close", "()V", false);
Label l29 = new Label();
mv.visitLabel(l29);
mv.visitLineNumber(51, l29);
mv.visitVarInsn(ALOAD, 11);
mv.visitLabel(l1);
mv.visitInsn(ARETURN);
mv.visitLabel(l2);
mv.visitLineNumber(53, l2);
mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] {"java/io/IOException"});
mv.visitVarInsn(ASTORE, 7);
Label l30 = new Label();
mv.visitLabel(l30);
mv.visitLineNumber(54, l30);
mv.visitVarInsn(ALOAD, 7);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/IOException", "printStackTrace", "()V", false);
mv.visitLabel(l22);
mv.visitLineNumber(63, l22);
mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
mv.visitMethodInsn(INVOKESTATIC, "net/minecraft/server/MinecraftServer", "getServer", "()Lnet/minecraft/server/MinecraftServer;", false);
mv.visitMethodInsn(INVOKEVIRTUAL, "net/minecraft/server/MinecraftServer", "getThePlayerList", "()Ljoebkt/PlayerList;", false);
mv.visitMethodInsn(INVOKEVIRTUAL, "joebkt/PlayerList", "getWhitelist", "()Z", false);
mv.visitVarInsn(ISTORE, 7);
Label l31 = new Label();
mv.visitLabel(l31);
mv.visitLineNumber(69, l31);
mv.visitVarInsn(ILOAD, 7);
Label l32 = new Label();
mv.visitJumpInsn(IFEQ, l32);
Label l33 = new Label();
mv.visitLabel(l33);
mv.visitLineNumber(70, l33);
mv.visitInsn(ACONST_NULL);
mv.visitVarInsn(ASTORE, 8);
mv.visitLabel(l3);
mv.visitLineNumber(72, l3);
mv.visitTypeInsn(NEW, "java/lang/String");
mv.visitInsn(DUP);
mv.visitFieldInsn(GETSTATIC, "joebkt/PlayerList", "fileWhitelist", "Ljava/io/File;");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/File", "toURI", "()Ljava/net/URI;", false);
mv.visitMethodInsn(INVOKESTATIC, "java/nio/file/Paths", "get", "(Ljava/net/URI;)Ljava/nio/file/Path;", false);
mv.visitMethodInsn(INVOKESTATIC, "java/nio/file/Files", "readAllBytes", "(Ljava/nio/file/Path;)[B", false);
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/String", "<init>", "([B)V", false);
mv.visitVarInsn(ASTORE, 8);
mv.visitLabel(l4);
mv.visitLineNumber(73, l4);
Label l34 = new Label();
mv.visitJumpInsn(GOTO, l34);
mv.visitLabel(l5);
mv.visitFrame(Opcodes.F_FULL, 9, new Object[] {"Testers/ClassToVisit", "java/net/SocketAddress", "com/mojang/authlib/GameProfile", "java/lang/String", "java/io/File", "joebkt/BannedPlayers", "java/util/concurrent/ConcurrentHashMap", Opcodes.INTEGER, "java/lang/String"}, 1, new Object[] {"java/io/IOException"});
mv.visitVarInsn(ASTORE, 9);
Label l35 = new Label();
mv.visitLabel(l35);
mv.visitLineNumber(74, l35);
mv.visitVarInsn(ALOAD, 9);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/IOException", "printStackTrace", "()V", false);
mv.visitLabel(l34);
mv.visitLineNumber(76, l34);
mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
mv.visitVarInsn(ALOAD, 8);
mv.visitLdcInsn("[]");
mv.visitJumpInsn(IF_ACMPEQ, l32);
Label l36 = new Label();
mv.visitLabel(l36);
mv.visitLineNumber(78, l36);
mv.visitVarInsn(ALOAD, 8);
mv.visitVarInsn(ALOAD, 2);
mv.visitMethodInsn(INVOKEVIRTUAL, "com/mojang/authlib/GameProfile", "getName", "()Ljava/lang/String;", false);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "contains", "(Ljava/lang/CharSequence;)Z", false);
mv.visitJumpInsn(IFNE, l32);
mv.visitVarInsn(ALOAD, 8);
mv.visitVarInsn(ALOAD, 3);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "contains", "(Ljava/lang/CharSequence;)Z", false);
mv.visitJumpInsn(IFNE, l32);
Label l37 = new Label();
mv.visitLabel(l37);
mv.visitLineNumber(79, l37);
mv.visitLdcInsn("You are not whitelisted on this server!");
mv.visitInsn(ARETURN);
mv.visitLabel(l32);
mv.visitLineNumber(83, l32);
mv.visitFrame(Opcodes.F_CHOP,1, null, 0, null);
mv.visitTypeInsn(NEW, "joebkt/BannedIPs");
mv.visitInsn(DUP);
mv.visitFieldInsn(GETSTATIC, "joebkt/PlayerList", "fileBannedIPs", "Ljava/io/File;");
mv.visitMethodInsn(INVOKESPECIAL, "joebkt/BannedIPs", "<init>", "(Ljava/io/File;)V", false);
mv.visitVarInsn(ASTORE, 8);
Label l38 = new Label();
mv.visitLabel(l38);
mv.visitLineNumber(84, l38);
mv.visitVarInsn(ALOAD, 8);
mv.visitVarInsn(ALOAD, 1);
mv.visitMethodInsn(INVOKEVIRTUAL, "joebkt/BannedIPs", "a", "(Ljava/net/SocketAddress;)Z", false);
Label l39 = new Label();
mv.visitJumpInsn(IFEQ, l39);
Label l40 = new Label();
mv.visitLabel(l40);
mv.visitLineNumber(85, l40);
mv.visitTypeInsn(NEW, "java/io/File");
mv.visitInsn(DUP);
mv.visitTypeInsn(NEW, "java/lang/StringBuilder");
mv.visitInsn(DUP);
mv.visitLdcInsn("plugins_mod");
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "(Ljava/lang/String;)V", false);
mv.visitFieldInsn(GETSTATIC, "java/io/File", "separator", "Ljava/lang/String;");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
mv.visitLdcInsn("RainbowBans");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
mv.visitFieldInsn(GETSTATIC, "java/io/File", "separator", "Ljava/lang/String;");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
mv.visitLdcInsn("banmessage.txt");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false);
mv.visitMethodInsn(INVOKESPECIAL, "java/io/File", "<init>", "(Ljava/lang/String;)V", false);
mv.visitVarInsn(ASTORE, 9);
mv.visitLabel(l6);
mv.visitLineNumber(87, l6);
mv.visitVarInsn(ALOAD, 8);
mv.visitVarInsn(ALOAD, 1);
mv.visitMethodInsn(INVOKEVIRTUAL, "joebkt/BannedIPs", "b", "(Ljava/net/SocketAddress;)Ljoebkt/se_BanByIP;", false);
mv.visitVarInsn(ASTORE, 10);
Label l41 = new Label();
mv.visitLabel(l41);
mv.visitLineNumber(88, l41);
mv.visitTypeInsn(NEW, "java/io/BufferedReader");
mv.visitInsn(DUP);
mv.visitTypeInsn(NEW, "java/io/FileReader");
mv.visitInsn(DUP);
mv.visitVarInsn(ALOAD, 9);
mv.visitMethodInsn(INVOKESPECIAL, "java/io/FileReader", "<init>", "(Ljava/io/File;)V", false);
mv.visitMethodInsn(INVOKESPECIAL, "java/io/BufferedReader", "<init>", "(Ljava/io/Reader;)V", false);
mv.visitVarInsn(ASTORE, 11);
Label l42 = new Label();
mv.visitLabel(l42);
mv.visitLineNumber(89, l42);
mv.visitVarInsn(ALOAD, 11);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/BufferedReader", "readLine", "()Ljava/lang/String;", false);
mv.visitVarInsn(ASTORE, 12);
Label l43 = new Label();
mv.visitLabel(l43);
mv.visitLineNumber(90, l43);
mv.visitVarInsn(ALOAD, 12);
mv.visitLdcInsn("%PLAYER%");
mv.visitVarInsn(ALOAD, 2);
mv.visitMethodInsn(INVOKEVIRTUAL, "com/mojang/authlib/GameProfile", "getName", "()Ljava/lang/String;", false);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "replaceAll", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", false);
mv.visitLdcInsn("%REASON%");
mv.visitVarInsn(ALOAD, 10);
mv.visitMethodInsn(INVOKEVIRTUAL, "joebkt/se_BanByIP", "d", "()Ljava/lang/String;", false);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "replaceAll", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", false);
mv.visitLdcInsn("%CURRENTTIME%");
mv.visitTypeInsn(NEW, "java/util/Date");
mv.visitInsn(DUP);
mv.visitMethodInsn(INVOKESPECIAL, "java/util/Date", "<init>", "()V", false);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/Date", "toString", "()Ljava/lang/String;", false);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "replaceAll", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", false);
mv.visitVarInsn(ASTORE, 13);
Label l44 = new Label();
mv.visitLabel(l44);
mv.visitLineNumber(91, l44);
mv.visitVarInsn(ALOAD, 11);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/BufferedReader", "close", "()V", false);
Label l45 = new Label();
mv.visitLabel(l45);
mv.visitLineNumber(92, l45);
mv.visitVarInsn(ALOAD, 13);
mv.visitLabel(l7);
mv.visitInsn(ARETURN);
mv.visitLabel(l8);
mv.visitLineNumber(93, l8);
mv.visitFrame(Opcodes.F_FULL, 10, new Object[] {"Testers/ClassToVisit", "java/net/SocketAddress", "com/mojang/authlib/GameProfile", "java/lang/String", "java/io/File", "joebkt/BannedPlayers", "java/util/concurrent/ConcurrentHashMap", Opcodes.INTEGER, "joebkt/BannedIPs", "java/io/File"}, 1, new Object[] {"java/io/IOException"});
mv.visitVarInsn(ASTORE, 10);
Label l46 = new Label();
mv.visitLabel(l46);
mv.visitLineNumber(94, l46);
mv.visitVarInsn(ALOAD, 10);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/IOException", "printStackTrace", "()V", false);
mv.visitLabel(l39);
mv.visitLineNumber(107, l39);
mv.visitFrame(Opcodes.F_CHOP,1, null, 0, null);
mv.visitMethodInsn(INVOKESTATIC, "net/minecraft/server/MinecraftServer", "getServer", "()Lnet/minecraft/server/MinecraftServer;", false);
mv.visitMethodInsn(INVOKEVIRTUAL, "net/minecraft/server/MinecraftServer", "getThePlayerList", "()Ljoebkt/PlayerList;", false);
mv.visitVarInsn(ASTORE, 9);
Label l47 = new Label();
mv.visitLabel(l47);
mv.visitLineNumber(108, l47);
mv.visitVarInsn(ALOAD, 9);
mv.visitMethodInsn(INVOKEVIRTUAL, "joebkt/PlayerList", "getNumPlayers", "()I", false);
mv.visitVarInsn(ALOAD, 9);
mv.visitMethodInsn(INVOKEVIRTUAL, "joebkt/PlayerList", "getMaxPlayers", "()I", false);
Label l48 = new Label();
mv.visitJumpInsn(IF_ICMPLT, l48);
mv.visitLdcInsn("The server is full!");
Label l49 = new Label();
mv.visitJumpInsn(GOTO, l49);
mv.visitLabel(l48);
mv.visitFrame(Opcodes.F_APPEND,1, new Object[] {"joebkt/PlayerList"}, 0, null);
mv.visitInsn(ACONST_NULL);
mv.visitLabel(l49);
mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] {"java/lang/String"});
mv.visitInsn(ARETURN);
Label l50 = new Label();
mv.visitLabel(l50);
mv.visitLocalVariable("this", "LTesters/ClassToVisit;", null, l9, l50, 0);
mv.visitLocalVariable("addr", "Ljava/net/SocketAddress;", null, l9, l50, 1);
mv.visitLocalVariable("profile", "Lcom/mojang/authlib/GameProfile;", null, l9, l50, 2);
mv.visitLocalVariable("ip", "Ljava/lang/String;", null, l10, l50, 3);
mv.visitLocalVariable("fileBannedPlayers", "Ljava/io/File;", null, l11, l50, 4);
mv.visitLocalVariable("bp", "Ljoebkt/BannedPlayers;", null, l12, l50, 5);
mv.visitLocalVariable("lastConnectTime", "Ljava/util/concurrent/ConcurrentHashMap;", "Ljava/util/concurrent/ConcurrentHashMap<Ljava/lang/String;Ljava/lang/Long;>;", l13, l50, 6);
mv.visitLocalVariable("pName", "Ljava/lang/String;", null, l15, l0, 7);
mv.visitLocalVariable("msNow", "Ljava/lang/Long;", null, l16, l0, 8);
mv.visitLocalVariable("msLast", "Ljava/lang/Long;", null, l17, l0, 9);
mv.visitLocalVariable("var5", "Ljoebkt/sw_BanByNameUUID;", null, l24, l2, 7);
mv.visitLocalVariable("file", "Ljava/io/File;", null, l25, l2, 8);
mv.visitLocalVariable("reader", "Ljava/io/BufferedReader;", null, l26, l2, 9);
mv.visitLocalVariable("reason", "Ljava/lang/String;", null, l27, l2, 10);
mv.visitLocalVariable("rep", "Ljava/lang/String;", null, l28, l2, 11);
mv.visitLocalVariable("e", "Ljava/io/IOException;", null, l30, l22, 7);
mv.visitLocalVariable("whitelist", "Z", null, l31, l50, 7);
mv.visitLocalVariable("whitelisters", "Ljava/lang/String;", null, l3, l32, 8);
mv.visitLocalVariable("e", "Ljava/io/IOException;", null, l35, l34, 9);
mv.visitLocalVariable("bi", "Ljoebkt/BannedIPs;", null, l38, l50, 8);
mv.visitLocalVariable("file", "Ljava/io/File;", null, l6, l39, 9);
mv.visitLocalVariable("var3", "Ljoebkt/se_BanByIP;", null, l41, l8, 10);
mv.visitLocalVariable("reader", "Ljava/io/BufferedReader;", null, l42, l8, 11);
mv.visitLocalVariable("line", "Ljava/lang/String;", null, l43, l8, 12);
mv.visitLocalVariable("rep", "Ljava/lang/String;", null, l44, l8, 13);
mv.visitLocalVariable("e", "Ljava/io/IOException;", null, l46, l39, 10);
mv.visitLocalVariable("ls", "Ljoebkt/PlayerList;", null, l47, l50, 9);
mv.visitMaxs(8, 14);
mv.visitEnd();
}
}
答案 0 :(得分:1)
我通过注释visitMaxs()调用来解决这个问题。我还将RBMethodVisitor的visitCode()方法中的所有代码移动到RBClassVisitor的visitMethod()方法中。