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


Java SimpleRemapper类代码示例

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


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

示例1: addMixin

import org.objectweb.asm.commons.SimpleRemapper; //导入依赖的package包/类
@RequiresNonNull("type")
private void addMixin(ClassNode mixinClassNode) {
    List<FieldNode> fieldNodes = mixinClassNode.fields;
    for (FieldNode fieldNode : fieldNodes) {
        fieldNode.accept(this);
    }
    List<MethodNode> methodNodes = mixinClassNode.methods;
    for (MethodNode mn : methodNodes) {
        if (mn.name.equals("<init>")) {
            continue;
        }
        String[] exceptions = Iterables.toArray(mn.exceptions, String.class);
        MethodVisitor mv =
                cw.visitMethod(mn.access, mn.name, mn.desc, mn.signature, exceptions);
        mn.accept(new MethodRemapper(mv,
                new SimpleRemapper(mixinClassNode.name, type.getInternalName())));
    }
}
 
开发者ID:glowroot,项目名称:glowroot,代码行数:19,代码来源:WeavingClassVisitor.java

示例2: handleClazz

import org.objectweb.asm.commons.SimpleRemapper; //导入依赖的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

示例3: applyMappings

import org.objectweb.asm.commons.SimpleRemapper; //导入依赖的package包/类
public static void applyMappings(Map<String, ClassNode> classMap, Map<String, String> remap) {
	log.debug("Applying mappings [");
	for (Map.Entry<String, String> entry : remap.entrySet()) {
		String k = entry.getKey();
		String v = entry.getValue();
		if (k.equals(v))
			continue;
		// skip members with same name
		// field format =   [ "<owner>.<name>"          : "<newname>" ]
		// method format =  [ "<owner>.<name> <desc>"   : "<newname>" ]
		int n = k.indexOf('.');
		if (n != -1 && v.length() >= n && v.substring(n).equals(k)) {
			continue;
		}
		log.debug(" Map {} to {}", entry.getKey(), entry.getValue());
	}
	log.debug("]");
	SimpleRemapper remapper = new SimpleRemapper(remap);
	for (ClassNode node : new ArrayList<>(classMap.values())) {
		ClassNode copy = new ClassNode();
		ClassRemapper adapter = new ClassRemapper(copy, remapper);
		node.accept(adapter);
		classMap.put(node.name, copy);
	}
}
 
开发者ID:CalebWhiting,项目名称:java-asm-obfuscator,代码行数:26,代码来源:BytecodeHelper.java

示例4: rename

import org.objectweb.asm.commons.SimpleRemapper; //导入依赖的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

示例5: visitEnd

