当前位置: 首页>>代码示例>>Java>>正文


Java RemappingClassAdapter类代码示例

本文整理汇总了Java中org.objectweb.asm.commons.RemappingClassAdapter的典型用法代码示例。如果您正苦于以下问题:Java RemappingClassAdapter类的具体用法?Java RemappingClassAdapter怎么用?Java RemappingClassAdapter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RemappingClassAdapter类属于org.objectweb.asm.commons包,在下文中一共展示了RemappingClassAdapter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleClazz

import org.objectweb.asm.commons.RemappingClassAdapter; //导入依赖的package包/类
@Override
protected void handleClazz(JarFile jarFile, JarOutputStream jos, JarEntry ze, String pathName) {

    //            logger.log(pathName);
    if (reMapping.containsKey(pathName.substring(0, pathName.length() - 6))) {
        logger.info("[ClazzReplacer] remove class  " + pathName + " form " + jarFile);
        return;
    }

    try {
        InputStream in = jarFile.getInputStream(ze);
        ClassReader cr = new ClassReader(in);
        ClassWriter cw = new ClassWriter(0);
        RemappingClassAdapter remappingClassAdapter = new RemappingClassAdapter(cw, new SimpleRemapper(reMapping));
        cr.accept(remappingClassAdapter, ClassReader.EXPAND_FRAMES);

        InputStream inputStream = new ByteArrayInputStream(cw.toByteArray());
        copyStreamToJar(inputStream, jos, pathName, ze.getTime());

    } catch (Throwable e) {

        System.err.println("[ClazzReplacer] rewrite error > " + pathName);
        justCopy(jarFile, jos, ze, pathName);
    }

}
 
开发者ID:alibaba,项目名称:atlas,代码行数:27,代码来源:ClazzReplacer.java

示例2: create

import org.objectweb.asm.commons.RemappingClassAdapter; //导入依赖的package包/类
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();
}
 
开发者ID:wildfly-swarm-archive,项目名称:ARCHIVE-wildfly-swarm,代码行数:27,代码来源:ApplicationFactory2.java

示例3: create

import org.objectweb.asm.commons.RemappingClassAdapter; //导入依赖的package包/类
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();
}
 
开发者ID:wildfly-swarm-archive,项目名称:ARCHIVE-wildfly-swarm,代码行数:23,代码来源:FaviconExceptionMapperFactory.java

示例4: run

import org.objectweb.asm.commons.RemappingClassAdapter; //导入依赖的package包/类
public void run() {
    if (getHooks() == null)
        return;
    
    RefactorMapper mapper = new RefactorMapper(getHooks());
    Map<String, ClassNode> refactored = new HashMap<>();
    for (ClassNode cn : BytecodeViewer.getLoadedClasses()) {
        String oldName = cn.name;
        ClassReader cr = new ClassReader(getClassNodeBytes(cn));
        ClassWriter cw = new ClassWriter(cr, 0);
        RemappingClassAdapter rca = new RemappingClassAdapter(cw, mapper);
        cr.accept(rca, ClassReader.EXPAND_FRAMES);
        cr = new ClassReader(cw.toByteArray());
        cn  = new ClassNode();
        cr.accept(cn, 0);
        refactored.put(oldName, cn);
    }
    /*for (Map.Entry<String, ClassNode> factor : refactored.entrySet()) {
        BytecodeViewer.relocate(factor.getKey(), factor.getValue());
    }*/
    mapper.printMap();
}
 
开发者ID:Konloch,项目名称:bytecode-viewer,代码行数:23,代码来源:Refactorer.java

示例5: rename

import org.objectweb.asm.commons.RemappingClassAdapter; //导入依赖的package包/类
public byte[] rename(byte[] b, Map mappings)
    throws ClassFormatError
{
    logger.info("Trying to rename class (" + b.length + " bytes)");

    try {
        SimpleRemapper m = new SimpleRemapper(mappings);
        ClassReader cr = new ClassReader(b);
        ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_FRAMES/* | ClassWriter.COMPUTE_MAXS*/);
        ClassVisitor cv = new RemappingClassAdapter(cw, m);
        cr.accept(cv, ClassReader.SKIP_DEBUG);
        return cw.toByteArray();
    } catch (Exception e) {
        logger.error("Failed renaming class: " + e);
    }

    return null;
}
 
