Java 类org.objectweb.asm.commons.Remapper 实例源码

项目:4Space-5    文件:ObfMapping.java   
public ObfMapping map(Remapper mapper) {
    if (mapper == null)
        return this;

    if (isMethod())
        s_name = mapper.mapMethodName(s_owner, s_name, s_desc);
    else if (isField())
        s_name = mapper.mapFieldName(s_owner, s_name, s_desc);

    s_owner = mapper.mapType(s_owner);

    if (isMethod())
        s_desc = mapper.mapMethodDesc(s_desc);
    else if (s_desc.length() > 0)
        s_desc = mapper.mapDesc(s_desc);

    return this;
}
项目:CodeChickenLib    文件:ObfMapping.java   
public ObfMapping map(Remapper mapper) {

        if (mapper == null) {
            return this;
        }

        if (isMethod()) {
            s_name = mapper.mapMethodName(s_owner, s_name, s_desc);
        } else if (isField()) {
            s_name = mapper.mapFieldName(s_owner, s_name, s_desc);
        }

        s_owner = mapper.mapType(s_owner);

        if (isMethod()) {
            s_desc = mapper.mapMethodDesc(s_desc);
        } else if (s_desc.length() > 0) {
            s_desc = mapper.mapDesc(s_desc);
        }

        return this;
    }
