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; }
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; }
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(); }
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(); }
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(); }
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; }
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(); }
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(); }
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; }
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); } }); } }
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; }
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; } }); }
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; }
@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); }
/** * 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; }
/** {@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(); }
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); }
@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); }
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; }
@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; } }
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; } }); }
public MethodOptimizer( ClassOptimizer classOptimizer, int access, String desc, MethodVisitor mv, Remapper remapper) { super(access, desc, mv, remapper); this.classOptimizer = classOptimizer; }
public StaticFixingMethodVisitor(int access, String desc, MethodVisitor mv, Remapper remapper) { super(access, desc, mv, remapper); }
public MethodOptimizer(ClassOptimizer classOptimizer, MethodVisitor mv, Remapper remapper) { super(Opcodes.ASM5, mv, remapper); this.classOptimizer = classOptimizer; }
public ClassOptimizer(final ClassVisitor cv, final Remapper remapper) { super(Opcodes.ASM5, cv, remapper); }
public JiffyRemappingClassAdapter(final ClassVisitor cv, final Remapper remapper) { super(cv, remapper); }
public ImprovedRemappingClassAdapter(ClassVisitor classVisitor, Remapper remapper) { super(classVisitor, remapper); }
protected RemappingMethodAdapter(final int api, final MethodVisitor mv, final Remapper remapper) { super(api, mv); this.remapper = remapper; }
public CustomRemappingClassAdapter(ClassVisitor cv, Remapper remapper) { super(cv, remapper); }