import org.objectweb.asm.commons.SimpleRemapper; //导入依赖的package包/类
@Override
public void visitEnd() {
  // add all the fields of the class we're going to merge.
  for (Iterator<?> it = classToMerge.fields.iterator(); it.hasNext();) {
    ((FieldNode) it.next()).accept(this);
  }

  // add all the methods that we to include.
  for (Iterator<?> it = classToMerge.methods.iterator(); it.hasNext();) {
    MethodNode mn = (MethodNode) it.next();

    if (mn.name.equals("<init>")) {
      continue;
    }

    String[] exceptions = new String[mn.exceptions.size()];
    mn.exceptions.toArray(exceptions);
    MethodVisitor mv = cv.visitMethod(mn.access | Modifier.FINAL, mn.name, mn.desc, mn.signature, exceptions);
    if (verifyBytecode) {
      mv = new CheckMethodVisitorFsm(api, mv);
    }

    mn.instructions.resetLabels();

    // mn.accept(new RemappingMethodAdapter(mn.access, mn.desc, mv, new
    // SimpleRemapper("org.apache.drill.exec.compile.ExampleTemplate", "Bunky")));
    ClassSet top = set;
    while (top.parent != null) {
      top = top.parent;
    }
    mn.accept(new RemappingMethodAdapter(mn.access, mn.desc, mv,
        new SimpleRemapper(top.precompiled.slash, top.generated.slash)));

  }
  super.visitEnd();
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:37,代码来源:MergeAdapter.java

示例6: addMethod

import org.objectweb.asm.commons.SimpleRemapper; //导入依赖的package包/类
/**
 * Adds the method to the base class
 * @param methodNode
 */
private void addMethod(MethodNode methodNode){
	String[] exceptions = new String[methodNode.exceptions.size()];
	methodNode.exceptions.toArray(exceptions);
	MethodVisitor mv = cv.visitMethod(methodNode.access, methodNode.name, methodNode.desc, methodNode.signature, exceptions);

	methodNode.instructions.resetLabels();
	// SimpleRemapper -> maps old name to new name
	// updates owners and descriptions appropriately
	methodNode.accept(new RemappingMethodAdapter(methodNode.access, methodNode.desc, mv, new SimpleRemapper(classToMerge.name, baseClassName)));
}
 
开发者ID:JReFrameworker,项目名称:JReFrameworker,代码行数:15,代码来源:MergeAdapter.java

示例7: writeTo

import org.objectweb.asm.commons.SimpleRemapper; //导入依赖的package包/类
/**
 * Creates a class visitor which weaves all changes and additions on the fly.
 *
 * @param classVisitor    The class visitor to which this entry is to be written to.
 * @param typeInitializer The type initializer to apply.
 * @param contextRegistry A context registry to register the lazily created implementation context to.
 * @param writerFlags     The writer flags being used.
 * @param readerFlags     The reader flags being used.
 * @return A class visitor which is capable of applying the changes.
 */
private ClassVisitor writeTo(ClassVisitor classVisitor,
                             TypeInitializer typeInitializer,
                             ContextRegistry contextRegistry,
                             int writerFlags,
                             int readerFlags) {
    classVisitor = new RedefinitionClassVisitor(classVisitor, typeInitializer, contextRegistry, writerFlags, readerFlags);
    return originalType.getName().equals(instrumentedType.getName())
            ? classVisitor
            : new ClassRemapper(classVisitor, new SimpleRemapper(originalType.getInternalName(), instrumentedType.getInternalName()));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:21,代码来源:TypeWriter.java

示例8: wrap

import org.objectweb.asm.commons.SimpleRemapper; //导入依赖的package包/类
@Override
public ClassVisitor wrap(TypeDescription instrumentedType,
                         ClassVisitor classVisitor,
                         Implementation.Context implementationContext,
                         TypePool typePool,
                         FieldList<FieldDescription.InDefinedShape> fields,
                         MethodList<?> methods,
                         int writerFlags,
                         int readerFlags) {
    return new ClassRemapper(classVisitor, new SimpleRemapper(oldName, newName));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:12,代码来源:ByteArrayClassLoaderChildFirstTest.java

示例9: visitEnd

import org.objectweb.asm.commons.SimpleRemapper; //导入依赖的package包/类
@Override
public void visitEnd() {
  // add all the fields of the class we're going to merge.
  for (Iterator<?> it = classToMerge.fields.iterator(); it.hasNext();) {

    // Special handling for nested classes. Drill uses non-static nested
    // "inner" classes in some templates. Prior versions of Drill would
    // create the generated nested classes as static, then this line
    // would copy the "this$0" field to convert the static nested class
    // into a non-static inner class. However, that approach is not
    // compatible with plain-old Java compilation. Now, Drill generates
    // the nested classes as non-static inner classes. As a result, we
    // do not want to copy the hidden fields; we'll end up with two if
    // we do.

    FieldNode field = (FieldNode) it.next();
    if (! field.name.startsWith("this$")) {
      field.accept(this);
    }
  }

  // add all the methods that we to include.
  for (Iterator<?> it = classToMerge.methods.iterator(); it.hasNext();) {
    MethodNode mn = (MethodNode) it.next();

    if (mn.name.equals("<init>")) {
      continue;
    }

    String[] exceptions = new String[mn.exceptions.size()];
    mn.exceptions.toArray(exceptions);
    MethodVisitor mv = cv.visitMethod(mn.access | Modifier.FINAL, mn.name, mn.desc, mn.signature, exceptions);
    if (verifyBytecode) {
      mv = new CheckMethodVisitorFsm(api, mv);
    }

    mn.instructions.resetLabels();

    // mn.accept(new RemappingMethodAdapter(mn.access, mn.desc, mv, new
    // SimpleRemapper("org.apache.drill.exec.compile.ExampleTemplate", "Bunky")));
    ClassSet top = set;
    while (top.parent != null) {
      top = top.parent;
    }
    mn.accept(new RemappingMethodAdapter(mn.access, mn.desc, mv,
        new SimpleRemapper(top.precompiled.slash, top.generated.slash)));

  }
  super.visitEnd();
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:51,代码来源:MergeAdapter.java

示例10: ClassMangler

import org.objectweb.asm.commons.SimpleRemapper; //导入依赖的package包/类
public ClassMangler(ClassVisitor visitor, String origName, String mangledName, String target)
{
	super(Opcodes.ASM4, new RemappingClassAdapter(visitor, new SimpleRemapper(origName, mangledName)));
	this.mangledName = mangledName;
	this.target = target;
}
 
开发者ID:bartbes,项目名称:mc-watercolor,代码行数:7,代码来源:Visitors.java


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