项目:wildfly-swarm    文件:FaviconFactory.java   
static byte[] createFaviconServletExtension(String name) throws IOException {
    ClassReader reader = new ClassReader(FaviconServletExtension.class.getClassLoader().getResourceAsStream(FaviconServletExtension.class.getName().replace('.', '/') + ".class"));

    String slashName = name.replace('.', '/');

    ClassWriter writer = new ClassWriter(0);
    Remapper remapper = new Remapper() {
        @Override
        public String map(String typeName) {
            if (typeName.equals("org/wildfly/swarm/undertow/internal/FaviconServletExtension")) {
                return slashName;
            }
            return super.map(typeName);
        }
    };

    ClassRemapper adapter = new ClassRemapper(writer, remapper);
    reader.accept(adapter, ClassReader.EXPAND_FRAMES);

    writer.visitEnd();

    return writer.toByteArray();
}
项目:wildfly-swarm    文件:FaviconFactory.java   
static byte[] createFaviconErrorHandler(String name) throws IOException {
    ClassReader reader = new ClassReader(FaviconErrorHandler.class.getClassLoader().getResourceAsStream(FaviconErrorHandler.class.getName().replace('.', '/') + ".class"));

    String slashName = name.replace('.', '/');

    ClassWriter writer = new ClassWriter(0);
    Remapper remapper = new Remapper() {
        @Override
        public String map(String typeName) {
            if (typeName.equals("org/wildfly/swarm/undertow/internal/FaviconErrorHandler")) {
                return slashName;
            }
            return super.map(typeName);
        }
    };

    ClassRemapper adapter = new ClassRemapper(writer, remapper);
    reader.accept(adapter, ClassReader.EXPAND_FRAMES);

    writer.visitEnd();

    return writer.toByteArray();
}
项目:wildfly-swarm    文件:DefaultApplicationFactory.java   
public static byte[] create(String name, String path) throws IOException {
    ClassReader reader = new ClassReader(basicClassBytes());

    String slashName = name.replace('.', '/');

    ClassWriter writer = new ClassWriter(0);
    Remapper remapper = new Remapper() {
        @Override
        public String map(String typeName) {
            if (typeName.equals("org/wildfly/swarm/jaxrs/runtime/DefaultApplication")) {
                return slashName;
            }
            return super.map(typeName);
        }
    };

    ClassRemapper adapter = new ClassRemapper(writer, remapper);
    reader.accept(adapter, 0);

    AnnotationVisitor ann = writer.visitAnnotation("Ljavax/ws/rs/ApplicationPath;", true);
    ann.visit("value", path);
    ann.visitEnd();
    writer.visitEnd();

    return writer.toByteArray();
}
项目:NOVA-Core    文件:ObfMapping.java   
public ObfMapping map(Remapper mapper) {
    if (isMethod()) {
        s_name = mapper.mapMethodName(s_owner, s_name, s_desc);
    } else if (isField()) {
        s_name = mapper.mapFieldName(s_owner, s_name, s_desc);
    }

    s_owner = mapper.mapType(s_owner);

    if (isMethod()) {
        s_desc = mapper.mapMethodDesc(s_desc);
    } else if (s_desc.length() > 0) {
        s_desc = mapper.mapDesc(s_desc);
    }

    return this;
}
项目:NOVA-Core    文件:ObfMapping.java   
public ObfMapping map(Remapper mapper) {
    if (isMethod()) {
        s_name = mapper.mapMethodName(s_owner, s_name, s_desc);
    } else if (isField()) {
        s_name = mapper.mapFieldName(s_owner, s_name, s_desc);
    }

    s_owner = mapper.mapType(s_owner);

    if (isMethod()) {
        s_desc = mapper.mapMethodDesc(s_desc);
    } else if (s_desc.length() > 0) {
        s_desc = mapper.mapDesc(s_desc);
    }

    return this;
}
项目:ARCHIVE-wildfly-swarm    文件:ApplicationFactory2.java   
static byte[] create(String name, String path) throws IOException {
    ClassReader reader = new ClassReader(DefaultApplication.class.getClassLoader().getResourceAsStream(DefaultApplication.class.getName().replace('.', '/') + ".class"));

    String slashName = name.replace('.', '/');

    ClassWriter writer = new ClassWriter(0);
    Remapper remapper = new Remapper() {
        @Override
        public String map(String typeName) {
            if (typeName.equals("org/wildfly/swarm/jaxrs/internal/DefaultApplication")) {
                return slashName;
            }
            return super.map(typeName);
        }
    };

    RemappingClassAdapter adapter = new RemappingClassAdapter(writer, remapper);
    reader.accept(adapter, 0);

    AnnotationVisitor ann = writer.visitAnnotation("Ljavax/ws/rs/ApplicationPath;", true);
    ann.visit("value", path);
    ann.visitEnd();
    writer.visitEnd();

    return writer.toByteArray();
}
项目:ARCHIVE-wildfly-swarm    文件:FaviconExceptionMapperFactory.java   
static byte[] create() throws IOException {
    ClassReader reader = new ClassReader(FaviconExceptionMapper.class.getClassLoader().getResourceAsStream(FaviconExceptionMapper.class.getName().replace('.', '/') + ".class"));

    ClassWriter writer = new ClassWriter(0);
    Remapper remapper = new Remapper() {
        @Override
        public String map(String typeName) {
            if (typeName.equals("org/wildfly/swarm/jaxrs/internal/FaviconExceptionMapper")) {
                return "org/wildfly/swarm/generated/FaviconExceptionMapper";
            }
            return super.map(typeName);
        }
    };

    RemappingClassAdapter adapter = new RemappingClassAdapter(writer, remapper);
    reader.accept(adapter, 0);

    writer.visitAnnotation("Ljavax/ws/rs/ext/Provider;", true).visitEnd();
    writer.visitEnd();

    return writer.toByteArray();
}
项目:bazel    文件:TryWithResourcesRewriter.java   
public CloseResourceMethodSpecializer(
    ClassVisitor cv, String targetResourceInternalName, boolean isResourceAnInterface) {
  super(
      cv,
      new Remapper() {
        @Override
        public String map(String typeName) {
          if (typeName.equals("java/lang/AutoCloseable")) {
            return targetResourceInternalName;
          } else {
            return typeName;
          }
        }
      });
  this.targetResourceInternalName = targetResourceInternalName;
  this.isResourceAnInterface = isResourceAnInterface;
}
项目:bazel    文件:CoreLibraryRewriter.java   
UnprefixingClassWriter(int flags) {
  super(Opcodes.ASM6);
  this.writer = new ClassWriter(flags);
  this.cv = this.writer;
  if (!prefix.isEmpty()) {
    this.cv =
        new ClassRemapper(
            this.writer,
            new Remapper() {
              @Override
              public String map(String typeName) {
                return unprefix(typeName);
              }
            });
  }
}
项目:CCObfuscator    文件:ObfMapping.java   
public ObfMapping map(Remapper mapper)
{
    if(isMethod())
        s_name = mapper.mapMethodName(s_owner, s_name, s_desc);
    else if(isField())
        s_name = mapper.mapFieldName(s_owner, s_name, s_desc);

    s_owner = mapper.mapType(s_owner);

    if(isMethod())
        s_desc = mapper.mapMethodDesc(s_desc);
    else if(s_desc.length() > 0)
        s_desc = mapper.mapDesc(s_desc);

    return this;
}
项目:RxJava2-Java6    文件:BackportingTypeRemapper.java   
BackportingTypeRemapper(ClassVisitor cv) {
  super(ASM5, cv, new Remapper() {
    @Override public String map(String type) {
      String remap = TYPES.get(type);
      if (remap != null) {
        System.out.println("  Mapping type " + type + " to " + remap);
        return remap;
      }
      return type;
    }
  });
}
项目:java-hot-update    文件:HotUpdateClassLoader.java   
private Class<?> loadClassFromFile(final String className)
        throws IOException {
    String relativePath = classNameToRelativePath(className);
    File file = classesRootDirPath.resolve(relativePath).toFile();
    byte[] bytes = FileUtils.readFileToByteArray(file);

    final String newClassName = className + System.currentTimeMillis();
    final String newClassInternalName = newClassName.replaceAll("\\.", "/");
    final String classInternalName = className.replaceAll("\\.", "/");

    ClassReader classReader = new ClassReader(bytes);
    ClassWriter classWriter = new ClassWriter(classReader,
            ClassWriter.COMPUTE_MAXS);
    RemappingClassAdapter remappingClassAdapter = new RemappingClassAdapter(
            classWriter, new Remapper() {
                @Override
                public String map(String type) {
                    if (classInternalName.equals(type)) {
                        return newClassInternalName;
                    } else {
                        return type;
                    }
                }
            });
    classReader.accept(remappingClassAdapter, Opcodes.ASM5 | ClassReader.EXPAND_FRAMES);
    byte[] newBytes = classWriter.toByteArray();

    Class<?> klass = defineClass(newClassName, newBytes, 0, newBytes.length);
    classNameToClass.put(className, klass);
    return klass;
}
项目:offheap-store    文件:SerializablePortabilityTestUtilities.java   
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
  for (Entry<String, String> mapping : remappings.entrySet()) {
    if (name.equals(mapping.getValue())) {
      String path = mapping.getKey().replace('.', '/').concat(".class");
      try {
        try (InputStream resource = getResourceAsStream(path)) {
          ClassReader reader = new ClassReader(resource);

          ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
          ClassVisitor visitor = new ClassRemapper(writer, new Remapper() {

            @Override
            public String map(String from) {
              String to = remappings.get(from.replace('/', '.'));
              if (to == null) {
                return from;
              } else {
                return to.replace('.', '/');
              }
            }
          });

          reader.accept(visitor, ClassReader.EXPAND_FRAMES);
          byte[] classBytes = writer.toByteArray();

          return defineClass(name, classBytes, 0, classBytes.length);
        }
      } catch (IOException e) {
        throw new ClassNotFoundException("IOException while loading", e);
      }
    }
  }
  return super.findClass(name);
}
项目:TFC2    文件:ASMHelper.java   
/**
 * Copy a method and rename it; everything else will be exactly the same
 * @return The renamed method copy
 */