开发者ID:ShiftMediaProject,项目名称:libbluray,代码行数:19,代码来源:BDJClassFileTransformer.java

示例6: transform

import org.objectweb.asm.commons.RemappingClassAdapter; //导入依赖的package包/类
@Override
public byte[] transform(String name, String transformedName, byte[] bytes)
{
    if (bytes == null)
    {
        return null;
    }
    ClassReader classReader = new ClassReader(bytes);
    ClassWriter classWriter = new ClassWriter(WRITER_FLAGS);
    RemappingClassAdapter remapAdapter = new FMLRemappingAdapter(classWriter);
    classReader.accept(remapAdapter, READER_FLAGS);
    return classWriter.toByteArray();
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:14,代码来源:DeobfuscationTransformer.java

示例7: transform

import org.objectweb.asm.commons.RemappingClassAdapter; //导入依赖的package包/类
@Override
public byte[] transform(String name, String transformedName, byte[] bytes)
{
    if (bytes == null)
    {
        return null;
    }
    ClassReader classReader = new ClassReader(bytes);
    ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    RemappingClassAdapter remapAdapter = new FMLRemappingAdapter(classWriter);
    classReader.accept(remapAdapter, ClassReader.EXPAND_FRAMES);
    return classWriter.toByteArray();
}
 
开发者ID:SchrodingersSpy,项目名称:TRHS_Club_Mod_2016,代码行数:14,代码来源:DeobfuscationTransformer.java

示例8: loadClassFromFile

import org.objectweb.asm.commons.RemappingClassAdapter; //导入依赖的package包/类
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;
}
 
开发者ID:Xianguang-Zhou,项目名称:java-hot-update,代码行数:32,代码来源:HotUpdateClassLoader.java

示例9: loadReplace

import org.objectweb.asm.commons.RemappingClassAdapter; //导入依赖的package包/类
/** {@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();
}
 
开发者ID:apache,项目名称:ignite,代码行数:31,代码来源:HadoopHelperImpl.java

示例10: testTransform

import org.objectweb.asm.commons.RemappingClassAdapter; //导入依赖的package包/类
@Test
public void testTransform() throws Exception {
    ClassRename rule = new ClassRename("java.lang.String", "com.tonicsystems.String");
    RemappingClassAdapter t = new RemappingClassAdapter(null, new PackageRemapper(rule));
    ClassReader reader = new ClassReader(getClass().getResourceAsStream("/Generics.class"));
    reader.accept(t, 0);
}
 
开发者ID:shevek,项目名称:jarjar,代码行数:8,代码来源:GenericsTest.java

示例11: _getExternalImports

import org.objectweb.asm.commons.RemappingClassAdapter; //导入依赖的package包/类
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);
}
 
开发者ID:lucee,项目名称:Lucee,代码行数:9,代码来源:JarUtil.java

示例12: findClass

import org.objectweb.asm.commons.RemappingClassAdapter; //导入依赖的package包/类
@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);
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:36,代码来源:SerializerTestUtilities.java

示例13: get

import org.objectweb.asm.commons.RemappingClassAdapter; //导入依赖的package包/类
private static final ClassNode get(final String name) throws IOException {
  final InputStream is = ClassVisitor.class.getClassLoader().getResource(name).openStream();
  final ByteArrayOutputStream baos = new ByteArrayOutputStream();
  final byte[] byteChunk = new byte[4096];
  int n;
  while ((n = is.read(byteChunk)) >= 0)
    baos.write(byteChunk, 0, n);
  is.close();
  final ClassReader cr = new ClassReader(baos.toByteArray());
  final ClassNode cn = new ClassNode();
  final RemappingClassAdapter rca = new RemappingClassAdapter(cn, rmp);
  cr.accept(rca, ClassReader.EXPAND_FRAMES);
  return cn;
}
 
开发者ID:yogpstop,项目名称:ForgeBuilder,代码行数:15,代码来源:AsmFixer.java

示例14: loadClass

import org.objectweb.asm.commons.RemappingClassAdapter; //导入依赖的package包/类
/**
 * Loads class from input stream
 *
 * @param in
 *
 * @throws IOException
 */
