Package org.objectweb.asm

Examples of org.objectweb.asm.ClassAdapter


    // 记录注入类数
    Profiler.instrumentClassCount.getAndIncrement();
    try {
      ClassReader reader = new ClassReader(classfileBuffer);
      ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
      ClassAdapter adapter = new ProfClassAdapter(writer, className);
      reader.accept(adapter, 0);
      // 生成新类字节码
      return writer.toByteArray();
    } catch (Throwable e) {
      e.printStackTrace();
View Full Code Here


      public void visitTypeInsn(int opcode, String type) {
        super.visitTypeInsn(opcode, cleanType(type));
      }
    }
    final ClassVisitor stagerVisitor = new ClassAdapter(cw) {

      public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
        super.visit(version, access, classname, signature, "java/lang/ClassLoader", interfaces);
      }

      public void visitEnd() {
        // not the end!
      }

      public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
        // strip constructors
        if (name.equals("<init>")) {
          return null;
        }
        return new MyMethodVisitor(super.visitMethod(access, name, desc, signature, exceptions), classname);
      }
    };
    visitClass(Class.forName("javapayload.stager." + stager), stagerVisitor, cw);
    final ClassVisitor stagerBaseVisitor = new ClassAdapter(cw) {

      public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
        // not the beginning!
      }

      public void visitEnd() {
        // not the end!
      }

      public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
        // strip abstract bootstrap method
        if (name.equals("bootstrap") && (access & Opcodes.ACC_ABSTRACT) != 0) {
          return null;
        }
        return new MyMethodVisitor(super.visitMethod(access, name, desc, signature, exceptions), classname);
      }
    };
    visitClass(Stager.class, stagerBaseVisitor, cw);
    final ClassVisitor loaderVisitor = new ClassAdapter(cw) {
      public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
        // not the beginning!
      }

      public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
View Full Code Here

                throw new ReaderException("could not retrieve the bytecode from the bytecode provider for class [" + annotationClassName+ "]", e);
            }
            ClassReader cr = new ClassReader(bytes);
            ClassWriter cw = new ClassWriter(false, true);
            cr.accept(
                    new ClassAdapter(cw) {
                        public MethodVisitor visitMethod(int access, final String name, String desc, String signature, String[] exceptions) {
                            return new MethodAdapter(super.visitMethod(access, name, desc, signature, exceptions)) {
                                public AnnotationVisitor visitAnnotationDefault() {
                                    return new DefaultAnnotationBuilderVisitor(newDefaults, name, loader);
                                }
View Full Code Here

        if (m_reader == null) {
            throw new IllegalStateException("attribute extractor is not initialized");
        }
        final List classAttributes = new ArrayList();
        m_reader.accept(
                new ClassAdapter(m_writer) {
                    public void visitAttribute(final Attribute attribute) {
                        if (attribute instanceof CustomAttribute) {
                            CustomAttribute customAttribute = (CustomAttribute)attribute;
                            byte[] bytes = customAttribute.getBytes();
                            try {
View Full Code Here

        if (m_reader == null) {
            throw new IllegalStateException("attribute extractor is not initialized");
        }
        final List methodAttributes = new ArrayList();
        m_reader.accept(
                new ClassAdapter(m_writer) {
                    public CodeVisitor visitMethod(
                            final int access, final String name, final String desc,
                            final String[] exceptions, final Attribute attribute) {
                        if (name.equals(methodName) &&
                            Arrays.equals(methodParamTypes, DescriptorUtil.getParameters(desc))) {
View Full Code Here

        if (m_reader == null) {
            throw new IllegalStateException("attribute extractor is not initialized");
        }
        final List fieldAttributes = new ArrayList();
        m_reader.accept(
                new ClassAdapter(m_writer) {
                    public void visitField(
                            final int access, final String name, final String desc, final Object value,
                            final Attribute attribute) {
                        if (name.equals(fieldName)) {
                            if (attribute instanceof CustomAttribute) {
View Full Code Here

    }
   
    public static String[] getClassInfo(ClassReader r) {
        final List array = new ArrayList();
        try {
            r.accept(new ClassAdapter(null) {
                public void visit(int version,
                                  int access,
                                  String name,
                                  String signature,
                                  String superName,
View Full Code Here

TOP

Related Classes of org.objectweb.asm.ClassAdapter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.