public static MethodNode copyAndRenameMethod(ClassNode classNode, MethodNode method, String newMethodName)
{
    MethodVisitor methodCopyVisitor = classNode.visitMethod(method.access, newMethodName, method.desc, method.signature, method.exceptions.toArray(new String[method.exceptions.size()]));
    method.accept(new RemappingMethodAdapter(method.access, method.desc, methodCopyVisitor, new Remapper(){}));
    return methodCopyVisitor instanceof MethodNode ? (MethodNode) methodCopyVisitor : null;
}
项目:ignite    文件:HadoopHelperImpl.java   
/** {@inheritDoc} */
@Override public byte[] loadReplace(InputStream in, final String originalName, final String replaceName) {
    ClassReader rdr;

    try {
        rdr = new ClassReader(in);
    }
    catch (IOException e) {
        throw new RuntimeException(e);
    }

    ClassWriter w = new ClassWriter(Opcodes.ASM4);

    rdr.accept(new RemappingClassAdapter(w, new Remapper() {
        /** */
        String replaceType = replaceName.replace('.', '/');

        /** */
        String nameType = originalName.replace('.', '/');

        @Override public String map(String type) {
            if (type.equals(replaceType))
                return nameType;

            return type;
        }
    }), ClassReader.EXPAND_FRAMES);

    return w.toByteArray();
}
项目:Lucee    文件:JarUtil.java   
private static void _getExternalImports(Set<String> imports, InputStream src,String[] ignores) throws IOException{
    final ClassReader reader = new ClassReader(src);
    final Remapper remapper = new Collector(imports,ignores);
    final ClassVisitor inner = new EmptyVisitor();
    final RemappingClassAdapter visitor =
        new RemappingClassAdapter(inner, remapper);
    reader.accept(visitor, 0);
}
项目:ehcache3    文件:SerializerTestUtilities.java   
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
  for (Entry<String, String> mapping : remappings.entrySet()) {
    if (name.equals(mapping.getValue())) {
      String path = mapping.getKey().replace('.', '/').concat(".class");
      try {
        try (InputStream resource = getResourceAsStream(path)) {
          ClassReader reader = new ClassReader(resource);

          ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
          ClassVisitor visitor = new RemappingClassAdapter(writer, new Remapper() {

            @Override
            public String map(String from) {
              String to = remappings.get(from.replace('/', '.'));
              if (to == null) {
                return from;
              } else {
                return to.replace('.', '/');
              }
            }
          });

          reader.accept(visitor, ClassReader.EXPAND_FRAMES);
          byte[] classBytes = writer.toByteArray();

          return defineClass(name, classBytes, 0, classBytes.length);
        }
      } catch (IOException e) {
        throw new ClassNotFoundException("IOException while loading", e);
      }
    }
  }
  return super.findClass(name);
}
项目:TFC2    文件:ASMHelper.java   
/**
 * Copy a method and rename it; everything else will be exactly the same
 * @return The renamed method copy
 */
