本文整理汇总了Java中org.objectweb.asm.commons.ClassRemapper类的典型用法代码示例。如果您正苦于以下问题:Java ClassRemapper类的具体用法?Java ClassRemapper怎么用?Java ClassRemapper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ClassRemapper类属于org.objectweb.asm.commons包,在下文中一共展示了ClassRemapper类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createFaviconServletExtension
import org.objectweb.asm.commons.ClassRemapper; //导入依赖的package包/类
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();
}
示例2: createFaviconErrorHandler
import org.objectweb.asm.commons.ClassRemapper; //导入依赖的package包/类
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();
}
示例3: create
import org.objectweb.asm.commons.ClassRemapper; //导入依赖的package包/类
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();
}
示例4: applyMappings
import org.objectweb.asm.commons.ClassRemapper; //导入依赖的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);
}
}
示例5: UnprefixingClassWriter
import org.objectweb.asm.commons.ClassRemapper; //导入依赖的package包/类
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);
}
});
}
}
示例6: transform
import org.objectweb.asm.commons.ClassRemapper; //导入依赖的package包/类
@Override
public final boolean transform() throws Throwable {
CustomRemapper remapper = new CustomRemapper();
remap(remapper);
Map<String, ClassNode> updated = new HashMap<>();
Set<String> removed = new HashSet<>();
classNodes().forEach(wr -> {
removed.add(wr.name);
ClassNode newNode = new ClassNode();
ClassRemapper classRemapper = new ClassRemapper(newNode, remapper);
wr.accept(classRemapper);
updated.put(newNode.name, newNode);
getDeobfuscator().setConstantPool(newNode, getDeobfuscator().getConstantPool(wr));
});
removed.forEach(classes::remove);
removed.forEach(classpath::remove);
classes.putAll(updated);
classpath.putAll(updated);
getDeobfuscator().resetHierachy();
return true;
}
示例7: apply
import org.objectweb.asm.commons.ClassRemapper; //导入依赖的package包/类
private byte[] apply(final RClass cls) {
ClassReader reader = new ClassReader(cls.data);
ClassWriter writer = new ClassWriter(0);
int flags = removeFrames ? ClassReader.SKIP_FRAMES : ClassReader.EXPAND_FRAMES;
reader.accept(new ClassRemapper(check ? new CheckClassAdapter(writer) : writer, remapper), flags);
// TODO: compute frames (-Xverify:all -XX:-FailOverToOldVerifier)
return writer.toByteArray();
}
示例8: findClass
import org.objectweb.asm.commons.ClassRemapper; //导入依赖的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 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);
}
示例9: testTransform
import org.objectweb.asm.commons.ClassRemapper; //导入依赖的package包/类
@Test
public void testTransform() throws Exception {
ClassRename rule = new ClassRename("java.lang.String", "com.tonicsystems.String");
ClassRemapper t = new ClassRemapper(null, new PackageRemapper(rule));
ClassReader reader = new ClassReader(getClass().getResourceAsStream("/Generics.class"));
reader.accept(t, 0);
}
示例10: writeTo
import org.objectweb.asm.commons.ClassRemapper; //导入依赖的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()));
}
示例11: wrap
import org.objectweb.asm.commons.ClassRemapper; //导入依赖的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));
}
示例12: transform
import org.objectweb.asm.commons.ClassRemapper; //导入依赖的package包/类
@Override
public ClassVisitor transform(ClassVisitor v) {
return new ClassRemapper(v, remapper);
}