protected void loadClass(InputStream in) throws IOException {
    ClassReader           cr    = new ClassReader(in);
    ClassNode             cn    = new ClassNode();
    RemappingClassAdapter rca   = new RemappingClassAdapter(cn, classRemapper);
    RedirectClassAdapter  redir = new RedirectClassAdapter(rca);
    cr.accept(redir, ClassReader.EXPAND_FRAMES);
    classNames.add(cn.name.replace('/', '.'));
    classes.put(cn.name, cn);
}
 
开发者ID:Parabot,项目名称:Parabot,代码行数:17,代码来源:ClassPath.java

示例15: getMergedClass

import org.objectweb.asm.commons.RemappingClassAdapter; //导入依赖的package包/类
public static MergedClassResult getMergedClass(final ClassSet set, final byte[] precompiledClass,
      ClassNode generatedClass, final boolean scalarReplace) {
    if (verifyBytecode) {
      if (!AsmUtil.isClassBytesOk(logger, "precompiledClass", precompiledClass)) {
        throw new IllegalStateException("Problem found in precompiledClass");
      }
      if ((generatedClass != null) && !AsmUtil.isClassOk(logger, "generatedClass", generatedClass)) {
        throw new IllegalStateException("Problem found in generatedClass");
      }
    }

    /*
     * Setup adapters for merging, remapping class names and class writing. This is done in
     * reverse order of how they will be evaluated.
     */
    final RemapClasses re = new RemapClasses(set);
    try {
      if (scalarReplace && generatedClass != null) {
        if (logger.isDebugEnabled()) {
          AsmUtil.logClass(logger, "generated " + set.generated.dot, generatedClass);
        }

        final ClassNode generatedMerged = new ClassNode();
        ClassVisitor mergeGenerator = generatedMerged;
        if (verifyBytecode) {
          mergeGenerator = new DrillCheckClassAdapter(CompilationConfig.ASM_API_VERSION,
              new CheckClassVisitorFsm(CompilationConfig.ASM_API_VERSION, generatedMerged), true);
        }

        /*
         * Even though we're effectively transforming-creating a new class in mergeGenerator,
         * there's no way to pass in ClassWriter.COMPUTE_MAXS, which would save us from having
         * to figure out stack size increases on our own. That gets handled by the
         * InstructionModifier (from inside ValueHolderReplacement > ScalarReplacementNode).
         */
        generatedClass.accept(new ValueHolderReplacementVisitor(mergeGenerator, verifyBytecode));
        if (verifyBytecode) {
          if (!AsmUtil.isClassOk(logger, "generatedMerged", generatedMerged)) {
            throw new IllegalStateException("Problem found with generatedMerged");
          }
        }
        generatedClass = generatedMerged;
      }

      final ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
      ClassVisitor writerVisitor = writer;
      if (verifyBytecode) {
        writerVisitor = new DrillCheckClassAdapter(CompilationConfig.ASM_API_VERSION,
            new CheckClassVisitorFsm(CompilationConfig.ASM_API_VERSION, writerVisitor), true);
      }
      ClassVisitor remappingAdapter = new RemappingClassAdapter(writerVisitor, re);
      if (verifyBytecode) {
        remappingAdapter = new DrillCheckClassAdapter(CompilationConfig.ASM_API_VERSION,
            new CheckClassVisitorFsm(CompilationConfig.ASM_API_VERSION, remappingAdapter), true);
      }

      ClassVisitor visitor = remappingAdapter;
      if (generatedClass != null) {
        visitor = new MergeAdapter(set, remappingAdapter, generatedClass);
      }
      ClassReader tReader = new ClassReader(precompiledClass);
      tReader.accept(visitor, ClassReader.SKIP_FRAMES);
      byte[] outputClass = writer.toByteArray();
      if (logger.isDebugEnabled()) {
        AsmUtil.logClassFromBytes(logger, "merged " + set.generated.dot, outputClass);
      }

      // enable when you want all the generated merged class files to also be written to disk.
//      Files.write(outputClass, new File(String.format("/src/scratch/drill-generated-classes/%s-output.class", set.generated.dot)));

      return new MergedClassResult(outputClass, re.getInnerClasses());
    } catch (Error | RuntimeException e) {
      logger.error("Failure while merging classes.", e);
      AsmUtil.logClass(logger, "generatedClass", generatedClass);
      throw e;
    }
  }
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:78,代码来源:MergeAdapter.java


注:本文中的org.objectweb.asm.commons.RemappingClassAdapter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。