public static MethodNode copyAndRenameMethod(ClassNode classNode, MethodNode method, String newMethodName)
{
    MethodVisitor methodCopyVisitor = classNode.visitMethod(method.access, newMethodName, method.desc, method.signature, method.exceptions.toArray(new String[method.exceptions.size()]));
    method.accept(new RemappingMethodAdapter(method.access, method.desc, methodCopyVisitor, new Remapper(){}));
    return methodCopyVisitor instanceof MethodNode ? (MethodNode) methodCopyVisitor : null;
}
项目:ForgeBuilder    文件:JarRemapper.java   
public Map<String, ClassNode> process(final Map<String, ClassNode> in, final int mode,
    final JarMapping jm, final Collection<String> depCls, final Collection<String> mask)
    throws Exception {
  final Remapper r = jm.getRemapper(mode, this);
  this.nodes = in;
  if (depCls != null && mask != null)
    for (final String dep : depCls) {
      boolean skip = true;
      for (final String ms : mask)
        if (dep.startsWith(ms)) {
          skip = false;
          break;
        }
      if (skip)
        continue;
      final ClassNode node = this.cp.get(dep);
      if (node != null)
        this.nodes.put(dep, node);
    }
  final Map<String, ClassNode> ret = new HashMap<String, ClassNode>();
  ClassVisitor mapper;
  ClassNode out;
  for (final Map.Entry<String, ClassNode> e : this.nodes.entrySet()) {
    out = new ClassNode();
    mapper = AsmFixer.InitAdapter(out, r);
    e.getValue().accept(mapper);
    ret.put(r.map(e.getKey()), out);
  }
  return ret;
}
项目:ForgeBuilder    文件:AsmFixer.java   
@SuppressWarnings("unchecked")
private final Constructor<? extends ClassVisitor> write(final ClassNode cn) {
  final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
  cn.accept(cw);
  final byte[] ba = cw.toByteArray();
  try {
    return (Constructor<? extends ClassVisitor>) defineClass(cn.name.replace('/', '.'), ba, 0,
        ba.length, null).getConstructor(ClassVisitor.class, Remapper.class);
  } catch (final NoSuchMethodException e) {
    return null;
  }
}
项目:proxyhotswap    文件:TestClassAdapter.java   
public TestClassAdapter(ClassVisitor cv, final Map<String, String> typeMappings) {
    super(cv, new Remapper() {
        @Override
        public String map(String type) {
            return typeMappings.containsKey(type) ? typeMappings.get(type) : type;
        }
    });
}
项目:HotswapAgent    文件:TestClassAdapter.java   
public TestClassAdapter(ClassVisitor cv, final Map<String, String> typeMappings) {
    super(cv, new Remapper() {
        @Override
        public String map(String type) {
            return typeMappings.containsKey(type) ? typeMappings.get(type) : type;
        }
    });
}
项目:objectweb-asm-4.0    文件:MethodOptimizer.java   
public MethodOptimizer(
    ClassOptimizer classOptimizer,
    int access,
    String desc,
    MethodVisitor mv,
    Remapper remapper)
{
    super(access, desc, mv, remapper);
    this.classOptimizer = classOptimizer;
}
项目:CustomWorldGen    文件:FMLRemappingAdapter.java   
public StaticFixingMethodVisitor(int access, String desc, MethodVisitor mv, Remapper remapper)
{
    super(access, desc, mv, remapper);
}
项目:fastAOP    文件:MethodOptimizer.java   
public MethodOptimizer(ClassOptimizer classOptimizer, MethodVisitor mv,
        Remapper remapper) {
    super(Opcodes.ASM5, mv, remapper);
    this.classOptimizer = classOptimizer;
}
项目:fastAOP    文件:ClassOptimizer.java   
public ClassOptimizer(final ClassVisitor cv, final Remapper remapper) {
    super(Opcodes.ASM5, cv, remapper);
}
项目:light    文件:MethodOptimizer.java   
public MethodOptimizer(ClassOptimizer classOptimizer, MethodVisitor mv,
        Remapper remapper) {
    super(Opcodes.ASM5, mv, remapper);
    this.classOptimizer = classOptimizer;
}
项目:light    文件:ClassOptimizer.java   
public ClassOptimizer(final ClassVisitor cv, final Remapper remapper) {
    super(Opcodes.ASM5, cv, remapper);
}
项目:TRHS_Club_Mod_2016    文件:FMLRemappingAdapter.java   
public StaticFixingMethodVisitor(int access, String desc, MethodVisitor mv, Remapper remapper)
{
    super(access, desc, mv, remapper);
}
项目:CauldronGit    文件:FMLRemappingAdapter.java   
public StaticFixingMethodVisitor(int access, String desc, MethodVisitor mv, Remapper remapper)
{
    super(access, desc, mv, remapper);
}
项目:Jiffy    文件:JiffyRemappingClassAdapter.java   
public JiffyRemappingClassAdapter(final ClassVisitor cv, final Remapper remapper) {
    super(cv, remapper);
}
项目:Patcher    文件:ImprovedRemappingClassAdapter.java   
public ImprovedRemappingClassAdapter(ClassVisitor classVisitor, Remapper remapper) {
    super(classVisitor, remapper);
}
项目:Patcher    文件:ImprovedRemappingClassAdapter.java   
protected RemappingMethodAdapter(final int api, final MethodVisitor mv, final Remapper remapper) {
    super(api, mv);
    this.remapper = remapper;
}
项目:JReFrameworker    文件:MethodOptimizer.java   
public MethodOptimizer(ClassOptimizer classOptimizer, MethodVisitor mv,
        Remapper remapper) {
    super(Opcodes.ASM5, mv, remapper);
    this.classOptimizer = classOptimizer;
}
项目:JReFrameworker    文件:ClassOptimizer.java   
public ClassOptimizer(final ClassVisitor cv, final Remapper remapper) {
    super(Opcodes.ASM5, cv, remapper);
}
项目:JReFrameworker    文件:MethodOptimizer.java   
public MethodOptimizer(ClassOptimizer classOptimizer, MethodVisitor mv,
        Remapper remapper) {
    super(Opcodes.ASM5, mv, remapper);
    this.classOptimizer = classOptimizer;
}
项目:JReFrameworker    文件:ClassOptimizer.java   
public ClassOptimizer(final ClassVisitor cv, final Remapper remapper) {
    super(Opcodes.ASM5, cv, remapper);
}
项目:DynamicMappings    文件:DynamicRemap.java   
public CustomRemappingClassAdapter(ClassVisitor cv, Remapper remapper) {
    super(cv, remapper);
}